📄 teefilterseditor.pas
字号:
rgb.rgbtGreen:=RoundColor2(Hue);
rgb.rgbtBlue:=RoundColor2(Hue-HLSMAXDiv3);
end;
end;
{ TRedFilter }
procedure TRedFilter.Apply(const R: TRect);
var x,y : Integer;
tmp : Single;
tmpFloat : Single;
tmpInt : Integer;
begin
inherited;
if FPercent then
begin
tmp:=FAmount*0.01;
for y:=R.Top to R.Bottom do
for x:=R.Left to R.Right do
with Lines[y,x] do
begin
tmpFloat:=rgbtRed+rgbtRed*tmp;
if (tmpFloat<0) then rgbtRed:=0
else
if (tmpFloat>255) then rgbtRed:=255
else
rgbtRed:=Round(tmpFloat);
end;
end
else
for y:=R.Top to R.Bottom do
for x:=R.Left to R.Right do
with Lines[y,x] do
begin
tmpInt:=rgbtRed+FAmount;
if (tmpInt<0) then rgbtRed:=0
else
if (tmpInt>255) then rgbtRed:=255
else
rgbtRed:=tmpInt;
end;
end;
class function TRedFilter.Description: String;
begin
result:='Red';
end;
{ TGreenFilter }
procedure TGreenFilter.Apply(const R: TRect);
var x,y : Integer;
tmp : Single;
tmpFloat : Single;
tmpInt : Integer;
begin
inherited;
if FPercent then
begin
tmp:=FAmount*0.01;
for y:=R.Top to R.Bottom do
for x:=R.Left to R.Right do
with Lines[y,x] do
begin
tmpFloat:=rgbtGreen+rgbtGreen*tmp;
if (tmpFloat<0) then rgbtGreen:=0
else
if (tmpFloat>255) then rgbtGreen:=255
else
rgbtGreen:=Round(tmpFloat);
end;
end
else
for y:=R.Top to R.Bottom do
for x:=R.Left to R.Right do
with Lines[y,x] do
begin
tmpInt:=rgbtGreen+FAmount;
if (tmpInt<0) then rgbtGreen:=0
else
if (tmpInt>255) then rgbtGreen:=255
else
rgbtGreen:=tmpInt;
end;
end;
class function TGreenFilter.Description: String;
begin
result:='Green';
end;
{ TBlueFilter }
procedure TBlueFilter.Apply(const R: TRect);
var x,y : Integer;
tmp : Single;
tmpFloat : Single;
tmpInt : Integer;
begin
inherited;
if FPercent then
begin
tmp:=FAmount*0.01;
for y:=R.Top to R.Bottom do
for x:=R.Left to R.Right do
with Lines[y,x] do
begin
tmpFloat:=rgbtBlue+rgbtBlue*tmp;
if (tmpFloat<0) then rgbtBlue:=0
else
if (tmpFloat>255) then rgbtBlue:=255
else
rgbtBlue:=Round(tmpFloat);
end;
end
else
for y:=R.Top to R.Bottom do
for x:=R.Left to R.Right do
with Lines[y,x] do
begin
tmpInt:=rgbtBlue+FAmount;
if (tmpInt<0) then rgbtBlue:=0
else
if (tmpInt>255) then rgbtBlue:=255
else
rgbtBlue:=tmpInt;
end;
end;
class function TBlueFilter.Description: String;
begin
result:='Blue';
end;
{ TConvolveFilter }
constructor TConvolveFilter.Create(Collection:TCollection);
const
Inv9=1.0/9.0;
begin
inherited;
InvTotalWeight:=Inv9;
end;
procedure TConvolveFilter.CalcWeightsFor(x:Integer);
begin
end;
procedure TConvolveFilter.Apply(const R:TRect);
var f2 : TFilter;
x,y,
tmp : Integer;
begin
inherited;
InvTotalWeight:=1.0 / ( Weights[-1,-1]+Weights[-1, 0]+Weights[-1, 1]+
Weights[ 0,-1]+Weights[ 0, 0]+Weights[ 0, 1]+
Weights[ 1,-1]+Weights[ 1, 0]+Weights[ 1, 1] ) ;
Prev:=Lines[0];
This:=Lines[1];
f2:=TFilter.Create(nil);
try
f2.Bitmap:=TBitmap.Create;
{$IFDEF D10}
f2.Bitmap.SetSize(Bitmap.Width,Bitmap.Height);
{$ELSE}
f2.Bitmap.Width:=Bitmap.Width;
f2.Bitmap.Height:=Bitmap.Height;
{$ENDIF}
f2.CalcLines;
for y:=R.Top+1 to R.Bottom-2 do
begin
Next:=Lines[y+1];
for x:=R.Left+1 to R.Right-2 do
with f2.Lines[y,x] do
begin
CalcWeightsFor(x);
tmp:=Round(
(
(Weights[-1,-1]*Prev[x-1].rgbtBlue)+
(Weights[-1, 0]*Prev[x].rgbtBlue)+
(Weights[-1, 1]*Prev[x+1].rgbtBlue)+
(Weights[ 0,-1]*This[x-1].rgbtBlue)+
(Weights[ 0, 0]*This[x].rgbtBlue)+
(Weights[ 0, 1]*This[x+1].rgbtBlue)+
(Weights[ 1,-1]*Next[x-1].rgbtBlue)+
(Weights[ 1, 0]*Next[x].rgbtBlue)+
(Weights[ 1, 1]*Next[x+1].rgbtBlue)
)*InvTotalWeight
);
if tmp>255 then tmp:=255 else if tmp<0 then tmp:=0;
rgbtBlue:=tmp;
tmp:=Round(
(
(Weights[-1,-1]*Prev[x-1].rgbtGreen)+
(Weights[-1, 0]*Prev[x].rgbtGreen)+
(Weights[-1, 1]*Prev[x+1].rgbtGreen)+
(Weights[ 0,-1]*This[x-1].rgbtGreen)+
(Weights[ 0, 0]*This[x].rgbtGreen)+
(Weights[ 0, 1]*This[x+1].rgbtGreen)+
(Weights[ 1,-1]*Next[x-1].rgbtGreen)+
(Weights[ 1, 0]*Next[x].rgbtGreen)+
(Weights[ 1, 1]*Next[x+1].rgbtGreen)
)*InvTotalWeight
);
if tmp>255 then tmp:=255 else if tmp<0 then tmp:=0;
rgbtGreen:=tmp;
tmp:=Round(
(
(Weights[-1,-1]*Prev[x-1].rgbtRed)+
(Weights[-1, 0]*Prev[x].rgbtRed)+
(Weights[-1, 1]*Prev[x+1].rgbtRed)+
(Weights[ 0,-1]*This[x-1].rgbtRed)+
(Weights[ 0, 0]*This[x].rgbtRed)+
(Weights[ 0, 1]*This[x+1].rgbtRed)+
(Weights[ 1,-1]*Next[x-1].rgbtRed)+
(Weights[ 1, 0]*Next[x].rgbtRed)+
(Weights[ 1, 1]*Next[x+1].rgbtRed)
)*InvTotalWeight
);
if tmp>255 then tmp:=255 else if tmp<0 then tmp:=0;
rgbtRed:=tmp;
end;
Prev:=This;
This:=Next;
end;
// Copy rectangle to destination bitmap
for y:=R.Top to R.Bottom do
for x:=R.Left to R.Right do
Lines[y,x]:=f2.Lines[y,x];
finally
f2.Free;
end;
end;
{ TSharpenFilter }
procedure TSharpenFilter.Apply(const R: TRect);
const Center=2.0;
Pix=-((Center-1)/8.0);
begin
Weights[-1,-1]:=Pix; Weights[-1,0]:=Pix; Weights[-1,1]:=Pix;
Weights[ 0,-1]:=Pix; Weights[ 0,0]:=Center; Weights[ 0,1]:=Pix;
Weights[ 1,-1]:=Pix; Weights[ 1,0]:=Pix; Weights[ 1,1]:=Pix;
InvTotalWeight:=1.0/16.0;
inherited;
end;
class function TSharpenFilter.Description: String;
begin
result:='Sharpen';
end;
{ TBlurFilter }
procedure TBlurFilter.Apply(const R: TRect);
begin
Weights[-1,-1]:=1; Weights[-1,0]:=2; Weights[-1,1]:=1;
Weights[ 0,-1]:=2; Weights[ 0,0]:=4; Weights[ 0,1]:=2;
Weights[ 1,-1]:=1; Weights[ 1,0]:=2; Weights[ 1,1]:=1;
InvTotalWeight:=1.0/16;
inherited;
end;
class function TBlurFilter.Description: String;
begin
result:='Blur';
end;
{ TGammaCorrectionFilter }
constructor TGammaCorrectionFilter.Create(Collection:TCollection);
begin
inherited;
FAmount:=70;
IOnlyPositive:=True;
end;
procedure TGammaCorrectionFilter.Apply(const R: TRect);
var t,
x,y : Integer;
IGamma : Array[0..255] of Byte;
tmp : Single;
begin
inherited;
tmp:=Max(0.001,Abs(Amount)*0.01);
IGamma[0]:=0;
for t:=1 to 255 do
IGamma[t]:=Round(Exp(Ln(t/255.0)/tmp)*255.0);
for y:=R.Top to R.Bottom do
for x:=R.Left to R.Right do
with Lines[y,x] do
begin
rgbtRed:=IGamma[rgbtRed];
rgbtGreen:=IGamma[rgbtGreen];
rgbtBlue:=IGamma[rgbtBlue];
end;
end;
class function TGammaCorrectionFilter.Description: String;
begin
result:='Gamma correction';
end;
{ TFilterItems }
function TFilterItems.Get(Index: Integer): TFilter;
begin
result:=TFilter(GetItem(Index));
end;
procedure TFilterItems.Put(Index: Integer; const Value: TFilter);
begin
SetItem(Index,Value);
end;
{$IFNDEF D7}
{$IFNDEF CLR}
type
TOwnedCollectionAccess=class(TOwnedCollection);
{$ENDIF}
function TFilterItems.Owner:TObject;
begin
result:=GetOwner;
end;
{$ENDIF}
procedure TFilterItems.Update(Item: TCollectionItem);
begin
inherited;
// Preview
FreeAndNil(TFilters(Owner).FBitmap);
end;
{ TFilters }
constructor TFilters.Create(AOwner: TComponent);
begin
inherited;
FItems:=TFilterItems.Create(Self,TFilter);
end;
destructor TFilters.Destroy;
begin
FItems.Free;
FBitmap.Free;
inherited;
end;
function TFilters.ApplyFilters(const R:TRect): TBitmap;
var t : Integer;
begin
with Panel do
result:=TeeCreateBitmap(Color,R,TeePixelFormat);
for t:=0 to Items.Count-1 do
with Items[t] do
if not Disabled then
begin
Bitmap:=result;
Apply;
end;
end;
function TFilters.Bitmap: TBitmap;
begin
if not Assigned(FBitmap) then
FBitmap:=ApplyFilters(Panel.GetRectangle);
result:=FBitmap;
end;
procedure TFilters.StretchTo(Picture:TPicture; AWidth,AHeight:Integer);
var tmpDest : TBitmap;
begin
tmpDest:=TBitmap.Create;
try
{$IFDEF D10}
tmpDest.SetSize(AWidth,AHeight);
{$ELSE}
tmpDest.Width:=AWidth;
tmpDest.Height:=AHeight;
{$ENDIF}
SmoothStretch(Bitmap,tmpDest);
Picture.Assign(tmpDest);
finally
tmpDest.Free;
end;
end;
procedure TFilters.SetItems(const Value: TFilterItems);
begin
FItems.Assign(Value);
FreeAndNil(FBitmap);
end;
{ TEmbossFilter }
procedure TEmbossFilter.Apply(const R: TRect);
begin
Weights[-1,-1]:= 0; Weights[-1,0]:=-1; Weights[-1,1]:=0;
Weights[ 0,-1]:=-1; Weights[ 0,0]:=1; Weights[ 0,1]:=1;
Weights[ 1,-1]:= 0; Weights[ 1,0]:=-1; Weights[ 1,1]:=0;
InvTotalWeight:=1.0/1.0;
inherited;
end;
class function TEmbossFilter.Description: String;
begin
result:='Emboss';
end;
{ TContrastFilter }
procedure TContrastFilter.Apply(const R: TRect);
var x,y,l : Integer;
IPercent : Single;
begin
inherited;
if Percent then
IPercent:=FAmount*0.01
else
IPercent:=1;
for y:=R.Top to R.Bottom do
for x:=R.Left to R.Right do
with Lines[y,x] do
begin
if Percent then l:=rgbtRed+(Round(rgbtRed*IPercent)*(rgbtRed-128) div 256)
else l:=rgbtRed+(Amount*(rgbtRed-128) div 256);
if l<0 then rgbtRed:=0 else if l>255 then rgbtRed:=255 else rgbtRed:=l;
if Percent then l:=rgbtGreen+(Round(rgbtGreen*IPercent)*(rgbtGreen-128) div 256)
else l:=rgbtGreen+(Amount*(rgbtGreen-128) div 256);
if l<0 then rgbtGreen:=0 else if l>255 then rgbtGreen:=255 else rgbtGreen:=l;
if Percent then l:=rgbtBlue+(Round(rgbtBlue*IPercent)*(rgbtBlue-128) div 256)
else l:=rgbtBlue+(Amount*(rgbtBlue-128) div 256);
if l<0 then rgbtBlue:=0 else if l>255 then rgbtBlue:=255 else rgbtBlue:=l;
end;
end;
class function TContrastFilter.Description: String;
begin
result:='Contrast';
end;
{ TAntiAliasFilter }
procedure TAntiAliasFilter.Apply(const R: TRect);
begin
Weights[-1,-1]:=0; Weights[-1,0]:=0; Weights[-1,1]:=0;
Weights[ 0,-1]:=0; Weights[ 0,0]:=1; Weights[ 0,1]:=1;
Weights[ 1,-1]:=0; Weights[ 1,0]:=1; Weights[ 1,1]:=1;
InvTotalWeight:=1.0/4.0;
inherited;
end;
class function TAntiAliasFilter.Description: String;
begin
result:='Antialias';
end;
procedure TFiltersEditor.Scaled1Click(Sender: TObject);
begin
Scaled1.Checked:=not Scaled1.Checked;
Preview;
end;
initialization
//RegisterComponents(TeeMsg_TeeChartPalette,[TFilters]);
TeeRegisterFilters([ TInvertFilter,
TGrayScaleFilter,
TMosaicFilter,
TFlipFilter,
TReverseFilter,
TBrightnessFilter,
TContrastFilter,
TRedFilter,
TGreenFilter,
TBlueFilter,
TBlurFilter,
TSharpenFilter,
TGammaCorrectionFilter,
TEmbossFilter,
TAntiAliasFilter ]);
InstallHook;
finalization
FreeAndNil(FilterClass);
RemoveHook;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -