]> Cypherpunks repositories - gostls13.git/commitdiff
image/color: order color computation to match rgb
authorMartin Möhrmann <martisch@uos.de>
Fri, 15 Apr 2016 06:56:01 +0000 (08:56 +0200)
committerNigel Tao <nigeltao@golang.org>
Fri, 15 Apr 2016 07:34:37 +0000 (07:34 +0000)
The order of computation was switched unintentionally
in https://go-review.googlesource.com/21910.

Revert the order to first compute g then b.

Change-Id: I8cedb5e45fbad2679246839f609bcac4f9052403
Reviewed-on: https://go-review.googlesource.com/22016
Reviewed-by: Nigel Tao <nigeltao@golang.org>
src/image/color/ycbcr.go
src/image/internal/imageutil/gen.go
src/image/internal/imageutil/impl.go

index 2e985fece1ef342406254153e336df5fecfaf561..55549c3fcee24275942b0312afc40db16f1b6d4a 100644 (file)
@@ -60,7 +60,7 @@ func YCbCrToRGB(y, cb, cr uint8) (uint8, uint8, uint8) {
        // but uses fewer branches and is faster.
        // Note that the uint8 type conversion in the return
        // statement will convert ^int32(0) to 0xff.
-       // The code below to compute b and g uses a similar pattern.
+       // The code below to compute g and b uses a similar pattern.
        r := yy1 + 91881*cr1
        if uint32(r)&0xff000000 == 0 {
                r >>= 16
@@ -68,13 +68,6 @@ func YCbCrToRGB(y, cb, cr uint8) (uint8, uint8, uint8) {
                r = ^(r >> 31)
        }
 
-       b := yy1 + 116130*cb1
-       if uint32(b)&0xff000000 == 0 {
-               b >>= 16
-       } else {
-               b = ^(b >> 31)
-       }
-
        g := yy1 - 22554*cb1 - 46802*cr1
        if uint32(g)&0xff000000 == 0 {
                g >>= 16
@@ -82,6 +75,13 @@ func YCbCrToRGB(y, cb, cr uint8) (uint8, uint8, uint8) {
                g = ^(g >> 31)
        }
 
+       b := yy1 + 116130*cb1
+       if uint32(b)&0xff000000 == 0 {
+               b >>= 16
+       } else {
+               b = ^(b >> 31)
+       }
+
        return uint8(r), uint8(g), uint8(b)
 }
 
index 6f8d2b2f5dc1b2900221e6d1c86d35d3fe8f269b..b9158d0ce96bd0e09aad071ab452c6f0e70468fb 100644 (file)
@@ -111,7 +111,7 @@ const sratioCase = `
                                // but uses fewer branches and is faster.
                                // Note that the uint8 type conversion in the return
                                // statement will convert ^int32(0) to 0xff.
-                               // The code below to compute b and g uses a similar pattern.
+                               // The code below to compute g and b uses a similar pattern.
                                r := yy1 + 91881*cr1
                                if uint32(r)&0xff000000 == 0 {
                                        r >>= 16
@@ -119,13 +119,6 @@ const sratioCase = `
                                        r = ^(r >> 31)
                                }
 
-                               b := yy1 + 116130*cb1
-                               if uint32(b)&0xff000000 == 0 {
-                                       b >>= 16
-                               } else {
-                                       b = ^(b >> 31)
-                               }
-
                                g := yy1 - 22554*cb1 - 46802*cr1
                                if uint32(g)&0xff000000 == 0 {
                                        g >>= 16
@@ -133,6 +126,13 @@ const sratioCase = `
                                        g = ^(g >> 31)
                                }
 
+                               b := yy1 + 116130*cb1
+                               if uint32(b)&0xff000000 == 0 {
+                                       b >>= 16
+                               } else {
+                                       b = ^(b >> 31)
+                               }
+
                                dpix[x+0] = uint8(r)
                                dpix[x+1] = uint8(g)
                                dpix[x+2] = uint8(b)
index 0993f3145ce885416ece5174089a4b9ef460d7b9..39b455fdfa41687d63333f5779954024f7f906cc 100644 (file)
@@ -60,7 +60,7 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
                                // but uses fewer branches and is faster.
                                // Note that the uint8 type conversion in the return
                                // statement will convert ^int32(0) to 0xff.
-                               // The code below to compute b and g uses a similar pattern.
+                               // The code below to compute g and b uses a similar pattern.
                                r := yy1 + 91881*cr1
                                if uint32(r)&0xff000000 == 0 {
                                        r >>= 16
@@ -68,13 +68,6 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
                                        r = ^(r >> 31)
                                }
 
-                               b := yy1 + 116130*cb1
-                               if uint32(b)&0xff000000 == 0 {
-                                       b >>= 16
-                               } else {
-                                       b = ^(b >> 31)
-                               }
-
                                g := yy1 - 22554*cb1 - 46802*cr1
                                if uint32(g)&0xff000000 == 0 {
                                        g >>= 16
@@ -82,6 +75,13 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
                                        g = ^(g >> 31)
                                }
 
+                               b := yy1 + 116130*cb1
+                               if uint32(b)&0xff000000 == 0 {
+                                       b >>= 16
+                               } else {
+                                       b = ^(b >> 31)
+                               }
+
                                dpix[x+0] = uint8(r)
                                dpix[x+1] = uint8(g)
                                dpix[x+2] = uint8(b)
@@ -115,7 +115,7 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
                                // but uses fewer branches and is faster.
                                // Note that the uint8 type conversion in the return
                                // statement will convert ^int32(0) to 0xff.
-                               // The code below to compute b and g uses a similar pattern.
+                               // The code below to compute g and b uses a similar pattern.
                                r := yy1 + 91881*cr1
                                if uint32(r)&0xff000000 == 0 {
                                        r >>= 16
@@ -123,13 +123,6 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
                                        r = ^(r >> 31)
                                }
 
-                               b := yy1 + 116130*cb1
-                               if uint32(b)&0xff000000 == 0 {
-                                       b >>= 16
-                               } else {
-                                       b = ^(b >> 31)
-                               }
-
                                g := yy1 - 22554*cb1 - 46802*cr1
                                if uint32(g)&0xff000000 == 0 {
                                        g >>= 16
@@ -137,6 +130,13 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
                                        g = ^(g >> 31)
                                }
 
+                               b := yy1 + 116130*cb1
+                               if uint32(b)&0xff000000 == 0 {
+                                       b >>= 16
+                               } else {
+                                       b = ^(b >> 31)
+                               }
+
                                dpix[x+0] = uint8(r)
                                dpix[x+1] = uint8(g)
                                dpix[x+2] = uint8(b)
@@ -170,7 +170,7 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
                                // but uses fewer branches and is faster.
                                // Note that the uint8 type conversion in the return
                                // statement will convert ^int32(0) to 0xff.
-                               // The code below to compute b and g uses a similar pattern.
+                               // The code below to compute g and b uses a similar pattern.
                                r := yy1 + 91881*cr1
                                if uint32(r)&0xff000000 == 0 {
                                        r >>= 16
@@ -178,13 +178,6 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
                                        r = ^(r >> 31)
                                }
 
-                               b := yy1 + 116130*cb1
-                               if uint32(b)&0xff000000 == 0 {
-                                       b >>= 16
-                               } else {
-                                       b = ^(b >> 31)
-                               }
-
                                g := yy1 - 22554*cb1 - 46802*cr1
                                if uint32(g)&0xff000000 == 0 {
                                        g >>= 16
@@ -192,6 +185,13 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
                                        g = ^(g >> 31)
                                }
 
+                               b := yy1 + 116130*cb1
+                               if uint32(b)&0xff000000 == 0 {
+                                       b >>= 16
+                               } else {
+                                       b = ^(b >> 31)
+                               }
+
                                dpix[x+0] = uint8(r)
                                dpix[x+1] = uint8(g)
                                dpix[x+2] = uint8(b)
@@ -224,7 +224,7 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
                                // but uses fewer branches and is faster.
                                // Note that the uint8 type conversion in the return
                                // statement will convert ^int32(0) to 0xff.
-                               // The code below to compute b and g uses a similar pattern.
+                               // The code below to compute g and b uses a similar pattern.
                                r := yy1 + 91881*cr1
                                if uint32(r)&0xff000000 == 0 {
                                        r >>= 16
@@ -232,13 +232,6 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
                                        r = ^(r >> 31)
                                }
 
-                               b := yy1 + 116130*cb1
-                               if uint32(b)&0xff000000 == 0 {
-                                       b >>= 16
-                               } else {
-                                       b = ^(b >> 31)
-                               }
-
                                g := yy1 - 22554*cb1 - 46802*cr1
                                if uint32(g)&0xff000000 == 0 {
                                        g >>= 16
@@ -246,6 +239,13 @@ func DrawYCbCr(dst *image.RGBA, r image.Rectangle, src *image.YCbCr, sp image.Po
                                        g = ^(g >> 31)
                                }
 
+                               b := yy1 + 116130*cb1
+                               if uint32(b)&0xff000000 == 0 {
+                                       b >>= 16
+                               } else {
+                                       b = ^(b >> 31)
+                               }
+
                                dpix[x+0] = uint8(r)
                                dpix[x+1] = uint8(g)
                                dpix[x+2] = uint8(b)