Page 1 of 1
Does Anyone have a GIF Decoder?
Posted: Wed Aug 06, 2008 5:24 pm
by akj
Neither Ward's WxCmmImageDecoder nor El_Choni's EC_ImagePluginOLE seem to be able to decode .GIF files under PB 4.20.
See:
www.purebasic.fr/english/viewtopic.php?t=20618
EC_ImagePluginOLE used to be able to decode them under PB 3.90.
Does anyone know of a GIF decoder routine/source/librar/etc that will handle [non-animated] .GIFs correctly in the current version of Pure Basic?
Posted: Wed Aug 06, 2008 6:15 pm
by srod
Can always use gdi+ (windows XP, 2003 , Vista).
The following uses some of Netmaestro's code taken from
http://www.purebasic.fr/english/viewtop ... lusstartup
Code: Select all
#GDIPLUS_OK = 0
;-Structures.
Structure GdiplusStartupInput ;{
GdiPlusVersion.l
*DebugEventCallback.DebugEventProc
SuppressBackgroundThread.l
SuppressExternalCodecs.l
EndStructure
;-Imports.
Import "gdiplus.lib"
GdiplusStartup(token, *input.GdiplusStartupInput, output)
GdipCreateBitmapFromFile(filename.p-unicode, *bitmap)
GdipGetImageWidth(*image, *width)
GdipGetImageHeight(*image, *height)
GdipCreateFromHDC(hdc.l, *graphics)
GdipDrawImageRectI(*graphics, *image, x.l, y.l, width.l, height.l)
GdipDeleteGraphics(*graphics)
GdipDisposeImage(image)
GdiplusShutdown(token)
EndImport
;Returns zero if an error or the PB image#.
Procedure.l LoadGif(filename$)
Protected result, width, height
Protected input.GdiplusStartupInput, token, image, imageID, hdc, graphics
;First initialise gdi+.
input\GdiPlusVersion = 1
GdiplusStartup(@token, @input, #Null)
;Was the initialisation successful?
If token
If GdipCreateBitmapFromFile(filename$, @image) = #GDIPLUS_OK
GdipGetImageWidth(image, @width)
GdipGetImageHeight(image, @height)
imageID = CreateImage(#PB_Any, Width, Height, 32)
If imageID
hdc = StartDrawing(ImageOutput(imageID))
If hdc
GdipCreateFromHDC(hdc, @graphics)
If graphics
GdipDrawImageRectI(graphics, image, 0, 0, width, height)
GdipDeleteGraphics(graphics)
result = imageID
EndIf
StopDrawing()
EndIf
EndIf
GdipDisposeImage(image)
EndIf
;Tidy up.
GdiplusShutdown(token)
EndIf
ProcedureReturn result
EndProcedure
;Test.
imageNum = LoadGif("test.gif")
Posted: Wed Aug 06, 2008 6:26 pm
by srod
An alternative would be the excellent FreeImage library.
Posted: Thu Aug 07, 2008 12:02 am
by PB
The code here is the best:
http://www.purebasic.fr/german/viewtopic.php?t=12155
It loads BMP, JPG, PNG and GIF files without using any third-party libraries
or PureBasic's in-built decoders. Saves on executable size immensely!
Posted: Thu Aug 07, 2008 4:17 am
by akj
Thank you for all the suggestions.
I am using Windows ME and this has led me to adopt PB's advice of using the routine[s] posted on the German Forum.
Incidently I notice some small errors in the routines CatchSpriteEx() and CatchImageEx() which are posted there:
Code: Select all
dxsf\Release()
EndIf
Stream\Release()
EndIf
dxtf\Release()
EndIf
should be:
Code: Select all
Stream\Release()
EndIf
dxsf\Release()
EndIf
dxtf\Release()
EndIf
The statement order and indendation both need correcting.
(I have not posted this in the German forum.)
Posted: Fri Aug 08, 2008 1:39 am
by localmotion34
Posted: Fri Aug 08, 2008 10:31 am
by akj
@locomotion34
Thank you for the link. I have been reading the source code and it is very interesting and informative.
I have two books that contain detailed information on the GIF format (and other formats). Using them makes the PB code much easier to follow.