-
Notifications
You must be signed in to change notification settings - Fork 18k
image/gif: transparency lost when encoding a wrapped *image.Paletted #30995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@splace Thanks for the issue report. When you say "images the same" under "what did you expect", can you clarify? There are 4 images, which ones did you expect to be the same? |
the images are in the order the code produced them, they should all be the same since the image is not being modified at any point. details.... |
The concrete type returned by I suspect this issue is happening because wrapping the Line 436 in c8aaec2
/cc @robpike @nigeltao Do you think this is working as intended, or is this a bug in |
FYI this was encountered when i put together a simple image geometry transforming utility. (any supported format input, any output.) with the very simple technique of wrapping the Image and modifying the x and y of the method At(x,y) then calling the embedded Image. works as expected, except for this. |
Yeah, it's a bug in
check should be something like
But that's not great. The first approach might not be feasible if it requires your wrapper type to also or conditionally implement the image.PalettedImage interface. The second approach would probably work. It won't be super-efficient to, for each pixel, call At and look up the color.Palette to turn it back into an index. But given the Go 1.x image interfaces that we have, it could be feasible. |
@nigeltao, what do you suggest we do? |
If somebody has the free time to fix the bug as I suggested (preferably the second approach), that's great. I don't have the free time, though. If nobody has the free time, then I think we just have to leave it as is for now. It's not a regression. |
@nigeltao, I tried your second approach, and it works fine. The first and second pictures are the results from @splace 's test. My code is as follows, pm, _ := m.(*image.Paletted)
if pm == nil {
if cp, ok := m.ColorModel().(color.Palette); ok {
pm = image.NewPaletted(b, cp)
for i:=b.Min.X ; i < b.Max.X ; i++ {
for j:=b.Min.Y ; j < b.Max.Y ; j++ {
pm.Set(i,j, cp.Convert(m.At(i, j)))
//pm.Set(i,j, m.At(i, j)) // also works
}
}
}
}
if (pm == nil) || (len(pm.Palette) > opts.NumColors) {
// TODO: Pick a better sub-sample of the Plan 9 palette.
pm = image.NewPaletted(b, palette.Plan9[:opts.NumColors])
if opts.Quantizer != nil {
pm.Palette = opts.Quantizer.Quantize(make(color.Palette, 0, opts.NumColors), m)
}
opts.Drawer.Draw(pm, b, m, image.ZP)
} Is this code what you expected? |
Yeah, that looks OK, broadly speaking. I guess that it wasn't as complicated as I first feared. It's not super-efficient, but it will work, and we can optimize later. There's some style nits (e.g. I'd call the variables |
Change https://golang.org/cl/177377 mentions this issue: |
go 1.12.1 linux/amd64
What did you do?
What did you expect to see?
images the same
What did you see instead?
gif has transparency converted to black, png retains origin transparency.
output:
The text was updated successfully, but these errors were encountered: