mam taki kod:
for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx+=3)
{
tempRGB = bitmapImage[imageIdx];
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
bitmapImage[imageIdx + 2] = tempRGB;
}
i przerabiam go na pascala. Napisałem coś takiego:
repeat
tempRGB := ImageData[i];
ImageData[i] := ImageData[i + 2];
ImageData[i + 2] := tempRGB;
i := i + 3
until i < BMPImageHeader.biImageSize;
I wyskakują mi błędy:
Error: Array type required
ImageData deklaruję w ten sposób
var
ImageData : Pointer
a bitmapImage jest zadeklarowane tak:
unsigned char*bitmapImage
z c++ mało umiem ale wydaje mi się ze jest to deklaracja wskaźnika na tablice charów i dlatego pierwszy kod działa.
Jak zadeklarować w moim kodzie ImageData bym mógł zamienić składowe R i B by uzyskać format RGB z BGR i mieć wskaźnik na ImageData który potem będę mógł użyć w glTexImage2D?
Coś mi się widzi że będę musiał się pobawić wskaźnikiem na tablicę Byte. coś w stylu:
type
PByteArray = ^array of Byte;
Ale nie jestem pewny czy to będzie działać z glTexImage2D.
Poniżej cały mój kod.
function LoadDataFromBMP(FileName : string) : Pointer;
const
BITMAP_ID = $4D42;
type
TBMPFileHeader = packed record // Nagłowek pliku BMP.
bfType : Word;
bfSize : LongWord;
bfReserved1 : Word;
bfReserved2 : Word;
bfOffBits : DWord;
end;
type
TBMPImageHeader = packed record // Nagłówek obrazu BMP.
biSize : LongWord;
biWidth : LongInt;
biHeight : LongInt;
biPlanes : Word;
biBitCount : Word;
biCompression : LongWord;
biImageSize : LongWord;
biXPelsPerMetter : LongInt;
biYPelsPerMetter : LongInt;
biClrUsed : LongWord;
biClrImportant : LongWord;
end;
var
BMPFile : TFileStream;
BMPFileHeader : TBMPFIleHeader;
BMPImageHEader : TBMPImageHeader;
ImageData : Pointer;
i : LongWord;
tempRGB : Byte;
begin
BMPFile := TFIleStream.Create(Filename, fmOpenRead);
BMPFIle.ReadBuffer(BMPFileHeader, SizeOf(BMPFileHeadeR));
if BMPFileHeader.bfType <> BITMAP_ID then
begin
FreeAndNil(BMPFile);
result := nil;
end;
BMPFile.ReadBuffer(BMPImageHeader, SizeOf(BMPImageHeader));
BMPFile.Seek(BMPFileHeader.bfOffBits, soFromBeginning);
GetMem(ImageData, BMPImageHeader.biImageSize);
BMPFile.ReadBuffer(ImageData, BMPImageHeader.biImageSize);
if ImageData = nil then
begin
FreeMem(ImageData, BMPImageHeader.biImageSize);
FreeAndNil(BMPFile);
result := nil;
end;
i := 0;
{ repeat
tempRGB := ImageData[i];
ImageData[i] := ImageData[i + 2];
ImageData[i + 2] := tempRGB; <- W tej pętli jest błąd
i := i + 3
until i < BMPImageHeader.biImageSize;}
result := ImageData;
end;