.gif lib for purebasic?

Everything else that doesn't fall into one of the other PB categories.
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

.gif lib for purebasic?

Post by es_91 »

I want to encode some pictures to gif. I need full control over the parameters used by the .gif engine, like dithering-value. I have seen these options in Paint.net.

Is there a user lib for such purpose?

greetings,

es_91.
:mrgreen:
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: .gif lib for purebasic?

Post by Shield »

There are codes here on the forums regarding gifs, because this question has been asked dozens of times before. :wink:
In addition, dithering doesn't really have anything to do with the gif format or its encoding. This is your application's
responsibility to create the "best looking" output. There are dithering algorithms on this forum as well.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
es_91
Enthusiast
Enthusiast
Posts: 298
Joined: Thu Jan 27, 2011 12:00 pm
Location: DE

Re: .gif lib for purebasic?

Post by es_91 »

What dithering algorithmn might Paint.NET use? I want my pictures to look like its value 4. I am keen to write a dithering algorithm.


AND BTW IF YOU HAVEN'T ALREADY KNOWN IT: RAR COMPRESSION OVER DITHERED 8 BIT BMP-FILES DOES BETTER COMPRESSION THAN .GIF!


Thanks.
:mrgreen:
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: .gif lib for purebasic?

Post by netmaestro »

I wrote code for converting images to 8 bits some time ago and incorporated Floyd-Steinberg dithering. I added saving as GIF as well. The code itself can be found in T&T, but I include here for your convenience the compiled dll which I've used regularly for around 5 years now:

http://lloydsplace.com/256colors.dll

and here is a sample code showing how to use it:

Code: Select all

Prototype ConvertTo8bit(hBitmap, dither)
Prototype Save8bitImage(hBitmap8, outpath$, memory=0)
Prototype SaveGIF(hBitmap, outfile$)

OpenLibrary(0, "256Colors.dll")
ConvertTo8bit.ConvertTo8bit = GetFunction(0, "ConvertTo8bit")
Save8bitImage.Save8bitImage = GetFunction(0, "Save8bitImage")
SaveGIF.SaveGIF             = GetFunction(0, "SaveGIF")

UsePNGImageDecoder()
UseJPEGImageDecoder() 
UseTIFFImageDecoder()

pattern$ = "PNG, BMP, JPEG, TIFF|*.png;*.bmp;*.jpg;*.jpeg;*.tiff|PNG (*.png)|*.png|BMP (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|TIFF (*.tif)|*.tif"
inpath$ = OpenFileRequester("Choose an image to convert to GIF:","",pattern$, 0)
prompt$ = RemoveString(GetFilePart(inpath$),"."+GetExtensionPart(inpath$))
prompt$ +".gif"
If FileSize(inpath$) < 1
  MessageRequester("Info:","No file selected. Ending...",#MB_ICONINFORMATION)
  End
EndIf

If inpath$
  hImage = LoadImage(#PB_Any, inpath$) 
Else
  End
EndIf

i = ConvertTo8bit(ImageID(hImage), 1) 

pattern$ = "GIF (*.gif)|*.gif;"
outpath$ = SaveFileRequester("Choose a path to save the .gif file:",prompt$,pattern$, 0)
outpath$ = RemoveString(outpath$, ".gif")
If outpath$
  outpath$ + ".gif"
  Debug Save8bitImage(i, "test.bmp",0)
  Debug SaveGIF(i, outpath$)
Else
  End 
EndIf

; Let's take a look at the results...
GetObject_(i, SizeOf(BITMAP), bmp.BITMAP)
w = bmp\bmWidth
h = bmp\bmHeight
OpenWindow(0,0,0,w,h,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu) 
ImageGadget(0,0,0,0,0,i)

Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow
I hope it's of use to you, however if not I won't be doing any more work on it.

Also, as it's a compiled library I should mention that all the credit for it isn't mine. For generating the colortable it uses Anthony Dekker's neural network code ported to PureBasic by luis and for the conversion to GIF I used the gdiplus library from Microsoft.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: .gif lib for purebasic?

Post by netmaestro »

Update: Better version (no dll needed) here: http://purebasic.fr/english/viewtopic.p ... 92#p428192
BERESHEIT
Post Reply