Re: GifDecoder module (All OS, single frame & animated gifs)
Posted: Fri Dec 13, 2013 5:36 pm
Why on PureBasic there is no Gif encoder animated gifs ?
http://www.purebasic.com
https://www.purebasic.fr/english/
Netmeastro already answered this in his threadkvitaliy wrote:Why on PureBasic there is no Gif encoder animated gifs ?
Code: Select all
EnableExplicit
IncludeFile "GifDecoder.pbi"
InitSprite()
Define Event, Item, NewFile, FileName.s
Define d, t, f, frame_count, *m
Dim Frames.GifDecoder::GIF_Frame(0)
If OpenWindow(0, 0, 0, 720, 420, "[Animated] GIF explorer", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EnableWindowDrop(0, #PB_Drop_Files, #PB_Drag_Copy)
ExplorerListGadget(0, 10, 10, 280, 400, GetHomeDirectory())
OpenWindowedScreen(WindowID(0), 310, 10, 400, 400)
ClearScreen($D8D8D8)
FlipBuffers()
f = 0
Repeat
Event = WindowEvent()
NewFile = #False
If Event = #PB_Event_WindowDrop
FileName = StringField(EventDropFiles(), 1, #LF$)
SetGadgetState(0, -1)
NewFile = #True
ElseIf EventType() = #PB_EventType_Change
Item = GetGadgetState(0)
If Item >= 0
FileName = GetGadgetText(0) + GetGadgetItemText(0, Item)
NewFile = #True
EndIf
EndIf
If NewFile And FileSize(FileName) > 32 And ReadFile(0, FileName)
*m = AllocateMemory(Lof(0), #PB_Memory_NoClear)
ReadData(0, *m, Lof(0))
CloseFile(0)
If GifDecoder::FrameCount(*m)
; remove existing sprites
For f = 0 To ArraySize(Frames())
If Frames(f)\image
FreeSprite(Frames(f)\image)
EndIf
Next
; get new sprites
GifDecoder::GetRenderedFrames(Frames(), *m, 0, 1)
frame_count = ArraySize(Frames()) + 1
If Frames(0)\width > 400 Or Frames(0)\height > 400
For f = 0 To frame_count - 1
With Frames(f)
If \width > \height
ZoomSprite(\image, 400, 400 * \height / \width)
Else
ZoomSprite(\image, 400 * \width / \height, 400)
EndIf
EndWith
Next
EndIf
; single frame ?, display now
If frame_count = 1
ClearScreen($D8D8D8)
DisplayTransparentSprite(frames(0)\image, 0, 0)
FlipBuffers()
Else
f = 0 : d = 0
EndIf
EndIf
FreeMemory(*m)
EndIf
If frame_count > 1 And ElapsedMilliseconds() - t >= d
While frames(f)\delay = 0
f = (f + 1) % frame_count
Wend
With frames(f)
ClearScreen($D8D8D8)
DisplayTransparentSprite(\image, 0, 0)
FlipBuffers()
d = \delay
t = ElapsedMilliseconds()
EndWith
f = (f + 1) % frame_count
EndIf
Delay(4)
Until Event = #PB_Event_CloseWindow
EndIf
















Glad to hear thatKwaï chang caïne wrote:All works with your splendid explorer !!!![]()


Code: Select all
EnableExplicit
IncludeFile "GifDecoder.pbi"
Define Event, Item, NewFile, FileName.s, *m
If OpenWindow(0, 0, 0, 820, 520, "[Animated] GIF explorer", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0, $EEEEEE)
EnableWindowDrop(0, #PB_Drop_Files, #PB_Drag_Copy)
ExplorerListGadget(0, 10, 10, 280, 500, GetHomeDirectory())
ImageGadget(1, 310, 10, 500, 500, 0)
Repeat
Event = WaitWindowEvent()
NewFile = #False
If Event = #PB_Event_WindowDrop
FileName = StringField(EventDropFiles(), 1, #LF$)
SetGadgetState(0, -1)
NewFile = #True
ElseIf EventType() = #PB_EventType_Change
Item = GetGadgetState(0)
If Item >= 0
FileName = GetGadgetText(0) + GetGadgetItemText(0, Item)
NewFile = #True
EndIf
EndIf
If NewFile And FileSize(FileName) > 32 And ReadFile(0, FileName)
*m = AllocateMemory(Lof(0), #PB_Memory_NoClear)
ReadData(0, *m, Lof(0))
CloseFile(0)
GifDecoder::Animate(1, *m, #True, GetWindowColor(0), 500, 500)
EndIf
Until Event = #PB_Event_CloseWindow
EndIfCode: Select all
IncludeFile "GifDecoder.pbi"
If OpenWindow(0, 0, 0, 220, 100, "[Animated] GIF demo", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ImageGadget(0, 10, 10, 200, 80, 0)
GifDecoder::Animate(0, ?icon_lol)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
DataSection
icon_lol:
Data.q $000F613938464947,$454545000DB3000F,$FFFF00000000EAFF,$FF00C9FF00CEFFFF,$13FDFF009DFE00B4
Data.q $FFFFC7FFFF93FEFF,$0000000000E5FFEB,$0BFF210000000000,$455041435354454E,$0000000103302E32
Data.q $000D00140504F921,$0F000F000000002C,$6A0949B05A040000,$06172252A5D5B89D,$130079410480822C
Data.q $0A7254AE9C6898A0,$5C29EB729A801E31,$2543058EC9B00561,$4A69440094A63C01,$103B7681A909412D
Data.q $F02DDB80AC00590C,$D251A66AA3020434,$780C016EE09C7885,$21002264B7633103,$2C000D00140504F9
Data.q $0007000B00020002,$A85B2449B0130400,$61F09FE8ABCDEB38,$210044D9D90C34A2,$2C000D000A0504F9
Data.q $0002000500070005,$8D6A394850050400,$0D000A0504F92100,$0005000700052C00,$2948300504000002
Data.q $0A0504F921008D6A,$000700052C000D00,$5005040000020005,$04F921008D6A3948,$00052C000D001405
Data.q $0400000200050007,$3B008D6A29483005
EndDataSectionCode: Select all
Procedure SetImageGadgetGif(GadgetImage.l, ImageId.l, CouleurFond.l, LargeurMax.i = 1000, HauteurMax.i = 1000)
Structure Animation
Target.i ; image gadget to target
*GIF_Data
ThreadID.i
MaxWidth.i
MaxHeight.i
BgColor.l
FreeData.l
Quit.l ; quit flag
EndStructure
Static *PtrAnimate.Animation
If ImageId
*PtrAnimate = GifDecoder::Animate(GadgetImage, ImageId, #True, CouleurFond, LargeurMax, HauteurMax)
Else
If *PtrAnimate And IsThread(*PtrAnimate\ThreadID)
KillThread(*PtrAnimate\ThreadID)
EndIf
EndIf
EndProcedureCode: Select all
SetImageGadgetGif(#GadgetImage, 0, 0)Code: Select all
*PtrAnimate\Quit = #True
It's a bad gif. It specifies a frame delay of 1/100 sec.Kwai chang caine wrote:This is the first (I love it, it's like fish in aquarium..i can watch it a long time, and for sleeping it's the top)
With IE all are good..but with your code the sheep win the 110 meter hurdle championship
Code: Select all
*PtrAnimate\Quit = #True