AutoBrightness亮度曲线的生成

打开
adb exec-out cmd display ab-logging-enable
关闭
adb exec-out cmd display ab-logging-disable
 adb logcat |grep  -Ei "AutomaticBrightnessController|BrightnessMappingStrategy"

AutomaticBrightnessController.configure(.... mLastUserSetScreenBrightness / (float) PowerManager.BRIGHTNESS_ON,...){
          if (userChangedBrightness && enable) {
              // Update the brightness curve with the new user control point. It's critical this
              // happens after we update the autobrightness adjustment since it may reset it.
              changed |= setScreenBrightnessByUser(brightness);
          }
}--->
AutomaticBrightnessController.setScreenBrightnessByUser--->
BrightnessMappingStrategy.SimpleMappingStrategy.addUserDataPoint(float lux, float brightness) --->//传入获取的Lux亮度值和背光值
BrightnessMappingStrategy.SimpleMappingStrategy.computeSpline-->
//将预先设置好xml中的Lux,Brightness数组和获取到的Lux亮度值和背光值的做计算
BrightnessMappingStrategy.getAdjustedCurve(float[] lux, float[] brightness,float userLux, float userBrightness, float adjustment, float maxGamma){
    .....
     Pair curve = insertControlPoint(newLux, newBrightness, userLux,userBrightness);
     return Pair.create(newLux, newBrightness);
    ....
}--->
//将用户设置的点作为曲线控制点插入相关数组中,计算得到新的Lux和Brightness对应关系
BrightnessMappingStrategy.insertControlPoint(float[] luxLevels, float[] brightnessLevels, float lux, float brightness){

//Returns the index of the first value that's less than or equal to {@code val}.
BrightnessMappingStrategy.findInsertionPoint(luxLevels, lux){
///private int findInsertionPoint(float[] arr, float val) {
    for (int i = 0; i < arr.length; i++) {
             if (val <= arr[i]) {
                 return i;
             }
         }
         return arr.length;
    }
 }
}--->//根据传入的Lux值大小得到在luxLevels预置中的位置idx
   .....
   //insertControlPoint中这边有三个判断条件,将输入的lux的插入到预置的Lux数组中
   1.//需要插入到末尾位置,且新Lux数组长度比原来大1
   2.//如果用户lux值已处于Lux值数组中,则copy原数组即可
   3.//如果用户lux值未处于Lux值数组中,则将Lux根据idx索引放到对应的位置,索引后面的Lux值对应的后移
   ......
   smoothCurve(newLuxLevels, newBrightnessLevels, idx);
   return Pair.create(newLuxLevels, newBrightnessLevels);
}
//返回一个携带有Lux和背光值的Pair对象给getAdjustedCurve(),在getAdjustedCurve()中将返回该Pair对象给到computeSpline()中,在computeSpline()将从返回的Pair对像中取出Lux数组值和背光数组值,完成曲线的创建。

Spline.createSpline(float[] x, float[] y)--->
createMonotoneCubicSpline(x, y)--->
MonotoneCubicSpline(float[] x, float[] y){
....
             mX = x;//光感强度
             mY = y;//背光亮度系数,最终亮度为255*mY
             mM = m;//根据光感和背光亮度得出一个平均斜率
....            
}
////
Spline.interpolate(float x){
...
  // Perform cubic Hermite spline interpolation.
  float h = mX[i + 1] - mX[i];
  float t = (x - mX[i]) / h;
  return (mY[i] * (1 + 2 * t) + h * mM[i] * t) * (1 - t) * (1 - t)
                + (mY[i + 1] * (3 - 2 * t) + h * mM[i + 1] * (t - 1)) * t * t;
...
}
--->

//传入mAmbientLux得到的亮度系数
SimpleMappingStrategy.getBrightness
          @Override
          public float getBrightness(float lux, String packageName,
                  @ApplicationInfo.Category int category) {
              return mSpline.interpolate(lux);
          }

 

你可能感兴趣的:(AutoBrightness亮度曲线的生成)