BAH.freeImage module Question

BlitzMax Forums/BlitzMax Programming/BAH.freeImage module Question

Afke(Posted 2011) [#1]
Hi guys,

I use free image module , what is replacement for standard LoadAnimImage ?

Or is there some way to convert ,I don't have idea :(


Afke(Posted 2011) [#2]
There is an way to convert TMultiFreeImage.toAnimImage() which is cool

I am switching my project to blitzMax and I need freeImage features.

I have animated images, most of them in PNG format with alpha channel .
I can save them in multi-page but because of alpha channel i have to use
TIF format then which is bad because of the file size. 0.5 MB Png image becomes 2.5 MB Tif image.

The best solution will be to load them with LoadAnimImage and then convert to TMultiFreeImage or something .

Is there something i missed , any help please


Kryzon(Posted 2011) [#3]
One way would be to write an application that reads a multi-frame\page TIFF, converts it to a regular animImage (just like you're doing with the .toAnimImage() method), but then merges all the frames into a single animation strip and saves this as a PNG.

If the FreeImage module doesn't have a function to load animation strips as animImages then you could recycle the one Max2D already has - reproduce the code but using the FreeImage module.

EDIT: I don't see why having to use an alpha channel prohibits you from using PNGs directly. PNGs support alpha channels.

Last edited 2011


Afke(Posted 2011) [#4]
Thanks for your replay ,

You didn't understand me , I am using already Png format with alpha channel :) All my animation strips are png files .

I don't know how to use png animation strip with freeImage ,as you already said there is no function to load animation strips as animImages.

Not sure ,what is best solution to solve that problem

any ideas ?

Thanks again

Last edited 2011

Last edited 2011


Kryzon(Posted 2011) [#5]
Oh, I see now. I didn't understand it indeed.
From what I've read from the source, I imagined this:

• Create an empty TMultiFreeImage.
• Load your PNG image-strip as a simple TFreeImage.
• Use the TFreeImage.copy() method to extract snapshots of each individual frame in the image strip. This Copy() method extracts a rectangular section of an image and returns it as a new TFreeImage. It is very similar to Max's PixmapWindow() function, but the way you specify the rectangle is different.
• Every time you snapshot a new frame, use the TMultiFreeImage.append() method to append the newly extracted frame as a new page in this multi-page image. Do this until there are no more frames left to extract.
• Free the original TFreeImage that contained the image-strip, since it's not necessary anymore.

This should leave you with a TMultiFreeImage that has one page for each frame from that image strip.

Last edited 2011


Afke(Posted 2011) [#6]
Thanks for your help


Afke(Posted 2011) [#7]
For those who has same problem works like charm:

Strict
Import bah.FreeImage
Import brl.glmax2d
Import maxgui.Drivers

Type TFreeAnimImage Extends TImage
	Field images:TFreeImage[]
'	
	Method SetPixmap(index, pixmap:TPixmap)
		If (flags & MASKEDIMAGE) And AlphaBitsPerPixel[pixmap.format]=0
			pixmap=MaskPixmap( pixmap,mask_r,mask_g,mask_b )
		EndIf
		images[index] = TFreeImage.CreateFromPixmap(pixmap)
		seqs[index]=0
		frames[index]=Null
	End Method
	Function CreateNew:TFreeAnimImage(width, height, frames = 1, flags = -1, mr = 0, mg = 0, mb = 0)
		Local t:TFreeAnimImage = New TFreeAnimImage
		t.width=width
		t.height=height
		t.flags=flags
		t.mask_r=mr
		t.mask_g=mg
		t.mask_b=mb
		t.images = New TFreeImage[frames]
		t.frames=New TImageFrame[frames]
		t.seqs=New Int[frames]
		Return t

	End Function
	Function LoadAnim:TFreeAnimImage(url:Object, cell_width, cell_height, first = 0, count = 1, flags = -1, mr = 0, mg = 0, mb = 0)
		Local pixmap:TPixmap=TPixmap(url)
		If Not pixmap pixmap=LoadPixmap(url)
		If Not pixmap Return

		Local x_cells=pixmap.width/cell_width
		Local y_cells=pixmap.height/cell_height
		If first+count>x_cells*y_cells Return
		
		Local t:TFreeAnimImage = CreateNew(cell_width, cell_height, count, flags, mr, mg, mb)

		For Local cell=first To first+count-1
			Local x=cell Mod x_cells * cell_width
			Local y=cell / x_cells * cell_height
			Local window:TPixmap=pixmap.Window( x,y,cell_width,cell_height )
			t.SetPixmap cell-first,window.Copy()
		Next
		Return t
	End Function
	
End Type


Last edited 2011