Bonjour a tous.
Pour les besoins d'OpenGL, j'ai besoin de transformer mon Jpeg en BMP puis de stocker le BMP sous forme de tableau.
J'ai récupéré et analysé 1000 fois une fonction trouvé sur internet, mais je ne comprend pas certaines lignes ....
Je vous copie le code, je met des etoiles sur les lignes que j'interprete mal ...
merci de votre aide
Dami
function LoadJPGTexture(Filename: String; var Texture: GLuint; LoadFromResource : Boolean): Boolean;
var
Data : Array of LongWord;
W, Width : Integer;
H, Height : Integer;
BMP : TBitmap;
JPG : TJPEGImage;
C : LongWord;
Line : ^LongWord;
ResStream : TResourceStream; // used for loading from resource
begin
result :=FALSE;
JPG:=TJPEGImage.Create;
// Create Bitmap
BMP:=TBitmap.Create;
BMP.pixelformat:=pf32bit;
BMP.width:=JPG.width;
BMP.height:=JPG.height;
BMP.canvas.draw(0,0,JPG); // Copy the JPEG onto the Bitmap
// BMP.SaveToFile('D:\test.bmp');
Width :=BMP.Width;
Height :=BMP.Height;
SetLength(Data, Width*Height);
For H:=0 to Height-1 do
Begin
* Line :=BMP.scanline[Height-H-1]; // flip JPEG
For W:=0 to Width-1 do
Begin
* c:=Line^ and $FFFFFF; // Need to do a color swap
* Data[W+(H*Width)] :=(((c and $FF) shl 16)+(c shr 16)*+ (c and $FF00)) or $FF000000; // 4 channel.
* inc(Line);
End;
End;
BMP.free;
JPG.free;
Texture :=CreateTexture(Width, Height, GL_RGBA, addr(Data[0]));
result :=TRUE;
end;