views:

391

answers:

1

In Delphi 7, I have to deal with pretty large 24bpp bitmaps (several 100 MB). Since I want to use the Graphcis32 library for further processing, they have to be converted to 32bpp (TBitmap32). The LoadFromFile method of TBitmap32, however, creates a temporary conventional TBitmap to load the original 24bpp bitmap which is then assigned to the TBitmap32 to do the required format conversion. Of course, memory load is roughly doubled by having two of these huge bitmaps in memory, and this can be fatal to my application.

What I am thinking of is a way to load the 24bpp bitmap into a preallocated buffer which is dimensioned such that the 32 bpp bitmap fits in. Then, starting from the buffer end, I want to move the RGB bytes to the offsets needed for 32bpp.

Is this possible? How can I load a bitmap into a preallocated buffer? Any idea?

+1  A: 

I don't know much of how Graphics32 works. However if you use a standard file format and have direct access to the TBitmap32 pixel data you should be able create your own image loader for the format that does the loading and the up conversion to 32bpp in one go if nothing else works.

Specifications for common file formats are all over the internet, which one are you using?

Laserallan
You're right, that will work. This solution, however, is not quite what I expected (maybe my description was not clear enough...) My input files are normally 24bpp Windows BMP files, but I cannot exclude other BMP variants such as compressed files. In this case, I would have to do all the decoding etc by myself. Aren't there any API functions which allow to read a BMP into a preallocated buffer such that the pixel matrix is already available?