Jpg and png texture performance
by Keith "The Dip" Wagner · in Torque Game Engine · 04/01/2005 (4:19 am) · 31 replies
Tried searching, but came up with no results.
Since jpg and png are two different image formats, they are no doubt read in differently. My question is if they are rendered any differently, and which has a better performance for slower machines. So far, png's have been smaller in size for all the textures I have compared, and it would be nice to stick with them. If jpgs have a performance benefit, though, I would rather use them and use a little more hd space.
Since jpg and png are two different image formats, they are no doubt read in differently. My question is if they are rendered any differently, and which has a better performance for slower machines. So far, png's have been smaller in size for all the textures I have compared, and it would be nice to stick with them. If jpgs have a performance benefit, though, I would rather use them and use a little more hd space.
#2
04/01/2005 (4:42 am)
However, the engine does not load the compressed PNG/JPGs -- it decompresses them before loading them into video card memory, meaning either way, you get BMPs.
#3
For example, if you save a screenshot in .jpg format, at 1024x768 it's roughly 200k. Saving it in .png format gives about a 1 meg image file.
Edit: And mike is right...it honestly doesn't matter since both have to be decompressed. Choice is basically a distribution focused one, not a performance one as far as I am aware.
04/01/2005 (4:50 am)
Hmmm...I find it pretty interesting that you guys are seeing .png files that are -smaller- than .jpg files--.jpg is a compressed file format that uses a strong but "lossy" compression algorithm, while to my knowledge .png uses a less "compressive", but lossless algorithm.For example, if you save a screenshot in .jpg format, at 1024x768 it's roughly 200k. Saving it in .png format gives about a 1 meg image file.
Edit: And mike is right...it honestly doesn't matter since both have to be decompressed. Choice is basically a distribution focused one, not a performance one as far as I am aware.
#4
04/01/2005 (4:55 am)
So the real question is how much decompression is done during gametime? Is the engine having to uncompress and load various textures during the game? If so, would it be better to save them uncompressed? And either way it would seem to get faster speeds you need smaller texture file sizes. Such as, reducing the detail and/or size of a .png to an uncompressed size of 400KB versus 600KB represents a (theoretical)33% performance improvement? Are these assumptions correct?
#5
04/01/2005 (4:59 am)
Zepp, I noticed purely by chance the other day that not only did I get better quality from the PNG but it was about 15% smaller than the JPG. I had to run some tests to confirm it because i assumed I did somethign wrong. But sure enough, by the time I compressed the .jpg to the same size as the .png I could see artifacts all over it and text had started blurring. Untill about 3 days ago I thought the exact same thing you did about the .png vs. .jpg.
#6
With your .jpg's getting artifacts, were you repeatedly loading and saving the .jpgs? That's the problem with a "lossy" compression algorithm--each time you save the file, it will lose detail. Do it enough, and I would imagine your file becomes unviewable, although I've never tried it!
04/01/2005 (5:11 am)
Well, I'm just basing it on the relative screen shot sizes for a .png vs a .jpg screenshot. It's a 5:1 ratio.With your .jpg's getting artifacts, were you repeatedly loading and saving the .jpgs? That's the problem with a "lossy" compression algorithm--each time you save the file, it will lose detail. Do it enough, and I would imagine your file becomes unviewable, although I've never tried it!
#7
When you export in .png it pretty much set's the compression for you and you gt what you get(you can choose no compression) and when you save in .jpg you can choose your compression in steps of 1%. So you can actually turn it up bit by bit to see where the artifacts start and then back off till they disappear. That's your optimum .jpg compression without artifacts. Or you can choose to compress more while viewing how much distortion you are willing to tolerate. As stated earlier, in my tests I found the same .psp image when exported to either format resulted in a better quality, smaller size file in .png.
04/01/2005 (5:16 am)
Exporting a newly designed image from the PSP7 pallet to either .png or .jpgWhen you export in .png it pretty much set's the compression for you and you gt what you get(you can choose no compression) and when you save in .jpg you can choose your compression in steps of 1%. So you can actually turn it up bit by bit to see where the artifacts start and then back off till they disappear. That's your optimum .jpg compression without artifacts. Or you can choose to compress more while viewing how much distortion you are willing to tolerate. As stated earlier, in my tests I found the same .psp image when exported to either format resulted in a better quality, smaller size file in .png.
#8
Also, Gonzo, I believe that the textures are loaded when the DTS shapes are loaded, which is the phase of mission loading where it says "LOADING OBJECTS", AFAIK. Therefore, any benefit would be loading time. Regardless, PNG is the best format quality-wise for skins and textures, especially for things like normal maps.
04/01/2005 (8:31 am)
From experience, I find that PNG compresses smaller than JPG in -small- images. When you get large images like screenshots, JPG is far more efficient, sizewise. I do not know the mechanism for this, however.Also, Gonzo, I believe that the textures are loaded when the DTS shapes are loaded, which is the phase of mission loading where it says "LOADING OBJECTS", AFAIK. Therefore, any benefit would be loading time. Regardless, PNG is the best format quality-wise for skins and textures, especially for things like normal maps.
#9
If you're getting smaller pngs with screenshots, thats weird... perhaps you're not compressing the JPEG or the .png isnt 24bit. In my experience a JPEG with only 10% compression will be a *LOT* smaller then the equivalent 24bit PNG. Note that JPEGs can only be either 24bit or greyscale, so its not a fair comparison if the PNG is not the same format.
T.
04/01/2005 (9:04 am)
How well either compresses is completely dependant on the image data. JPEG generally does a lot better with things like photographs and screenshots, but will generally mangle fine details such as text. PNG uses the Deflate algorithm (the same as used in .zip files) and is not very good at compressing 24bit images, but its better then not compressing at all.If you're getting smaller pngs with screenshots, thats weird... perhaps you're not compressing the JPEG or the .png isnt 24bit. In my experience a JPEG with only 10% compression will be a *LOT* smaller then the equivalent 24bit PNG. Note that JPEGs can only be either 24bit or greyscale, so its not a fair comparison if the PNG is not the same format.
T.
#10
Thanks for all the info guys
04/01/2005 (1:43 pm)
I thought that's how it worked, they get kept in memory as bmps, but I wasn't 100% sure. As far as using 24 bit pngs, I would consider that another form of compression. If you arent using enough colors to warrant 24 bit, then why wouldn't you want to save on bits?Thanks for all the info guys
#11

