diff --git a/graphics/java/android/graphics/ColorSpace.java b/graphics/java/android/graphics/ColorSpace.java index bf114b969b674..e6cf42e51370f 100644 --- a/graphics/java/android/graphics/ColorSpace.java +++ b/graphics/java/android/graphics/ColorSpace.java @@ -984,11 +984,12 @@ public abstract class ColorSpace { * {@link Named#SRGB sRGB} primaries. * *
  • - * 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}. *
  • *
  • Its opto-electronic transfer function is not linear.
  • *
  • Its electro-optical transfer function is not linear.
  • + *
  • Its transfer functions yield values within 1e-3 of {@link Named#SRGB}.
  • *
  • Its range is \([0..1]\).
  • * *

    This method always returns true for {@link Named#SRGB}.

    @@ -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 > 90%