Optimizing the game package - > PNG into JPG+PNG

Blitz3D Forums/Blitz3D Programming/Optimizing the game package - > PNG into JPG+PNG

AJirenius(Posted 2007) [#1]
I'm trying to optimize all my 32 bits png images as they are pretty big in my (hopefully) finished game just to reduce packagesize.

The theory is instead of using 32-bits pngimages which is rather big sizedimages, I would like to use one JPG instead and apply a 8bit-alpha.png on that one instead.

Is it possible to do this on textured entities without having to rewrite all my code???


AJirenius(Posted 2007) [#2]
Ok, to clarify and put it in one simple question:

Is it possible to load COLOUR-DATAfrom one image and ALPHA-DATA from another and store it in the same texture (not multitextures)????


Who was John Galt?(Posted 2007) [#3]
It's possible, but I think you will have to write your own code to do it. As jpg compression is lossy, you will lose image quality.


AJirenius(Posted 2007) [#4]
Yes I know it's lossy, it's unfortunately the only way to go to lower it more than png 32bits images.

What I tried at the moment is this:

Tex = 	LoadTexture ("Data\Buttons1.jpg", 3)	
Tex2 = LoadTexture ("Data\Buttons1.jpg", 1)
CopyRect 0,0,w,h,0,0,TextureBuffer (Tex2),TextureBuffer(Tex)
return Tex


but appearently it just didnt work and only kept the alpha channel anyway :(
any suggestions?


_33(Posted 2007) [#5]
Bug already reported.

http://www.blitzbasic.com/Community/posts.php?topic=71621

Some people think it's not a bug, but I think it is. Textures do have alpha channels, as well as 32bit graphics modes. But Blitz3D doesn't copy the whole 32bit, only 24 bit (RGB color values). So we are out of luck for this one. If you build your texture in memory as an image, you can't define alpha values and then copy that back to the texture buffer.


AJirenius(Posted 2007) [#6]
But I am doing it the other way around and not copying the alphachannels but the normal colourchannels (RGB), alphachannel would hopefully stay intact, but it doesn't seem to work anyway.


Subirenihil(Posted 2007) [#7]
Suggestion: Don't use compressed images.

Now, I know that sounded very strange, but I have my reasons.
Image compression is very poor compression, even .jpg

Here is a list of compression of an image:
.bmp - filesize 3841KB (no compression)
.jpg - 537KB
pure blitz3D coded compression of .bmp - 396KB
.zip - 122KB

I'll try to find the link to the compression algorythm.

there is also a dll to pack/unpack .zip files


jfk EO-11110(Posted 2007) [#8]
I've published some code that does exactly what you want, in the code archives. Instead of copyrect you simply use WritePixelfast to set the alphabyte:

rgb=readpixelfast(x,y,jpgbuf) and $ffffff
a=readpixefast(x,y,pngbuf) and $ff000000
writepixelfast x,y, (rgb or a)


_33(Posted 2007) [#9]
Suggestion: Don't use compressed images.


What do you mean by:
pure blitz3D coded compression of .bmp - 396KB


And omitting to mention PNG... tsk tsk.


Subirenihil(Posted 2007) [#10]
.png - 229KB

Interesting, I'll have to check my sources, I was under the impression that .png and .jpg used the same compression algorithm, only .png adds alpha layer and keeps colors exactly. It would seem that I was mistaken.

Purely B3D coded Compression
Purely B3D coded Decompression

(Note: I applied the compression algorithm multiple times to get the stated file size)


_33(Posted 2007) [#11]
Thanks Subirenihil for the compress / decompress code. I'll have a look at it this weekend.


jfk EO-11110(Posted 2007) [#12]

.bmp - filesize 3841KB (no compression)
.jpg - 537KB
pure blitz3D coded compression of .bmp - 396KB
.zip - 122KB



Wait a minute. zip 122k? I think this depends a lot. As far as I know the packing algos of jpg, PNG and GIF are about as efficient as zip. Where in JPG you can greatly control the amount of loss, so whenever you list JPG then you should say at what quality percentage. Depending on the kind of image (cell shaded something, or a complete chaos) lossless compression is more or less efficient.

IMHO the best format sizewise is DDS anyway. (not for lightmaps)


Rroff(Posted 2007) [#13]
I'd just use DDS for everything anyway (using the appropriate DDS settings for lightmaps and normalmaps)