As you can see, the .png was nearly half the size with no distortion of the image at all. But the .jpg was greatly impacted by the .jpg compresson. So much so that it ruined the image completely in the fact that the entire point was to have clean lines. Even reducing the compresson to 1(which triples the image size in bytes) was still no match for the .png quality and was still artifacted and blurred.
I did run a test on a 6MB image just for fun, and the .jpg shrank to about 240KB while the .png was still 4MB, lol. But you do lose quality in the image when you compress with the .jpg. No doubt about it.
04/02/2005 (2:14 am)
Here's a pic that shows what the compression did to the same raw 515x512 image I had just created and what the resulting size was...
As you can see, the .png was nearly half the size with no distortion of the image at all. But the .jpg was greatly impacted by the .jpg compresson. So much so that it ruined the image completely in the fact that the entire point was to have clean lines. Even reducing the compresson to 1(which triples the image size in bytes) was still no match for the .png quality and was still artifacted and blurred.
I did run a test on a 6MB image just for fun, and the .jpg shrank to about 240KB while the .png was still 4MB, lol. But you do lose quality in the image when you compress with the .jpg. No doubt about it.
#12
04/02/2005 (2:46 am)
PNG is going to do better than JPEG when there is a limited number of colors, if I remember right. Which I may not.
#13
You can tweak the quality of JPEG compression, of course, too. At high levels it copes decently even with fairly difficult images, like line drawings. PNG tends to do better in those cases, though.
With careful tweaking, you can get phenomenal compression out of JPEG - see the ThinkTanks demo for a good example.
DXT is grand but only gets you 4:1 compression, and that by cutting out most low-end hardware...
04/02/2005 (10:44 pm)
PNG uses a lossless, zlib-inspired compression system. It supports aggressive palletization (so good for images with limited numbers of colors). JPEG uses a wavelet system, much better for "real world" images. It all gets decompressed to the same size in memory, so don't worry about that. (Things like DXT help, but not a lot, around 1:4 or so).You can tweak the quality of JPEG compression, of course, too. At high levels it copes decently even with fairly difficult images, like line drawings. PNG tends to do better in those cases, though.
With careful tweaking, you can get phenomenal compression out of JPEG - see the ThinkTanks demo for a good example.
DXT is grand but only gets you 4:1 compression, and that by cutting out most low-end hardware...
#14
04/03/2005 (12:02 am)
The important thing about DXT is that it stays compressed in video memory, so it takes up less RAM and can also improve performance. It's not meant to compete with PNG and JPG as an "on-disk" compressor.
#15
04/03/2005 (7:33 am)
Right, DXT is great for certain situations in run-time, but don't count on it.
#16
04/03/2005 (8:52 am)
DXT is only worth it if you have hardware support for it, like Ben says. Another possibility is to split out the alpha channel of a PNG into a seperate image and jpeg compress it along with it's RGB channels.
#17
04/03/2005 (4:40 pm)
Yes, doing that sort of splitting let BT save a lot of space on ThinkTanks.
#18
04/05/2005 (7:19 pm)
PNG is almost always bigger when I use it. The issue with JPEGs is having no alpha channel though. That is a big deal for a lot of games these days. I make my images in PSD and keep the originals in that format. Then I use JPEG whenever I can and PNGs for the images that I need with alphas. That way you don't have to worry about continuing to make your tesxtures "lossy". I think the main benefit is disk and download space since most of the games being made on GG won't be sold in stores, they will be downloaded.
#19
04/06/2005 (2:23 am)
How do you go about splitting out the alpha channels?
#20
.pngs compress well if you have a few colors and a lot of black space. if it is a texture map (like one would normally use for a model) the .jpg will compress WAY more.
side note.. just did a little testing with the .dds and the DXT stuff... neat that it stays compressed in memory.. crazy what it can do to yoru textures, especially the weird results with the alpha channel compression..
maybe I will bug clark to write up something about the .jpg splitting stuff we did for TT.
04/06/2005 (3:37 am)
For thinktanks, clark wrote a little thing that stripped the alpha out of the jpg and turned them into 2 jpgs. one for the image, one for the alpha, which we could them compress the hell out of.. resulting in small file sizes.. just open up the images in the demo and take a look at the files.. you can get them really small..pngs compress well if you have a few colors and a lot of black space. if it is a texture map (like one would normally use for a model) the .jpg will compress WAY more.
side note.. just did a little testing with the .dds and the DXT stuff... neat that it stays compressed in memory.. crazy what it can do to yoru textures, especially the weird results with the alpha channel compression..
maybe I will bug clark to write up something about the .jpg splitting stuff we did for TT.
Torque Owner Dreamer
However given that w/o compression my PNG's are 50-75% smaller than thier equivanlent JPGs and the fact that memory savings tends to = speeup, I would stick with PNGs