From 48a72ca8e36bc87e76f4c4a9b37e438422d26439 Mon Sep 17 00:00:00 2001 From: Ryo Ota Date: Wed, 31 Jul 2019 01:52:00 +0900 Subject: [PATCH] [change] Use diff image --- gif_progress.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/gif_progress.go b/gif_progress.go index effe5b5..e8d6e1e 100644 --- a/gif_progress.go +++ b/gif_progress.go @@ -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 @@ -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 } }