-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrightness.patch
More file actions
73 lines (65 loc) · 3.07 KB
/
brightness.patch
File metadata and controls
73 lines (65 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
From 28d824f7c22d2e166246837d4561de2275051852 Mon Sep 17 00:00:00 2001
From: SagarMakhar <sagarmakhar@gmail.com>
Date: Sun, 16 Jan 2022 08:25:59 +0000
Subject: [PATCH] Fix brightness slider curve for some devices
- these devices report max brightness as 2047 or 4095
Change-Id: I83b38a1334b8df156e4e53b06243c48d565be5d5
Signed-off-by: SagarMakhar <sagarmakhar@gmail.com>
---
.../settingslib/display/BrightnessUtils.java | 33 ++++---------------
1 file changed, 7 insertions(+), 26 deletions(-)
diff --git a/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java b/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java
index 4f86afaa995c..e4490c851081 100644
--- a/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java
@@ -18,10 +18,12 @@
import android.util.MathUtils;
+import com.android.internal.display.BrightnessSynchronizer;
+
public class BrightnessUtils {
public static final int GAMMA_SPACE_MIN = 0;
- public static final int GAMMA_SPACE_MAX = 65535;
+ public static final int GAMMA_SPACE_MAX = 255;
// Hybrid Log Gamma constant values
private static final float R = 0.5f;
@@ -75,21 +77,8 @@ public static final int convertGammaToLinear(int val, int min, int max) {
* @return The corresponding setting value.
*/
public static final float convertGammaToLinearFloat(int val, float min, float max) {
- final float normalizedVal = MathUtils.norm(GAMMA_SPACE_MIN, GAMMA_SPACE_MAX, val);
- final float ret;
- if (normalizedVal <= R) {
- ret = MathUtils.sq(normalizedVal / R);
- } else {
- ret = MathUtils.exp((normalizedVal - C) / A) + B;
- }
-
- // 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, normalizedRet / 12);
+ return MathUtils.constrain(BrightnessSynchronizer.brightnessIntToFloat(val),
+ min, max);
}
/**
@@ -127,15 +116,7 @@ public static final int convertLinearToGamma(int val, int min, int max) {
* @return The corresponding slider value
*/
public static final int convertLinearToGammaFloat(float val, float min, float 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 BrightnessSynchronizer.brightnessFloatToInt(
+ MathUtils.constrain(val, min, max));
}
}