var
FileHeader: TBITMAPFILEHEADER;
// was FileHeader: BITMAPFILEHEADER; undeclared identifier
InfoHeader: TBITMAPINFOHEADER;
// was InfoHeader: BITMAPINFOHEADER; undeclared identifier
Palette:
array [byte]
of TRGBQUAD;
// Palette: array of RGBQUAD; declaration of array not supported by D2 and undeclared identifier RGBQUAD
BitmapFile: THandle;
BitmapLength: Integer;
// changed from variant
PaletteLength: Integer;
// '' '' ''
ReadBytes: Integer;
// changed for incompatibility whith declaration of Win function Readfile
Front: ^Byte;
Back: ^Byte;
Temp: Byte;
I : Integer;
Width, Height : Integer;
pData : Pointer;
// used for loading from resource
ResStream : TResourceStream;
begin
[.....................]
BitmapFile := CreateFile(PChar(Filename), GENERIC_READ, FILE_SHARE_READ,
nil, OPEN_EXISTING, 0, 0);
if (BitmapFile = INVALID_HANDLE_VALUE)
then begin
MessageBox(0, PChar('
Error opening ' + Filename), PChar('
BMP Unit'), MB_OK);
Exit;
end;
// Get header information
ReadFile(BitmapFile, FileHeader, SizeOf(FileHeader), ReadBytes,
nil);
ReadFile(BitmapFile, InfoHeader, SizeOf(InfoHeader), ReadBytes,
nil);
// Get palette
PaletteLength := InfoHeader.biClrUsed;
//SetLength(Palette, PaletteLength); commented by fabrizio ( i don't know how to solve !!)
ReadFile(BitmapFile, Palette, PaletteLength, ReadBytes,
nil);
if (ReadBytes <> PaletteLength)
then begin
MessageBox(0, PChar('
Error reading palette'), PChar('
BMP Unit'), MB_OK);
Exit;
end;
Width := InfoHeader.biWidth;
Height := InfoHeader.biHeight;
BitmapLength := InfoHeader.biSizeImage;
if BitmapLength = 0
then
BitmapLength := Width * Height * InfoHeader.biBitCount
Div 8;
// Get the actual pixel data
GetMem(pData, BitmapLength);
ReadFile(BitmapFile, pData^, BitmapLength, ReadBytes,
nil);
if (ReadBytes <> BitmapLength)
then begin
MessageBox(0, PChar('
Error reading bitmap data'), PChar('
BMP Unit'), MB_OK);
Exit;
end;
CloseHandle(BitmapFile);
end;
// Bitmaps are stored BGR and not RGB, so swap the R and B bytes.
for I :=0
to Width * Height - 1
do
begin
Front := Pointer(Integer(pData) + I*3);
Back := Pointer(Integer(pData) + I*3 + 2);
Temp := Front^;
Front^ := Back^;
Back^ := Temp;
end;