Some bugs in libgfl.pas (for Delphi)

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

Moderators: XnTriq, xnview

Post Reply
User avatar
reggi
Posts: 16
Joined: Thu Sep 16, 2004 1:32 pm
Contact:

Some bugs in libgfl.pas (for Delphi)

Post by reggi » Wed Feb 07, 2007 12:21 pm

Hi.

I use libgfl in Delphi and found some bugs in declarations of the funcions.

The functions using PGFL_COLOR type don't work correctly so I chenged the declarations to INT64 and it work - for example:

Code: Select all

function gflDrawLineColor(src: PGFL_BITMAP; x0, y0, x1, y1: GFL_INT32;
  line_width: GFL_UINT32; var line_color: int64{PGFL_COLOR};
  dst: PPGFL_BITMAP): GFL_ERROR; stdcall;
I found so very important bug in declaration of gflDrawRectangleColor - the 6. parameter named (by me) fill_color is missing in original file - look below:

Code: Select all

function gflDrawRectangleColor(src: PGFL_BITMAP; x0, y0, width, height: GFL_INT32;
  var fill_color: int64{PGFL_COLOR};
  line_width: GFL_UINT32; var line_color: int64{PGFL_COLOR}; line_style: GFL_LINE_STYLE;
  dst: PPGFL_BITMAP): GFL_ERROR; stdcall;
Best regards

User avatar
MaierMan
Posts: 78
Joined: Wed Aug 04, 2004 8:32 pm
Contact:

Post by MaierMan » Wed Feb 14, 2007 5:15 pm

And again, missing parameters...

Patch (I just checked stuff from previous bugreport and this one).

Code: Select all

--- libgfl.pas.orig	2007-02-06 13:42:38.000000000 +0100
+++ libgfl.pas	2007-02-14 17:41:54.000000000 +0100
@@ -134,6 +134,7 @@
     Red: array[0..255] of GFL_UINT8;
     Green: array[0..255] of GFL_UINT8;
     Blue: array[0..255] of GFL_UINT8;
+		Alpha: array[0..255] of GFL_UINT8;
   end;
 
 // Color
@@ -286,17 +287,17 @@
     CameraRawUseAutomaticBalance: GFL_UINT8; 
     CameraRawUseCameraBalance: GFL_UINT8; 
     Reserved4: GFL_UINT16; 
-    CameraRawGamma: GFL_UINT32; 
-    CameraRawBrightness: GFL_UINT32; 
-    CameraRawRedScaling: GFL_UINT32; 
-    CameraRawBlueScaling: GFL_UINT32; 
-    CameraRawFilterDomain: GFL_UINT32; 
-    CameraRawFilterRange: GFL_UINT32; 
+    CameraRawGamma: Single; 
+    CameraRawBrightness: Single; 
+    CameraRawRedScaling: Single; 
+    CameraRawBlueScaling: Single; 
+    CameraRawFilterDomain: Single; 
+    CameraRawFilterRange: Single; 
          
          // Own callback
     Callbacks: TGFL_LoadCallbacks;
     
-    UserParams: PChar;
+    UserParams: Pointer;
   end;
 
 
@@ -335,7 +336,7 @@
          // Own callback
     Callbacks: TGFL_SaveCallbacks;
 
-    UserParams: PChar;
+    UserParams: Pointer;
   end;
 
 // Color model
@@ -769,29 +770,30 @@
 const GFL_LINE_STYLE_DASHDOTDOT = 4;
 
 function gflDrawLineColor(src: PGFL_BITMAP; x0, y0, x1, y1: GFL_INT32;
-  line_width: GFL_UINT32; var line_color: PGFL_COLOR;
+  line_width: GFL_UINT32; line_color: PGFL_COLOR; line_style: GFL_LINE_STYLE;
   dst: PPGFL_BITMAP): GFL_ERROR; stdcall;
 
