How to use gflSaveBitmapIntoMemory in Delphi

Discussions on GFL SDK, the graphic library for reading and writing graphic files

Moderators: XnTriq, helmut, xnview

ioio
Posts: 3
Joined: Wed Nov 12, 2008 9:26 am

How to use gflSaveBitmapIntoMemory in Delphi

Post by ioio »

Hi,
i have some issues with using gflSaveBitmapIntoMemory in Delphi, better say with freeing memory after that.

....
var Size:integer;
Mem:PGFL_UINT8;
sp: TGFL_SAVE_PARAMS;
e: GFL_ERROR;
FS:TFileStream;
.....
gflGetDefaultSaveParams(sp);
sp.FormatIndex := tiff;
sp.Compression := GFL_LZW;

e := gflSaveBitmapIntoMemory(Mem, @Size, gfl_bmp, sp);
FS.Write(Mem^,Size);
gflMemoryFree(Pointer(Mem));

Is it right ? Probably not, because on gflMemoryFree(Pointer(Mem)); i get exception "Invalid address specified ... " How to free memory after save ?

Thanks.
User avatar
xnview
Author of XnView
Posts: 44325
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: How to use gflSaveBitmapIntoMemory in Delphi

Post by xnview »

I'm not expert in Delphi :-), but in C here is the code:

Code: Select all

GFL_UINT8* data; 
GFL_UINT32 length; 
gflSaveBitmapIntoMemory( &data, &length, pBitmap, &save_params ); 
gflMemoryFree( data ); 
Pierre.
ioio
Posts: 3
Joined: Wed Nov 12, 2008 9:26 am

Post by ioio »

So what's the different? Thats exception is catched bay gflMemoryFree, so I see it only in debug mode, but no memory is freed.
When I make a loop ... for example:

Code: Select all

for I := 0 to 500 do begin
   e := gflSaveBitmapIntoMemory(Mem, @Size, gfl_bmp, sp);
   FS.Write(Mem^,Size);
   gflMemoryFree(Pointer(Mem));
end;
used memory still growing. So what's wrong?
ioio
Posts: 3
Joined: Wed Nov 12, 2008 9:26 am

Post by ioio »

I have found the bug. It's in the LibGfl.pas

Wrong:

Code: Select all

function gflMemoryRealloc(var Ptr: Pointer; size: GFL_UINT32): Pointer; stdcall;
procedure gflMemoryFree(var Ptr: Pointer); stdcall;
Right:

Code: Select all

function gflMemoryRealloc(Ptr: Pointer; size: GFL_UINT32): Pointer; stdcall;
procedure gflMemoryFree(Ptr: Pointer); stdcall;
User avatar
xnview
Author of XnView
Posts: 44325
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Post by xnview »

Ok, i fix the .pas
Pierre.