-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The bar is not moving, and suggestions? #1
Comments
@sliday Quite interesting... Thanks! In my assumption, the moving of the GIF is the guy on the right corner, so GIF optimization stores only diff parts, in this case, the right guy. However, the position of the progress bar is on the bottom. Thus, the progress bar is not under diff part and gone. I'll create a proof of concept. |
Proof of conceptI changed the following code Lines 1 to 25 in bd5a18d
into the following. package gif_progress
import (
"image"
"image/color"
"image/gif"
)
func AddProgressBar(inOutGif *gif.GIF, barTop bool, barHeight int, barColor color.RGBA) {
// NOTE: inOutGif is changed destructively
width := inOutGif.Config.Width
height := inOutGif.Config.Height
image_len := len(inOutGif.Image)
//outGif := gif.GIF{Delay: inOutGif.Delay, LoopCount: inOutGif.LoopCount, Disposal}
for i, paletted := range inOutGif.Image {
w := int(float32(width) * ((float32(i)+1)/float32(image_len)))
bounds := image.Rect(0, 0, width, height)
// Get whole image not only diff
wholeImage := paletted.SubImage(bounds)
// Create new empty paletted
newPaletted := image.NewPaletted(bounds, paletted.Palette)
// Copy whole image to the new paletted
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
newPaletted.Set(x, y, wholeImage.At(x, y))
}
}
// Attach progress bar
for x := 0; x < w; x++ {
for h := 0; h < barHeight; h++ {
var y = h
if !barTop {
y = height - h
}
newPaletted.Set(x, y, barColor)
}
}
inOutGif.Image[i] = newPaletted
}
} Then, I got the following GIF. Sorry for ver blinking, but I got the progress bar. As you know, this output GIF is not perfect I have to remove the green parts. I'm investigating how to remove. |
No blinkingFinally, I got animated GIF without blinking! CodeSome part may be unnecessary. package gif_progress
import (
"image"
"image/color"
"image/gif"
)
func AddProgressBar(inOutGif *gif.GIF, barTop bool, barHeight int, barColor color.RGBA) {
// NOTE: inOutGif is changed destructively
width := inOutGif.Config.Width
height := inOutGif.Config.Height
imageLen := len(inOutGif.Image)
// Image size
imageSize := image.Rect(0, 0, width, height)
// Previous frame
previousImage := inOutGif.Image[0].SubImage(imageSize)
firstPalette := inOutGif.Image[0].Palette
for i, paletted := range inOutGif.Image {
// Create new empty paletted
newPaletted := image.NewPaletted(imageSize, firstPalette)
// Copy previous frame to the new paletted
for x := 0; x < width; x++ {
for y := 0; y < height; y++ {
newPaletted.Set(x, y, previousImage.At(x, y))
}
}
// Copy whole image to the new paletted
rect := paletted.Rect
for x := rect.Min.X; x < rect.Max.X; x++ {
for y := rect.Min.Y; y < rect.Max.Y; y++ {
newPaletted.Set(x, y, paletted.At(x, y))
}
}
// Save as previous
previousImage = newPaletted.SubImage(imageSize)
// Attach progress bar
w := int(float32(width) * ((float32(i)+1)/float32(imageLen)))
for x := 0; x < w; x++ {
for h := 0; h < barHeight; h++ {
var y = h
if !barTop {
y = height - h
}
newPaletted.Set(x, y, barColor)
}
}
inOutGif.Image[i] = newPaletted
}
} Generated GIFProblemBecause the frame has whole size pixels without using diff, the file size of the output is larger than the input and it takes more time. I want to solve this issue before creating PR. branch: https://github.com/nwtgck/gif-progress/tree/feature/fix-not-moving-progress-bar |
Cool, thanks, I'll try it later today!
Stas Kulesh
Creative Director at Sliday.com
…On Wed, Jul 31st, 2019 at 1:10 AM, Ryo Ota ***@***.***> wrote:
-----------
No blinking
-----------
Finally, I got animated GIF without blinking!
----
Code
----
Some part may be unnecessary.
package gif_progress import ( " image " " image/color " " image/gif " ) func
AddProgressBar ( inOutGif * gif. GIF , barTop bool , barHeight int , barColor
color. RGBA ) { // NOTE: inOutGif is changed destructively width := inOutGif.
Config. Width height := inOutGif. Config. Height imageLen := len (inOutGif.
Image ) // Image size imageSize := image. Rect ( 0 , 0 , width, height) //
Previous frame previousImage := inOutGif. Image [ 0 ]. SubImage (imageSize)
firstPalette := inOutGif. Image [ 0 ]. Palette for i , paletted := range inOutGif.
Image { // Create new empty paletted newPaletted := image. NewPaletted (imageSize,
firstPalette) // Copy previous frame to the new paletted for x := 0 ; x <
width; x++ { for y := 0 ; y < height; y++ { newPaletted. Set (x, y,
previousImage. At (x, y)) } } // Copy whole image to the new paletted rect
:= paletted. Rect for x := rect. Min. X ; x < rect. Max. X ; x++ { for y :=
rect. Min. Y ; y < rect. Max. Y ; y++ { newPaletted. Set (x, y, paletted. At
(x, y)) } } // Save as previous previousImage = newPaletted. SubImage (imageSize)
// Attach progress bar w := int ( float32 (width) * (( float32 (i)+ 1 )/ float32
(imageLen))) for x := 0 ; x < w; x++ { for h := 0 ; h < barHeight; h++ { var
y = h if !barTop { y = height - h } newPaletted. Set (x, y, barColor) } }
inOutGif. Image [i] = newPaletted } }
-------------
Generated GIF
-------------
out (
https://user-images.githubusercontent.com/10933561/62131774-c955b300-b316-11e9-824d-857f2bd35656.gif
)
-------
Problem
-------
* file size
* time
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (
#1?email_source=notifications&email_token=AABI27GLAGVUNGYTPLDNUS3QCA4U7A5CNFSM4IHX2MK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3D5ECQ#issuecomment-516411914
) , or mute the thread (
https://github.com/notifications/unsubscribe-auth/AABI27GKJKPGIXTUELPGDG3QCA4U7ANCNFSM4IHX2MKQ
).
|
@jasonraimondi Thank you very much! Your images are very helpful to investigate the issue. |
I attached a tag to the working branch to fix this issue. You can check the latest behavior easily. Note that the tag will be dynamically changed if the branch is updated. |
I simply launched main.go with this:
The text was updated successfully, but these errors were encountered: