Delphi AV When Using gflGetColorAt

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

Moderators: XnTriq, helmut, xnview

Guest

Delphi AV When Using gflGetColorAt

Post by Guest »

Me again

I'm converting an bmp toolbar icon to it's disabled state. So grey scale, lighten it and put the background colour back on by using a copy of the original image. However it AV's on the gflGetColorAt line. I've tried updating LibGFL.pas TGFL_COLOR record to add Alpha as the last element (as all other includes have it) but didn't help. Any ideas.

Code: Select all

var
  finfo: TGFL_FILE_INFORMATION;
  lp: TGFL_LOAD_PARAMS;
  sp: TGFL_SAVE_PARAMS;
  gfl_bmp: PGFL_BITMAP;
  gfl_bmp2: PGFL_BITMAP;
  e: GFL_ERROR;
  x, y: GFL_INT32;
  bpp: Integer;
  filename: string;
  background : PGFL_COLOR;
begin

  // Load Test BMP
  gflGetDefaultLoadParams(lp);
  lp.ColorModel := GFL_RGB; 
  lp.LinePadding := 4;
  e := gflLoadBitmap('test.bmp', gfl_bmp, lp, finfo);

  if (e <> gfl_no_error) then begin
    MessageDlg('File not readable: ' + string(gflGetErrorString(e)), mtError, [mbOK], 0);
    exit;
  end;

  if (gfl_bmp.Btype = GFL_BINARY) then begin
    bpp := 1;
  end else begin
    bpp := gfl_bmp.BytesPerPixel * 8;
  end;

  if not (bpp in [1, 4, 8, 24, 32]) then begin
    MessageDlg('Only 1, 4, 8, 24 or 32 BitsPerPixel are supported in this demo !', mtError, [mbOK], 0);
    gflFreeBitmap(gfl_bmp);
    gflFreeBitmap(gfl_bmp2);
    exit;
  end;

  // Make A Copy Of The Original So That When We Grey Scale The First One
  // We Can Copy The Background Back Over 
  gfl_bmp2 := gflCloneBitmap(gfl_bmp);

  // Grey Scale, RGB And Then Gamma Correct The First Image To Make It Disabled (light grey)
  gflChangeColorDepth(gfl_bmp, NIL, GFL_MODE_TO_256GREY, GFL_MODE_NO_DITHER);
  gflChangeColorDepth(gfl_bmp, NIL, GFL_MODE_TO_RGB, GFL_MODE_NO_DITHER);
  gflGamma(gfl_bmp, nil, 1.25);
  gflGamma(gfl_bmp, nil, 1.5);

  // Copy All RGB 255,0,255 Background Pixels From 2nd Image To First
  // As The First Images Background is now grey due to grey scaling it
  for y := 1 to gfl_bmp2.Height do begin
    for x := 1 to gfl_bmp2.Width do begin


      // *****
      // * THIS LINE AV's
      // *****
      gflGetColorAt(gfl_bmp2, x, y, background);


      if ((background.Red = 255) and (background.green = 0) and (background.blue = 255)) then begin
        gflSetColorAt(gfl_bmp, x, y, background);
      end;
    end;
  end;

  gflGetDefaultSaveParams(sp);
  sp.Flags := GFL_SAVE_REPLACE_EXTENSION;
  sp.FormatIndex := gflGetFormatIndexByName('bmp');
  sp.ChannelType := GFL_RGB;
  gflSaveBitmap('output.bmp', gfl_bmp, sp);

  // Free Resources
  gflFreeBitmap(gfl_bmp);
  gflFreeBitmap(gfl_bmp2);
Thanks

Marc
mkeeley
Posts: 9
Joined: Sun Jan 29, 2006 7:09 pm

Post by mkeeley »

Sorry, hadn't logged in!
User avatar
xnview
Author of XnView
Posts: 44920
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: Delphi AV When Using gflGetColorAt

Post by xnview »

Anonymous wrote:Me again

