FreeTGA?

BlitzPlus Forums/BlitzPlus Programming/FreeTGA?

Tyler(Posted 2006) [#1]
I'm using the LoadTGA and DrawTGA functions I found in the code archives, but I need to know if there's a way to write my own FreeTGA function, and how I'd go about doing that.

I'm not sure whether it's the amount of TGAs I've got drawn (only 7), or the way I'm loading / deleting them whenever the image list updates, but Blitz+ slows to a crawl and dies after only 6-7 small TGA files (72x72 pixels), so I think it's that I've got no equivalent to "FreeImage" with the TGAs. Please help! Thanks!


Matty(Posted 2006) [#2]
To free the TGA you would need to do the following, I assume you are using Andres Code Archive Entry:

free the image then free the bank like so:

Function FreeTGA(%image)

imghandle=peekint(image,2)
if imghandle<>0 then freeimage imghandle
freebank %image

end function



Also you may notice that in the LoadTGA command he does not close the file that was read from so you should include a "closefile file" command prior to the command "return bank"

There are ways to optimise drawing of images like this.

Because these images have to be drawn pixel by pixel, as in the DrawTGA function, a few tips would be:

1.Rather than calculating the color of an alpha blended sprite for each pixel regardless of whether it is fully transparent or fully opaque only calculate the alpha for those pixels with an alpha value of neither 0 nor 255.

2.Locking buffers does speed things up, which he does, but it is faster to do all your pixel writes in one hit than locking/unlocking buffers between each image to be drawn.

Those are some of my thoughts on the matter, hope it can help a little.


Tyler(Posted 2006) [#3]
Thank you! You've helped me immensely, and I'll see about taking your advice on selective calculating of the alpha pixels and buffer locking! Thank you again :D


Andres(Posted 2006) [#4]
You don't need to worrie about the first aspect provided by Matty because it already does draw pixels 0/255 with DrawImage.

One more thing: Do you even need to use lockbuffer/unlockbuffer when using PokeInt to draw a pixel?

Updated the archives.


Tyler(Posted 2006) [#5]
I appreciate all the help and thank you Andres for writing the TGA functions :D