Re: AnimatedGIFSprite
Posted: Sun Jan 22, 2023 12:33 pm
Can someone check with my small tool if on macOS the PB GIFDecoder returns correct results for the FrameDelay?
http://www.purebasic.com
https://www.purebasic.fr/english/
Well, I'm getting Zero, but most animated gifs have a zero-delay! I'll re-check!infratec wrote: Sun Jan 22, 2023 12:33 pm Can someone check with my small tool if on macOS the PB GIFDecoder returns correct results for the FrameDelay?
If FrameDelay = 0, the code never draws the image on the sprite.animated-dog-image-0175.gif
Size: 145x72
Frames: 7
FrameDelay: 100ms
Code: Select all
EnableExplicit
Define Filename$, Message$, X
UseGIFImageDecoder()
Filename$ = OpenFileRequester("Choose an animated GIF", "", "GIF|*.gif", 0)
If Filename$
If LoadImage(0, Filename$)
Message$ = GetFilePart(Filename$) + #LF$ + #LF$
Message$ + "Size: " + Str(ImageWidth(0)) + "x" + Str(ImageHeight(0)) + #LF$
Message$ + "Frames: " + Str(ImageFrameCount(0)) + #LF$
Message$ + "FrameDelay: " + Str(GetImageFrameDelay(x)) + "ms"
For X=0 To ImageFrameCount(0)
SetImageFrame(0,X)
Message$ + " , " + Str(GetImageFrameDelay(0))
Next X
Message$ + "ms"
MessageRequester("GIF Info", Message$)
FreeImage(0)
Else
MessageRequester("Error", "Error loading GIF" + #LF$ + #LF$ + Filename$)
EndIf
EndIf
animated-dog-image-0175.gif
Size: 145x72
Frames: 7
FrameDelay: 0ms , 100 , 100 , 100 , 100 , 100 , 100 , 100 , 100ms
Code: Select all
*AnimatedGIFSprite = AddMapElement(AnimatedGIFSprite\GIFInfoMap(), Str(Sprite))
*AnimatedGIFSprite\OrgImage = Image
*AnimatedGIFSprite\Sprite = Sprite
*AnimatedGIFSprite\Frames = ImageFrameCount(Image)
*AnimatedGIFSprite\FrameDelay = GetImageFrameDelay(Image)
If *AnimatedGIFSprite\FrameDelay = 0 : *AnimatedGIFSprite\FrameDelay = 1 : EndIf
animated-dog-image-0175.gif
Size: 145x72
Frames: 7
FrameDelay: 100 - 100 - 100 - 100 - 100 - 100 - 100 - 100 - ms
Code: Select all
EnableExplicit
Define Filename$, Message$, X
UseGIFImageDecoder()
Filename$ = OpenFileRequester("Choose an animated GIF", "", "GIF|*.gif", 0)
If Filename$
If LoadImage(0, Filename$)
Message$ = GetFilePart(Filename$) + #LF$ + #LF$
Message$ + "Size: " + Str(ImageWidth(0)) + "x" + Str(ImageHeight(0)) + #LF$
Message$ + "Frames: " + Str(ImageFrameCount(0)) + #LF$
Message$ + "FrameDelay: "
For X=0 To ImageFrameCount(0)
SetImageFrame(0,X)
Message$ + Str(GetImageFrameDelay(0)) + " - "
Next X
Message$ + "ms"
MessageRequester("GIF Info", Message$)
FreeImage(0)
Else
MessageRequester("Error", "Error loading GIF" + #LF$ + #LF$ + Filename$)
EndIf
EndIf
Code: Select all
For X=0 To ImageFrameCount(0) - 1
Of course... stupid guy.... If frames 7, starting on 0... YES!infratec wrote: Sun Jan 22, 2023 2:12 pm Yur modification is still wrong.
You need:Since the index starts from 0Code: Select all
For X=0 To ImageFrameCount(0) - 1
Or this one:ScanLand.gif
Size: 588x440
Frames: 121
FrameDelay: 30 - 30 - 20 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 20 - 30 - 30 - 30 - 20 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 20 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 20 - 30 - 30 - 30 - 20 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 20 - 30 - 30 - 30 - 30 - 30 - 30 - 20 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 40 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 20 - 30 - 30 - 30 - 20 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 20 - 30 - 30 - 30 - 20 - 30 - 30 - 30 - 30 - 20 - 30ms.
See my problem? And I also have to put Sprites on top of this GIFs while running... Maybe, I'll have to put aside the idea of using Animated Gifs!Radar.gif
Size: 800x600
Frames: 299
FrameDelay: 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20 - 20ms.
Code: Select all
EnableExplicit
Define Filename$, Message$, X, FIN
UseGIFImageDecoder()
Repeat
Filename$ = OpenFileRequester("Choose an animated GIF", "", "GIF|*.gif", 0)
If Filename$
If LoadImage(0, Filename$)
Message$ = GetFilePart(Filename$) + #LF$ + #LF$
Message$ + "Size: " + Str(ImageWidth(0)) + "x" + Str(ImageHeight(0)) + #LF$
Message$ + "Frames: " + Str(ImageFrameCount(0)) + #LF$
Message$ + "FrameDelay: "
If MessageRequester("Loop or Not","Use the LOOP?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
For X=0 To ImageFrameCount(0)-1
SetImageFrame(0,X)
Message$ + Str(GetImageFrameDelay(0))
If X<ImageFrameCount(0)-1 : Message$ + " - " : EndIf
Next X
Message$ + "ms."
Else
Message$ + Str(GetImageFrameDelay(0)) + "ms"
EndIf
MessageRequester("GIF Info", Message$)
FreeImage(0)
Else
MessageRequester("Error", "Error loading GIF" + #LF$ + #LF$ + Filename$)
EndIf
EndIf
If MessageRequester("AGAIN?","Do it again with another image?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_No
FIN=1
Else
FreeImage(#PB_All)
EndIf
Until FIN=1