summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/com/android/internal/colorextraction/types/Tonal.java51
-rw-r--r--core/res/res/xml/color_extraction.xml107
-rw-r--r--tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java39
3 files changed, 2 insertions, 195 deletions
diff --git a/core/java/com/android/internal/colorextraction/types/Tonal.java b/core/java/com/android/internal/colorextraction/types/Tonal.java
index d6a8934566b2..9d85a039420c 100644
--- a/core/java/com/android/internal/colorextraction/types/Tonal.java
+++ b/core/java/com/android/internal/colorextraction/types/Tonal.java
@@ -56,7 +56,6 @@ public class Tonal implements ExtractionType {
private final TonalPalette mGreyPalette;
private final ArrayList<TonalPalette> mTonalPalettes;
- private final ArrayList<ColorRange> mBlacklistedColors;
// Temporary variable to avoid allocations
private float[] mTmpHSL = new float[3];
@@ -65,7 +64,6 @@ public class Tonal implements ExtractionType {
ConfigParser parser = new ConfigParser(context);
mTonalPalettes = parser.getTonalPalettes();
- mBlacklistedColors = parser.getBlacklistedColors();
mGreyPalette = mTonalPalettes.get(0);
mTonalPalettes.remove(0);
@@ -131,7 +129,7 @@ public class Tonal implements ExtractionType {
Color.blue(colorValue), hsl);
// Stop when we find a color that meets our criteria
- if (!generatedFromBitmap || !isBlacklisted(hsl)) {
+ if (!generatedFromBitmap) {
bestColor = color;
break;
}
@@ -300,22 +298,6 @@ public class Tonal implements ExtractionType {
return getColorPalette(palette.h, palette.s, palette.l);
}
-
- /**
- * Checks if a given color exists in the blacklist
- * @param hsl float array with 3 components (H 0..360, S 0..1 and L 0..1)
- * @return true if color should be avoided
- */
- private boolean isBlacklisted(float[] hsl) {
- for (int i = mBlacklistedColors.size() - 1; i >= 0; i--) {
- ColorRange badRange = mBlacklistedColors.get(i);
- if (badRange.containsColor(hsl[0], hsl[1], hsl[2])) {
- return true;
- }
- }
- return false;
- }
-
/**
* Offsets all colors by a delta, clamping values that go beyond what's
* supported on the color space.
@@ -364,11 +346,6 @@ public class Tonal implements ExtractionType {
return minErrorIndex;
}
- @VisibleForTesting
- public List<ColorRange> getBlacklistedColors() {
- return mBlacklistedColors;
- }
-
@Nullable
private TonalPalette findTonalPalette(float h, float s) {
// Fallback to a grey palette if the color is too desaturated.
@@ -502,11 +479,9 @@ public class Tonal implements ExtractionType {
@VisibleForTesting
public static class ConfigParser {
private final ArrayList<TonalPalette> mTonalPalettes;
- private final ArrayList<ColorRange> mBlacklistedColors;
public ConfigParser(Context context) {
mTonalPalettes = new ArrayList<>();
- mBlacklistedColors = new ArrayList<>();
// Load all palettes and the blacklist from an XML.
try {
@@ -520,8 +495,6 @@ public class Tonal implements ExtractionType {
String tagName = parser.getName();
if (tagName.equals("palettes")) {
parsePalettes(parser);
- } else if (tagName.equals("blacklist")) {
- parseBlacklist(parser);
}
} else {
throw new XmlPullParserException("Invalid XML event " + eventType + " - "
@@ -538,28 +511,6 @@ public class Tonal implements ExtractionType {
return mTonalPalettes;
}
- public ArrayList<ColorRange> getBlacklistedColors() {
- return mBlacklistedColors;
- }
-
- private void parseBlacklist(XmlPullParser parser)
- throws XmlPullParserException, IOException {
- parser.require(XmlPullParser.START_TAG, null, "blacklist");
- while (parser.next() != XmlPullParser.END_TAG) {
- if (parser.getEventType() != XmlPullParser.START_TAG) {
- continue;
- }
- String name = parser.getName();
- // Starts by looking for the entry tag
- if (name.equals("range")) {
- mBlacklistedColors.add(readRange(parser));
- parser.next();
- } else {
- throw new XmlPullParserException("Invalid tag: " + name, parser, null);
- }
- }
- }
-
private ColorRange readRange(XmlPullParser parser)
throws XmlPullParserException, IOException {
parser.require(XmlPullParser.START_TAG, null, "range");
diff --git a/core/res/res/xml/color_extraction.xml b/core/res/res/xml/color_extraction.xml
index 93ab0ff26754..c3ebe4e7c478 100644
--- a/core/res/res/xml/color_extraction.xml
+++ b/core/res/res/xml/color_extraction.xml
@@ -246,109 +246,4 @@
0.6549019607843137,0.7549019607843137,0.8509803921568627,
0.9411764705882353"/>
</palettes>
- <blacklist>
- <!-- Red -->
- <range h="0, 20"
- s="0.7, 1"
- l="0.21, 0.79"/>
- <range h="0, 20"
- s="0.3, 0.7"
- l="0.355, 0.653"/>
- <!-- Red Orange -->
- <range h="20, 40"
- s="0.7, 1"
- l="0.2, 0.643"/>
- <range h="20, 40"
- s="0.3, 0.7"
- l="0.414, 0.561"/>
- <range h="20, 40"
- s="0, 0.3"
- l="0.343, 0.584"/>
- <!-- Orange -->
- <range h="40, 60"
- s="0.7, 1"
- l="0.173, 0.38"/>
- <range h="40, 60"
- s="0.3, 0.7"
- l="0.233, 0.427"/>
- <range h="40, 60"
- s="0, 0.3"
- l="0.231, 0.48"/>
- <!-- Yellow 60 -->
- <range h="60, 80"
- s="0.7, 1"
- l="0.15, 0.40"/>
- <range h="60, 80"
- s="0.3, 0.7"
- l="0.15, 0.42"/>
- <range h="60, 80"
- s="0, 0.3"
- l="0.35, 0.57"/>
- <!-- Yellow Green 80 -->
- <range h="80, 100"
- s="0.7, 1"
- l="0.36, 0.65"/>
- <range h="80, 100"
- s="0.3, 0.7"
- l="0.48, 0.57"/>
- <!-- Yellow green 100 -->
- <range h="100, 120"
- s="0.7, 1"
- l="0.388, 0.67"/>
- <range h="100, 120"
- s="0.3, 0.7"
- l="0.424, 0.58"/>
- <!-- Green -->
- <range h="120, 140"
- s="0.7, 1"
- l="0.37, 0.65"/>
- <range h="120, 140"
- s="0.3, 0.7"
- l="0.435, 0.58"/>
- <!-- Green Blue 140 -->
- <range h="140, 160"
- s="0.7, 1"
- l="0.43, 0.641"/>
- <!-- Seaoam -->
- <range h="160, 180"
- s="0.7, 1"
- l="0.496, 0.567"/>
- <!-- Cyan -->
- <range h="180, 200"
- s="0.7, 1"
- l="0.52, 0.729"/>
- <!-- Blue -->
- <range h="220, 240"
- s="0.7, 1"
- l="0.396, 0.571"/>
- <range h="220, 240"
- s="0.3, 0.7"
- l="0.425, 0.551"/>
- <!-- Blue Purple 240 -->
- <range h="240, 260"
- s="0.7, 1"
- l="0.418, 0.639"/>
- <range h="220, 240"
- s="0.3, 0.7"
- l="0.441, 0.576"/>
- <!-- Blue Purple 260 -->
- <range h="260, 280"
- s="0.3, 1"
- l="0.461, 0.553"/>
- <!-- Fuchsia -->
- <range h="300, 320"
- s="0.7, 1"
- l="0.484, 0.588"/>
- <range h="300, 320"
- s="0.3, 0.7"
- l="0.48, 0.592"/>
- <!-- Pink -->
- <range h="320, 340"
- s="0.7, 1"
- l="0.466, 0.629"/>
- <!-- Soft red -->
- <range h="340, 360"
- s="0.7, 1"
- l="0.437, 0.596"/>
- </blacklist>
-</colorextraction> \ No newline at end of file
+</colorextraction>
diff --git a/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java b/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java
index d92cfce0379b..300182dd5791 100644
--- a/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java
+++ b/tests/Internal/src/com/android/internal/colorextraction/types/TonalTest.java
@@ -27,7 +27,6 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.colorextraction.ColorExtractor.GradientColors;
-import com.android.internal.graphics.ColorUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -96,7 +95,6 @@ public class TonalTest {
Tonal.ConfigParser config = new Tonal.ConfigParser(InstrumentationRegistry.getContext());
// 1 to avoid regression where only first item would be parsed.
assertTrue("Tonal palettes are empty", config.getTonalPalettes().size() > 1);
- assertTrue("Blacklisted colors are empty", config.getBlacklistedColors().size() > 1);
}
@Test
@@ -113,41 +111,4 @@ public class TonalTest {
assertTrue("L should be <= to 1.", palette.l[1] <= 1);
}
}
-
- @Test
- public void tonal_blacklistTest() {
- // Make sure that palette generation will fail.
- final Tonal tonal = new Tonal(InstrumentationRegistry.getContext());
-
- // Creating a WallpaperColors object that contains *only* blacklisted colors.
- final float[] hsl = tonal.getBlacklistedColors().get(0).getCenter();
- final int blacklistedColor = ColorUtils.HSLToColor(hsl);
- WallpaperColors colorsFromBitmap = new WallpaperColors(Color.valueOf(blacklistedColor),
- null, null, WallpaperColors.HINT_FROM_BITMAP);
-
- // Make sure that palette generation will fail
- final GradientColors normal = new GradientColors();
- tonal.extractInto(colorsFromBitmap, normal, new GradientColors(),
- new GradientColors());
- assertTrue("Cannot generate a tonal palette from blacklisted colors.",
- normal.getMainColor() == Tonal.MAIN_COLOR_DARK);
- }
-
- @Test
- public void tonal_ignoreBlacklistTest() {
- final Tonal tonal = new Tonal(InstrumentationRegistry.getContext());
-
- // Creating a WallpaperColors object that contains *only* blacklisted colors.
- final float[] hsl = tonal.getBlacklistedColors().get(0).getCenter();
- final int blacklistedColor = ColorUtils.HSLToColor(hsl);
- WallpaperColors colors = new WallpaperColors(Color.valueOf(blacklistedColor),
- null, null);
-
- // Blacklist should be ignored when HINT_FROM_BITMAP isn't present.
- final GradientColors normal = new GradientColors();
- tonal.extractInto(colors, normal, new GradientColors(),
- new GradientColors());
- assertTrue("Blacklist should never be used on WallpaperColors generated using "
- + "default constructor.", normal.getMainColor() == blacklistedColor);
- }
}