Miguel Casas uploaded patch set #2 to this change.
Image Capture: correct White Balance for Android Camera 2
This CL follows the previous one on the same bug:
- decouples white-balance setting from auto white balance (it'll
be enforced at the Blink level in subsequent patches, so it's lined
up with UVC platforms, i.e. Linux/CrOs and Win).
- corrects a few color temperatures that were wrongly set, and
also fixes this value in Camera 1 -- the names do no correspond
to particular colour temperatures so I'm setting on what a
Pixel and a Samsung agree upon.
- simplified the colorTemperature step to 50 and aligned the
values to that, in both Camera 1 and 2.
Bug: 724626
Change-Id: Ia2a92340c051d6f82c9950def1a262b8d0ae149f
---
M media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java
M media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
2 files changed, 30 insertions(+), 18 deletions(-)
To view, visit change 509963. To unsubscribe, visit settings.
Miguel Casas uploaded patch set #3 to this change.
Image Capture: correct White Balance for Android Camera 2
This CL follows the previous one on the same bug:
- decouples white-balance setting from auto white balance (it'll
be enforced at the Blink level in subsequent patches, so it's lined
up with UVC platforms, i.e. Linux/CrOs and Win).
- corrects a few color temperatures that were wrongly set, and
also fixes this value in Camera 1 -- the names do no correspond
to particular colour temperatures so I'm setting on what a
Pixel and a Samsung agree upon.
- simplified the colorTemperature step to 50 and aligned the
values to that boundary, in both Camera 1 and 2, since a step
of 1 doesn't make any sense given the steps at hand.
Bug: 724626
Change-Id: Ia2a92340c051d6f82c9950def1a262b8d0ae149f
---
M media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java
M media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
2 files changed, 30 insertions(+), 18 deletions(-)
To view, visit change 509963. To unsubscribe, visit settings.
Miguel Casas posted comments on this change.
Patch set 3:
reillyg@ more color temperature, PTAL
Miguel Casas would like Reilly Grant to review this change.
Image Capture: correct White Balance for Android Camera 2
This CL follows the previous one on the same bug:
- decouples white-balance setting from auto white balance (it'll
be enforced at the Blink level in subsequent patches, so it's lined
up with UVC platforms, i.e. Linux/CrOs and Win).
- corrects a few color temperatures that were wrongly set, and
also fixes this value in Camera 1 -- the names do no correspond
to particular colour temperatures so I'm setting on what a
Pixel and a Samsung agree upon.
- simplified the colorTemperature step to 50 and aligned the
values to that boundary, in both Camera 1 and 2, since a step
of 1 doesn't make any sense given the steps at hand.
Bug: 724626
Change-Id: Ia2a92340c051d6f82c9950def1a262b8d0ae149f
---
M media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java
M media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
2 files changed, 30 insertions(+), 18 deletions(-)
diff --git a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java
index e99eb16..357b903 100644
--- a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java
+++ b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java
@@ -47,11 +47,11 @@
COLOR_TEMPERATURES_MAP.append(
2850, android.hardware.Camera.Parameters.WHITE_BALANCE_INCANDESCENT);
COLOR_TEMPERATURES_MAP.append(
- 2940, android.hardware.Camera.Parameters.WHITE_BALANCE_WARM_FLUORESCENT);
+ 2950, android.hardware.Camera.Parameters.WHITE_BALANCE_WARM_FLUORESCENT);
COLOR_TEMPERATURES_MAP.append(
- 3000, android.hardware.Camera.Parameters.WHITE_BALANCE_TWILIGHT);
+ 4250, android.hardware.Camera.Parameters.WHITE_BALANCE_FLUORESCENT);
COLOR_TEMPERATURES_MAP.append(
- 4230, android.hardware.Camera.Parameters.WHITE_BALANCE_FLUORESCENT);
+ 4600, android.hardware.Camera.Parameters.WHITE_BALANCE_TWILIGHT);
COLOR_TEMPERATURES_MAP.append(
5500, android.hardware.Camera.Parameters.WHITE_BALANCE_DAYLIGHT);
COLOR_TEMPERATURES_MAP.append(
@@ -582,6 +582,7 @@
final int index = COLOR_TEMPERATURES_MAP.indexOfValue(parameters.getWhiteBalance());
if (index >= 0) builder.setCurrentColorTemperature(COLOR_TEMPERATURES_MAP.keyAt(index));
}
+ builder.setStepColorTemperature(50);
final List<String> flashModes = parameters.getSupportedFlashModes();
if (flashModes != null) {
diff --git a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
index 197cacf..257bb32 100644
--- a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
+++ b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
@@ -246,11 +246,11 @@
static {
COLOR_TEMPERATURES_MAP = new SparseIntArray();
COLOR_TEMPERATURES_MAP.append(2850, CameraMetadata.CONTROL_AWB_MODE_INCANDESCENT);
- COLOR_TEMPERATURES_MAP.append(2940, CameraMetadata.CONTROL_AWB_MODE_WARM_FLUORESCENT);
- COLOR_TEMPERATURES_MAP.append(3000, CameraMetadata.CONTROL_AWB_MODE_TWILIGHT);
- COLOR_TEMPERATURES_MAP.append(4230, CameraMetadata.CONTROL_AWB_MODE_FLUORESCENT);
+ COLOR_TEMPERATURES_MAP.append(2950, CameraMetadata.CONTROL_AWB_MODE_WARM_FLUORESCENT);
+ COLOR_TEMPERATURES_MAP.append(4250, CameraMetadata.CONTROL_AWB_MODE_FLUORESCENT);
+ COLOR_TEMPERATURES_MAP.append(4600, CameraMetadata.CONTROL_AWB_MODE_TWILIGHT);
+ COLOR_TEMPERATURES_MAP.append(5000, CameraMetadata.CONTROL_AWB_MODE_DAYLIGHT);
COLOR_TEMPERATURES_MAP.append(6000, CameraMetadata.CONTROL_AWB_MODE_CLOUDY_DAYLIGHT);
- COLOR_TEMPERATURES_MAP.append(6504, CameraMetadata.CONTROL_AWB_MODE_DAYLIGHT);
COLOR_TEMPERATURES_MAP.append(7000, CameraMetadata.CONTROL_AWB_MODE_SHADE);
};
@@ -359,6 +359,8 @@
}
private void configureCommonCaptureSettings(CaptureRequest.Builder requestBuilder) {
+ final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(mId);
+
// |mFocusMode| indicates if we're in auto/continuous, single-shot or manual mode.
if (mFocusMode == AndroidMeteringMode.CONTINUOUS) {
requestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
@@ -384,7 +386,6 @@
// We need to configure by hand the exposure time when AE mode is off. Set it to the
// middle of the allowed range. Further tuning will be done via |mIso|.
- final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(mId);
Range<Long> range = cameraCharacteristics.get(
CameraCharacteristics.SENSOR_INFO_EXPOSURE_TIME_RANGE);
requestBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME,
@@ -441,11 +442,13 @@
CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_OFF);
} else if (mWhiteBalanceMode == AndroidMeteringMode.FIXED) {
requestBuilder.set(CaptureRequest.CONTROL_AWB_LOCK, true);
- if (mColorTemperature > 0) {
- final int colorSetting = getClosestWhiteBalance(mColorTemperature);
- if (colorSetting != -1) {
- requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, colorSetting);
- }
+ }
+ if (mColorTemperature > 0) {
+ final int colorSetting = getClosestWhiteBalance(mColorTemperature,
+ cameraCharacteristics.get(CameraCharacteristics.CONTROL_AWB_AVAILABLE_MODES));
+ Log.d(TAG, " Color temperature (%d ==> %d)", mColorTemperature, colorSetting);
+ if (colorSetting != -1) {
+ requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, colorSetting);
}
}
@@ -492,11 +495,21 @@
return closestSize;
}
- private int getClosestWhiteBalance(int colorTemperature) {
+ private static int findInIntArray(int[] hayStack, int needle) {
+ for (int i = 0; i < hayStack.length; ++i) {
+ if (needle == hayStack[i]) return i;
+ }
+ return -1;
+ }
+
+ private int getClosestWhiteBalance(int colorTemperature, int[] supportedTemperatures) {
int minDiff = Integer.MAX_VALUE;
int matchedTemperature = -1;
for (int i = 0; i < COLOR_TEMPERATURES_MAP.size(); ++i) {
+ if (findInIntArray(supportedTemperatures, COLOR_TEMPERATURES_MAP.valueAt(i)) == -1) {
+ continue;
+ }
final int diff = Math.abs(colorTemperature - COLOR_TEMPERATURES_MAP.keyAt(i));
if (diff >= minDiff) continue;
minDiff = diff;
@@ -880,7 +893,7 @@
if (index >= 0) {
builder.setCurrentColorTemperature(COLOR_TEMPERATURES_MAP.keyAt(index));
}
- builder.setStepColorTemperature(1);
+ builder.setStepColorTemperature(50);
if (!cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)) {
builder.setSupportsTorch(false);
@@ -983,9 +996,7 @@
.floatValue());
}
if (iso > 0) mIso = (int) Math.round(iso);
- if (mWhiteBalanceMode == AndroidMeteringMode.FIXED && colorTemperature > 0) {
- mColorTemperature = (int) Math.round(colorTemperature);
- }
+ if (colorTemperature > 0) mColorTemperature = (int) Math.round(colorTemperature);
if (hasRedEyeReduction) mRedEyeReduction = redEyeReduction;
if (fillLightMode != AndroidFillLightMode.NOT_SET) mFillLightMode = fillLightMode;
To view, visit change 509963. To unsubscribe, visit settings.
Reilly Grant posted comments on this change.
Patch set 3:Code-Review +1
Miguel Casas posted comments on this change.
Patch set 3:Commit-Queue +2
Commit Bot merged this change.
Image Capture: correct White Balance for Android Camera 2
This CL follows the previous one on the same bug:
- decouples white-balance setting from auto white balance (it'll
be enforced at the Blink level in subsequent patches, so it's lined
up with UVC platforms, i.e. Linux/CrOs and Win).
- corrects a few color temperatures that were wrongly set, and
also fixes this value in Camera 1 -- the names do no correspond
to particular colour temperatures so I'm setting on what a
Pixel and a Samsung agree upon.
- simplified the colorTemperature step to 50 and aligned the
values to that boundary, in both Camera 1 and 2, since a step
of 1 doesn't make any sense given the steps at hand.
Bug: 724626
Change-Id: Ia2a92340c051d6f82c9950def1a262b8d0ae149f
Reviewed-on: https://chromium-review.googlesource.com/509963
Reviewed-by: Reilly Grant <rei...@chromium.org>
Commit-Queue: Miguel Casas <mca...@chromium.org>
Cr-Commit-Position: refs/heads/master@{#473658}
index ff12dec..d67dc9e 100644
--- a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
+++ b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java
@@ -246,11 +246,11 @@
static {
COLOR_TEMPERATURES_MAP = new SparseIntArray();
COLOR_TEMPERATURES_MAP.append(2850, CameraMetadata.CONTROL_AWB_MODE_INCANDESCENT);
- COLOR_TEMPERATURES_MAP.append(2940, CameraMetadata.CONTROL_AWB_MODE_WARM_FLUORESCENT);
- COLOR_TEMPERATURES_MAP.append(3000, CameraMetadata.CONTROL_AWB_MODE_TWILIGHT);
- COLOR_TEMPERATURES_MAP.append(4230, CameraMetadata.CONTROL_AWB_MODE_FLUORESCENT);
+ COLOR_TEMPERATURES_MAP.append(2950, CameraMetadata.CONTROL_AWB_MODE_WARM_FLUORESCENT);
+ COLOR_TEMPERATURES_MAP.append(4250, CameraMetadata.CONTROL_AWB_MODE_FLUORESCENT);
+ COLOR_TEMPERATURES_MAP.append(4600, CameraMetadata.CONTROL_AWB_MODE_TWILIGHT);
+ COLOR_TEMPERATURES_MAP.append(5000, CameraMetadata.CONTROL_AWB_MODE_DAYLIGHT);
COLOR_TEMPERATURES_MAP.append(6000, CameraMetadata.CONTROL_AWB_MODE_CLOUDY_DAYLIGHT);
- COLOR_TEMPERATURES_MAP.append(6504, CameraMetadata.CONTROL_AWB_MODE_DAYLIGHT);
COLOR_TEMPERATURES_MAP.append(7000, CameraMetadata.CONTROL_AWB_MODE_SHADE);
};
@@ -371,6 +371,8 @@
}
private void configureCommonCaptureSettings(CaptureRequest.Builder requestBuilder) {
+ final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(mId);
+
// |mFocusMode| indicates if we're in auto/continuous, single-shot or manual mode.
if (mFocusMode == AndroidMeteringMode.CONTINUOUS) {
requestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
@@ -396,7 +398,6 @@
// We need to configure by hand the exposure time when AE mode is off. Set it to the
// middle of the allowed range. Further tuning will be done via |mIso|.
- final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(mId);
Range<Long> range = cameraCharacteristics.get(
CameraCharacteristics.SENSOR_INFO_EXPOSURE_TIME_RANGE);
requestBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME,
@@ -453,11 +454,13 @@
CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_OFF);
} else if (mWhiteBalanceMode == AndroidMeteringMode.FIXED) {
requestBuilder.set(CaptureRequest.CONTROL_AWB_LOCK, true);
- if (mColorTemperature > 0) {
- final int colorSetting = getClosestWhiteBalance(mColorTemperature);
- if (colorSetting != -1) {
- requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, colorSetting);
- }
+ }
+ if (mColorTemperature > 0) {
+ final int colorSetting = getClosestWhiteBalance(mColorTemperature,
+ cameraCharacteristics.get(CameraCharacteristics.CONTROL_AWB_AVAILABLE_MODES));
+ Log.d(TAG, " Color temperature (%d ==> %d)", mColorTemperature, colorSetting);
+ if (colorSetting != -1) {
+ requestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, colorSetting);
}
}
@@ -504,11 +507,21 @@
return closestSize;
}
- private int getClosestWhiteBalance(int colorTemperature) {
+ private static int findInIntArray(int[] hayStack, int needle) {
+ for (int i = 0; i < hayStack.length; ++i) {
+ if (needle == hayStack[i]) return i;
+ }
+ return -1;
+ }
+
+ private int getClosestWhiteBalance(int colorTemperature, int[] supportedTemperatures) {
int minDiff = Integer.MAX_VALUE;
int matchedTemperature = -1;
for (int i = 0; i < COLOR_TEMPERATURES_MAP.size(); ++i) {
+ if (findInIntArray(supportedTemperatures, COLOR_TEMPERATURES_MAP.valueAt(i)) == -1) {
+ continue;
+ }
final int diff = Math.abs(colorTemperature - COLOR_TEMPERATURES_MAP.keyAt(i));
if (diff >= minDiff) continue;
minDiff = diff;
@@ -892,7 +905,7 @@
if (index >= 0) {
builder.setCurrentColorTemperature(COLOR_TEMPERATURES_MAP.keyAt(index));
}
- builder.setStepColorTemperature(1);
+ builder.setStepColorTemperature(50);
if (!cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)) {
builder.setSupportsTorch(false);
@@ -995,9 +1008,7 @@
.floatValue());
}
if (iso > 0) mIso = (int) Math.round(iso);
- if (mWhiteBalanceMode == AndroidMeteringMode.FIXED && colorTemperature > 0) {
- mColorTemperature = (int) Math.round(colorTemperature);
- }
+ if (colorTemperature > 0) mColorTemperature = (int) Math.round(colorTemperature);
if (hasRedEyeReduction) mRedEyeReduction = redEyeReduction;
if (fillLightMode != AndroidFillLightMode.NOT_SET) mFillLightMode = fillLightMode;
To view, visit change 509963. To unsubscribe, visit settings.