go/src/image
Jed Denlea 31cd20a70e image/gif: try harder to use global color table
The GIF format allows for an image to contain a global color table which
might be used for some or every frame in an animated GIF.  This palette
contains 24-bit opaque RGB values.  An individual frame may use the
global palette and enable transparency by picking one number to be
transparent, instead of the color value in the palette.

image/gif decodes a GIF, which contains an []*image.Paletted that holds
each frame.  When decoded, if a frame has a transparent color and uses
the global palette, a copy of the global []color.Color is made, and the
transparency color index is replaced with color.RGBA{}.

When encoding a GIF, each frame's palette is encoded to the form it
might exist in a GIF, up to 768 bytes "RGBRGBRGBRGB...". If a frame's
encoded palette is equal to the encoded global color table, the frame
will be encoded with the flag set to use the global color table,
otherwise the frame's palette will be included.

So, if the color in the global color table that matches the transparent
index of one frame wasn't black (and it frequently is not), reencoding a
GIF will likely result in a larger file because each frame's palette
will have to be encoded inline.

This commit takes a frame's transparent color index into account when
comparing an individual image.Paletted's encoded color table to the
global color table.

Fixes #22137

Change-Id: I5460021da6e4d7ce19198d5f94a8ce714815bc08
Reviewed-on: https://go-review.googlesource.com/68313
Reviewed-by: Nigel Tao <nigeltao@golang.org>
2017-10-13 04:28:53 +00:00
..
color all: fix article typos 2017-09-15 02:39:16 +00:00
draw image/draw: add FloydSteinberg Drawer example 2016-09-21 00:08:58 +00:00
gif image/gif: try harder to use global color table 2017-10-13 04:28:53 +00:00
internal/imageutil image/color: tweak the YCbCr to RGBA conversion formula again. 2017-02-10 22:57:50 +00:00
jpeg image/gif: add BenchmarkDecode. 2017-10-07 05:23:42 +00:00
png image/gif: add BenchmarkDecode. 2017-10-07 05:23:42 +00:00
testdata image/jpeg: reconstruct progressive images even if incomplete. 2016-03-31 00:33:24 +00:00
decode_example_test.go
decode_test.go image/jpeg: reconstruct progressive images even if incomplete. 2016-03-31 00:33:24 +00:00
format.go
geom.go image: fix the overlap check in Rectangle.Intersect. 2017-02-10 05:05:59 +00:00
geom_test.go image: fix the overlap check in Rectangle.Intersect. 2017-02-10 05:05:59 +00:00
image.go image: add NYCbCrA types. 2015-10-11 11:07:25 +00:00
image_test.go all: remove some unused parameters in test code 2017-04-25 14:38:10 +00:00
names.go
ycbcr.go image: add NYCbCrA types. 2015-10-11 11:07:25 +00:00
ycbcr_test.go