how to compress pictures efficiently

BlitzMax Forums/BlitzMax Beginners Area/how to compress pictures efficiently

Kemi(Posted 2006) [#1]
I use alphablend-mode for smooth edges in my png's with Blitzmax. However, I have to choose 24-bit png in Photoshop in order to create a png with alphamask. When I save as 8-bit png, alpha isn't supported.

Now, with 8-bit, the png file is less than 100k, while in 24-bit mode, it's almost 400k. Too large!

Any idea of how to save with a smaller file-size that still supports the alpha-mask?


Grisu(Posted 2006) [#2]
I think this is impossible. Don't use an alpha mask, just a transparency color like 255,0,255 and you will be fine.

An alternative way to get smaller filesizes would be to compress your media with the bmx zip module from Gman.


anawiki(Posted 2006) [#3]
or save images as jpeg2000 but be aware of slow loading.


ImaginaryHuman(Posted 2006) [#4]
Draw your image in 256 colors. Somehow convert the entire image into a single 8-bit channel, such as the Red channel. Keep your 8-bit alpha channel as well. Make the green and blue channels empty. Save as a 24-bit PNG - should be smaller. Load it in, then using a palette lookup table convert it back to 24-bit color.
?


FlameDuck(Posted 2006) [#5]
You can:
a) Use pngcrush to reduce the size of your 24-bit pngs.
b) Save the alpha channel as a seperate 8-bit image, and apply it to the image at runtime (this wouldn't be too fast but would work).


Kemi(Posted 2006) [#6]
Hm, how can I apply the alpha-channel at runtime? Let's say i loaded the pic into one image and the alpha-channel into another, then what?


Dreamora(Posted 2006) [#7]
Modify the rgba data pixel per pixel on the pixmap (so load pixmap not image and load the image from the modified pixmap afterwards)

Ok thats the noob approach at least.

Interstingly, if you check the Pixmap Documentation you will find out that it supports more formats than just the RGBA format, especially the a8 format ...
Haven't checked that but theoretically you might be able to load the grayscale to a8 and draw it over the original to apply alpha (perhaps with alphablend, don't know if it works on pixmaps) and then grab it again.


ImaginaryHuman(Posted 2006) [#8]
I've used A8 to create alpha textures. It doesn't seem to be much different to I8 (intensity), although intensity is like a grayscale version of a color image usually.

I don't think you can load 256-color images into a pixmap directly, when you use LoadPNG or it loads a PNG automatically, it converts it to a 24-bit pixmap RGB I think. You would need to then ConvertPixmap to RGBA format and then MAYBE you could load your alpha channel as A8 format and do pixmap.paste of the alpha channel into the RGBA pixmap?


H&K(Posted 2006) [#9]
Make the directory where the pictures are stored, into a compressed Directory. And then just forget about it.


Dreamora(Posted 2006) [#10]
Thats of exactly 0 use
Compressed directory only have use if the file format does not already use a compression technique (ie BMP and perhaps uncompressed TGA but thats it). Beside that: Those folders won't be compressed on other users system, so you would need to use real zip and zlib :-)


H&K(Posted 2006) [#11]
Oh. Live and learn

Mind you, I probably knew that.