How to use the FreeImage DLL?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to use the FreeImage DLL?

Post by Shardik »

applePi wrote:is it possible to display animated gifs,...
There exist different approaches to display animated GIFs:
- Using the WebGadget
http://www.purebasic.fr/english/viewtopic.php?t=3817 (from PB in 2002 :wink:)
- Using the ATL.DLL
http://www.purebasic.fr/german/viewtopic.php?t=4082 (from mueckerich)
- using external DLLs like FreeImage.DLL or others

localmotion even demonstrated how to load and display each single GIF
frame solely with PB:
http://www.purebasic.fr/english/viewtopic.php?t=27575
Collection of cross-platform examples with API functions to extend PureBasic
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: How to use the FreeImage DLL?

Post by srod »

There is also an ActiveX control bundled up with COMatePLUS which shows animated gifs etc. :wink:
I may look like a mule, but I'm not a complete ass.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to use the FreeImage DLL?

Post by Shardik »

srod wrote:There is also an ActiveX control bundled up with COMatePLUS which shows animated gifs etc.
Sorry, srod, for the omission. I am just getting old... :wink:
Even the older COMate and PureDispHelper libs contained an example code for animated GIFs from Kiffi...
Collection of cross-platform examples with API functions to extend PureBasic
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: How to use the FreeImage DLL?

Post by srod »

No need to aplogise; indeed there is nothing to apologise for. :) I was just adding yet another option. Admittedly, I'd probably go with the web-gadget option myself. :)
I may look like a mule, but I'm not a complete ass.
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Re: How to use the FreeImage DLL?

Post by mskuma »

I need to write a JPEG using 4:2:2 subsampling (the PB JPEG lib seems to write at 4:4:4 all the time) so I'm come to the FreeImage lib to help me write out an JPEG image created in PB using CreateImage etc (e.g. see below). However the pointer to the image provided by PB seems to be not compatible with the one expected by FreeImage. I'm not so familiar with PB's internal image format. I wonder if anyone's had any experience to save an image using FreeImage like how I'm trying it. I'd be grateful for a suggestion.

Code: Select all

IncludePath "FreeImage\"
IncludeFile "RW_FreeImage_Inc.pb"

UsePNGImageDecoder()

FreeImage_Initialise()

; Create a temporary image

comp = CreateImage(#PB_Any, 1024, 576, 32)

; load background & image to overlay

image1 = LoadImage(#PB_Any, "image1.png")
image2 = LoadImage(#PB_Any, "image2.png")

; every drawing operation must be done between "StartDrawing" and "StopDrawing"

StartDrawing(ImageOutput(comp))

  DrawImage(ImageID(image1), 0, 0)
  DrawAlphaImage(ImageID(image2), 0, 0, 255)

StopDrawing()

; save as 4:2:2 JPEG using FreeImage

If comp

;  newcomp = FreeImage_ConvertTo24Bits(comp)  ; probably needed later to downconvert 32 to 24 bits prior to saving
  
  If FreeImage_Save(#FIF_JPEG, comp, "c:\temp\test.jpg", #JPEG_SUBSAMPLING_422)   ; <- my problem is comp is causing an error
    Debug "free image save: success!"
  Else
    Debug "free image save: fail!"
  EndIf
  
EndIf

FreeImage(comp)
FreeImage(image1)
FreeImage(image2)

FreeImage_DeInitialise()
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: How to use the FreeImage DLL?

Post by c4s »

Code: Select all

If FreeImage_Save(#FIF_JPEG, ImageID(comp), "c:\temp\test.jpg", #JPEG_SUBSAMPLING_422)
:?:
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Re: How to use the FreeImage DLL?

Post by mskuma »

Thanks c4s, I tried that before - I get an 'invalid memory address' error when I try ImageID(..)
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Re: How to use the FreeImage DLL?

Post by mskuma »

I found the solution here under the section "How do I convert a HBITMAP to a FreeImage image ?"

This code needs to be inserted after StopDrawing()

Code: Select all

If comp

    bm.BITMAP
    GetObject_(ImageID(comp), SizeOf(BITMAP), @bm)
       
    dib = FreeImage_Allocate(bm\bmWidth, bm\bmHeight, bm\bmBitsPixel)
        
    ; the GetDIBits function clears the biClrUsed And biClrImportant BITMAPINFO members (dont't know why)
    ; so we save these infos below. This is needed for palettized images only.
    
;     nColors = FreeImage_GetColorsUsed(dib)

    dc = GetDC_(#Null)
    success = GetDIBits_(dc, ImageID(comp), 0, FreeImage_GetHeight(dib), FreeImage_GetBits(dib), FreeImage_GetInfo(dib), #DIB_RGB_COLORS)
    ReleaseDC_(#Null, dc);
    
    ; restore BITMAPINFO members  
    
;    *bmInfo.bitmapinfo = FreeImage_GetInfoHeader(dib)
;     *bmInfo\bmiHeader\biClrUsed = nColors
;     *bmInfo\bmiHeader\biClrImportant = nColors
        
EndIf  
The parts I've commented out are not needed except perhaps for the case indicated in the original comments.
Post Reply