PNG vs BMP!

Started by
8 comments, last by teebee 16 years, 10 months ago
Some people prefer PNG to BMP but I really don't see a difference. What is the difference between the two formats? Which one is better? What are the pros and cons?
Advertisement
PNG has very good lossless compression. BMP isn't compressed. The fact that you don't see a difference is why people like PNG. [smile] To see the real difference, look at the file size.

EDIT: I shouldn't say BMP isn't compressed... it isn't usually compressed. It can be, using run-length encoding, I think. BTW, PNG also handles transparency more easily.
You won't kill your bandwidth as quick with PNG. As smitty pointed out, file size is the key difference. Just use PNG and forget BMP for the time being [grin]

Beginner in Game Development?  Read here. And read here.

 

I use PNG almost exclusively as my image/texture format for basically the same two reasons mentioned above. PNG is compressed so the overall size of you game (or app) will be smaller when you go to distribute it. PNG also has an alpha channel which allows for gradient transparency as opposed to binary transparency. (aka. transparent or opaque)
Other than the fact that the code to load PNG files is more complex, i dont see any disadvantages compared to BMP.

---
Stevo
----Stevo
The two main reasons, as have been said, are transparancy and compression. PNG is nice because it can have transparancy built-in, while adding transparancy to a bitmap is really a bit of a hack, and not supported by many editors. PNG compresses nicely because it has several compression methods at its disposal Some work better for flat-shaded images (cartoons, limited color images) while others work better for more realistic scenes (textures, photos); PNG chooses the best one. The net result is that simple images often compress better than GIFs, while more complex images offer compression very close to JPEG, with similar visual quality.

The main benefit that BMP offers over PNG and most other formats is that it is incredibly simple to load, since its essentially a memory-image of the graphic data plus a small header. PNG and other compressed formats require a loader to de-compress the image as its loaded, making the loader more difficult to write. That said, there are very mature, free loaders for nearly every image format, including PNG.

TGA is another nice format that was/is common in games. In many ways, TGA is a middle-ground as it supports transparancy, is easier to load than PNG, but doesn't compress as well.

throw table_exception("(? ???)? ? ???");

Bitmaps really are the most straightforward way of storing images. That's why they're great if you want to store/load images and not bother with compression. However, an uncompressed image can become pretty big. The formula for the size of an uncompressed Bitmap is width * height * bytes per pixel. So a bitmap that is 1024x768 at 32 bits per pixel will be 3 megs in size.
PNGs are just like bitmaps (in that they store pixel images), but a lossless compression is applied before saving the images. This results in relatively small files. What's nice about PNGs is that the compression algorithm used is not covered by any patents which means you're free to use PNGs in your programs even if you plan on selling them. Unfortunately, uncompressing PNGs isn't easy. So while you could write the code to load a bitmap in about five minutes, with PNGs you will usually resort to using some sort of library.
Also loading PNG:s takes much longer, so if have loads of images and your application needs to be loaded as quickly as possible, you might want to consider another format.

Also remember that while PNG files are much smaller that BMP:s when they are stored in your hard drive, they take the same amount of memory as BMP:s when uncompressed and loaded in to your application.
Quote:Original post by teebee
Also loading PNG:s takes much longer, so if have loads of images and your application needs to be loaded as quickly as possible, you might want to consider another format.


I suspect that's not entirely cut-and-dried. Disk access is incredibly slow compared to memory accesses and computation. A Typical processor runs about 40 million cycles in the time it takes to read 1MB of data from a hard drive (assuming 60MB/s transfer, which is a pretty generous estimate). The question becomes "Does it take longer to load 2 or 3 times as much data, or to decompress less data.)

There's likely many factors - Hard-drive speed, fragmentation of the file then there's the contents of the image and how well it was compressed and how easily it is uncompressed.


Your assertion is likely true for small images that, for whatever reason, generated a file exhibiting decompression requirements that approach worst-case.

I presume that the average case is comperable to, or better than, bitmap, but most certainly not "much longer".

throw table_exception("(? ???)? ? ???");

Quote:Original post by Harry Hunt
So while you could write the code to load a bitmap in about five minutes, with PNGs you will usually resort to using some sort of library.


And those libraries are pretty easy to get a hold of, and best of all, they're usually free!
Quote:Original post by ravyne2001
Your assertion is likely true for small images that, for whatever reason, generated a file exhibiting decompression requirements that approach worst-case.

I presume that the average case is comperable to, or better than, bitmap, but most certainly not "much longer".


You are correct. I've had troubles with small files, yes, but i based my reply mostly on one of our projects, where we needed to load user-interface graphics during runtime. It was damn slow until we changed almost all images from PNG to DDS format. Of course, it probably wasn't the uncompressing time that slowed down the loading, but the conversion of PNGs pixel data to D3D surface. Ugh, stupid me.

This topic is closed to new replies.

Advertisement