Конференция "FreePascal" » Портинг из Дельфи в FPC, OpenGL [Win32]
 
  • tero (31.01.05 01:08) [0]
    Хочу перевести данный кусок из Дельфи в FPC 1.9.6
    Есть ли аналоги у типов TJPEGImage, TBitmap ?

    {------------------------------------------------------------------}
    {  Load JPEG textures                                              }
    {------------------------------------------------------------------}
    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;

     if LoadFromResource then // Load from resource
     begin
       try
         ResStream := TResourceStream.Create(hInstance, PChar(copy(Filename, 1, Pos('.', Filename)-1)), 'JPEG');
         JPG.LoadFromStream(ResStream);
         ResStream.Free;
       except on
         EResNotFound do
         begin
           MessageBox(0, PChar('File not found in resource - ' + Filename), PChar('JPG Texture'), MB_OK);
           Exit;
         end
         else
         begin
           MessageBox(0, PChar('Couldn''t load JPG Resource - \"'+ Filename +'\"'), PChar('BMP Unit'), MB_OK);
           Exit;
         end;
       end;
     end
     else
     begin
       try
         JPG.LoadFromFile(Filename);
       except
         MessageBox(0, PChar('Couldn''t load JPG - \"'+ Filename +'\"'), PChar('BMP Unit'), MB_OK);
         Exit;
       end;
     end;

     // 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;

  • tero (31.01.05 01:42) [1]
    Только сейчас заметил, что похожее обсуждается в http://pda.delphimaster.net/?id=1098048479&n=11 [Модуль Texture.pas от Jan Horn] (* модераторам - можно объединить туда *)
    Суть та же - перевести его в FPC...
 
Конференция "FreePascal" » Портинг из Дельфи в FPC, OpenGL [Win32]
Есть новые Нет новых   [119285   +20][b:0][p:0.002]