summaryrefslogtreecommitdiffstats
path: root/camera/fake-pipeline2/Sensor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'camera/fake-pipeline2/Sensor.cpp')
-rw-r--r--camera/fake-pipeline2/Sensor.cpp90
1 files changed, 77 insertions, 13 deletions
diff --git a/camera/fake-pipeline2/Sensor.cpp b/camera/fake-pipeline2/Sensor.cpp
index ac3961f..61c7f28 100644
--- a/camera/fake-pipeline2/Sensor.cpp
+++ b/camera/fake-pipeline2/Sensor.cpp
@@ -339,19 +339,23 @@ bool Sensor::threadLoop() {
captureRGBA(b.img, gain, b.stride);
break;
case HAL_PIXEL_FORMAT_BLOB:
- // Add auxillary buffer of the right size
- // Assumes only one BLOB (JPEG) buffer in
- // mNextCapturedBuffers
- StreamBuffer bAux;
- bAux.streamId = 0;
- bAux.width = b.width;
- bAux.height = b.height;
- bAux.format = HAL_PIXEL_FORMAT_RGB_888;
- bAux.stride = b.width;
- bAux.buffer = NULL;
- // TODO: Reuse these
- bAux.img = new uint8_t[b.width * b.height * 3];
- mNextCapturedBuffers->push_back(bAux);
+ if (b.dataSpace != HAL_DATASPACE_DEPTH) {
+ // Add auxillary buffer of the right size
+ // Assumes only one BLOB (JPEG) buffer in
+ // mNextCapturedBuffers
+ StreamBuffer bAux;
+ bAux.streamId = 0;
+ bAux.width = b.width;
+ bAux.height = b.height;
+ bAux.format = HAL_PIXEL_FORMAT_RGB_888;
+ bAux.stride = b.width;
+ bAux.buffer = NULL;
+ // TODO: Reuse these
+ bAux.img = new uint8_t[b.width * b.height * 3];
+ mNextCapturedBuffers->push_back(bAux);
+ } else {
+ captureDepthCloud(b.img);
+ }
break;
case HAL_PIXEL_FORMAT_YCrCb_420_SP:
captureNV21(b.img, gain, b.stride);
@@ -360,6 +364,9 @@ bool Sensor::threadLoop() {
// TODO:
ALOGE("%s: Format %x is TODO", __FUNCTION__, b.format);
break;
+ case HAL_PIXEL_FORMAT_Y16:
+ captureDepth(b.img, gain, b.stride);
+ break;
default:
ALOGE("%s: Unknown format %x, no output", __FUNCTION__,
b.format);
@@ -543,4 +550,61 @@ void Sensor::captureNV21(uint8_t *img, uint32_t gain, uint32_t stride) {
ALOGVV("NV21 sensor image captured");
}
+void Sensor::captureDepth(uint8_t *img, uint32_t gain, uint32_t stride) {
+ float totalGain = gain/100.0 * kBaseGainFactor;
+ // In fixed-point math, calculate scaling factor to 13bpp millimeters
+ int scale64x = 64 * totalGain * 8191 / kMaxRawValue;
+ uint32_t inc = kResolution[0] / stride;
+
+ for (unsigned int y = 0, outY = 0; y < kResolution[1]; y += inc, outY++ ) {
+ mScene.setReadoutPixel(0, y);
+ uint16_t *px = ((uint16_t*)img) + outY * stride;
+ for (unsigned int x = 0; x < kResolution[0]; x += inc) {
+ uint32_t depthCount;
+ // TODO: Make up real depth scene instead of using green channel
+ // as depth
+ const uint32_t *pixel = mScene.getPixelElectrons();
+ depthCount = pixel[Scene::Gr] * scale64x;
+
+ *px++ = depthCount < 8191*64 ? depthCount / 64 : 0;
+ for (unsigned int j = 1; j < inc; j++)
+ mScene.getPixelElectrons();
+ }
+ // TODO: Handle this better
+ //simulatedTime += kRowReadoutTime;
+ }
+ ALOGVV("Depth sensor image captured");
+}
+
+void Sensor::captureDepthCloud(uint8_t *img) {
+
+ android_depth_points *cloud = reinterpret_cast<android_depth_points*>(img);
+
+ cloud->num_points = 16;
+
+ // TODO: Create point cloud values that match RGB scene
+ const int FLOATS_PER_POINT = 4;
+ const float JITTER_STDDEV = 0.1f;
+ for (size_t y = 0, i = 0; y < 4; y++) {
+ for (size_t x = 0; x < 4; x++, i++) {
+ float randSampleX = std::rand() * (2.5f / (1.0f + RAND_MAX)) - 1.25f;
+ randSampleX *= JITTER_STDDEV;
+
+ float randSampleY = std::rand() * (2.5f / (1.0f + RAND_MAX)) - 1.25f;
+ randSampleY *= JITTER_STDDEV;
+
+ float randSampleZ = std::rand() * (2.5f / (1.0f + RAND_MAX)) - 1.25f;
+ randSampleZ *= JITTER_STDDEV;
+
+ cloud->xyzc_points[i * FLOATS_PER_POINT + 0] = x - 1.5f + randSampleX;
+ cloud->xyzc_points[i * FLOATS_PER_POINT + 1] = y - 1.5f + randSampleY;
+ cloud->xyzc_points[i * FLOATS_PER_POINT + 2] = 3.f + randSampleZ;
+ cloud->xyzc_points[i * FLOATS_PER_POINT + 3] = 0.8f;
+ }
+ }
+
+ ALOGVV("Depth point cloud captured");
+
+}
+
} // namespace android