Merge "Make ColorSpace#isSrgb more restrictive"

This commit is contained in:
Leon Scroggins
2019-01-14 17:23:36 +00:00
committed by Android (Google) Code Review

View File

@@ -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 &gt; 90%