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

1

8

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.

Sanhedrin answered 5/4, 2012 at 16:53 Comment(4)
Are you positive the BMP and PNG files have the same number of pixels and BitsPerPixel?Occiput
What you are using to print the image? Are you writing directly on the Printer.Canvas or you are using a component on a report like QuickReport or Rave?Partheniaparthenocarpy
Francois: Yes, I got the customers file and tried it myself. rkawano: I print to DIB tiles that I send to the printer canvas.Sanhedrin
Sounds like you have yourself a memory leak somewhere.Middleoftheroad
Q
1

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/

Quyenr answered 12/4, 2012 at 13:35 Comment(4)
In tracing through the code the PNG is expanded to a DIB of equal size to the BMP in memory. I suppose more memory efficient code would do the conversion as needed.Sanhedrin
Are you saying that tiling doesn't help? I draw a portion to the tile, at device resolution, which is then passed to the printer. I'd draw directly and let the printer driver handle it but then I'd lose the ability to do transparency.Sanhedrin
im not entirely sure what you are doing but the basic concept is that every chunk of that image you send to the printer it has to process and it has to do this as uncompressed "raw" data usually. This mightb e the cause of your resource issue ... resource on the printer not on the computer ... does that make sense?Quyenr
Not really, the tiling sends the same amount of data (DIB) whether the original image was PNG or BMP. As a matter of fact both images are stored by the library I'm using in memory as Device Independent Bitmaps (DIB). That's why this whole issue makes no sense.Sanhedrin

© 2022 - 2024 — McMap. All rights reserved.