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

Commit 203034fe authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

Make ColorSpace#isSrgb more restrictive

Test: Ide74c2e98d4aadba8bb0a24d132f161dbe64f4db

Previously, BT709 was believed to be SRGB, resulting in errors when we
tried to convert between them. Make isSrgb test several values passed to
OETF and EOTF to verify that it is very close to SRGB. This results in
BT709 no longer being considered SRGB, fixing the conversion.

Update the documentation to reflect the new behavior.

Now that isSrgb is more restrictive, a gamma of 2.2 is no longer
considered to be SRGB, which requires a change to a CTS test.

Change-Id: I7bf8d5e3af2f91e38ca0b0d5d906713a125dd484
parent a068624d
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -984,11 +984,12 @@ public abstract class ColorSpace {
     *         {@link Named#SRGB sRGB} primaries.
     *     </li>
     *     <li>
     *         Its white point is withing 1e-3 of the CIE standard
     *         Its white point is within 1e-3 of the CIE standard
     *         illuminant {@link #ILLUMINANT_D65 D65}.
     *     </li>
     *     <li>Its opto-electronic transfer function is not linear.</li>
     *     <li>Its electro-optical transfer function is not linear.</li>
     *     <li>Its transfer functions yield values within 1e-3 of {@link Named#SRGB}.</li>
     *     <li>Its range is \([0..1]\).</li>
     * </ul>
     * <p>This method always returns true for {@link Named#SRGB}.</p>
@@ -3115,19 +3116,35 @@ public abstract class ColorSpace {
                float max,
                @IntRange(from = MIN_ID, to = MAX_ID) int id) {
            if (id == 0) return true;
            if (!compare(primaries, SRGB_PRIMARIES)) {
            if (!ColorSpace.compare(primaries, SRGB_PRIMARIES)) {
                return false;
            }
            if (!compare(whitePoint, ILLUMINANT_D65)) {
            if (!ColorSpace.compare(whitePoint, ILLUMINANT_D65)) {
                return false;
            }
            if (OETF.applyAsDouble(0.5) < 0.5001) return false;
            if (EOTF.applyAsDouble(0.5) > 0.5001) return false;

            if (min != 0.0f) return false;
            if (max != 1.0f) return false;

            // We would have already returned true if this was SRGB itself, so
            // it is safe to reference it here.
            ColorSpace.Rgb srgb = (ColorSpace.Rgb) get(Named.SRGB);

            for (double x = 0.0; x <= 1.0; x += 1 / 255.0) {
                if (!compare(x, OETF, srgb.mOetf)) return false;
                if (!compare(x, EOTF, srgb.mEotf)) return false;
            }

            return true;
        }

        private static boolean compare(double point, @NonNull DoubleUnaryOperator a,
                @NonNull DoubleUnaryOperator b) {
            double rA = a.applyAsDouble(point);
            double rB = b.applyAsDouble(point);
            return Math.abs(rA - rB) <= 1e-3;
        }

        /**
         * Computes whether the specified CIE xyY or XYZ primaries (with Y set to 1) form
         * a wide color gamut. A color gamut is considered wide if its area is &gt; 90%