unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
BGRABitmap, BGRABitmapTypes, BGRAGradients, BGRAGradientScanner;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormPaint(Sender: TObject);
private
public
function AVGColor(c1, c2: TBGRAPixel; Percent: single): TBGRAPixel;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormPaint(Sender: TObject);
var
bmp: TBGRABitmap;
p1, p2: TPointF;
g: TBGRAMultiGradient;
gs: TBGRAGradientScanner;
ArrBgraColor: array [0..2] of TBGRAPixel;
//ArrBgraColor: array [0..1] of TBGRAPixel;
begin
bmp := TBGRABitmap.Create(Width, Height);
p1 := PointF(0, Height / 2);
p2 := PointF(Width, Height / 2);
//Way1
//ArrBgraColor[0] := BGRABlack;
//ArrBgraColor[1] := BGRAWhite;
//g := TBGRAMultiGradient.Create(ArrBgraColor, [0, 1], True, False);
//Way2
ArrBgraColor[0] := BGRABlack;
ArrBgraColor[1] := AVGColor(BGRABlack, BGRAWhite, 50);
ArrBgraColor[2] := BGRAWhite;
g := TBGRAMultiGradient.Create(ArrBgraColor, [0, 0.5, 1], True, False);
g.InterpolationFunction := @g.CosineInterpolation;
gs := TBGRAGradientScanner.Create(g, gtLinear, p1, p2);
bmp.FillRect(0, 0, Width, Height, gs, dmDrawWithTransparency, daFloydSteinberg);
bmp.SaveToFile('Pics\w2.png');
bmp.Draw(Canvas, 0, 0);
bmp.Free;
end;
function TForm1.AVGColor(c1, c2: TBGRAPixel; Percent: single): TBGRAPixel;
var
h1, h2, Res: THSLAPixel;
begin
h1 := BGRAToHSLA(c1);
h2 := BGRAToHSLA(c2);
with Res do
begin
hue := round((h1.hue + h2.hue) * Percent / 100);
saturation := round((h1.saturation + h2.saturation) * Percent / 100);
lightness := round((h1.lightness + h2.lightness) * Percent / 100);
alpha := round((h1.alpha + h2.alpha) * Percent / 100);
end;
Result := HSLAToBGRA(Res);
end;
end.