阅读:4725回复:1

Android9.0背光调节曲线变化改为线性变化

楼主#
更多 发布于:2022-10-21 13:40
平台:RK3288-9.0


需求:背光调节,曲线变化改为线性变化,范围限制在60-255


由于Android自带的背光调节是曲线变化,前面70%左右背光都很暗,调节进度条没有明显变化,最后30%变化特别特别大,一瞬间就很刺眼了,用户体验很差,所以客户要求改为线性变化,且限制背光范围在60~255 这样保证进度条设置最低时不至于黑屏。


要求0%对应背光值60 ,50%背光值158左右,100%背光值255



diff --git a/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java b/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java
index 55723f9d8ed..e4295b9470b 100644
--- a/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/display/BrightnessUtils.java
@@ -20,8 +20,8 @@ import android.util.MathUtils;

public class BrightnessUtils {

-    public static final int GAMMA_SPACE_MAX = 1023;
-
+    //public static final int GAMMA_SPACE_MAX = 1023;
+ public static final int GAMMA_SPACE_MAX = 195;
    // Hybrid Log Gamma constant values
    private static final float R = 0.5f;
    private static final float A = 0.17883277f;
@@ -61,7 +61,8 @@ public class BrightnessUtils {

        // HLG is normalized to the range [0, 12], so we need to re-normalize to the range [0, 1]
        // in order to derive the correct setting value.
-        return Math.round(MathUtils.lerp(min, max, ret / 12));
+        //return Math.round(MathUtils.lerp(min, max, ret / 12));
+        return val;
    }

    /**
@@ -95,7 +96,7 @@ public class BrightnessUtils {
        } else {
            ret = A * MathUtils.log(normalizedVal - B) + C;
        }
-
-        return Math.round(MathUtils.lerp(0, GAMMA_SPACE_MAX, ret));
+     return val;
+        //return Math.round(MathUtils.lerp(0, GAMMA_SPACE_MAX, ret));
    }
}
diff --git a/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java b/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
index 2902cb48e7e..8d782197181 100755
--- a/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
+++ b/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
@@ -224,9 +224,13 @@ public class BrightnessController implements ToggleSlider.Listener {
                val = Settings.System.getIntForUser(mContext.getContentResolver(),
                        Settings.System.SCREEN_BRIGHTNESS, mDefaultBacklight,
                        UserHandle.USER_CURRENT);
+
            }
-            mHandler.obtainMessage(MSG_UPDATE_SLIDER, val, inVrMode ? 1 : 0).sendToTarget();
+            //Add by jackly 20221021
+            int mVal = val - 60;
+            Log.d(TAG,"mUpdateSliderRunnable,screenBrightness = " + val + " seekBar = " + mVal);
+            mHandler.obtainMessage(MSG_UPDATE_SLIDER, mVal, inVrMode ? 1 : 0).sendToTarget();
        }
    };

@@ -380,18 +384,20 @@ public class BrightnessController implements ToggleSlider.Listener {
            setting = Settings.System.SCREEN_BRIGHTNESS;
        }


        if (stopTracking) {
            MetricsLogger.action(mContext, metric, val);
        }
-
-        setBrightness(val);
+        //Add by jackly 20221021
+        final int mVal = val + 60;
+        Log.d(TAG, "onChanged, seekBar = " + val + " screenBrightness = " + mVal);
+        setBrightness(mVal);
        if (!tracking) {
            AsyncTask.execute(new Runnable() {
                    public void run() {
                        Settings.System.putIntForUser(mContext.getContentResolver(),
-                                setting, val, UserHandle.USER_CURRENT);
+                                setting, mVal, UserHandle.USER_CURRENT);
                    }
                });
        }
@@ -437,16 +443,16 @@ public class BrightnessController implements ToggleSlider.Listener {
        }
    }

@@ -479,7 +485,8 @@ public class BrightnessController implements ToggleSlider.Listener {
            min = mMinimumBacklight;
            max = mMaximumBacklight;
        }
+      Log.d(TAG, "updateSlider, val = " + val + " seekBar = " + mControl.getValue());
       if (val == convertGammaToLinear(mControl.getValue(), min, max)) {
            // If we have more resolution on the slider than we do in the actual setting, then
            // multiple slider positions will map to the same setting value. Thus, if we see a
            // setting value here that maps to the current slider position, we don't bother to
@@ -487,7 +494,7 @@ public class BrightnessController implements ToggleSlider.Listener {
            // change to the user even though it isn't one.
            return;
        }
        animateSliderTo(sliderVal);
    }


Settings修改

diff --git a/src/com/android/settings/display/BrightnessLevelPreferenceController.java b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
index 5d4cc6c83e..f427995cfa 100755
--- a/src/com/android/settings/display/BrightnessLevelPreferenceController.java
+++ b/src/com/android/settings/display/BrightnessLevelPreferenceController.java
@@ -132,19 +132,23 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
                     System.SCREEN_BRIGHTNESS_FOR_VR, mMaxBrightness),
                     mMinVrBrightness, mMaxVrBrightness);
         } else {
                     System.SCREEN_BRIGHTNESS, mMinBrightness),
                     mMinBrightness, mMaxBrightness);
             Log.d(TAG,"convertLinearToGamma, value="+value);
         }
-        return getPercentage(value, 0, GAMMA_SPACE_MAX);
+        //Add by jackly 20221021
+        int mValue = value - 60;
+        Log.d(TAG, "getCurrentBrightness, screenBrightness = " + value + " seekBar = " + mValue);
+        return getPercentage(mValue, 0, GAMMA_SPACE_MAX);
+        //return getPercentage(value, 0, GAMMA_SPACE_MAX);
     }
     private double getPercentage(double value, int min, int max) {
@@ -154,8 +158,6 @@ public class BrightnessLevelPreferenceController extends AbstractPreferenceContr
         if (value < min) {
             return 0.0;
         }
         return (value - min) / (max - min);
     }
 


————————————————
版权声明:本文为CSDN博主「zhaoyufei133」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhaoyufei133/article/details/127443619
[url]http://190.lsal.cn/195/1329.gif?0728100424873[/url]
沙发#
发布于:2022-12-13 10:57
这个gama算法是挺恶心的,估计是为了自动背光设计的,但对手动调光来说亮度变化很不规则,相比之下线性调光会友好很多
补充一点点,amlogic的更恶心,参考:http://www.vaststargames.com/read.php?tid=416
游客

返回顶部