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