Bug 965533 - fix the zoom attribute, r=dhylands

This commit is contained in:
Mike Habicher 2014-02-21 13:14:52 -05:00
parent 94291c60fa
commit 3ef173f7e0
3 changed files with 111 additions and 15 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 Mozilla Foundation
* Copyright (C) 2013-2014 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -153,6 +153,10 @@ GonkCameraParameters::Initialize()
if (NS_FAILED(rv)) {
return rv;
}
rv = GetListAsArray(CAMERA_PARAM_SUPPORTED_ZOOMRATIOS, mZoomRatios);
if (NS_FAILED(rv)) {
return rv;
}
mInitialized = true;
return NS_OK;
@ -401,16 +405,53 @@ GonkCameraParameters::GetTranslated(uint32_t aKey, int64_t& aValue)
nsresult
GonkCameraParameters::SetTranslated(uint32_t aKey, const double& aValue)
{
if (aKey == CAMERA_PARAM_EXPOSURECOMPENSATION) {
/**
* Convert from real value to a Gonk index, round
* to the nearest step; index is 1-based.
*/
int index =
(aValue - mExposureCompensationMin + mExposureCompensationStep / 2) /
mExposureCompensationStep + 1;
DOM_CAMERA_LOGI("Exposure compensation = %f --> index = %d\n", aValue, index);
return SetImpl(CAMERA_PARAM_EXPOSURECOMPENSATION, index);
int index;
int value;
switch (aKey) {
case CAMERA_PARAM_EXPOSURECOMPENSATION:
/**
* Convert from real value to a Gonk index, round
* to the nearest step; index is 1-based.
*/
index =
(aValue - mExposureCompensationMin + mExposureCompensationStep / 2) /
mExposureCompensationStep + 1;
DOM_CAMERA_LOGI("Exposure compensation = %f --> index = %d\n", aValue, index);
return SetImpl(CAMERA_PARAM_EXPOSURECOMPENSATION, index);
case CAMERA_PARAM_ZOOM:
{
/**
* Convert from a real zoom multipler (e.g. 2.5x) to
* the index of the nearest supported value.
*/
value = aValue * 100.0;
// mZoomRatios is sorted, so we can binary search it
unsigned int bottom = 0;
unsigned int top = mZoomRatios.Length() - 1;
unsigned int middle;
while (bottom != top) {
middle = (top + bottom) / 2;
if (value == mZoomRatios[middle]) {
// exact match
break;
}
if (value > mZoomRatios[middle] && value < mZoomRatios[middle + 1]) {
// the specified zoom value lies in this interval
break;
}
if (value > mZoomRatios[middle]) {
bottom = middle + 1;
} else {
top = middle - 1;
}
}
index = middle;
}
return SetImpl(CAMERA_PARAM_ZOOM, index);
}
return SetImpl(aKey, aValue);
@ -427,9 +468,9 @@ GonkCameraParameters::GetTranslated(uint32_t aKey, double& aValue)
switch (aKey) {
case CAMERA_PARAM_ZOOM:
rv = GetImpl(CAMERA_PARAM_ZOOM, val);
rv = GetImpl(CAMERA_PARAM_ZOOM, index);
if (NS_SUCCEEDED(rv)) {
val /= 100.0;
val = mZoomRatios[index] / 100.0;
} else {
// return 1x when zooming is not supported
val = 1.0;
@ -557,6 +598,16 @@ ParseItem(const char* aStart, const char* aEnd, double* aItem)
return NS_ERROR_FAILURE;
}
nsresult
ParseItem(const char* aStart, const char* aEnd, int* aItem)
{
if (sscanf(aStart, "%d", aItem) == 1) {
return NS_OK;
}
return NS_ERROR_FAILURE;
}
template<class T> nsresult
GonkCameraParameters::GetListAsArray(uint32_t aKey, nsTArray<T>& aArray)
{
@ -609,6 +660,14 @@ GonkCameraParameters::GetTranslated(uint32_t aKey, nsTArray<nsString>& aValues)
nsresult
GonkCameraParameters::GetTranslated(uint32_t aKey, nsTArray<double>& aValues)
{
if (aKey == CAMERA_PARAM_SUPPORTED_ZOOMRATIOS) {
aValues.Clear();
for (int i = 0; i < mZoomRatios.Length(); ++i) {
*aValues.AppendElement() = mZoomRatios[i] / 100.0;
}
return NS_OK;
}
return GetListAsArray(aKey, aValues);
}

View File

@ -94,6 +94,7 @@ protected:
// Required internal properties
double mExposureCompensationMin;
double mExposureCompensationStep;
nsTArray<int> mZoomRatios;
// This subclass of android::CameraParameters just gives
// all of the AOSP getters and setters the same signature.

View File

@ -33,8 +33,8 @@ function onError(e) {
}
var capabilities = [ 'previewSizes', 'pictureSizes', 'fileFormats', 'maxFocusAreas', 'minExposureCompensation',
'maxExposureCompensation', 'stepExposureCompensation', 'maxMeteringAreas', 'videoSizes',
'recorderProfiles'];
'maxExposureCompensation', 'stepExposureCompensation', 'maxMeteringAreas', 'videoSizes',
'recorderProfiles', 'zoomRatios'];
var Camera = {
cameraObj: null,
@ -49,6 +49,7 @@ var Camera = {
_zoomRatios: null,
_sceneModes: null,
_focusModes: null,
_zoomRatios: null,
_testsCompleted: 0,
_shutter: 0,
_config: {
@ -67,6 +68,12 @@ var Camera = {
setFocus: function camera_setfocus(mode) {
this.cameraObj.focus = mode;
},
setZoom: function camera_setZoom(zoom) {
this.cameraObj.zoom = zoom;
},
getZoom: function camera_getZoom() {
return this.cameraObj.zoom;
},
getFileFormats: function camera_formats() {
this._fileFormats = this.cameraObj.capabilities.fileFormats;
},
@ -91,6 +98,9 @@ var Camera = {
getPreviewSizes: function camera_preview() {
this._previewSizes = this.cameraObj.capabilities.previewSizes;
},
getZoomRatios: function camera_preview() {
this._zoomRatios = this.cameraObj.capabilities.zoomRatios;
},
takePictureSuccess: function taken_foto(blob) {
var img = new Image();
var test = this._currentTest;
@ -137,9 +147,35 @@ var Camera = {
Camera.getPreviewSizes();
Camera.getFileFormats();
Camera.getFocusModes();
Camera.getZoomRatios();
ok(Camera._previewSizes.length > 0, "previewSizes length = " + Camera._previewSizes.length);
ok(Camera._pictureSizes.length > 0, "picturesizes length = " + Camera._pictureSizes.length);
ok(Camera._fileFormats.length > 0, "file formats length = " + Camera._fileFormats.length);
info("zoom ratios length = " + Camera._zoomRatios.length);
if (Camera._zoomRatios.length > 0) {
Camera._zoomRatios.forEach(function(element, index) {
info("zoom[" + index + "] = " + element + "x");
Camera.setZoom(element);
ok(Camera.getZoom() === element, "zoom[" + index + "] = " + element + "x");
});
var zoom = Camera._zoomRatios[0] - 0.1;
Camera.setZoom(zoom);
ok(Camera.getZoom() === Camera._zoomRatios[0],
zoom + "x zoom clamps to minimum: " + Camera._zoomRatios[0]);
zoom = Camera._zoomRatios.slice(-1)[0] + 1.0;
Camera.setZoom(zoom);
ok(Camera.getZoom() === Camera._zoomRatios[0],
zoom + "x zoom clamps to maximum: " + Camera._zoomRatios.slice(-1)[0]);
if (Camera._zoomRatios.length > 1) {
zoom = (Camera._zoomRatios[0] + Camera._zoomRatios[1]) / 2;
Camera.setZoom(zoom);
ok(Camera.getZoom() === Camera._zoomRatios[0],
zoom + "x zoom rounded down to maximum: " + Camera._zoomRatios.slice[0]);
}
}
Camera._tests = new Array();
for (var i in Camera._pictureSizes) {
for (var l in Camera._fileFormats) {