Skip to content

Commit

Permalink
adapt to gif with empty color table
Browse files Browse the repository at this point in the history
  • Loading branch information
logica0419 committed Aug 13, 2024
1 parent 5ab238b commit d99c495
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ func (p *processor) resize(ctx context.Context, src *gif.GIF, width, height int)
// To avoid the noise, pile up frames on this canvas before resizing
tempCanvas = image.NewNRGBA(image.Rect(0, 0, srcWidth, srcHeight))

// Uniform image of background color
// nolint:forcetypeassert
bgColorUniform = image.NewUniform(src.Config.ColorModel.(color.Palette)[src.BackgroundIndex])

// Destination GIF image
dst = &gif.GIF{
Image: make([]*image.Paletted, len(src.Image)),
Expand Down Expand Up @@ -111,9 +107,13 @@ func (p *processor) resize(ctx context.Context, src *gif.GIF, width, height int)
if src.Disposal[i] == gif.DisposalBackground {
// If the transparent color is in the frame palette, use it as the background color
r, g, b, a := srcFrame.Palette[srcFrame.Palette.Index(color.Transparent)].RGBA()

if r == 0 && g == 0 && b == 0 && a == 0 {
draw.Draw(tempCanvas, srcBounds, image.Transparent, image.Point{X: 0, Y: 0}, draw.Src)
} else {
} else if globalColorTable, ok := src.Config.ColorModel.(color.Palette); ok && int(src.BackgroundIndex) < len(globalColorTable) {
// Workaround to the GIF images with empty global color table
bgColorUniform := image.NewUniform(globalColorTable[src.BackgroundIndex])

draw.Draw(tempCanvas, srcBounds, bgColorUniform, image.Point{X: 0, Y: 0}, draw.Src)
}
}
Expand Down

0 comments on commit d99c495

Please sign in to comment.