-function gflDrawPolylineColor(src: PGFL_BITMAP; var points: PGFL_POINT; num_points: GFL_INT32;
-  line_width: GFL_UINT32; var line_color: PGFL_COLOR; line_style: GFL_LINE_STYLE; 
+function gflDrawPolylineColor(src: PGFL_BITMAP; points: PGFL_POINT; num_points: GFL_INT32;
+  line_width: GFL_UINT32; line_color: PGFL_COLOR; line_style: GFL_LINE_STYLE; 
   dst: PPGFL_BITMAP): GFL_ERROR; stdcall;
 
-function gflDrawPolygonColor(src: PGFL_BITMAP; var points: PGFL_POINT; num_points: GFL_INT32;
-  var fill_color: PGFL_COLOR;
-  line_width: GFL_UINT32; var line_color: PGFL_COLOR; line_style: GFL_LINE_STYLE; 
+function gflDrawPolygonColor(src: PGFL_BITMAP; points: PGFL_POINT; num_points: GFL_INT32;
+  fill_color: PGFL_COLOR;
+  line_width: GFL_UINT32; line_color: PGFL_COLOR; line_style: GFL_LINE_STYLE; 
   dst: PPGFL_BITMAP): GFL_ERROR; stdcall;
 
 function gflDrawRectangleColor(src: PGFL_BITMAP; x0, y0, width, height: GFL_INT32;
-  line_width: GFL_UINT32; var line_color: PGFL_COLOR; line_style: GFL_LINE_STYLE; 
+	fill_color: PGFL_COLOR;
+  line_width: GFL_UINT32;  line_color: PGFL_COLOR; line_style: GFL_LINE_STYLE; 
   dst: PPGFL_BITMAP): GFL_ERROR; stdcall;
 
-function gflDrawPointColor(src: PGFL_BITMAP; x0, y0, width, height: GFL_INT32;
-  line_width: GFL_UINT32; var line_color: PGFL_COLOR; line_style: GFL_LINE_STYLE; 
+function gflDrawPointColor(src: PGFL_BITMAP; x, y: GFL_INT32;
+  line_width: GFL_UINT32; line_color: PGFL_COLOR;
   dst: PPGFL_BITMAP): GFL_ERROR; stdcall;
 
 function gflDrawCircleColor(src: PGFL_BITMAP; x, y, radius: GFL_INT32;
   var fill_color: PGFL_COLOR;
-  line_width: GFL_UINT32; var line_color: PGFL_COLOR; line_style: GFL_LINE_STYLE; 
+  line_width: GFL_UINT32; line_color: PGFL_COLOR; line_style: GFL_LINE_STYLE; 
   dst: PPGFL_BITMAP): GFL_ERROR; stdcall;
 
 {$ENDIF}


I extended my tiny little tool to test that functionality, and it seems to work.
(Note that I'm not a Delphi developer and actually don't like that language very much :p)

Code: Select all

program testgflsizeof;

{$APPTYPE CONSOLE}

uses
  SysUtils, ShellApi,
  LibGfl in 'Z:\Profile\Desktop\GflSDK-win\GflSDK\Delphi\Include\libgfl.pas';
var
  bmp: PGFL_BITMAP;
  params: TGFL_LOAD_PARAMS;
  sparams: TGFL_SAVE_PARAMS;
  info: TGFL_FILE_INFORMATION;
  test: String;
  color, fill: TGFL_COLOR;
begin
  WriteLn('load: ' + IntToStr(SizeOf(TGFL_LOAD_PARAMS)));
  WriteLn('save: ' + IntToStr(SizeOf(TGFL_SAVE_PARAMS)));

  WriteLn('32  : ' + IntToStr(SizeOf(GFL_INT32)));
  WriteLn('16  : ' + IntToStr(SizeOf(GFL_INT16)));
  WriteLn('8   : ' + IntToStr(SizeOf(GFL_INT8)));
  WriteLn('BOOL: ' + IntToStr(SizeOf(GFL_BOOL)));
  WriteLn('ORIG: ' + IntToStr(SizeOf(GFL_ORIGIN)));
  WriteLn('CALL: ' + IntToStr(SizeOf(TGFL_LoadCallbacks)));

  gflLibraryInit();
  test := 'test.jpg';
  gflGetDefaultLoadParams(params);
  if gflLoadBitmap(PAnsiChar(test), bmp, params, info) <> GFL_NO_ERROR then
  begin
    WriteLn('error');
  end
  else
  begin
    color.Red := 255;
    fill.Blue := 255;
    gflDrawLineColor(bmp, 0, 0, 20, 20, 10, @color, 0, nil);
    gflDrawRectangleColor(bmp, 50, 50, 60, 60, @fill, 10, @color, 0, nil);
    gflGetDefaultSaveParams(sparams);
    sparams.FormatIndex := gflGetFormatIndexByName('bmp');
    gflSaveBitmap('test.jpg.bmp', bmp, sparams);
    gflFreeBitmap(bmp);
    gflFreeFileInformation(info);
  end;

  ReadLn;
  gflLibraryExit();  
end.

User avatar
xnview
Author of XnView
Posts: 32070
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Post by xnview » Thu Feb 15, 2007 8:43 am

MaierMan wrote:And again, missing parameters...
Ok, thanks
Pierre.

Post Reply