BlitzMax Image load/save support

BlitzMax Forums/BlitzMax Programming/BlitzMax Image load/save support

Brucey(Posted 2007) [#1]
Introducing a new cross-platform module that adds support for some more image formats (loading and saving).

Loading of : GIF, BMP, DDS, HDR, ICO, IFF, JNG, JPG, KOALA, LBM, Kodak, MNG, PCS, PBM, PGM, PNG, PPM, Photoshop (PSD), Fax G3, SGI, RAS, TARGA, TIFF, WBMP, XBM and XPM.

Saving of : BMP, GIF, HDR, ICO, JPEG, PBM, PGM, PNG, PPM, TARGA, TIFF, WBMP and XPM.

Uses the open source FreeImage library.

Requires my "modified" BMK to build the module (due to compile/linking flags that the standard BMK doesn't support). Link to the zip is on my site.

For Windows, there's a freeimage.dll included, which you can ship with your app. I would have preferred to build the library statically, but I couldn't get it to work with MinGW.

For Linux and Mac, the library compiles into the module, so there are no external files required with deployment.

You can use the standard LoadPixmap if you only require load support. Just import the module and BlitzMax will pick the best loader for the image.

Loading and Saving have Stream support, so in theory you can even load/save in memory - something I haven't tried, but a RAMStream might work....


The module is available from http://brucey.net/programming/blitz/#bahfreeimage

Tested on Linux, Windows and Mac PPC (should work fine on Mac X86).



Any problems, comments, suggestions.... ;-)


Tachyon(Posted 2007) [#2]
You, my friend, are a god.


FlameDuck(Posted 2007) [#3]
Yeah. Do you have an army of clones working on these? How do you find the time? I really, desperately need to know!


Brucey(Posted 2007) [#4]
Just like to keep myself busy, is all.

I should have an update for this tomorrow at some point... which will add a CreateFromPixmap function - which effectively lets you save any old pixmap to any of the supported file formats... (got it working on Linux... need to test on the rest).

;-)


kronholm(Posted 2007) [#5]
Tagging this so I can find it later, very nice work Brucey :)


Brucey(Posted 2007) [#6]
Hallo,

Just to say there's an update which adds some nice functionality and improved documentation.

1.01
* Added CreateFromPixmap() function.
* Added colorQuantize, dither, threshold, toneMapping, tmoDrago03 and tmoReinhard05 methods.
* Added convertTo 4, 8, 16 methods.
* Added more documentation.


With CreateFromPixmap you are now free to move image data back and forth between BlitzMax and the FreeImage library.

I've implemented two layers of imaging. The first holds the "real" image data, which you can manipulate, load, save etc.
The second resamples that image data for displaying in BlitzMax via Pixmaps - mapped to the nearest pixmap format.
This way, you don't have to mess about converting and reconverting....

Anyhoo... hope you find it useful

:-)


popcade(Posted 2007) [#7]
Brucey, you're really great :)

A little whisper.. (ODE next please....),....


Brucey(Posted 2007) [#8]
aren't there several ODE wrappers out there already??


popcade(Posted 2007) [#9]
Can't make the old mak.ode working, JV-ODE is great but is limited to win32 yet....

I really hope it's possible to have an ODE module, and Brucey's modules have the highest quality/portability .

It's only a with but maybe some people have same wishes.

However I have to thanks your great libs first, they saves my day especially the database ones, thanks.


CASO(Posted 2007) [#10]
It is a great module!

I had some problems though....
1.I can't get it to save .ico files (the file is there but it doesn't show like a regular icon and won't open in Photoshop)(Oops...I was trying to save a PNG format as a .ico)
2.The image is upside down when I save it (fyi .ico to .png)(It is easy to go around this but I'm just curious)

Those are my only problems. (I would really like to save icons)

Overall it is AWESOME. Thank You Brucey.


Brucey(Posted 2007) [#11]
Coordinate system of freeimage is bottom-left so I flip it on load... I wonder if I shouldn't flip it back before saving then...
Saving wasn't as fully tested as loading of formats, so perhaps this slipped by.

It's quite a feature-packed library. Glad you are finding it useful :-)


CASO(Posted 2007) [#12]
Just curious... does Freeimage allow the saving of an icon with multiple formats/sizes?


Brucey(Posted 2007) [#13]
Hmmm, apparently it does. There's a "Multipage" section in the documentation which says it can handle TIFF, ICO and GIF formats in a multipage way.

I guess this would be a reasonably useful feature to add to the module then?


CASO(Posted 2007) [#14]
I am asking if it can create an icon file that contains any combination of sizes 16x16,24x24,32x32,48x48... and color depths 2 bit, 8bit, 24 bit, 32 bit.


Brucey(Posted 2007) [#15]
I assume that's what multipage implies, yes.


CASO(Posted 2007) [#16]
I almost feel guilty asking, but... could you explain how to use that feature?


Brucey(Posted 2007) [#17]
I haven't implemented the multipage part of the library in the module yet, so it's not going to be easy to use that until it's in there...

I guess I should put it on my list of things to do ?


Brucey(Posted 2007) [#18]
Sorry for the delay.... Seem to have got side-tracked somehow ;-)

Update of BaH.FreeImage module (1.02) :

* Hacked MNG plugin to validate images using the .mng header.
* Re-applied internal LibPNG support. Do not Import Pub.Libpng
* Loaded TFreeImages bitmaps are now not y-flipped at load-time. Therefore when saving they should now be in the correct orientation.
* New TMultiFreeImage type for multi-page image support (gif, ico and tiff).
* New LoadAnimFreeImage() function to create a multi-frame TImage from a multi-page image.

2.The image is upside down when I save it

I was y-flipping the image at load-time, so that pixmaps displayed correctly. I've disabled that foolishness, and therefore loaded images are not changed at all internally. I moved the y-flip to the "display" pixmap, that you see when you use getPixmap() - which creates a new image of a viewable resolution.
Hopefully that solves the inadvertent flip problem when saving between formats. Sorry about that.

The multi-page handling appears to be working (on the anim gifs I've been playing with). Haven't tried loading icon files, but I'm supporting all the multi-page features of FreeImage now, so if it works in FreeImage, it should in theory work in the module.

btw, FreeImage does not support multi-page MNG images. It will only display the FIRST page of a multi-page MNG image. This is a problem with FreeImage itself :-)


Anyways... Enjoy.

:o)