GIF Frame and delay preview test code
Posted: Tue Feb 21, 2017 5:45 pm
This code is a part from BucketFill advanced
http://www.purebasic.fr/english/viewtop ... 12&t=66927
http://www.purebasic.fr/english/viewtop ... 12&t=66927
Code: Select all
; GIF Frame and delay preview test code
; This code generate a complete sheet from a GIF and also a separately Info file
; You must see a grey background with a grid on the transparence GIF parts and each frame exactely, then it is OK
; Author W. Albus - http://www.nachtoptik.de - http://www.quick-aes-256.de
UsePNGImageDecoder()
UseJPEGImageDecoder()
UseGIFImageDecoder()
UsePNGImageEncoder()
EnableExplicit
Define gif_ID, sheet_ID, i, ii, iii, iiii, file
Define gif_width, gif_height, sheet_width, sheet_height, frames, frames_x, frames_y
Define path$
Define background_color=$808080 ; Set here The Background color for the transparence color
path$=OpenFileRequester("Select a GIF picture", "", "", 0)
If path$="" : End : EndIf
gif_ID=LoadImage(#PB_Any, path$) ; Sprite mode
gif_width=ImageWidth(gif_ID)
gif_height=ImageHeight(gif_ID)
frames=ImageFrameCount(gif_ID)
frames_x=Sqr(frames)
frames_y=frames/frames_x+1
sheet_width=frames_x*gif_width
sheet_height=frames_y*gif_height
For i=0 To frames-1
iiii=iii : ii+gif_width
If ii=>sheet_width
ii=0 : iii+gif_height
EndIf
Next i
sheet_ID=CreateImage(#PB_Any, sheet_width, iiii+gif_height, 24, background_color)
StartDrawing(ImageOutput(sheet_ID))
For i=1 To sheet_width-1 Step 3
LineXY(i, 0, i, sheet_height, $DCDCDC)
Next i
For i=1 To sheet_height-1 Step 3
LineXY(0, i, sheet_width, i, $DCDCDC)
Next i
StopDrawing()
file=OpenFile(#PB_Any, GetPathPart(path$)+GetFilePart(path$, #PB_FileSystem_NoExtension)+"_sheet_info.txt")
WriteStringN(file, " Frames #"+RSet(Str(frames), 8, "0 "), #PB_Ascii)
WriteStringN(file, " Frame width #"+RSet(Str(gif_width), 8, "0 "), #PB_Ascii)
WriteStringN(file, " Frame height #"+RSet(Str(gif_height), 8, "0 "), #PB_Ascii)
ii=0 : iii=0
For i=0 To frames-1
SetImageFrame(gif_ID, i)
WriteStringN(file, " Frame / delay :"+RSet(Str(i), 8, "0 ")+" *"+RSet(Str(GetImageFrameDelay(gif_ID)), 8, "0"), #PB_Ascii)
StartDrawing(ImageOutput(sheet_ID))
DrawingMode(#PB_2DDrawing_AlphaBlend)
DrawImage(ImageID(gif_ID), ii, iii)
StopDrawing()
ii+gif_width
If ii=>sheet_width
ii=0 : iii+gif_height
EndIf
Next i
CloseFile(file)
SaveImage(sheet_ID, GetPathPart(path$)+GetFilePart(path$, #PB_FileSystem_NoExtension)+".png", #PB_ImagePlugin_PNG, 10, 24)