View Poll Results: need some help plz

Voters
1. You may not vote on this poll
  • 1

    1 100.00%
  • 2

    0 0%
Results 1 to 7 of 7

Thread: loading jpg/gif/bmp without VCL

  1. #1

    loading jpg/gif/bmp without VCL

    hi

    i've tryed translating cpp function to pascal , but it dosen't work
    the function is simply convert jpeg file to HBITMAP Object , using IPicture interface

    the cpp code work fine , could any one correct my pascal translation !!

    // CPP CODE
    Code:
     HBITMAP Ole2BITMAP(char *szFile)
    {
    
    HBITMAP hBitmap;
    HBITMAP bmp;
    DWORD dwFileSize;
    DWORD dwBytesRead;
    HANDLE hFile;
    LPPICTURE gpPicture;
    LPVOID lpPicData;
    LPVOID pvData;
    LPSTREAM pstm;
    LPVOID hrlp;
    HGLOBAL hGlobal;
    BITMAP bm ;
    
     
    
    hFile=CreateFile(szFile,GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
    dwFileSize=GetFileSize(hFile,NULL);
    
    
    pvData=NULL;
    hGlobal=GlobalAlloc(GMEM_MOVEABLE,dwFileSize);
    pvData=GlobalLock(hGlobal);
    ReadFile(hFile,pvData,dwFileSize,&dwBytesRead,NULL);
    GlobalUnlock(hGlobal);
    CloseHandle(hFile);
    
    
    CreateStreamOnHGlobal(hGlobal,TRUE,&pstm);
    OleLoadPicture(pstm,0,FALSE,IID_IPicture,(void**)&gpPicture);
    pstm->Release();
    gpPicture->get_Handle((OLE_HANDLE*)&hBitmap);
    
    GetObject (hBitmap, sizeof (BITMAP), (PSTR) &bm) ;
    
    
    
    bmp = (HBITMAP)CopyImage(hBitmap,IMAGE_BITMAP,bm.bmWidth, bm.bmHeight,LR_COPYRETURNORG);
    return bmp;
    
    }

    // PASCAL TRANSLATION

    Code:
    uses activex
    function ole2bitmap(name : string): HBITMAP;
    var hBmp ,bmp : HBITMAP;
      dwFileSize,dwBytesRead : DWORD;
      hFile : integer;
      gpPicture : IPicture;
      pvData  : pointer;
      pstm   : ISTREAM;
      hGlob   : hGlobal;
      bm    : BITMAP;
    begin
    
      hFile := CreateFile(Pchar(name),GENERIC_READ,0,NIL,OPEN_EXISTING,0,0);
      dwFileSize :=GetFileSize(hFile,NIL);
    
      pvData := NIL;
      hGlob := GlobalAlloc(GMEM_MOVEABLE,dwFileSize);
      pvData:=GlobalLock(hGlob);
      ReadFile(hFile,pvData,dwFileSize,dwBytesRead,NIL);
      GlobalUnlock(hGlob);
      CloseHandle(hFile);
    
      CreateStreamOnHGlobal(hGlob,TRUE,pstm);
      OleLoadPicture(pstm,0,FALSE,IPICTURE,gpPicture);
      pstm._Release();
      gpPicture.get_Handle(LongWord(hBmp));
    
      GetObject (hBmp, sizeof (BITMAP), @bm) ;
    
      bmp := CopyImage(hBmp,IMAGE_BITMAP,bm.bmWidth, bm.bmHeight,LR_COPYRETURNORG);
    
     Result := bmp;
    
    end;
    thanks

  2. #2

    Re: loading jpg/gif/bmp without VCL

    Try this one:

    [pascal]
    {------------------------------------------------------------------}
    { Load BMP Texture }
    {------------------------------------------------------------------}
    function LoadBMPTexture(Filename: Tstream; var Texture: GLuint): Boolean;
    var
    FileHeader: TBITMAPFILEHEADER;
    InfoHeader: TBITMAPINFOHEADER;
    Palette: array of RGBQUAD;
    BitmapLength: LongWord;
    PaletteLength: LongWord;
    ReadBytes: LongWord;
    TextureImage: TTextureImage;
    begin
    LoadBMPTexture:=False;
    // Get header information
    Filename.Read(FileHeader, SizeOf(FileHeader));
    Filename.Read(InfoHeader, SizeOf(InfoHeader));
    // Get palette
    PaletteLength := InfoHeader.biClrUsed;
    SetLength(Palette, PaletteLength);
    ReadBytes:=Filename.Read(Palette,PaletteLength);
    if (ReadBytes <> PaletteLength) then
    begin
    MessageBox(0, PChar('Error reading palette'), PChar('BMP Loader'), MB_OK);
    Exit;
    end;
    textureimage.Width := InfoHeader.biWidth;
    textureimage.Height := InfoHeader.biHeight;
    BitmapLength := InfoHeader.biSizeImage;
    if BitmapLength = 0 then
    BitmapLength := Textureimage.Width * Textureimage.Height * InfoHeader.biBitCount Div 8;
    // Get the actual pixel data
    GetMem(textureimage.imageData, BitmapLength);
    ReadBytes:=Filename.Read(textureimage.imagedata^, BitmapLength);
    if (ReadBytes <> BitmapLength) then
    begin
    MessageBox(0, PChar('Error reading bitmap data'), PChar('BMP Unit'), MB_OK);
    Exit;
    end;
    //BMP files are stored BGR so use GL_BGR
    Texture:=CreateTexture(textureimage.width, textureimage.height, GL_BGR, textureimage.imagedata);
    //clean up
    FreeMem(textureimage.imageData)
    end;
    [/pascal]

    You may want to remove opengl specifcs like the call to CreateTexture.
    http://3das.noeska.com - create adventure games without programming

  3. #3

    Re: loading jpg/gif/bmp without VCL

    thanks noeska

    but i am looking for JPG
    because i belive that this is the easy way to load jpg using pure API
    and this function keep my exe small ~ 20kb .

    so any one have an idea how to fix this function ?!

  4. #4

    Re: loading jpg/gif/bmp without VCL

    looks suspicious

    anyway,
    i don't have delphi to test,
    but try removing "pstm._realease();", instead just set "pstm := nil;"
    From brazil (:

    Pascal pownz!

  5. #5

    Re: loading jpg/gif/bmp without VCL

    the problem is in : gpPicture.get_Handle(LongWord(hBmp)); the program crash here

  6. #6

    Re: loading jpg/gif/bmp without VCL

    Quote Originally Posted by virtual
    the problem is in : gpPicture.get_Handle(LongWord(hBmp)); the program crash here
    try
    gpPicture.get_Handle(LongWord(@hBmp));
    From brazil (:

    Pascal pownz!

  7. #7

    Re: loading jpg/gif/bmp without VCL

    i't suggest you use vampyre imaging lib, it loads jpg, bmp and gif with no vcl.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •