From e62b517726fedce568ab7eb7bfd6fe42513304c0 Mon Sep 17 00:00:00 2001 From: Mike Habicher Date: Wed, 4 Jun 2014 15:20:12 -0400 Subject: [PATCH] Bug 1018820 - fix exposure compensation index calculations, r=dhylands --- dom/camera/GonkCameraParameters.cpp | 52 ++++++++++------ dom/camera/GonkCameraParameters.h | 3 +- .../test/test_camera_fake_parameters.html | 61 +++++++++++++++++++ 3 files changed, 96 insertions(+), 20 deletions(-) diff --git a/dom/camera/GonkCameraParameters.cpp b/dom/camera/GonkCameraParameters.cpp index 75171a5a5de0..502da7de2c4a 100644 --- a/dom/camera/GonkCameraParameters.cpp +++ b/dom/camera/GonkCameraParameters.cpp @@ -138,6 +138,7 @@ GonkCameraParameters::GonkCameraParameters() : mLock(PR_NewRWLock(PR_RWLOCK_RANK_NONE, "GonkCameraParameters.Lock")) , mDirty(false) , mInitialized(false) + , mExposureCompensationStep(0.0) { MOZ_COUNT_CTOR(GonkCameraParameters); if (!mLock) { @@ -199,15 +200,20 @@ GonkCameraParameters::Initialize() { nsresult rv; - rv = GetImpl(CAMERA_PARAM_SUPPORTED_MINEXPOSURECOMPENSATION, mExposureCompensationMin); - if (NS_FAILED(rv)) { - NS_WARNING("Failed to initialize minimum exposure compensation"); - mExposureCompensationMin = 0; - } - rv = GetImpl(CAMERA_PARAM_SUPPORTED_EXPOSURECOMPENSATIONSTEP, mExposureCompensationStep); + rv = GetImpl(Parameters::KEY_EXPOSURE_COMPENSATION_STEP, mExposureCompensationStep); if (NS_FAILED(rv)) { NS_WARNING("Failed to initialize exposure compensation step size"); - mExposureCompensationStep = 0; + mExposureCompensationStep = 0.0; + } + rv = GetImpl(Parameters::KEY_MIN_EXPOSURE_COMPENSATION, mExposureCompensationMinIndex); + if (NS_FAILED(rv)) { + NS_WARNING("Failed to initialize minimum exposure compensation index"); + mExposureCompensationMinIndex = 0; + } + rv = GetImpl(Parameters::KEY_MAX_EXPOSURE_COMPENSATION, mExposureCompensationMaxIndex); + if (NS_FAILED(rv)) { + NS_WARNING("Failed to initialize maximum exposure compensation index"); + mExposureCompensationMaxIndex = 0; } rv = GetListAsArray(CAMERA_PARAM_SUPPORTED_ZOOMRATIOS, mZoomRatios); @@ -540,8 +546,8 @@ GonkCameraParameters::SetTranslated(uint32_t aKey, const double& aValue) switch (aKey) { case CAMERA_PARAM_EXPOSURECOMPENSATION: - if (mExposureCompensationStep == 0) { - DOM_CAMERA_LOGE("Exposure compensation not supported, can't set %f\n", aValue); + if (mExposureCompensationStep == 0.0) { + DOM_CAMERA_LOGE("Exposure compensation not supported, can't set EV=%f\n", aValue); return NS_ERROR_NOT_AVAILABLE; } @@ -549,9 +555,16 @@ GonkCameraParameters::SetTranslated(uint32_t aKey, const double& aValue) * Convert from real value to a Gonk index, round * to the nearest step; index is 1-based. */ - index = - (aValue - mExposureCompensationMin + mExposureCompensationStep / 2) / - mExposureCompensationStep + 1; + { + double i = round(aValue / mExposureCompensationStep); + if (i < mExposureCompensationMinIndex) { + index = mExposureCompensationMinIndex; + } else if (i > mExposureCompensationMaxIndex) { + index = mExposureCompensationMaxIndex; + } else { + index = i; + } + } DOM_CAMERA_LOGI("Exposure compensation = %f --> index = %d\n", aValue, index); return SetImpl(CAMERA_PARAM_EXPOSURECOMPENSATION, index); @@ -643,15 +656,16 @@ GonkCameraParameters::GetTranslated(uint32_t aKey, double& aValue) break; case CAMERA_PARAM_EXPOSURECOMPENSATION: + case CAMERA_PARAM_SUPPORTED_MINEXPOSURECOMPENSATION: + case CAMERA_PARAM_SUPPORTED_MAXEXPOSURECOMPENSATION: + if (mExposureCompensationStep == 0.0) { + DOM_CAMERA_LOGE("Exposure compensation not supported, can't get EV\n"); + return NS_ERROR_NOT_AVAILABLE; + } rv = GetImpl(aKey, index); if (NS_SUCCEEDED(rv)) { - if (!index) { - // NaN indicates automatic exposure compensation - val = NAN; - } else { - val = (index - 1) * mExposureCompensationStep + mExposureCompensationMin; - DOM_CAMERA_LOGI("index = %d --> compensation = %f\n", index, val); - } + val = index * mExposureCompensationStep; + DOM_CAMERA_LOGI("exposure compensation (aKey=%d): index=%d --> EV=%f\n", aKey, index, val); } break; diff --git a/dom/camera/GonkCameraParameters.h b/dom/camera/GonkCameraParameters.h index 41d6b92e2a39..bda980c7b422 100644 --- a/dom/camera/GonkCameraParameters.h +++ b/dom/camera/GonkCameraParameters.h @@ -95,8 +95,9 @@ protected: bool mInitialized; // Required internal properties - double mExposureCompensationMin; double mExposureCompensationStep; + int32_t mExposureCompensationMinIndex; + int32_t mExposureCompensationMaxIndex; nsTArray mZoomRatios; nsTArray mIsoModes; diff --git a/dom/camera/test/test_camera_fake_parameters.html b/dom/camera/test/test_camera_fake_parameters.html index 8200583f7e6e..c4f3dbe6371e 100644 --- a/dom/camera/test/test_camera_fake_parameters.html +++ b/dom/camera/test/test_camera_fake_parameters.html @@ -207,6 +207,67 @@ var tests = [ ok(areas[0].right == 504, "area[0] right = " + areas[0].right); ok(areas[0].weight == 105, "area[0] weight = " + areas[0].weight); + next(); + }, + }, + { + key: "fake-exposure-compensation", + prep: function setupFakeExposureCompensation(test) { + test.setFakeParameters("exposure-compensation=-1;max-exposure-compensation=6;min-exposure-compensation=-6;exposure-compensation-step=0.5", function () { + run(); + }); + }, + test: function testFakeFocusAreas(cam, cap) { + ok(cap.exposureCompensationStep == 0.5, + "exposureCompensationStep = " + cap.exposureCompensationStep); + ok(cap.minExposureCompensation == -3.0, + "minExposureCompensation = " + cap.minExposureCompensation); + ok(cap.maxExposureCompensation == 3.0, + "maxExposureCompensation = " + cap.maxExposureCompensation); + ok(cam.exposureCompensation == -0.5, + "exposureCompensation = " + cam.exposureCompensation); + + // Check normal values + cam.setExposureCompensation(0.0); + ok(cam.exposureCompensation == 0.0, + "exposureCompensation = " + cam.exposureCompensation); + cam.setExposureCompensation(cap.minExposureCompensation); + ok(cam.exposureCompensation == cap.minExposureCompensation, + "exposureCompensation(min) = " + cam.exposureCompensation); + cam.setExposureCompensation(cap.maxExposureCompensation); + ok(cam.exposureCompensation == cap.maxExposureCompensation, + "exposureCompensation(max) = " + cam.exposureCompensation); + + // Rounding + cam.setExposureCompensation(1.24); + ok(cam.exposureCompensation == 1.0, + "exposureCompensation(1.24) = " + cam.exposureCompensation); + cam.setExposureCompensation(1.25); + ok(cam.exposureCompensation == 1.5, + "exposureCompensation(1.25) = " + cam.exposureCompensation); + cam.setExposureCompensation(-1.24); + ok(cam.exposureCompensation == -1.0, + "exposureCompensation(-1.24) = " + cam.exposureCompensation); + cam.setExposureCompensation(-1.25); + ok(cam.exposureCompensation == -1.5, + "exposureCompensation(-1.25) = " + cam.exposureCompensation); + + // Check out-of-bounds values + cam.setExposureCompensation(cap.minExposureCompensation - 1.0); + ok(cam.exposureCompensation == cap.minExposureCompensation, + "exposureCompensation(min - 1.0) = " + cam.exposureCompensation); + cam.setExposureCompensation(cap.maxExposureCompensation + 1.0); + ok(cam.exposureCompensation == cap.maxExposureCompensation, + "exposureCompensation(max + 1.0) = " + cam.exposureCompensation); + + // Check extreme values + cam.setExposureCompensation(-1 * Math.pow(2, 32)); + ok(cam.exposureCompensation == cap.minExposureCompensation, + "exposureCompensation(-2^32) = " + cam.exposureCompensation); + cam.setExposureCompensation(Math.pow(2, 32)); + ok(cam.exposureCompensation == cap.maxExposureCompensation, + "exposureCompensation(2^32) = " + cam.exposureCompensation); + next(); }, },