I'm converting an bmp toolbar icon to it's disabled state. So grey scale, lighten it and put the background colour back on by using a copy of the original image. However it AV's on the gflGetColorAt line. I've tried updating LibGFL.pas TGFL_COLOR record to add Alpha as the last element (as all other includes have it) but didn't help. Any ideas.
The better solution is to have a mask (8bits) of toolbar, apply your changes on toolbar, and combine mask and modified toolbar...
Pierre.
mkeeley
Posts: 9
Joined: Sun Jan 29, 2006 7:09 pm

Post by mkeeley »

You mean have two source images, one being the mask and the other the actual graphic? If so unfortunately that's not really practical as I'll want to convert 1000+ toolbar images all of which are BMP's with #FF00FF backgrounds.

Or is there a way to do this using your library? Couldn't find anything to do with masks in libgfl.pas.

Any idea why gflGetColorAt might be AV'ing? Wasn't sure if the height/width loop should start from 0 or 1 so tried both but didn't help.

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

Post by xnview »

mkeeley wrote:You mean have two source images, one being the mask and the other the actual graphic? If so unfortunately that's not really practical as I'll want to convert 1000+ toolbar images all of which are BMP's with #FF00FF backgrounds.

Or is there a way to do this using your library? Couldn't find anything to do with masks in libgfl.pas.

Any idea why gflGetColorAt might be AV'ing? Wasn't sure if the height/width loop should start from 0 or 1 so tried both but didn't help.

Marc
What's happened with gflGetColorAt?
Pierre.
Guest

Post by Guest »

Still there! Just to be totally safe I did the loops from 1 to Width/Height-1 as I don't know if the 1st pixel is 0 or 1. Not sure if there's anyting mistakes in the code I wrote (I based it on your Delphi example) or if there's any info I can collect for you, if there is let me know.

I'm going to download some exception utilities and see if it helps pinpoint the problem.

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

Post by xnview »

Anonymous wrote:Still there! Just to be totally safe I did the loops from 1 to Width/Height-1 as I don't know if the 1st pixel is 0 or 1. Not sure if there's anyting mistakes in the code I wrote (I based it on your Delphi example) or if there's any info I can collect for you, if there is let me know.

I'm going to download some exception utilities and see if it helps pinpoint the problem.

Marc
First pixel is 0
Pierre.
mkeeley
Posts: 9
Joined: Sun Jan 29, 2006 7:09 pm

Post by mkeeley »

I assumed it would be, so looped from 0 to width/height -1 but it Av'ed so I thought I'd try 1 to width/height just in case but didn't help!

