-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Closed
Labels
Milestone
Description
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:
Author: Nigel Tao <nigeltao@golang.org> 2015-03-25 18:47:24
Committer: Nigel Tao <nigeltao@golang.org> 2015-03-26 18:30:55
Parent: b5c3a9e572a1257c0db47d74b45f8e03f2f91f27 (image: add image.CMYK and color.CMYK types.)
Child: 0def13ac3f5a5e9f8e5540d3f5469cd469bddfad (image/color: have CMYK.RGBA work in 16-bit color, per the Color interface.)
Branches: master, remotes/origin/dev.ssa, remotes/origin/master
Follows: go1.4beta1
Precedes: go1.5beta1
image/color: have YCbCr.RGBA work in 16-bit color, per the Color
interface.
Change-Id: Ie025753df08ae93e7a5095a3426aff15fa2016fd
Reviewed-on: https://go-review.googlesource.com/8073
Reviewed-by: Rob Pike <r@golang.org>
I tried reverting the RGBA() code for YCbCr code to the original one and that works fine
package main
import (
"image"
"image/color"
_ "image/jpeg"
"image/png"
"log"
"os"
)
func main() {
r, err := os.Open("start_screen.jpg")
check(err)
defer r.Close()
img, _, err := image.Decode(r)
check(err)
b := img.Bounds()
rgba := image.NewRGBA(b)
for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
r32, g32, b32, a32 := img.At(x, y).RGBA()
c := color.RGBA{uint8(r32), uint8(g32), uint8(b32), uint8(a32)}
rgba.SetRGBA(x, y, c)
}
}
w, err := os.Create("test.png")
check(err)
defer w.Close()
err = png.Encode(w, rgba)
check(err)
}
func check(err error) {
if err != nil {
log.Fatal(err)
}
}

