2005. október 17., hétfő

Some remarks on working with very large images


Problem/Question/Abstract:

I have a function that reads about 100 images of about 3000 x 2000 pixels and makes a small image of 200 x 100 of each. My problem is that I can only read 10 or 15 and then the application crashes. I have inspected the memory and it maintains stable and enough, so I don't know where the problem is. If the images that I load are smaller, I can read all.

Answer:

Differing versions of Windows, graphics drivers, and hardware will fail at some point when working with "huge bitmaps" or "huge DIBs".

I define a "huge bitmap/dib" as a bitmap or DIB that either exceeds the screen's width and or height, or exceeds the memory allocationof one single screen at the native color depth of screen (ie even though a 24 bit bitmap was the same size as the screen in width, it would be considered to be "huge" if it was more than one third the height of the screen when used under a 8 bit (256 color) video mode.

I make this definition of "huge", as we know that it is safe to work with bitmaps/dibs that are screensize or smaller, and the failures will generally occur at some size that is larger. This is not ment to say that working with bitmaps that are screensize or smaller will always work, as that depends on the amount GDI resources already in use when compared with the GDI resources that might be available at a given time. I am also not saying that you will always get a failure when working with a huge bitmap, only that it is very common (as you have already found out).

Let me quickly mention that resizing can bring one other possible limitation to the table. Certain versions of Windows (and/or Drivers) may be limited to stretching an image to a minimum of 8 times its original size.

Your only safe solution for "huge bitmaps/dibs" is to work with them without getting Windows and its drivers involved in the process until you actually display them. This means you would work with the bitmaps as DIBS (device independent bitmaps) (for example in the raw form that they exist on the disk), and do all resizing using internal code that does not depend on Windows or its drivers.

I will mention that it requires a large amount of low level code to work with the differing bitmap formats, where you might want to copy, and resize between them. The trick for drawing to huge dibs is you would need to copy workable sized sections from the DIB, convert the section to a bitmap (or use a DIB section) draw on it, convert back to a DIB, and copy the section back to the original huge DIB.

Nincsenek megjegyzések:

Megjegyzés küldése