Bug 1018820 - fix exposure compensation index calculations, r=dhylands

This commit is contained in:
Mike Habicher 2014-06-04 15:20:12 -04:00
Родитель 997e8c7d3a
Коммит e62b517726
3 изменённых файлов: 96 добавлений и 20 удалений

Просмотреть файл

@ -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;

Просмотреть файл

@ -95,8 +95,9 @@ protected:
bool mInitialized;
// Required internal properties
double mExposureCompensationMin;
double mExposureCompensationStep;
int32_t mExposureCompensationMinIndex;
int32_t mExposureCompensationMaxIndex;
nsTArray<int> mZoomRatios;
nsTArray<nsString> mIsoModes;

Просмотреть файл

@ -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();
},
},