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

Commit 62918fe1 authored by James O'Leary's avatar James O'Leary
Browse files

Fix error computing tertiary hue

After adding 60 degrees to the hue, the result needs to be normalized to
0 to 360. Code downstream of Shades.of does not perform the
normalization, so the resulting color will be the result of undefined
behavior.

Test: `atest ColorSchemeTest`, newly added testTertiaryHueWrapsProperly
passes.
Bug: 204463343

Change-Id: I93168c98ba64fb865888469220571dc6d437105d
parent 62924f12
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -85,9 +85,10 @@ public class ColorScheme(@ColorInt seed: Int, val darkTheme: Boolean) {
        val camSeed = Cam.fromInt(seedArgb)
        val hue = camSeed.hue
        val chroma = camSeed.chroma.coerceAtLeast(ACCENT1_CHROMA)
        val tertiaryHue = wrapDegrees((hue + ACCENT3_HUE_SHIFT).toInt())
        accent1 = Shades.of(hue, chroma).toList()
        accent2 = Shades.of(hue, ACCENT2_CHROMA).toList()
        accent3 = Shades.of(hue + ACCENT3_HUE_SHIFT, ACCENT3_CHROMA).toList()
        accent3 = Shades.of(tertiaryHue.toFloat(), ACCENT3_CHROMA).toList()
        neutral1 = Shades.of(hue, NEUTRAL1_CHROMA).toList()
        neutral2 = Shades.of(hue, NEUTRAL2_CHROMA).toList()
    }
+10 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.testing.AndroidTestingRunner;

import androidx.test.filters.SmallTest;

import com.android.internal.graphics.cam.Cam;
import com.android.systemui.SysuiTestCase;

import org.junit.Assert;
@@ -90,4 +91,13 @@ public class ColorSchemeTest extends SysuiTestCase {
        List<Integer> rankedSeedColors = ColorScheme.getSeedColors(wallpaperColors);
        Assert.assertEquals(rankedSeedColors, List.of(0xffaec00a, 0xffbe0000, 0xffcc040f));
    }

    @Test
    public void testTertiaryHueWrapsProperly() {
        int colorInt = 0xffB3588A; // H350 C50 T50
        ColorScheme colorScheme = new ColorScheme(colorInt, false /* darkTheme */);
        int tertiaryMid = colorScheme.getAccent3().get(colorScheme.getAccent3().size() / 2);
        Cam cam = Cam.fromInt(tertiaryMid);
        Assert.assertEquals(cam.getHue(), 50.0, 10.0);
    }
}