diff --git a/tools/emulator/system/camera/EmulatedCamera.cpp b/tools/emulator/system/camera/EmulatedCamera.cpp index 9cabe75d9..f18ed30c7 100755 --- a/tools/emulator/system/camera/EmulatedCamera.cpp +++ b/tools/emulator/system/camera/EmulatedCamera.cpp @@ -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; /* diff --git a/tools/emulator/system/camera/EmulatedCameraDevice.cpp b/tools/emulator/system/camera/EmulatedCameraDevice.cpp index e09bead0c..71464d201 100755 --- a/tools/emulator/system/camera/EmulatedCameraDevice.cpp +++ b/tools/emulator/system/camera/EmulatedCameraDevice.cpp @@ -27,6 +27,7 @@ #define LOG_TAG "EmulatedCamera_Device" #include #include +#include #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()) { diff --git a/tools/emulator/system/camera/EmulatedCameraDevice.h b/tools/emulator/system/camera/EmulatedCameraDevice.h index 88e2dd272..357c9e6dd 100755 --- a/tools/emulator/system/camera/EmulatedCameraDevice.h +++ b/tools/emulator/system/camera/EmulatedCameraDevice.h @@ -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 { diff --git a/tools/emulator/system/camera/EmulatedFakeCameraDevice.cpp b/tools/emulator/system/camera/EmulatedFakeCameraDevice.cpp index 53a5b1bfb..36668272e 100755 --- a/tools/emulator/system/camera/EmulatedFakeCameraDevice.cpp +++ b/tools/emulator/system/camera/EmulatedFakeCameraDevice.cpp @@ -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; diff --git a/tools/emulator/system/camera/EmulatedFakeCameraDevice.h b/tools/emulator/system/camera/EmulatedFakeCameraDevice.h index f54127e12..0920be7a2 100755 --- a/tools/emulator/system/camera/EmulatedFakeCameraDevice.h +++ b/tools/emulator/system/camera/EmulatedFakeCameraDevice.h @@ -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(static_cast(inputY) * + mExposureCompensation); + } #if EFCD_ROTATE_FRAME void drawSolid(YUVPixel* color); void drawStripes();