Skip to content

Commit

Permalink
[change] Use diff image
Browse files Browse the repository at this point in the history
  • Loading branch information
nwtgck committed Jul 30, 2019
1 parent 9d1ae8c commit 48a72ca
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions gif_progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ func AddProgressBar(inOutGif *gif.GIF, barTop bool, barHeight int, barColor colo
// Save as previous
previousPix = clonePix(newPaletted.Pix)

// Attach progress bar
// Calculate bar width
w := int(float32(width) * ((float32(i)+1)/float32(imageLen)))
// Attach progress bar
for x := 0; x < w; x++ {
for h := 0; h < barHeight; h++ {
var y = h
Expand All @@ -48,7 +49,18 @@ func AddProgressBar(inOutGif *gif.GIF, barTop bool, barHeight int, barColor colo
}
}

// Rect of progress bar
var barRect image.Rectangle
if barTop {
barRect = image.Rect(0, 0, w, barHeight)
} else {
barRect = image.Rect(0, height - barHeight, w, height)
}
// Calculate diff image
mergedRect := barRect.Union(paletted.Rect)
diffImage := newPaletted.SubImage(mergedRect).(*image.Paletted)

// Update image to new paletted
inOutGif.Image[i] = newPaletted
inOutGif.Image[i] = diffImage
}
}

0 comments on commit 48a72ca

Please sign in to comment.