PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Which Image Format?

Which image format do people normally store their art assets in?

I was using PNG, but JPEG seems to give much smaller files. For example, I can get one file from 106135 bytes down to 14678 bytes, just by converting it from PNG to JPEG. Both images look good.

(As an aside, perhaps I'm using the wrong options in the PNG file? Is this much difference typical, or am I misusing PNG?)

Sure, JPEG can't handle transparency, but I can just use a key colour so long as I don't need a full alpha channel (I don't).

What are peoples' thoughts and experiences here? Any good URLs for reading?
Hi Mhel,

I prefer PNG esp of it's transparency feature and a million colors support.

If you need to change your image background, you dont need to worry erasing the background unlike .jpg

Regards.
What do you mean about erasing the image background?
Since PNG supports transparency, it's better if you save your image as transparent. So if you need to change your image background all you have to do is to paste it on top of another image or differenct colors like black, blue etc.
I tried converting a bunch of my images. (I'm mostly concerned with the larger ones, screen sized or larger.)

Some I found were smaller as JPEG (typically the less computer-looking, more photo-looking ones), but some remained smaller as PNG.

Here's one neat effect. I currently load tiled animation frames from a single image. When converted to JPEG, each tile now looks slightly different even in the places where it should be the same. This gives a bit of a "glimmer" effect when I animate. I'm not sure if this is neat or annoying.

It looks like, at least for now, I'll leave my app as being able to load either, and just use whichever seems suitable for the particular image.
I think a decent sized level image, for my game, will be about 150K (using PNG.)

That means if I have 25 levels, it will take roughly 3.75MB. Is that acceptable?

If the same image was about 20K (using JPEG), then 25 levels would only be about 0.5MB. Much more acceptable, but not as nice looking.

How about this revolutionary idea: I give the user the choice whether to install the good-looking but larger PNGs, or the smaller but not-as-nice JPEGs?

This all goes to the other thread I started in the general developer discussion area, about how big is too big (for the application). [Actually I'm not sure where I posted that but I'm relatively sure I did.]
denthorq wrote:
Since PNG supports transparency, it's better if you save your image as transparent. So if you need to change your image background all you have to do is to paste it on top of another image or differenct colors like black, blue etc.


But how is that different from just picking a key colour (e.g. magenta) to serve as transparent in a JPEG?
Some games just save the images in a \directory and not using resource. PNG image quality is far better than JPG.

What I mean with background is for future use. You can easily edit or resize PNG image without sacrificing the quality.
PNG uses a lossless compression algoritm and JPG doesn't. That is one of the reasons JPG can compress better because it makes up pixels. So if you want your image to look exactly as in Photoshop/Paint Shop Pro/etc save it as PNG.

Maurice
I use a directory and not resources.

I understand the lossy/lossless difference. I just thought PNG compressed a little better than what I'm seeing.

My app can now handle both, so I guess I'll just make them all as PNG, and if it looks like they are too big, think about changing some to JPEG, perhaps as an installation option.

The thing that lets me get away with this, is that my level images actually look like photos and so even under lossy compression, they still look really nice.
Does not reducing the colour depth of your PNG files give you better file sizes?
mlepage: Also, run-time memory is much lower if you use PNG. JPEG images are decoded using the built-in IMGDECMP.DLL library, which always creates and extra 24-bit copy.

So if you have an image of say, 300x200 pixels.. Decompressing it as a PNG requires (300x200x2 + 300x3) bytes of memory (one gapisurface and one rgb row). Decompressing it as a JPG requires (300x200x2 + 300x200x3) bytes of memory. Of course, those (300x200x3) will be deallocated once the image is loaded..

This is perhaps not an issue with small images, but if you have large tilesets it will make quite the difference...
StarFury: Yes, it helps a lot to reduce number of colors. Well, guess only if you get it below 256 colors. Do check Image Optimizer on www.xat.com we use that for our mobile games and it is great for PNG files. Can also reduce size of other images.

Best,

Sam
Warlords II is about 4M in size, about half of of which is image resources - the other half being sounds, music, data and a 700K executable. pocketPachisi on the other hand is only a 500K install with all media resources compiled in. While size of the install needs to be monitored so it doesn't get out of hand, I wouldn't let that govern what I develop. Warlords III - RoH and DLR will probably be in the 12M neighborhood and I'm not too concerned about it - as long as it fits on the typical device thats fine with me.

I do all of my images in PNG format because it of its lossless compression and alpha channel. I also always try to convert each image to 256 color (Paintshop Pro makes this easy) - if there are palette slots left over, I leave it at 256 colors. If there are no palette slots, I leave it at 16K colors so I don't lose anything.

I also store nearly all of my images in a subdirectory, except for the few splash screens (ppcStudios and Infinite Interactive logos, demo screen and game title) which are compiled in as resources so noone alters them (easily at least).
Thanks for the info Gary.

Right now even my splash screens are files. I'm not sure if I'll make them resources or not. A determined person could still change them. If people buy my game, they can change it all they want. :-) I might bundle everything into a PAK-like file though.
mlepage wrote:
But how is that different from just picking a key colour (e.g. magenta) to serve as transparent in a JPEG?




the problem when using jpeg & magenta as
a key color: as the image is compressed losing data, you
could get some of the magenta background colors slightly
changed (i.e. expecting 255,0,255 and getting 250,3,250).
As gapidraw works at 12,15 or 16 bpp this might not be
an issue, but it'd be in 24 or 32 bpp displays.

the reason some jpegs are compressed better than pngs
is that jpeg analizes the images and detects which
information is not detected by our eyes, removing them.
IIRC high frequency data (edges) take more space in
the jpeg, as it's more important (visually speaking)
than low frequency, which gets a lower amount of data.
Just take a photo and convert it to jpg and png. PNG
is a LOT bigger.

Pixelated graphics contain a big amount of high
frequencies, that's why jpeg doesn't do well compressing
them, and even distorts them in some way. In example, get
a image file with 1 line white, 1 line black, 1 white,
1 black... for 320 pixels width, 200 height.
Then draw over the grid with twhite color a
little bit (10, 15 lines, not straight), so that lines
look very "cut" and it's not a perfect grid image.
compress it with jpeg and png. you'll probably get a
3 kb png versus a 35 kbs jpg (even losing quality)

hope this helps :)
Kak
I'm going to stick with PNG mostly, and just use JPEG for some photo-like images, if they are significantly smaller and there are no ill effects from compression.
I personally dislike the use of JPEG in nearly all situations. JPEG has an amazing (and complex) compression algorithm, but it's only suitable for photographs or some very specific cases. For games, I use both 8bit and 24bit PNGs. JPEG is just way too lossy. PDA games use small graphics, so it's important to mind the graphical precision. I try to use PNG-24b whenever possible, but I'd rather use PNG-8b than JPEG.

Oh, and please note that PNG-8b is NOT necessairily smaller than PNG-24b, specially in small images (I guess it must take space to store the pallete).
Oh, and please note that PNG-8b is NOT necessairily smaller than PNG-24b, specially in small images (I guess it must take space to store the pallete).


Very correct. Worse is that most programs will save all 256 colors, even if only 3 is used. Again as said before, check Image Optimzer from www.xat.com or find PngCrunch http://pmt.sourceforge.net/pngcrush/

-Sam
I'm trying out Image Optimizer for another project right now, and I must say I'm impressed. It allows us to save a png with 10-25% less size than the original. And on a 64k max. device it can be just enough :)

