From 3c6b51a9ec146fa006785709f59a07cb1572fed0 Mon Sep 17 00:00:00 2001 From: Fiona Campbell Date: Tue, 21 Apr 2020 16:32:21 +0100 Subject: Convert BrightnessUtils to use brightness as float convertGammaToLinear needed to be constrained to 0-12, as sometimes ret variable was 12.000001. The first parameter for gammaToLinear_minValue_shouldReturnMin has been changed - initally it used 1 (MIN_INT) but it should have been using 0 (GAMMA_SPACE_MIN). Since the function rounded the value at the end, the result ended up the same. The original functions cannot be removed yet since Car uses these methods. Bug: 150671605 Test: m -j99 RunSettingsLibRoboTests ROBOTEST_FILTER="com.android.settingslib.display.BrightnessUtilsTest" Change-Id: I4bba2ca0785f94597590c8f4bb3a7a8a834d6c83 --- .../settingslib/display/BrightnessUtils.java | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'packages/SettingsLib/src/com/android/settingslib') diff --git a/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java b/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java index 57d95942bcb9..4f86afaa995c 100644 --- a/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java +++ b/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java @@ -67,7 +67,7 @@ public class BrightnessUtils { /** * Version of {@link #convertGammaToLinear} that takes and returns float values. - * TODO: brightnessfloat Merge with above method later. + * TODO(flc): refactor Android Auto to use float version * * @param val The slider value. * @param min The minimum acceptable value for the setting. @@ -83,9 +83,13 @@ public class BrightnessUtils { ret = MathUtils.exp((normalizedVal - C) / A) + B; } - // HLG is normalized to the range [0, 12], so we need to re-normalize to the range [0, 1] + // HLG is normalized to the range [0, 12], ensure that value is within that range, + // it shouldn't be out of bounds. + final float normalizedRet = MathUtils.constrain(ret, 0, 12); + + // Re-normalize to the range [0, 1] // in order to derive the correct setting value. - return MathUtils.lerp(min, max, ret / 12); + return MathUtils.lerp(min, max, normalizedRet / 12); } /** @@ -111,16 +115,7 @@ public class BrightnessUtils { * @return The corresponding slider value */ public static final int convertLinearToGamma(int val, int min, int max) { - // For some reason, HLG normalizes to the range [0, 12] rather than [0, 1] - final float normalizedVal = MathUtils.norm(min, max, val) * 12; - final float ret; - if (normalizedVal <= 1f) { - ret = MathUtils.sqrt(normalizedVal) * R; - } else { - ret = A * MathUtils.log(normalizedVal - B) + C; - } - - return Math.round(MathUtils.lerp(GAMMA_SPACE_MIN, GAMMA_SPACE_MAX, ret)); + return convertLinearToGammaFloat((float) val, (float) min, (float) max); } /** -- cgit v1.2.3