Brucey's Freeimage.. Compile error..

BlitzMax Forums/BlitzMax Beginners Area/Brucey's Freeimage.. Compile error..

BachFire(Posted 2007) [#1]
Hey Brucey, (or someone else who can help)

Your freeimage module looks very interresting. I have read how to install it on your page. However, when I build the module, and it reaches the file "NNQuantizer.cpp", it gives me this compile error: "error: exception handling disabled, use -fexceptions to enable".

I'm on a Mac, if that should make a difference.. Any idea what I can do?


Brucey(Posted 2007) [#2]
You need to compile it using my modified BMK (the executable that comes with BlitzMax which controls compiling modules and apps).

There's a link on the downloads page in the Notes section of the freeimage bit which points you to a .zip of bmk. You need to unzip this somewhere, and compile bmk.bmx with debug and GUI disabled. Then you copy the resulting "bmk" executable to the BlitzMax/bin folder. (warning - remember to take a backup of your original bmk executable before you overwrite it with this one!!!!).

The reason it needs a modified bmk is to allow the setting of non-default compilation options required for the library - like in this case, enabling of c++ exceptions.


BachFire(Posted 2007) [#3]
Ahh, thank you!! :)

I was so careful to follow the instructions on your page, but did not think about compiling it. Maybe that was a given, I'm sorry.

Anyway, that helped. Compiling completed without errors. But now there is a another problem. I have read the help, and I don't think I'm doing anything wrong:

Import BaH.FreeImage
SuperStrict

Local style:Int = WINDOW_TITLEBAR
Local MainWindow:TGadget=CreateWindow("Blitz Basic Test Bed",200,200,600,600,Null,style)

Global Picture:TPixmap = LoadPixmap("screenshot.gif")
Global Canvas:TGadget = CreateCanvas(0,0,550,550,MainWindow)

SetGraphics CanvasGraphics(Canvas)
Cls
' DrawImage Picture,0,0
DrawPixmap Picture,0,0
Flip

Repeat
	WaitEvent()
Until EventID()=EVENT_WINDOWCLOSE
End


With the above code, it says "Unable to convert 'brl.pixmap.TPixmap' to 'TImage'".. If I use TImage instead of TPixmap, it says it can't convert that to 'brl.max2d.TImage'.. If I load it with "LoadFreeImage" it gives me the same kind of error. If I omit the type specifier for "Picture", and removes SuperStrict, it compiles with no errors, but then program crashes with a "Null object" error, as if it could not load the Gif image. Of course the Gif image is present and working, and I wrote the right name for it. I don't see what I'm doing wrong. Does that make any sense?


fredborg(Posted 2007) [#4]
You are trying to use DrawImage with a Pixmap, which is not possible. There are two solutions:

1) Use DrawPixmap instead.

2) Use LoadImage to load the pixmap into an image, like this:
Local image:TImage = LoadImage( Picture )
DrawImage image,0,0



BachFire(Posted 2007) [#5]
@fredborg

Thanks. Yes, that was certainly a mistake. Your suggestion works, if the picture format was something BB supported internally, like .png. I'm trying to load a .Gif with Brucey's FreeImage module. ;)


fredborg(Posted 2007) [#6]
It works regardless of which format it is, because you are loading the pixmap not the file into the image...

picture:TPixmap = LoadPixmap("some.thing.bla")
image:TImage = LoadImage(picture)

Like that!


BachFire(Posted 2007) [#7]
Well.. With LoadPixmap, it loads a .png image just fine and displays it with no problems. That will NOT work with a .gif image - at least, not on my machine..

PS. Just in case: When I said it was a mistake, I meant that I made the mistake. ;)


Brucey(Posted 2007) [#8]
Thanks fredborg for the help :-)

Bachfire, there's a "tests" folder with the module. Open test_01.bmx and change the LoadPixmap line from "logo.jpg" to "logo.gif". Then run it...
It should work. (there's a set of test images in there that I used during development - exported from The Gimp app).

:-)


BachFire(Posted 2007) [#9]
I'm sorry, that I'm maybe a bit slow learner.

Ah, thanks. That works. I'll just study your code in the example. And that works with my own .gif too, except it is VERY dark when it displays it in BB? How can that be? Maybe something is wrong with the image..


Brucey(Posted 2007) [#10]
I'm wondering if perhaps it's a "Framework" problem...

Without using a Framework, Blitz automatically imports the Pub and BRL modules into your app. Which bloats your app size a lot more than it needs to be.

If you use Framework <some-base-module.mod>, and Import only the modules you need, your app size will end up much smaller...

It's possible that the libjpeg in FreeImage is clashing with the libjpeg in Pub, causing the app to misbehave... (trying this on Linux, the app crashes when it tries to load using the jpegLoader.)

I did *try* to use the Pub.libjpeg during development, but the two versions don't seem to be compatible, so I had to go with the freeimage one in the end to make my life easier when it came to compiling the library...

There is a nice app called Framework Assistant (search the forums!) which can "guess" the list of imports you might need for any particular app.


Brucey(Posted 2007) [#11]
Here's an example of using Framework :
Framework BRL.Max2d

?win32
Import BRL.d3d7max2d
?
Import BRL.GLMax2d

Import BaH.FreeImage
Import Pub.LibPng ' for png support

' GUI
?macos
Import BRL.CocoaMaxGUI
?linux
Import BRL.FLTKMaxGUI ' or BaH.GTKMaxGUI
?win32
Import BRL.Win32MaxGUI
?

Import BRL.EventQueue



BachFire(Posted 2007) [#12]
Okay, interresting.. So, if I understand this correctly.. In your test_01.bmx, shouldn't it work just the same (not counting resulting filesize) if I just did an "Import BaH.FreeImage", and left out "Framework BaH.FreeImage"?


Brucey(Posted 2007) [#13]
In theory, but because of a possible name-clash (between libjpeg in Pub and libjpeg in freeimage) the results may be undetermined...

I would hope that Best Practice dictates that Framework is used over letting Blitz include everything by default... anyhoo. Might require some extra notes in the module...

As far as the darkness of the image goes. There's a suite of image manipulation methods available with the library - although to use them you need to use LoadFreeImage().
From there you can acquire a pixmap for drawing purposes through the getPixmap() method of the TFreeImage object.

HTH :-)