Roll skia/third_party/skcms 4642d9fe69e1..23e7777f421d (1 commits)

https://skia.googlesource.com/skcms.git/+log/4642d9fe69e1..23e7777f421d

2018-07-27 mtklein@google.com clamp before premul


The AutoRoll server is located here: https://skcms-skia-roll.skia.org

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC'd on the roll, and stop the roller if necessary.



CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel
TBR=benjaminwagner@google.com

Change-Id: Ia9898102aae04ad07057e1a5af1de8ad108d9631
Reviewed-on: https://skia-review.googlesource.com/143735
Reviewed-by: skcms-skia-autoroll <skcms-skia-autoroll@skia-buildbots.google.com.iam.gserviceaccount.com>
Commit-Queue: skcms-skia-autoroll <skcms-skia-autoroll@skia-buildbots.google.com.iam.gserviceaccount.com>
diff --git a/third_party/skcms/skcms.cc b/third_party/skcms/skcms.cc
index e81f949..0a82062 100644
--- a/third_party/skcms/skcms.cc
+++ b/third_party/skcms/skcms.cc
@@ -2285,6 +2285,15 @@
         if (!is_identity_tf(&inv_dst_tf_b)) { *ops++ = Op_tf_b; *args++ = &inv_dst_tf_b; }
     }
 
+    // Clamp here before premul to make sure we're clamping to fixed-point values _and_ gamut,
+    // not just to values that fit in the fixed point representation.
+    //
+    // E.g. r = 1.1, a = 0.5 would fit fine in fixed point after premul (ra=0.55,a=0.5),
+    // but would be carrying r > 1, which is really unexpected for downstream consumers.
+    // TODO(mtklein): add a unit test
+    if (dstFmt < skcms_PixelFormat_RGB_hhh) {
+        *ops++ = Op_clamp;
+    }
     if (dstAlpha == skcms_AlphaFormat_Opaque) {
         *ops++ = Op_force_opaque;
     } else if (dstAlpha == skcms_AlphaFormat_PremulAsEncoded) {
@@ -2293,9 +2302,6 @@
     if (dstFmt & 1) {
         *ops++ = Op_swap_rb;
     }
-    if (dstFmt < skcms_PixelFormat_RGB_hhh) {
-        *ops++ = Op_clamp;
-    }
     switch (dstFmt >> 1) {
         default: return false;
         case skcms_PixelFormat_A_8           >> 1: *ops++ = Op_store_a8;       break;