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.
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);
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...
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.
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.
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.
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.
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.
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.
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;
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.