Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cbc94469 authored by Daniel Solomon's avatar Daniel Solomon Committed by Android (Google) Code Review
Browse files

Merge "Add ambient-display CCT LUT to Display White Balance"

parents 2ab332d5 fb393e56
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -3903,4 +3903,22 @@
         The ambient color temperature (in cct) to which we fall back when the ambient brightness
         drops beneath a certain threshold. -->
    <item name="config_displayWhiteBalanceLowLightAmbientColorTemperature" format="float" type="dimen">6500.0</item>

    <!-- See DisplayWhiteBalanceController.
         A float array containing a list of ambient color temperatures, in Kelvin. This array,
         together with config_displayWhiteBalanceDisplayTemperatureValues, is used to generate a
         lookup table used in DisplayWhiteBalanceController. This lookup table is used to map
         ambient color temperature readings to a target color temperature for the display.
         This table is optional. If used, this array must,
         1) Contain at least two entries
         2) Be the same length as config_displayWhiteBalanceDisplayTemperatureValues. -->
    <array name="config_displayWhiteBalanceAmbientTemperatureValues">
    </array>

    <!-- See DisplayWhiteBalanceController.
         An array containing a list of display color temperatures, in Kelvin. See
         config_displayWhiteBalanceAmbientTemperatureValues for additional details.
         The same restrictions apply to this array. -->
    <array name="config_displayWhiteBalanceDisplayTemperatureValues">
    </array>
</resources>
+2 −1
Original line number Diff line number Diff line
@@ -3643,6 +3643,7 @@
  <java-symbol type="array" name="config_displayWhiteBalanceDecreaseThresholds" />
  <java-symbol type="dimen" name="config_displayWhiteBalanceLowLightAmbientBrightnessThreshold" />
  <java-symbol type="dimen" name="config_displayWhiteBalanceLowLightAmbientColorTemperature" />

  <java-symbol type="array" name="config_displayWhiteBalanceAmbientTemperatureValues" />
  <java-symbol type="array" name="config_displayWhiteBalanceDisplayTemperatureValues" />
  <java-symbol type="drawable" name="ic_action_open" />
</resources>
+22 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.display.whitebalance;

import android.annotation.NonNull;
import android.util.Slog;
import android.util.Spline;

import com.android.internal.util.Preconditions;
import com.android.server.LocalServices;
@@ -75,6 +76,9 @@ public class DisplayWhiteBalanceController implements
    // Override the ambient color temperature for debugging purposes.
    private float mAmbientColorTemperatureOverride;

    // A piecewise linear relationship between ambient and display color temperatures
    private Spline.LinearSpline mAmbientToDisplayTemperatureSpline;

    /**
     * @param brightnessSensor
     *      The sensor used to detect changes in the ambient brightness.
@@ -109,7 +113,8 @@ public class DisplayWhiteBalanceController implements
            @NonNull AmbientSensor.AmbientColorTemperatureSensor colorTemperatureSensor,
            @NonNull AmbientFilter colorTemperatureFilter,
            @NonNull DisplayWhiteBalanceThrottler throttler,
            float lowLightAmbientBrightnessThreshold, float lowLightAmbientColorTemperature) {
            float lowLightAmbientBrightnessThreshold, float lowLightAmbientColorTemperature,
            float[] ambientTemperatures, float[] displayTemperatures) {
        validateArguments(brightnessSensor, brightnessFilter, colorTemperatureSensor,
                colorTemperatureFilter, throttler);
        mLoggingEnabled = false;
@@ -127,6 +132,14 @@ public class DisplayWhiteBalanceController implements
        mLastAmbientColorTemperature = -1.0f;
        mAmbientColorTemperatureHistory = new History(HISTORY_SIZE);
        mAmbientColorTemperatureOverride = -1.0f;

        try {
            mAmbientToDisplayTemperatureSpline = new Spline.LinearSpline(ambientTemperatures,
                    displayTemperatures);
        } catch (Exception e) {
            mAmbientToDisplayTemperatureSpline = null;
        }

        mColorDisplayServiceInternal = LocalServices.getService(ColorDisplayServiceInternal.class);
    }

@@ -227,6 +240,9 @@ public class DisplayWhiteBalanceController implements
        writer.println("  mLastAmbientColorTemperature=" + mLastAmbientColorTemperature);
        writer.println("  mAmbientColorTemperatureHistory=" + mAmbientColorTemperatureHistory);
        writer.println("  mAmbientColorTemperatureOverride=" + mAmbientColorTemperatureOverride);
        writer.println("  mAmbientToDisplayTemperatureSpline="
                + (mAmbientToDisplayTemperatureSpline == null ? "unused" :
                    mAmbientToDisplayTemperatureSpline));
    }

    @Override // AmbientSensor.AmbientBrightnessSensor.Callbacks
@@ -250,6 +266,11 @@ public class DisplayWhiteBalanceController implements
        final long time = System.currentTimeMillis();
        float ambientColorTemperature = mColorTemperatureFilter.getEstimate(time);

        if (mAmbientToDisplayTemperatureSpline != null) {
            ambientColorTemperature =
                mAmbientToDisplayTemperatureSpline.interpolate(ambientColorTemperature);
        }

        final float ambientBrightness = mBrightnessFilter.getEstimate(time);
        if (ambientBrightness < mLowLightAmbientBrightnessThreshold) {
            if (mLoggingEnabled) {
+6 −1
Original line number Diff line number Diff line
@@ -67,9 +67,14 @@ public class DisplayWhiteBalanceFactory {
        final float lowLightAmbientColorTemperature = getFloat(resources,
                com.android.internal.R.dimen
                .config_displayWhiteBalanceLowLightAmbientColorTemperature);
        final float[] ambientTemperatures = getFloatArray(resources,
                com.android.internal.R.array.config_displayWhiteBalanceAmbientTemperatureValues);
        final float[] displayTemperatures = getFloatArray(resources,
                com.android.internal.R.array.config_displayWhiteBalanceDisplayTemperatureValues);
        final DisplayWhiteBalanceController controller = new DisplayWhiteBalanceController(
                brightnessSensor, brightnessFilter, colorTemperatureSensor, colorTemperatureFilter,
                throttler, lowLightAmbientBrightnessThreshold, lowLightAmbientColorTemperature);
                throttler, lowLightAmbientBrightnessThreshold, lowLightAmbientColorTemperature,
                ambientTemperatures, displayTemperatures);
        brightnessSensor.setCallbacks(controller);
        colorTemperatureSensor.setCallbacks(controller);
        return controller;