diff options
| -rw-r--r-- | graphics/java/android/graphics/ColorSpace.java | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/graphics/java/android/graphics/ColorSpace.java b/graphics/java/android/graphics/ColorSpace.java index f0efb581dab6..95317a4d0bf2 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. * </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> @@ -3145,19 +3146,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% |