To other members using Delphi (I'm using D5) has anyone used gflGetColorAt sucessfully? If so I'd appreciated it if you'd have a quick look at my function and see if there's anything obvious error.

The function is taken from the installed Delphi example, basically with the displaying of the image removed (BTW which didn't work here, the canvas size was OK but it displayed 3 versions of the image very squashed vertically, quite squashed and a bit squashed) so there are some redundant variables.

Thanks

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

Post by xnview »

mkeeley wrote:I assumed it would be, so looped from 0 to width/height -1 but it Av'ed so I thought I'd try 1 to width/height just in case but didn't help!

To other members using Delphi (I'm using D5) has anyone used gflGetColorAt sucessfully? If so I'd appreciated it if you'd have a quick look at my function and see if there's anything obvious error.

The function is taken from the installed Delphi example, basically with the displaying of the image removed (BTW which didn't work here, the canvas size was OK but it displayed 3 versions of the image very squashed vertically, quite squashed and a bit squashed) so there are some redundant variables.
But what's happened?
Pierre.
Guest

Post by Guest »

I compiled it with EurekaLog which provides more info on the AV, not sure if it's any use to you.

Code: Select all

Access Violation at address 00403DA8 in modeule 'test.exe'. Read of address 000000F7

Registers:
-----------------------------
EAX: 0012F3EC   EDI: 00000000
EBX: 00000000   ESI: 00000000
ECX: 00000000   ESP: 0012EA74
EDX: 000000FF   EIP: 00403DA8

Stack:	Memory Dump:
------------------	---------------------------------------------------------------------------
0012EA74: 0049BC2A	00403DA8: 8B 4A F8 49 7C 10 F0 FF 4A F8 75 0A 50 8D 42 F8  .J.I|...J.u.P.B.
0012EA78: 00403700	00403DB8: E8 57 E9 FF FF 58 C3 90 53 56 89 C3 89 D6 8B 13  .W...X..SV......
0012EA7C: 0012EAAC	00403DC8: 85 D2 74 1A C7 03 00 00 00 00 8B 4A F8 49 7C 0E  ..t........J.I|.
0012EA80: 00000000	00403DD8: F0 FF 4A F8 75 08 8D 42 F8 E8 2E E9 FF FF 83 C3  ..J.u..B........
0012EA84: 00000000	00403DE8: 04 4E 75 DA 5E 5B C3 90 85 D2 74 24 8B 4A F8 41  .Nu.^[....t$.J.A
0012EA88: 00000000	00403DF8: 7F 1A 50 52 8B 42 FC E8 5C 00 00 00 89 C2 58 52  ..PR.B..\.....XR
0012EA8C: 77FB172E	00403E08: 8B 48 FC E8 DC EA FF FF 5A 58 EB 04 F0 FF 42 F8  .H......ZX....B.
0012EA90: 0012EF8C	00403E18: 87 10 85 D2 74 14 8B 4A F8 49 7C 0E F0 FF 4A F8  ....t..J.I|...J.
0012EA94: 0012F274	00403E28: 75 08 8D 42 F8 E8 E2 E8 FF FF C3 90 85 D2 74 0A  u..B..........t.
0012EA98: 0012EAF8	00403E38: 8B 4A F8 41 7E 04 F0 FF 42 F8 87 10 85 D2 74 14  .J.A~...B.....t.
0012EA9C: 0012EE64	00403E48: 8B 4A F8 49 7C 0E F0 FF 4A F8 75 08 8D 42 F8 E8  .J.I|...J.u..B..
0012EAA0: 0012F274	00403E58: B8 E8 FF FF C3 8D 40 00 85 C0 7E 1C 50 83 C0 09  ......@...~.P...
0012EAA4: 77FB1769	00403E68: E8 8F E8 FF FF 83 C0 08 5A 89 50 FC C7 40 F8 01  ........Z.P..@..
0012EAA8: 0012F274	00403E78: 00 00 00 C6 04 10 00 C3 31 C0 C3 90 53 56 57 89  ........1...SVW.
0012EAAC: 0012EE70	00403E88: C3 89 D6 89 CF 89 F8 E8 CC FF FF FF 89 F9 89 C7  ................
0012EAB0: 77FB1700	00403E98: 85 F6 74 09 89 C2 89 F0 E8 47 EA FF FF 89 D8 E8  ..t......G......
Marc
User avatar
xnview
Author of XnView
Posts: 44920
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Post by xnview »

Anonymous wrote:I compiled it with EurekaLog which provides more info on the AV, not sure if it's any use to you.
If you make only that:

Code: Select all

for y := 0 to gfl_bmp2.Height-1 do begin
    for x := 0 to gfl_bmp2.Width-1 do begin


      // *****
      // * THIS LINE AV's
      // *****
      gflGetColorAt(gfl_bmp2, x, y, background);
    end; 
end; 
Do you have a crash?
Pierre.
Guest

Post by Guest »

Yes on that line.
User avatar
xnview
Author of XnView
Posts: 44920
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Post by xnview »

Anonymous wrote:Yes on that line.
Your picture is in 24bits?
Pierre.
mkeeley
Posts: 9
Joined: Sun Jan 29, 2006 7:09 pm

Post by mkeeley »

Yes it starts off as a 24bit BMP, I then greyscale it and then set it back to RGB and Gamma correct to make it lighter.

I removed the greysacle/RGB, gamma and SetColorAt lines so just ended up with a loop performing a GetColorAt's and it still AV'ed.

Before, as an experiment, I removed the GetColorAt and used SetColorAt to basically set each pixel to a colour and it worked fine, the output "image" was filled with that colour. Soon as I re-added the GetColorAt it crashed.
User avatar
xnview
Author of XnView
Posts: 44920
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Post by xnview »

Anonymous wrote:Yes on that line.
The problem is:
background : PGFL_COLOR;
Use

Code: Select all

background : TGFL_COLOR; 
Pierre.