Fix for JPEG Compression w/ Unknown Orientation
TaskCompressImageToJpeg blindly passed the orientation from the camera to
JpegUtilNative.compressJpegFromYUV420Image, which then threw a run-time
exception. Behavior for TaskCompressImageToJpeg with an image of
UNKNOWN orientation is to treat it as CLOCKWISE_0 for purposes of
JPEG compression. Instead of crashing, the camera now receives a JPEG
of the dark image of one's tabletop.
Bug: 19000723
Change-Id: I412fb6fed5d80035b180db7f6e8504d6d36b4fcc
diff --git a/src/com/android/camera/processing/imagebackend/TaskCompressImageToJpeg.java b/src/com/android/camera/processing/imagebackend/TaskCompressImageToJpeg.java
index 7df8c53..ea69440 100644
--- a/src/com/android/camera/processing/imagebackend/TaskCompressImageToJpeg.java
+++ b/src/com/android/camera/processing/imagebackend/TaskCompressImageToJpeg.java
@@ -47,8 +47,8 @@
* @param imageTaskManager Link to ImageBackend for reference counting
* @param captureSession Handler for UI/Disk events
*/
- TaskCompressImageToJpeg(ImageToProcess image, Executor executor, ImageTaskManager imageTaskManager,
- CaptureSession captureSession) {
+ TaskCompressImageToJpeg(ImageToProcess image, Executor executor,
+ ImageTaskManager imageTaskManager, CaptureSession captureSession) {
super(image, executor, imageTaskManager, ProcessingPriority.SLOW, captureSession);
}
@@ -79,8 +79,12 @@
ByteBuffer compressedData = ByteBuffer.allocateDirect(3 * resultImage.width
* resultImage.height);
- int numBytes = JpegUtilNative.compressJpegFromYUV420Image(img.proxy, compressedData,
- DEFAULT_JPEG_COMPRESSION_QUALITY, inputImage.orientation.getDegrees());
+ // If Orientation is UNKNOWN, treat input image orientation as
+ // CLOCKWISE_0.
+ int numBytes = JpegUtilNative.compressJpegFromYUV420Image(
+ img.proxy, compressedData, DEFAULT_JPEG_COMPRESSION_QUALITY,
+ (inputImage.orientation == DeviceOrientation.UNKNOWN) ? 0 : inputImage.orientation
+ .getDegrees());
if (numBytes < 0) {
throw new RuntimeException("Error compressing jpeg.");
@@ -95,8 +99,9 @@
onJpegEncodeDone(mId, inputImage, resultImage, writeOut, TaskInfo.Destination.FINAL_IMAGE);
- // TODO: the app actually crashes here on a race condition: TaskCompressImageToJpeg might
- // complete before TaskConvertImageToRGBPreview.
+ // TODO: the app actually crashes here on a race condition:
+ // TaskCompressImageToJpeg might complete before
+ // TaskConvertImageToRGBPreview.
mSession.saveAndFinish(writeOut, resultImage.width, resultImage.height,
resultImage.orientation.getDegrees(), createExif(resultImage),
new MediaSaver.OnMediaSavedListener() {