summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Leon Scroggins III <scroggo@google.com> 2019-01-09 15:00:30 -0500
committer Leon Scroggins III <scroggo@google.com> 2019-01-11 14:31:52 -0500
commit203034fe2cb099f97d5ff3ea433ca657e231daef (patch)
tree55e090010105b288c7b30a76b24f135a577c1e93
parenta068624dce06a9948bcef377ac417394def31a4d (diff)
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
-rw-r--r--graphics/java/android/graphics/ColorSpace.java27
1 files changed, 22 insertions, 5 deletions
diff --git a/graphics/java/android/graphics/ColorSpace.java b/graphics/java/android/graphics/ColorSpace.java
index bf114b969b67..e6cf42e51370 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>
@@ -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%