Connect ColorStateList to CAM
ColorStateList recently added an attribute, lStar, that means the color should have its perceptual luminance adjusted. The color appearance model library transforms the given color to one with the desired luminance. Test: added new test to ColorStateListTest, ran atest locally, tests passed. (no link, atest/my build is broken, can't upload results) Bug: 186640057 Change-Id: I5252b7c03d76ec1f0a7ca97cd671e8ea63d4b88b
This commit is contained in:
@@ -35,6 +35,7 @@ import android.util.Xml;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.graphics.ColorUtils;
|
||||
import com.android.internal.graphics.cam.Cam;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.internal.util.GrowingArrayUtils;
|
||||
|
||||
@@ -555,9 +556,8 @@ public class ColorStateList extends ComplexColor implements Parcelable {
|
||||
final int alpha = MathUtils.constrain((int) (baseAlpha * alphaMod + 0.5f), 0, 255);
|
||||
|
||||
if (validLStar) {
|
||||
final double[] labColor = new double[3];
|
||||
ColorUtils.colorToLAB(baseColor, labColor);
|
||||
baseColor = ColorUtils.LABToColor(lStar, labColor[1], labColor[2]);
|
||||
final Cam baseCam = ColorUtils.colorToCAM(baseColor);
|
||||
baseColor = ColorUtils.CAMToColor(baseCam.getHue(), baseCam.getChroma(), lStar);
|
||||
}
|
||||
|
||||
return (baseColor & 0xFFFFFF) | (alpha << 24);
|
||||
|
||||
20
core/tests/coretests/res/color/color_with_lstar.xml
Normal file
20
core/tests/coretests/res/color/color_with_lstar.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2021 The Android Open Source 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.
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="#ff0000" android:lStar="50" />
|
||||
</selector>
|
||||
@@ -25,5 +25,6 @@
|
||||
<drawable name="yellow">#ffffff00</drawable>
|
||||
<color name="testcolor1">#ff00ff00</color>
|
||||
<color name="testcolor2">#ffff0000</color>
|
||||
<color name="testcolor3">#fff00000</color>
|
||||
<color name="failColor">#ff0000ff</color>
|
||||
</resources>
|
||||
|
||||
@@ -67,4 +67,10 @@ public class ColorStateListTest extends AndroidTestCase {
|
||||
int defaultColor = mResources.getColor(R.color.color_no_default);
|
||||
assertEquals(mResources.getColor(R.color.testcolor1), defaultColor);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testLstar() throws Exception {
|
||||
int defaultColor = mResources.getColor(R.color.color_with_lstar);
|
||||
assertEquals(mResources.getColor(R.color.testcolor3), defaultColor);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user