On Mon, Jan 23, 2017 at 6:03 AM, kalekold via golang-nuts
<golang-nuts@googlegroups.com> wrote:
> Hmm.. the source gif I'm using must be compressed. Doesn't Go handle
> compressed gifs in the same way? When you say 'I may get unexpected results'
> is that because the current gif package doesn't support compression?

A GIF image is a sequence of frames. Some frames are complete
pictures, some frames contain only those pixels that changed from the
previous frame. (If you're familiar with video formats like MPEG, you
might recognize these concepts as I-frames and P-frames).

The second type of frame, delta frames or P-frames, often encode much
smaller since they're often mostly transparent, and so are sometimes
called "compressed" GIFs. Both sorts of frames also use LZW
compression, but that's probably not what we're discussing here.

The Go image/gif package supports complete and delta frames. As per
the GIF spec (http://www.w3.org/Graphics/GIF/spec-gif89a.txt), the
package calls this the disposal method. Support means that decoding a
GIF image will give you the per-frame disposal methods, and passing a
slice of per-frame disposal methods to Encode will produce a well
formatted GIF.

However, the package does not apply the deltas to previous frames for
you. If you want to load an animated GIFs and replace some frames, it
is up to the user of the image/gif package (i.e. you) to apply the
deltas when decoding, or re-calculate the deltas when encoding. Or you
can set decoded.Disposal[i] to gif.DisposalNone to change the frame
from a P-frame to an I-frame, but that might lead to a larger GIF
file.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to