/frameworks/base/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java
线性范围(3-255),非线性范围(0-1023)
线性转为非线性
117 public static final int convertLinearToGamma(int val, int min, int max) { 118 return convertLinearToGammaFloat((float) val, (float) min, (float) max); 119 }
逆向转换
54 public static final int convertGammaToLinear(int val, int min, int max) { 55 final float normalizedVal = MathUtils.norm(GAMMA_SPACE_MIN, GAMMA_SPACE_MAX, val); 56 final float ret; 57 if (normalizedVal <= R) { 58 ret = MathUtils.sq(normalizedVal / R); 59 } else { 60 ret = MathUtils.exp((normalizedVal - C) / A) + B; 61 } 62 63 // HLG is normalized to the range [0, 12], so we need to re-normalize to the range [0, 1] 64 // in order to derive the correct setting value. 65 return Math.round(MathUtils.lerp(min, max, ret / 12)); 66 }