From 4d7f7de7007c7effd2518e581275fef32536c862 Mon Sep 17 00:00:00 2001 From: Vladimir Chtchetkine Date: Wed, 21 Sep 2011 15:33:18 -0700 Subject: [PATCH] Use actual JPEG quality when compressing picture Sometimes framework chooses to override the default JPEG quality value (90), so we need to respect that when compressing frame during picture taking. Change-Id: Ic7ad8938d33d94d34ecd0b979e5c8c3e8246fd53 --- tools/emulator/system/camera/CallbackNotifier.cpp | 6 +++++- tools/emulator/system/camera/CallbackNotifier.h | 9 +++++++++ tools/emulator/system/camera/EmulatedCamera.cpp | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/emulator/system/camera/CallbackNotifier.cpp b/tools/emulator/system/camera/CallbackNotifier.cpp index 7d83bb171..c2a84e266 100755 --- a/tools/emulator/system/camera/CallbackNotifier.cpp +++ b/tools/emulator/system/camera/CallbackNotifier.cpp @@ -93,6 +93,7 @@ CallbackNotifier::CallbackNotifier() mLastFrameTimestamp(0), mFrameRefreshFreq(0), mMessageEnabler(0), + mJpegQuality(90), mVideoRecEnabled(false), mTakingPicture(false) { @@ -196,7 +197,9 @@ void CallbackNotifier::cleanupCBNotifier() mCBOpaque = NULL; mLastFrameTimestamp = 0; mFrameRefreshFreq = 0; + mJpegQuality = 90; mVideoRecEnabled = false; + mTakingPicture = false; } void CallbackNotifier::onNextFrameAvailable(const void* frame, @@ -235,7 +238,8 @@ void CallbackNotifier::onNextFrameAvailable(const void* frame, NV21JpegCompressor compressor; status_t res = compressor.compressRawImage(frame, camera_dev->getFrameWidth(), - camera_dev->getFrameHeight(), 90); + camera_dev->getFrameHeight(), + mJpegQuality); if (res == NO_ERROR) { camera_memory_t* jpeg_buff = mGetMemoryCB(-1, compressor.getCompressedSize(), 1, NULL); diff --git a/tools/emulator/system/camera/CallbackNotifier.h b/tools/emulator/system/camera/CallbackNotifier.h index fe6c03a36..3722d21b4 100755 --- a/tools/emulator/system/camera/CallbackNotifier.h +++ b/tools/emulator/system/camera/CallbackNotifier.h @@ -168,6 +168,12 @@ public: mTakingPicture = taking; } + /* Sets JPEG quality used to compress frame during picture taking. */ + void setJpegQuality(int jpeg_quality) + { + mJpegQuality = jpeg_quality; + } + /**************************************************************************** * Private API ***************************************************************************/ @@ -206,6 +212,9 @@ protected: /* Message enabler. */ uint32_t mMessageEnabler; + /* JPEG quality used to compress frame during picture taking. */ + int mJpegQuality; + /* Video recording status. */ bool mVideoRecEnabled; diff --git a/tools/emulator/system/camera/EmulatedCamera.cpp b/tools/emulator/system/camera/EmulatedCamera.cpp index d050413bb..80e723914 100755 --- a/tools/emulator/system/camera/EmulatedCamera.cpp +++ b/tools/emulator/system/camera/EmulatedCamera.cpp @@ -322,6 +322,11 @@ status_t EmulatedCamera::takePicture() LOGE("%s: Unsupported pixel format %s", __FUNCTION__, pix_fmt); return EINVAL; } + /* Get JPEG quality. */ + int jpeg_quality = mParameters.getInt(CameraParameters::KEY_JPEG_QUALITY); + if (jpeg_quality <= 0) { + jpeg_quality = 90; /* Fall back to default. */ + } /* * Make sure preview is not running, and device is stopped before taking @@ -358,6 +363,7 @@ status_t EmulatedCamera::takePicture() } /* Deliver one frame only. */ + mCallbackNotifier.setJpegQuality(jpeg_quality); mCallbackNotifier.setTakingPicture(true); res = camera_dev->startDeliveringFrames(true); if (res != NO_ERROR) {