Merge changes I080e6cb5,I4c2d76c9,I295ef3a6 into sc-v2-dev

* changes:
  [CP] Adjust chroma/lstar filters for seed colors
  [CP] If there are > 4 colors, maximize difference
  [CP] Use chroma max of 40 at tone 90
This commit is contained in:
James O'Leary
2021-09-23 19:39:47 +00:00
committed by Android (Google) Code Review
2 changed files with 39 additions and 22 deletions

View File

@@ -37,8 +37,7 @@ const val NEUTRAL2_CHROMA = 8.0f
const val GOOGLE_BLUE = 0xFF1b6ef3.toInt() const val GOOGLE_BLUE = 0xFF1b6ef3.toInt()
const val MIN_CHROMA = 15 const val MIN_CHROMA = 5
const val MIN_LSTAR = 10
public class ColorScheme(@ColorInt seed: Int, val darkTheme: Boolean) { public class ColorScheme(@ColorInt seed: Int, val darkTheme: Boolean) {
@@ -75,7 +74,14 @@ public class ColorScheme(@ColorInt seed: Int, val darkTheme: Boolean) {
get() = ColorUtils.setAlphaComponent(if (darkTheme) accent1[2] else accent1[6], 0xFF) get() = ColorUtils.setAlphaComponent(if (darkTheme) accent1[2] else accent1[6], 0xFF)
init { init {
val seedArgb = if (seed == Color.TRANSPARENT) GOOGLE_BLUE else seed val proposedSeedCam = Cam.fromInt(seed)
val seedArgb = if (seed == Color.TRANSPARENT) {
GOOGLE_BLUE
} else if (proposedSeedCam.chroma < 5) {
GOOGLE_BLUE
} else {
seed
}
val camSeed = Cam.fromInt(seedArgb) val camSeed = Cam.fromInt(seedArgb)
val hue = camSeed.hue val hue = camSeed.hue
val chroma = camSeed.chroma.coerceAtLeast(ACCENT1_CHROMA) val chroma = camSeed.chroma.coerceAtLeast(ACCENT1_CHROMA)
@@ -129,9 +135,7 @@ public class ColorScheme(@ColorInt seed: Int, val darkTheme: Boolean) {
val distinctColors = wallpaperColors.mainColors.map { val distinctColors = wallpaperColors.mainColors.map {
it.toArgb() it.toArgb()
}.distinct().filter { }.distinct().filter {
val cam = Cam.fromInt(it) Cam.fromInt(it).chroma >= MIN_CHROMA
val lstar = lstarFromInt(it)
cam.chroma >= MIN_CHROMA && lstar >= MIN_LSTAR
}.toList() }.toList()
if (distinctColors.isEmpty()) { if (distinctColors.isEmpty()) {
@@ -164,30 +168,38 @@ public class ColorScheme(@ColorInt seed: Int, val darkTheme: Boolean) {
val cam = it.value val cam = it.value
val lstar = lstarFromInt(it.key) val lstar = lstarFromInt(it.key)
val proportion = intToHueProportion[it.key]!! val proportion = intToHueProportion[it.key]!!
cam.chroma >= MIN_CHROMA && lstar >= MIN_LSTAR && cam.chroma >= MIN_CHROMA &&
(totalPopulationMeaningless || proportion > 0.01) (totalPopulationMeaningless || proportion > 0.01)
} }
// Sort the colors by score, from high to low. // Sort the colors by score, from high to low.
val seeds = mutableListOf<Int>()
val intToScoreIntermediate = filteredIntToCam.mapValues { val intToScoreIntermediate = filteredIntToCam.mapValues {
score(it.value, intToHueProportion[it.key]!!) score(it.value, intToHueProportion[it.key]!!)
} }
val intToScore = intToScoreIntermediate.entries.toMutableList() val intToScore = intToScoreIntermediate.entries.toMutableList()
intToScore.sortByDescending { it.value } intToScore.sortByDescending { it.value }
// Go through the colors, from high score to low score. If there isn't already a seed // Go through the colors, from high score to low score.
// color with a hue close to color being examined, add the color being examined to the // If the color is distinct in hue from colors picked so far, pick the color.
// seed colors. // Iteratively decrease the amount of hue distinctness required, thus ensuring we
// maximize difference between colors.
val minimumHueDistance = 15
val seeds = mutableListOf<Int>()
maximizeHueDistance@ for (i in 90 downTo minimumHueDistance step 1) {
seeds.clear()
for (entry in intToScore) { for (entry in intToScore) {
val int = entry.key val int = entry.key
val existingSeedNearby = seeds.find { val existingSeedNearby = seeds.find {
val hueA = intToCam[int]!!.hue val hueA = intToCam[int]!!.hue
val hueB = intToCam[it]!!.hue val hueB = intToCam[it]!!.hue
hueDiff(hueA, hueB) < 15 } != null hueDiff(hueA, hueB) < i } != null
if (existingSeedNearby) { if (existingSeedNearby) {
continue continue
} }
seeds.add(int) seeds.add(int)
if (seeds.size >= 4) {
break@maximizeHueDistance
}
}
} }
if (seeds.isEmpty()) { if (seeds.isEmpty()) {

View File

@@ -53,10 +53,15 @@ public class Shades {
*/ */
public static @ColorInt int[] of(float hue, float chroma) { public static @ColorInt int[] of(float hue, float chroma) {
int[] shades = new int[12]; int[] shades = new int[12];
shades[0] = ColorUtils.CAMToColor(hue, chroma, 99); // At tone 90 and above, blue and yellow hues can reach a much higher chroma.
shades[1] = ColorUtils.CAMToColor(hue, chroma, 95); // To preserve a consistent appearance across all hues, use a maximum chroma of 40.
shades[0] = ColorUtils.CAMToColor(hue, Math.min(40f, chroma), 99);
shades[1] = ColorUtils.CAMToColor(hue, Math.min(40f, chroma), 95);
for (int i = 2; i < 12; i++) { for (int i = 2; i < 12; i++) {
float lStar = (i == 6) ? MIDDLE_LSTAR : 100 - 10 * (i - 1); float lStar = (i == 6) ? MIDDLE_LSTAR : 100 - 10 * (i - 1);
if (lStar >= 90) {
chroma = Math.min(40f, chroma);
}
shades[i] = ColorUtils.CAMToColor(hue, chroma, lStar); shades[i] = ColorUtils.CAMToColor(hue, chroma, lStar);
} }
return shades; return shades;