Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
image/color: YcCbCr conversion to RGBA bug #11648
The image attached is decoded to color.YCbCr, if you do image encoding directly on it, ie, png.Encode(out, img) then it will generate the correct output, however, if you loop through it and use RGBA() to build the image, it will give you a garbled output as shown below.
The regression happened after this commit:
I tried reverting the RGBA() code for YCbCr code to the original one and that works fine
The bug is here:
r32, g32, b32, a32 := img.At(x, y).RGBA()
http://golang.org/pkg/image/color/#Color says that "each value [returned by RGBA] ranges within [0, 0xFFFF]". Thus, the r32 value is effectively a 16-bit value (as a uint32).
You then say "uint8(r32)", which takes the 8 low bits, not the 8 high bits, of that 16-bit value. Instead, it should be "uint8(r32 >> 8)".
Separately, if you want to convert a YCbCr image to an RGBA image, you don't have to roll your own loop. Instead, the easiest way to do that is the "Converting an Image to RGBA" section of http://blog.golang.org/go-imagedraw-package
This is becoming tangential, but I don't think the C-ness of the pixel buffer makes a difference.
Separately, using color.RGBAModel is fine, but note that it pretty much just does what I recommended to do. The rgbaModel function in http://golang.org/src/image/color/color.go says:
r, g, b, a := c.RGBA()