Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficiency of Using PNG's vs. BMP's With Large Files

I've written a mapping program in Delphi where the user can load a raster image in the background which I store in memory. In one case the user loaded a 44MB BMP successfully but the program was sluggish and when they printed (I tile the output) they got an Out Of Resources error. I converted the BMP to a PNG (3MB) and the program performs much better and the print job was successful.

Since the PNG has to be expanded to a DIB of the same size anyway why is there a performance/resource difference? If anything it should take more work and memory allocations to load the PNG. What am I missing?

Since there don't seem to be any obvious answers I'll write a small demo project so I can research this further.

like image 514
Mitch Avatar asked Apr 05 '12 16:04

Mitch


1 Answers

The difference is compression.

BMP = raw data as is PNG = same raw data using "lossless" compression

This has a saving in more than 1 way in programming circles ...

  1. loading the image results in loading less raw data in to ram.
  2. You are then processing less raw data so you need less resource.

Tiling means the problem for you is exponential for example ...

44MB x 10 tiles = 440MB

Vs

3MB x 10 tiles = 30MB

Printers don't like being handed massive chunks of data and all but the more expensive printers tend to like to print and entire document in one go (eg buffer the whole stream).

So from your app the user says "Print" ... your code then says "right i'm gonna send 10 copies of this" and the printer starts "caching" 440MB of raw data.

Most common home printers rely on the pc to do the caching and print what it's given but a standard office printer will do the caching then print the doc.

However ... i think this is an optional thing you can tweak (i'm thinking it varies from printer to printer though).

EDIT:

heres something from the world of game programming:

http://www.gamedev.net/topic/450104-png-vs-bmp/

like image 192
War Avatar answered Nov 14 '22 13:11

War