Added exposure compensation control for the fake camera.

Change-Id: I10bc16d9d521f82e12ff335eed29465ac08b5595
This commit is contained in:
Christine Chen
2011-10-14 13:29:28 -07:00
parent ab50fca4f0
commit 366396d9b0
5 changed files with 64 additions and 2 deletions

View File

@@ -96,6 +96,7 @@ status_t EmulatedCamera::Initialize()
mParameters.set(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION, "6");
mParameters.set(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION, "-6");
mParameters.set(CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP, "0.5");
mParameters.set(CameraParameters::KEY_EXPOSURE_COMPENSATION, "0");
mParameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, "512");
mParameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, "384");
mParameters.set(CameraParameters::KEY_JPEG_QUALITY, "90");
@@ -396,6 +397,34 @@ status_t EmulatedCamera::setParameters(const char* parms)
CameraParameters new_param;
String8 str8_param(parms);
new_param.unflatten(str8_param);
int new_exposure_compensation = new_param.getInt(
CameraParameters::KEY_EXPOSURE_COMPENSATION);
const int min_exposure_compensation = new_param.getInt(
CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION);
const int max_exposure_compensation = new_param.getInt(
CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION);
// Checks if the exposure compensation change is supported.
if ((min_exposure_compensation != 0) || (max_exposure_compensation != 0)) {
if (new_exposure_compensation > max_exposure_compensation) {
new_exposure_compensation = max_exposure_compensation;
}
if (new_exposure_compensation < min_exposure_compensation) {
new_exposure_compensation = min_exposure_compensation;
}
const int current_exposure_compensation = mParameters.getInt(
CameraParameters::KEY_EXPOSURE_COMPENSATION);
if (current_exposure_compensation != new_exposure_compensation) {
const float exposure_value = new_exposure_compensation *
new_param.getFloat(
CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP);
getCameraDevice()->setExposureCompensation(
exposure_value);
}
}
mParameters = new_param;
/*

View File

@@ -27,6 +27,7 @@
#define LOG_TAG "EmulatedCamera_Device"
#include <cutils/log.h>
#include <sys/select.h>
#include <cmath>
#include "EmulatedCameraDevice.h"
#include "Converters.h"
@@ -37,6 +38,7 @@ EmulatedCameraDevice::EmulatedCameraDevice(EmulatedCamera* camera_hal)
mCurFrameTimestamp(0),
mCameraHAL(camera_hal),
mCurrentFrame(NULL),
mExposureCompensation(1.0f),
mState(ECDS_CONSTRUCTED)
{
}
@@ -101,6 +103,17 @@ status_t EmulatedCameraDevice::stopDeliveringFrames()
return res;
}
void EmulatedCameraDevice::setExposureCompensation(const float ev) {
LOGV("%s", __FUNCTION__);
if (!isStarted()) {
LOGW("%s: Fake camera device is not started.", __FUNCTION__);
}
mExposureCompensation = std::pow(2.0f, ev);
LOGV("New exposure compensation is %f", mExposureCompensation);
}
status_t EmulatedCameraDevice::getCurrentPreviewFrame(void* buffer)
{
if (!isStarted()) {

View File

@@ -143,6 +143,10 @@ public:
*/
virtual status_t stopDeliveringFrames();
/* Sets the exposure compensation for the camera device.
*/
virtual void setExposureCompensation(const float ev);
/* Gets current framebuffer, converted into preview frame format.
* This method must be called on a connected instance of this class with a
* started camera device. If it is called on a disconnected instance, or
@@ -471,6 +475,9 @@ protected:
/* Total number of pixels */
int mTotalPixels;
/* Exposure compensation value */
float mExposureCompensation;
/* Defines possible states of the emulated camera device object.
*/
enum EmulatedCameraDeviceState {

View File

@@ -44,6 +44,13 @@ EmulatedFakeCameraDevice::EmulatedFakeCameraDevice(EmulatedFakeCamera* camera_ha
mCurrentColor(&mWhiteYUV)
#endif // EFCD_ROTATE_FRAME
{
// Makes the image with the original exposure compensation darker.
// So the effects of changing the exposure compensation can be seen.
mBlackYUV.Y = mBlackYUV.Y / 4;
mWhiteYUV.Y = mWhiteYUV.Y / 4;
mRedYUV.Y = mRedYUV.Y / 4;
mGreenYUV.Y = mGreenYUV.Y / 4;
mBlueYUV.Y = mBlueYUV.Y / 4;
}
EmulatedFakeCameraDevice::~EmulatedFakeCameraDevice()
@@ -258,6 +265,7 @@ void EmulatedFakeCameraDevice::drawCheckerboard()
} else {
mWhiteYUV.get(Y, U, V);
}
*Y = changeExposure(*Y);
Y[1] = *Y;
Y += 2; U += mUVStep; V += mUVStep;
countx += 2;
@@ -309,6 +317,7 @@ void EmulatedFakeCameraDevice::drawSquare(int x,
uint8_t* sqY = Y_pos;
for (int i = x; i < square_xstop; i += 2) {
color->get(sqY, sqU, sqV);
*sqY = changeExposure(*sqY);
sqY[1] = *sqY;
sqY += 2; sqU += mUVStep; sqV += mUVStep;
}
@@ -321,7 +330,7 @@ void EmulatedFakeCameraDevice::drawSquare(int x,
void EmulatedFakeCameraDevice::drawSolid(YUVPixel* color)
{
/* All Ys are the same. */
memset(mCurrentFrame, color->Y, mTotalPixels);
memset(mCurrentFrame, changeExposure(color->Y), mTotalPixels);
/* Fill U, and V panes. */
uint8_t* U = mFrameU;
@@ -357,7 +366,7 @@ void EmulatedFakeCameraDevice::drawStripes()
}
/* All Ys at the row are the same. */
memset(pY, color->Y, mFrameWidth);
memset(pY, changeExposure(color->Y), mFrameWidth);
/* Offset of the current row inside U/V panes. */
const int uv_off = (y / 2) * mUVInRow;

View File

@@ -110,6 +110,10 @@ private:
*/
void drawSquare(int x, int y, int size, const YUVPixel* color);
inline uint8_t changeExposure(uint8_t inputY) {
return static_cast<uint8_t>(static_cast<float>(inputY) *
mExposureCompensation);
}
#if EFCD_ROTATE_FRAME
void drawSolid(YUVPixel* color);
void drawStripes();