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

Commit a23d0548 authored by James O'Leary's avatar James O'Leary
Browse files

Color appearance model library

Create colors using CAM16 hue and chroma, L*a*b* L*,
and map them to RGB without distortion.

Test: atest FrameworksCoreTests:com.android.internal.graphics.cam
.CamTest, all passed. No link, atest/my build are broken and cannot
upload results.
Bug: 186640057
Change-Id: I64b605dd452d64e57be0047d2e4672917c01c2a8
parent a54b7154
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.annotation.IntRange;
import android.annotation.NonNull;
import android.graphics.Color;

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

/**
 * Copied from: frameworks/support/core-utils/java/android/support/v4/graphics/ColorUtils.java
 *
@@ -332,6 +334,35 @@ public final class ColorUtils {
        return Color.rgb(r, g, b);
    }

    /**
     * Convert the ARGB color to a color appearance model.
     *
     * The color appearance model is based on CAM16 hue and chroma, using L*a*b*'s L* as the
     * third dimension.
     *
     * @param color the ARGB color to convert. The alpha component is ignored.
     */
    public static Cam colorToCAM(@ColorInt int color) {
        return Cam.fromInt(color);
    }

    /**
     * Convert a color appearance model representation to an ARGB color.
     *
     * Note: the returned color may have a lower chroma than requested. Whether a chroma is
     * available depends on luminance. For example, there's no such thing as a high chroma light
     * red, due to the limitations of our eyes and/or physics. If the requested chroma is
     * unavailable, the highest possible chroma at the requested luminance is returned.
     *
     * @param hue hue, in degrees, in CAM coordinates
     * @param chroma chroma in CAM coordinates.
     * @param lstar perceptual luminance, L* in L*a*b*
     */
    @ColorInt
    public static int CAMToColor(float hue, float chroma, float lstar) {
        return Cam.getInt(hue, chroma, lstar);
    }

    /**
     * Set the alpha component of {@code color} to be {@code alpha}.
     */
+509 −0

File added.

Preview size limit exceeded, changes collapsed.

+165 −0

File added.

Preview size limit exceeded, changes collapsed.

+194 −0

File added.

Preview size limit exceeded, changes collapsed.

+196 −0

File added.

Preview size limit exceeded, changes collapsed.