pngcrush doesn't seem to work under Windows 2000 (needs a real DOS prompt, which isn't available under w2k)

Maurice
We are also mainly developing for J2ME devices (often 64 KB limit) and yeah, saving that much on PNG's are very good. I used it a lot for title screens also where you often can remove a lot of colors without anyone will notice, and then save a few KB.

pngcrush doesn't seem to work under Windows 2000 (needs a real DOS prompt, which isn't available under w2k)


how about using 4nt (4dos for Win 2000/XP/NT). Does the trick regarding command line interface.. I always surprised how people can work without it :)

-Sam
mlepage wrote:
I think a decent sized level image, for my game, will be about 150K (using PNG.)

That means if I have 25 levels, it will take roughly 3.75MB. Is that acceptable?

If the same image was about 20K (using JPEG), then 25 levels would only be about 0.5MB. Much more acceptable, but not as nice looking.

How about this revolutionary idea: I give the user the choice whether to install the good-looking but larger PNGs, or the smaller but not-as-nice JPEGs?

This all goes to the other thread I started in the general developer discussion area, about how big is too big (for the application). [Actually I'm not sure where I posted that but I'm relatively sure I did.]


Test and see how small the files are with zip compression -- I'll bet your 150 KB PNG can be stored in a ~30-50 KB archive. No reason to store them uncompressed in your final product. Using zlib or another library you can easily create a class or set of functions to decompress them into memory when the game loads. Also if you're worried about art being ripped off or modified, it would be easy to store the compressed archive with some sort of symmetric encryption - take your pick of various 128-bit algorithms. You'd have to hard-code a way to generate the key (I would not just store it in the executable) so it would never be 100% secure, but I'll bet nobody would ever go to the trouble to break it. Obviously the amount of program memory needed when running the app would still reflect the uncompressed size of the image data. I would only include very very small images as resources, and very few of them at that, because I don't like bloating the executable with resources, but that's just me (plus having to recompile everytime you modify art).
Pngs are by default stored in a compressed format.
Of course, since this is a loseless compression, it will never be as efficient as say jpegs.
Anyway, I highly doubt zipping pngs will make any difference.
PNG files are compressed with zlib, so close to zip.

Just for your information.