cmsdk/livedisplay: Add support for picture adjustment

* Allows adjustment of hue, saturation, intensity, and contrast.

Change-Id: Icf8ff6200a07b68e09dcd7f140a82e57b53944f7
This commit is contained in:
Steve Kondik
2016-07-20 11:20:02 -07:00
parent 3e7dac120a
commit 87590f0b1e
14 changed files with 835 additions and 8 deletions

View File

@@ -23,6 +23,7 @@ import android.util.Log;
import android.util.Range;
import cyanogenmod.app.CMContextConstants;
import cyanogenmod.hardware.HSIC;
import java.io.UnsupportedEncodingException;
import java.lang.IllegalArgumentException;
@@ -135,6 +136,12 @@ public final class CMHardwareManager {
*/
public static final int FEATURE_COLOR_BALANCE = 0x20000;
/**
* HSIC picture adjustment
*/
public static final int FEATURE_PICTURE_ADJUSTMENT = 0x40000;
private static final List<Integer> BOOLEAN_FEATURES = Arrays.asList(
FEATURE_ADAPTIVE_BACKLIGHT,
FEATURE_COLOR_ENHANCEMENT,
@@ -809,6 +816,9 @@ public final class CMHardwareManager {
return false;
}
/**
* @return the available range for color temperature adjustments
*/
public Range<Integer> getColorBalanceRange() {
int min = 0;
int max = 0;
@@ -822,6 +832,9 @@ public final class CMHardwareManager {
return new Range<Integer>(min, max);
}
/**
* @return the current color balance value
*/
public int getColorBalance() {
try {
if (checkService()) {
@@ -832,6 +845,13 @@ public final class CMHardwareManager {
return 0;
}
/**
* Sets the desired color balance. Must fall within the range obtained from
* getColorBalanceRange()
*
* @param value
* @return true if success
*/
public boolean setColorBalance(int value) {
try {
if (checkService()) {
@@ -842,6 +862,76 @@ public final class CMHardwareManager {
return false;
}
/**
* Gets the current picture adjustment values
*
* @return HSIC object with current settings
*/
public HSIC getPictureAdjustment() {
try {
if (checkService()) {
return sService.getPictureAdjustment();
}
} catch (RemoteException e) {
}
return null;
}
/**
* Gets the default picture adjustment for the current mode
*
* @return HSIC object with default settings
*/
public HSIC getDefaultPictureAdjustment() {
try {
if (checkService()) {
return sService.getDefaultPictureAdjustment();
}
} catch (RemoteException e) {
}
return null;
}
/**
* Sets the desired hue/saturation/intensity/contrast
*
* @param hsic
* @return true if success
*/
public boolean setPictureAdjustment(final HSIC hsic) {
try {
if (checkService()) {
return sService.setPictureAdjustment(hsic);
}
} catch (RemoteException e) {
}
return false;
}
/**
* Get a list of ranges valid for picture adjustment.
*
* @return range list
*/
public List<Range<Float>> getPictureAdjustmentRanges() {
try {
if (checkService()) {
float[] ranges = sService.getPictureAdjustmentRanges();
if (ranges.length > 7) {
return Arrays.asList(new Range<Float>(ranges[0], ranges[1]),
new Range<Float>(ranges[2], ranges[3]),
new Range<Float>(ranges[4], ranges[5]),
new Range<Float>(ranges[6], ranges[7]),
(ranges.length > 9 ?
new Range<Float>(ranges[8], ranges[9]) :
new Range<Float>(0.0f, 0.0f)));
}
}
} catch (RemoteException e) {
}
return null;
}
/**
* @return true if service is valid
*/

View File

@@ -0,0 +1,19 @@
/*
* Copyright (C) 2015 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cyanogenmod.hardware;
parcelable HSIC;

View File

@@ -0,0 +1,127 @@
/*
* Copyright (C) 2016 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cyanogenmod.hardware;
import android.graphics.Color;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
public class HSIC implements Parcelable {
private final float mHue;
private final float mSaturation;
private final float mIntensity;
private final float mContrast;
private final float mSaturationThreshold;
public HSIC(float hue, float saturation, float intensity,
float contrast, float saturationThreshold) {
mHue = hue;
mSaturation = saturation;
mIntensity = intensity;
mContrast = contrast;
mSaturationThreshold = saturationThreshold;
}
public float getHue() {
return mHue;
}
public float getSaturation() {
return mSaturation;
}
public float getIntensity() {
return mIntensity;
}
public float getContrast() {
return mContrast;
}
public float getSaturationThreshold() {
return mSaturationThreshold;
}
public String flatten() {
return String.format("%f|%f|%f|%f|%f", mHue, mSaturation,
mIntensity, mContrast, mSaturationThreshold);
}
public static HSIC unflattenFrom(String flat) throws NumberFormatException {
final String[] unflat = TextUtils.split(flat, "\\|");
if (unflat.length != 4 && unflat.length != 5) {
throw new NumberFormatException("Failed to unflatten HSIC values: " + flat);
}
return new HSIC(Float.valueOf(unflat[0]), Float.valueOf(unflat[1]),
Float.valueOf(unflat[2]), Float.valueOf(unflat[3]),
unflat.length == 5 ? Float.valueOf(unflat[4]) : 0.0f);
}
public int[] toRGB() {
final int c = Color.HSVToColor(toFloatArray());
return new int[] { Color.red(c), Color.green(c), Color.blue(c) };
}
public float[] toFloatArray() {
return new float[] { mHue, mSaturation, mIntensity, mContrast, mSaturationThreshold };
}
public static HSIC fromFloatArray(float[] hsic) {
if (hsic.length == 5) {
return new HSIC(hsic[0], hsic[1], hsic[2], hsic[3], hsic[4]);
} else if (hsic.length == 4) {
return new HSIC(hsic[0], hsic[1], hsic[2], hsic[3], 0.0f);
}
return null;
}
@Override
public String toString() {
return String.format("HSIC={ hue=%f saturation=%f intensity=%f " +
"contrast=%f saturationThreshold=%f }",
mHue, mSaturation, mIntensity, mContrast, mSaturationThreshold);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeFloatArray(toFloatArray());
}
/**
* @hide
*/
public static final Parcelable.Creator<HSIC> CREATOR =
new Parcelable.Creator<HSIC>() {
public HSIC createFromParcel(Parcel in) {
float[] fromParcel = new float[5];
in.readFloatArray(fromParcel);
return HSIC.fromFloatArray(fromParcel);
}
@Override
public HSIC[] newArray(int size) {
return new HSIC[size];
}
};
};

View File

@@ -17,6 +17,7 @@
package cyanogenmod.hardware;
import cyanogenmod.hardware.DisplayMode;
import cyanogenmod.hardware.HSIC;
import cyanogenmod.hardware.IThermalListenerCallback;
/** @hide */
@@ -63,4 +64,10 @@ interface ICMHardwareService {
int getColorBalanceMax();
int getColorBalance();
boolean setColorBalance(int value);
HSIC getPictureAdjustment();
HSIC getDefaultPictureAdjustment();
boolean setPictureAdjustment(in HSIC hsic);
float[] getPictureAdjustmentRanges();
}

View File

@@ -16,6 +16,7 @@
package cyanogenmod.hardware;
import cyanogenmod.hardware.HSIC;
import cyanogenmod.hardware.LiveDisplayConfig;
/** @hide */
@@ -47,4 +48,8 @@ interface ILiveDisplayService {
boolean isAutomaticOutdoorModeEnabled();
boolean setAutomaticOutdoorModeEnabled(boolean enabled);
HSIC getPictureAdjustment();
HSIC getDefaultPictureAdjustment();
boolean setPictureAdjustment(in HSIC adj);
}

View File

@@ -15,6 +15,7 @@
*/
package cyanogenmod.hardware;
import static cyanogenmod.hardware.LiveDisplayManager.FEATURE_COLOR_BALANCE;
import static cyanogenmod.hardware.LiveDisplayManager.FEATURE_FIRST;
import static cyanogenmod.hardware.LiveDisplayManager.FEATURE_LAST;
import static cyanogenmod.hardware.LiveDisplayManager.MODE_FIRST;
@@ -25,7 +26,9 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.util.Range;
import java.util.Arrays;
import java.util.BitSet;
import java.util.List;
import cyanogenmod.os.Build;
import cyanogenmod.os.Concierge;
@@ -53,13 +56,23 @@ public class LiveDisplayConfig implements Parcelable {
private final Range<Integer> mColorTemperatureRange;
private final Range<Integer> mColorBalanceRange;
private final Range<Float> mHueRange;
private final Range<Float> mSaturationRange;
private final Range<Float> mIntensityRange;
private final Range<Float> mContrastRange;
private final Range<Float> mSaturationThresholdRange;
public LiveDisplayConfig(BitSet capabilities, int defaultMode,
int defaultDayTemperature, int defaultNightTemperature,
boolean defaultAutoOutdoorMode, boolean defaultAutoContrast,
boolean defaultCABC, boolean defaultColorEnhancement,
Range<Integer> colorTemperatureRange,
Range<Integer> colorBalanceRange) {
Range<Integer> colorBalanceRange,
Range<Float> hueRange,
Range<Float> saturationRange,
Range<Float> intensityRange,
Range<Float> contrastRange,
Range<Float> saturationThresholdRange) {
super();
mCapabilities = (BitSet) capabilities.clone();
mAllModes.set(MODE_FIRST, MODE_LAST);
@@ -72,6 +85,11 @@ public class LiveDisplayConfig implements Parcelable {
mDefaultColorEnhancement = defaultColorEnhancement;
mColorTemperatureRange = colorTemperatureRange;
mColorBalanceRange = colorBalanceRange;
mHueRange = hueRange;
mSaturationRange = saturationRange;
mIntensityRange = intensityRange;
mContrastRange = contrastRange;
mSaturationThresholdRange = saturationThresholdRange;
}
private LiveDisplayConfig(Parcel parcel) {
@@ -92,6 +110,7 @@ public class LiveDisplayConfig implements Parcelable {
int maxColorTemperature = 0;
int minColorBalance = 0;
int maxColorBalance = 0;
float[] paRanges = new float[10];
if (parcelableVersion >= Build.CM_VERSION_CODES.FIG) {
capabilities = parcel.readLong();
@@ -106,6 +125,7 @@ public class LiveDisplayConfig implements Parcelable {
maxColorTemperature = parcel.readInt();
minColorBalance = parcel.readInt();
maxColorBalance = parcel.readInt();
parcel.readFloatArray(paRanges);
}
// set temps
@@ -120,6 +140,11 @@ public class LiveDisplayConfig implements Parcelable {
mDefaultColorEnhancement = defaultColorEnhancement;
mColorTemperatureRange = Range.create(minColorTemperature, maxColorTemperature);
mColorBalanceRange = Range.create(minColorBalance, maxColorBalance);
mHueRange = Range.create(paRanges[0], paRanges[1]);
mSaturationRange = Range.create(paRanges[2], paRanges[3]);
mIntensityRange = Range.create(paRanges[4], paRanges[5]);
mContrastRange = Range.create(paRanges[6], paRanges[7]);
mSaturationThresholdRange = Range.create(paRanges[8], paRanges[9]);
// Complete parcel info for the concierge
parcelInfo.complete();
@@ -137,7 +162,16 @@ public class LiveDisplayConfig implements Parcelable {
sb.append(" defaultCABC=").append(mDefaultCABC);
sb.append(" defaultColorEnhancement=").append(mDefaultColorEnhancement);
sb.append(" colorTemperatureRange=").append(mColorTemperatureRange);
sb.append(" colorBalanceRange=").append(mColorBalanceRange);
if (mCapabilities.get(LiveDisplayManager.FEATURE_COLOR_BALANCE)) {
sb.append(" colorBalanceRange=").append(mColorBalanceRange);
}
if (mCapabilities.get(LiveDisplayManager.FEATURE_PICTURE_ADJUSTMENT)) {
sb.append(" hueRange=").append(mHueRange);
sb.append(" saturationRange=").append(mSaturationRange);
sb.append(" intensityRange=").append(mIntensityRange);
sb.append(" contrastRange=").append(mContrastRange);
sb.append(" saturationThresholdRange=").append(mSaturationThresholdRange);
}
return sb.toString();
}
@@ -165,6 +199,12 @@ public class LiveDisplayConfig implements Parcelable {
out.writeInt(mColorTemperatureRange.getUpper());
out.writeInt(mColorBalanceRange.getLower());
out.writeInt(mColorBalanceRange.getUpper());
out.writeFloatArray(new float[] {
mHueRange.getLower(), mHueRange.getUpper(),
mSaturationRange.getLower(), mSaturationRange.getUpper(),
mIntensityRange.getLower(), mIntensityRange.getUpper(),
mContrastRange.getLower(), mContrastRange.getUpper(),
mSaturationThresholdRange.getLower(), mSaturationThresholdRange.getUpper() } );
// Complete the parcel info for the concierge
parcelInfo.complete();
@@ -285,6 +325,55 @@ public class LiveDisplayConfig implements Parcelable {
return mColorBalanceRange;
}
/**
* Get the supported range for hue adjustment
*
* @return float range
*/
public Range<Float> getHueRange() { return mHueRange; }
/**
* Get the supported range for saturation adjustment
*
* @return float range
*/
public Range<Float> getSaturationRange() { return mSaturationRange; }
/**
* Get the supported range for intensity adjustment
*
* @return float range
*/
public Range<Float> getIntensityRange() { return mIntensityRange; }
/**
* Get the supported range for contrast adjustment
*
* @return float range
*/
public Range<Float> getContrastRange() { return mContrastRange; }
/**
* Get the supported range for saturation threshold adjustment
*
* @return float range
*/
public Range<Float> getSaturationThresholdRange() {
return mSaturationThresholdRange;
}
/**
* Convenience method to get a list of all picture adjustment ranges
* with a single call.
*
* @return List of float ranges
*/
public List<Range<Float>> getPictureAdjustmentRanges() {
return Arrays.asList(mHueRange, mSaturationRange, mIntensityRange,
mContrastRange, mSaturationThresholdRange);
}
/** @hide */
public static final Parcelable.Creator<LiveDisplayConfig> CREATOR =
new Parcelable.Creator<LiveDisplayConfig>() {

View File

@@ -20,6 +20,11 @@ import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;
import android.util.Range;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import cyanogenmod.app.CMContextConstants;
@@ -109,10 +114,21 @@ public class LiveDisplayManager {
*/
public static final int FEATURE_COLOR_BALANCE = 16;
/**
* System supports manual hue/saturation/intensity/contrast
* adjustment of display.
*/
public static final int FEATURE_PICTURE_ADJUSTMENT = 17;
public static final int ADJUSTMENT_HUE = 0;
public static final int ADJUSTMENT_SATURATION = 1;
public static final int ADJUSTMENT_INTENSITY = 2;
public static final int ADJUSTMENT_CONTRAST = 3;
/** @hide */
public static final int FEATURE_FIRST = FEATURE_CABC;
/** @hide */
public static final int FEATURE_LAST = FEATURE_COLOR_BALANCE;
public static final int FEATURE_LAST = FEATURE_PICTURE_ADJUSTMENT;
private static final String TAG = "LiveDisplay";
@@ -422,4 +438,48 @@ public class LiveDisplayManager {
return false;
}
}
/**
* Gets the current picture adjustment settings (hue, saturation, intensity, contrast)
*
* @return HSIC object with current settings
*/
public HSIC getPictureAdjustment() {
try {
if (checkService()) {
return sService.getPictureAdjustment();
}
} catch (RemoteException e) {
}
return null;
}
/**
* Sets a new picture adjustment
*
* @param hsic
* @return true if success
*/
public boolean setPictureAdjustment(final HSIC hsic) {
try {
return checkService() && sService.setPictureAdjustment(hsic);
} catch (RemoteException e) {
}
return false;
}
/**
* Gets the default picture adjustment for the current display mode
*
* @return HSIC object with default values
*/
public HSIC getDefaultPictureAdjustment() {
try {
if (checkService()) {
return sService.getDefaultPictureAdjustment();
}
} catch (RemoteException e) {
}
return null;
}
}

View File

@@ -1822,6 +1822,31 @@ public final class CMSettings {
public static final Validator TOUCHSCREEN_GESTURE_HAPTIC_FEEDBACK_VALIDATOR =
sBooleanValidator;
/**
* The current custom picture adjustment values as a delimited string
*/
public static final String DISPLAY_PICTURE_ADJUSTMENT =
"display_picture_adjustment";
/** @hide */
public static final Validator DISPLAY_PICTURE_ADJUSTMENT_VALIDATOR =
new Validator() {
@Override
public boolean validate(String value) {
if (TextUtils.isEmpty(value)) {
return true;
}
final String[] sp = TextUtils.split(value, ",");
for (String s : sp) {
final String[] sp2 = TextUtils.split(s, ":");
if (sp2.length != 2) {
return false;
}
}
return true;
}
};
/**
* I can haz more bukkits
* @hide
@@ -2087,6 +2112,8 @@ public final class CMSettings {
VALIDATORS.put(ZEN_PRIORITY_ALLOW_LIGHTS, ZEN_PRIORITY_ALLOW_LIGHTS_VALIDATOR);
VALIDATORS.put(TOUCHSCREEN_GESTURE_HAPTIC_FEEDBACK,
TOUCHSCREEN_GESTURE_HAPTIC_FEEDBACK_VALIDATOR);
VALIDATORS.put(DISPLAY_PICTURE_ADJUSTMENT,
DISPLAY_PICTURE_ADJUSTMENT_VALIDATOR);
VALIDATORS.put(__MAGICAL_TEST_PASSING_ENABLER,
__MAGICAL_TEST_PASSING_ENABLER_VALIDATOR);
};

View File

@@ -307,8 +307,8 @@ public class ColorUtils {
* Convert a color temperature value (in Kelvin) to a RGB units as floats.
* This can be used in a transform matrix or hardware gamma control.
*
* @param tempK
* @return
* @param degreesK
* @return array of floats representing rgb values 0->1
*/
public static float[] temperatureToRGB(int degreesK) {
int k = MathUtils.constrain(degreesK, 1000, 20000);