Does Anyone have a GIF Decoder?

Everything else that doesn't fall into one of the other PB categories.
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Does Anyone have a GIF Decoder?

Post 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?
Last edited by akj on Wed Aug 06, 2008 6:21 pm, edited 1 time in total.
Anthony Jordan
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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")
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

An alternative would be the excellent FreeImage library.
I may look like a mule, but I'm not a complete ass.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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!
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post 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.)
Anthony Jordan
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

here you go. 100% PB source for loading a GIF:


http://www.purebasic.fr/english/viewtop ... if+decoder

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post 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.
Anthony Jordan
Post Reply