diff options
author | Timothy Knight <tknight@google.com> | 2014-08-06 00:06:03 -0700 |
---|---|---|
committer | Timothy Knight <tknight@google.com> | 2014-08-06 00:08:51 -0700 |
commit | ea35e1bf67bf965a67b4f3a291c9b509bfb8836b (patch) | |
tree | d81f2705243da01fe26a89b413b443a5686bfad1 | |
parent | 0eb3dbf3bdb61e98fb6c5a30ebc6f3d0af1ca6bd (diff) | |
download | pdk-ea35e1bf67bf965a67b4f3a291c9b509bfb8836b.tar.gz |
CameraITS: Bug fixes in RAW10 handling
Change-Id: I85edcce4ba184acc20256f8995136f27f9efa42f
4 files changed, 13 insertions, 34 deletions
diff --git a/apps/CameraITS/pymodules/its/device.py b/apps/CameraITS/pymodules/its/device.py index 2c9f3fe..5a51cc6 100644 --- a/apps/CameraITS/pymodules/its/device.py +++ b/apps/CameraITS/pymodules/its/device.py @@ -418,7 +418,6 @@ class ItsSession(object): mds = [] widths = None heights = None - byte_strides = [] while nbufs < ncap*nsurf or len(mds) < ncap: jsonObj,buf = self.__read_response_from_socket() if jsonObj['tag'] in ['jpegImage', 'yuvImage', 'rawImage', \ @@ -426,11 +425,6 @@ class ItsSession(object): fmt = jsonObj['tag'][:-5] bufs[fmt].append(buf) nbufs += 1 - if jsonObj['tag'] == 'raw10Image': - if not (jsonObj.has_key('objValue') and \ - jsonObj['objValue'].has_key('byteStride')): - raise its.error.Error('Invalid raw-10 buffer') - byte_strides.append(jsonObj['objValue']['byteStride']) elif jsonObj['tag'] == 'captureResults': mds.append(jsonObj['objValue']['captureResult']) outputs = jsonObj['objValue']['outputs'] @@ -447,8 +441,6 @@ class ItsSession(object): obj["data"] = bufs[fmt][i] obj["width"] = widths[j] obj["height"] = heights[j] - if len(byte_strides) > 0: - obj["byteStride"] = byte_strides[j] obj["format"] = fmt obj["metadata"] = mds[i] objs.append(obj) diff --git a/apps/CameraITS/pymodules/its/image.py b/apps/CameraITS/pymodules/its/image.py index 9c82141..adba4c5 100644 --- a/apps/CameraITS/pymodules/its/image.py +++ b/apps/CameraITS/pymodules/its/image.py @@ -91,15 +91,10 @@ def unpack_raw10_capture(cap, props): # Data is packed as 4x10b pixels in 5 bytes, with the first 4 bytes holding # the MSPs of the pixels, and the 5th byte holding 4x2b LSBs. w,h = cap["width"], cap["height"] - bs = cap["byteStride"] - if w % 4 != 0 or w*5/4 > bs: + if w % 4 != 0: raise its.error.Error('Invalid raw-10 buffer width') - # Remove the row padding. - img10 = cap["data"][0:h*bs].reshape(h,bs)[::, 0:w*5/4] - img16 = unpack_raw10_image(img10, w, h, bs) - # Package up into a new capture object. cap = copy.deep_copy(cap) - cap["data"] = img16 + cap["data"] = unpack_raw10_image(cap["data"].reshape(h,w*5/4)) cap["format"] = "raw" return cap diff --git a/apps/CameraITS/service/src/com/android/camera2/its/ItsService.java b/apps/CameraITS/service/src/com/android/camera2/its/ItsService.java index 0cefcba..67ffa4a 100644 --- a/apps/CameraITS/service/src/com/android/camera2/its/ItsService.java +++ b/apps/CameraITS/service/src/com/android/camera2/its/ItsService.java @@ -526,18 +526,9 @@ public class ItsService extends Service implements SensorEventListener { sendResponse(tag, null, obj, null); } - public void sendResponseCaptureBuffer(String tag, ByteBuffer bbuf, int byteStride) + public void sendResponseCaptureBuffer(String tag, ByteBuffer bbuf) throws ItsException { - try { - JSONObject obj = null; - if (byteStride > 0) { - obj = new JSONObject(); - obj.put("byteStride", byteStride); - } - sendResponse(tag, null, obj, bbuf); - } catch (org.json.JSONException e) { - throw new ItsException("JSON error: ", e); - } + sendResponse(tag, null, null, bbuf); } public void sendResponse(LinkedList<MySensorEvent> events) @@ -1019,27 +1010,26 @@ public class ItsService extends Service implements SensorEventListener { Log.i(TAG, "Received JPEG capture"); ByteBuffer buf = capture.getPlanes()[0].getBuffer(); int count = mCountJpg.getAndIncrement(); - mSocketRunnableObj.sendResponseCaptureBuffer("jpegImage", buf, 0); + mSocketRunnableObj.sendResponseCaptureBuffer("jpegImage", buf); } else if (format == ImageFormat.YUV_420_888) { Log.i(TAG, "Received YUV capture"); byte[] img = ItsUtils.getDataFromImage(capture); ByteBuffer buf = ByteBuffer.wrap(img); int count = mCountYuv.getAndIncrement(); - mSocketRunnableObj.sendResponseCaptureBuffer("yuvImage", buf, 0); + mSocketRunnableObj.sendResponseCaptureBuffer("yuvImage", buf); } else if (format == ImageFormat.RAW10) { Log.i(TAG, "Received RAW10 capture"); - int byteStride = capture.getPlanes()[0].getRowStride(); byte[] img = ItsUtils.getDataFromImage(capture); ByteBuffer buf = ByteBuffer.wrap(img); int count = mCountRaw10.getAndIncrement(); - mSocketRunnableObj.sendResponseCaptureBuffer("raw10Image", buf, byteStride); + mSocketRunnableObj.sendResponseCaptureBuffer("raw10Image", buf); } else if (format == ImageFormat.RAW_SENSOR) { Log.i(TAG, "Received RAW16 capture"); int count = mCountRawOrDng.getAndIncrement(); if (! mCaptureRawIsDng) { byte[] img = ItsUtils.getDataFromImage(capture); ByteBuffer buf = ByteBuffer.wrap(img); - mSocketRunnableObj.sendResponseCaptureBuffer("rawImage", buf, 0); + mSocketRunnableObj.sendResponseCaptureBuffer("rawImage", buf); } else { // Wait until the corresponding capture result is ready. while (! mThreadExitFlag) { @@ -1051,7 +1041,7 @@ public class ItsService extends Service implements SensorEventListener { dngCreator.writeImage(dngStream, capture); byte[] dngArray = dngStream.toByteArray(); ByteBuffer dngBuf = ByteBuffer.wrap(dngArray); - mSocketRunnableObj.sendResponseCaptureBuffer("dngImage", dngBuf, 0); + mSocketRunnableObj.sendResponseCaptureBuffer("dngImage", dngBuf); break; } else { Thread.sleep(1); diff --git a/apps/CameraITS/service/src/com/android/camera2/its/ItsUtils.java b/apps/CameraITS/service/src/com/android/camera2/its/ItsUtils.java index da083d0..a065326 100644 --- a/apps/CameraITS/service/src/com/android/camera2/its/ItsUtils.java +++ b/apps/CameraITS/service/src/com/android/camera2/its/ItsUtils.java @@ -140,7 +140,8 @@ public class ItsUtils { data = new byte[buffer.capacity()]; buffer.get(data); return data; - } else if (format == ImageFormat.YUV_420_888 || format == ImageFormat.RAW_SENSOR) { + } else if (format == ImageFormat.YUV_420_888 || format == ImageFormat.RAW_SENSOR + || format == ImageFormat.RAW10) { Log.i(TAG, String.format("Reading image, format %d", format)); int offset = 0; data = new byte[width * height * ImageFormat.getBitsPerPixel(format) / 8]; @@ -163,7 +164,7 @@ public class ItsUtils { offset += length; } else { // Generic case: should work for any pixelStride but slower. - // Use use intermediate buffer to avoid read byte-by-byte from + // Use intermediate buffer to avoid read byte-by-byte from // DirectByteBuffer, which is very bad for performance. // Also need avoid access out of bound by only reading the available // bytes in the bytebuffer. @@ -194,6 +195,7 @@ public class ItsUtils { case ImageFormat.YV12: return 3 == planes.length; case ImageFormat.RAW_SENSOR: + case ImageFormat.RAW10: case ImageFormat.JPEG: return 1 == planes.length; default: |