VCL Image Utilities and Color Constants
VCL Image Utilities and Color Constants
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
PngImage, GifImg, Math, Jpeg, Types;
const
clAliceBlue = $FFF8F0;
clAntiqueWhite = $D7EBFA;
clAquamarine = $D4FF7F;
clAzure = $FFFFF0;
clBeige = $DCF5F5;
clBisque = $C4E4FF;
clBlanchedAlmond = $CDEBFF;
clBlueViolet = $E22B8A;
clBrown = $2A2AA5;
clBurlyWood = $87B8DE;
clCadetBlue = $A09E5F;
clChartreuse = $00FF7F;
clChocolate = $1E69D2;
clCoral = $507FFF;
clCornflowerBlue = $ED9564;
clCornsilk = $DCF8FF;
clCrimson = $3C14DC;
clCyan = $FFFF00;
clDarkBlue = $8B0000;
clDarkCyan = $8B8B00;
clDarkGoldenrod = $0B86B8;
clDarkGray = $A9A9A9;
clDarkGreen = $006400;
clDarkKhaki = $6BB7BD;
clDarkMagenta = $8B008B;
clDarkOliveGreen = $2F6B55;
clDarkOrange = $008CFF;
clDarkOrchid = $CC3299;
clDarkRed = $00008B;
clDarkSalmon = $7A96E9;
clDarkSeaGreen = $8BBC8F;
clDarkSlateBlue = $8B3D48;
clDarkSlateGray = $4F4F2F;
clDarkTurquoise = $D1CE00;
clDarkViolet = $D30094;
clDeepPink = $9314FF;
clDeepSkyBlue = $FFBF00;
clDimGray = $696969;
clDodgerBlue = $FF901E;
clFirebrick = $2222B2;
clFloralWhite = $F0FAFF;
clForestGreen = $228B22;
clGainsboro = $DCDCDC;
clGhostWhite = $FFF8F8;
clGold = $00D7FF;
clGoldenrod = $20A5DA;
clGreenYellow = $2FFFAD;
clHoneydew = $F0FFF0;
clHotPink = $B469FF;
clIndianRed = $5C5CCD;
clIndigo = $82004B;
clIvory = $F0FFFF;
clKhaki = $8CE6F0;
clLavender = $FAE6E6;
clLavenderBlush = $F5F0FF;
clLawnGreen = $00FC7C;
clLemonChiffon = $CDFAFF;
clLightBlue = $E6D8AD;
clLightCoral = $8080F0;
clLightCyan = $FFFFE0;
clLightGoldenrodYellow = $D2FAFA;
clLightGray = $D3D3D3;
clLightGreen = $90EE90;
clLightPink = $C1B6FF;
clLightSalmon = $7AA0FF;
clLightSeaGreen = $AAB220;
clLightSkyBlue = $FACE87;
clLightSlateGray = $998877;
clLightSteelBlue = $DEC4B0;
clLightYellow = $E0FFFF;
clLimeGreen = $32CD32;
clLinen = $E6F0FA;
clMagenta = $FF00FF;
clMediumAquamarine = $AACD66;
clMediumBlue = $CD0000;
clMediumOrchid = $D355BA;
clMediumPurple = $DB7093;
clMediumSeaGreen = $71B33C;
clMediumSlateBlue = $EE687B;
clMediumSpringGreen = $9AFA00;
clMediumTurquoise = $CCD148;
clMediumVioletRed = $8515C7;
clMidnightBlue = $701919;
clMintCream = $FAFFF5;
clMistyRose = $E1E4FF;
clMoccasin = $B5E4FF;
clNavajoWhite = $ADDEFF;
clOldLace = $E6F5FD;
clOliveDrab = $238E6B;
clOrange = $00A5FF;
clOrangeRed = $0045FF;
clOrchid = $D670DA;
clPaleGoldenrod = $AAE8EE;
clPaleGreen = $98FB98;
clPaleTurquoise = $EEEEAF;
clPaleVioletRed = $9370DB;
clPapayaWhip = $D5EFFF;
clPeachPuff = $B9DAFF;
clPeru = $3F85CD;
clPink = $CBC0FF;
clPlum = $DDA0DD;
clPowderBlue = $E6E0B0;
clPurple = $800080;
clRosyBrown = $8F8FBC;
clRoyalBlue = $E16941;
clSaddleBrown = $13458B;
clSalmon = $7280FA;
clSandyBrown = $60A4F4;
clSeaGreen = $578B2E;
clSeaShell = $EEF5FF;
clSienna = $2D52A0;
clSkyBlue = $EBCE87;
clSlateBlue = $CD5A6A;
clSlateGray = $908070;
clSnow = $FAFAFF;
clSpringGreen = $7FFF00;
clSteelBlue = $B48246;
clTan = $8CB4D2;
clThistle = $D8BFD8;
clTomato = $4763FF;
clTurquoise = $D0E040;
clViolet = $EE82EE;
clWheat = $B3DEF5;
clWhiteSmoke = $F5F5F5;
clYellowGreen = $32CD9A;
type
TFlipType = (ftUpDown, ftLeftRight);
TRGBQuadArray = array[BYTE] of TRGBQuad;
TErrorDiffusion = (edNone, edFloydSteinberg, edStucki, edSierra, edJaJuNi);
TResizeMode = (rmNearest, rmBilinear, rmBicubic, rmLagrange,
rmBSpline, rmMitchell);
TRankMode = (rkMax, rkMin);
TPointF = packed record
X, Y: single;
end;
TMirrorType = (mtLeft, mtRight);
TCylinderDirection = (cdVertical, cdHorizontal);
TBathWindowMode = (bwVertical, bwHorizontal, bwBoth);
TWaveType = (wtVertical, wtHorizontal, wtBoth);
TSineMask = (smVert, smHorz, smBoth);
TBmpData24 = class(TObject)
private
sl: array of Pointer;
FWidth, FHeight: integer;
function GetData(x, y: integer):PRGBTriple;
protected
public
constructor Create(bmp: TBitmap);
destructor Destroy; override;
property Data[x, y: integer]: PRGBTriple read GetData; default;
property Width: integer read FWidth;
property Height: integer read FHeight;
end;
TBmpData8 = class(TObject)
private
sl: array of Pointer;
FWidth, FHeight: integer;
function GetData(x, y: integer):PByte;
protected
public
constructor Create(bmp: TBitmap);
destructor Destroy; override;
property Data[x, y: integer]: PByte read GetData; default;
property Width: integer read FWidth;
property Height: integer read FHeight;
end;
TBmpData4 = class(TObject)
private
sl: array of Pointer;
function GetData(x, y: integer):Byte;
procedure SetData(x, y: integer; value: Byte);
protected
public
constructor Create(bmp: TBitmap);
destructor Destroy; override;
property Data[x, y: integer]: Byte read GetData write SetData; default;
end;
TBmpData1 = class(TObject)
private
sl: array of Pointer;
FWidth, FHeight: integer;
function GetData(x, y: integer):Boolean;
procedure SetData(x, y: integer; value: Boolean);
protected
public
constructor Create(bmp: TBitmap);
destructor Destroy; override;
property Data[x, y: integer]: Boolean read GetData write SetData; default;
property Width: integer read FWidth;
property Height: integer read FHeight;
end;
implementation
destructor [Link];
begin
inherited;
end;
destructor [Link];
begin
inherited;
end;
destructor [Link];
begin
inherited;
end;
tmp8 := BmpClone(bmp);
if not GrayScale(tmp8) then
begin
[Link];
exit;
end;
if Stretch then
// if not HistoStretchGray(tmp8) then
if not HistoStretch(tmp8) then
begin
[Link];
exit;
end;
bmp4 := [Link];
[Link] := pf4bit;
[Link] := w;
[Link] := h;
for i := 0 to 15 do
begin
ct[i].rgbBlue := i shl 4;
ct[i].rgbGreen := i shl 4;
ct[i].rgbRed := i shl 4;
ct[i].rgbReserved := 0;
end;
SetDIBColorTable([Link],0,15,ct);
DeleteObject([Link]);
src := [Link](tmp8);
dst := [Link](bmp4);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
v := src[ix,iy]^ shr 4;
if (src[ix,iy]^ and $F) > 8 then Inc(v);
if v > $F then v := $F;
dst[ix, iy] := v;
x := ix+1; y := iy;
if (x < w) then src[x,y]^ := AdjustByte(src[x,y]^+ dif*7/16);
x := ix-1; y := iy+1;
if (x > -1) and (y < h) then src[x,y]^ := AdjustByte(src[x,y]^+ dif*3/16);
x := ix; y := iy+1;
if (y < h) then src[x,y]^ := AdjustByte(src[x,y]^+ dif*5/16);
x := ix+1; y := iy+1;
if (x < w) and (y < h) then src[x,y]^ := AdjustByte(src[x,y]^+ dif/16);
end;
[Link];
[Link];
[Link];
[Link];
bmp := bmp4;
result := true;
end;
destructor [Link];
begin
inherited;
end;
//-------------------------------------------------------------
except
FreeAndNil(result);
end;
finally
[Link];
end;
end;
jpg := [Link];
try
[Link](filename);
result := [Link];
try
[Link](jpg);
except
FreeAndNil(result)
end;
finally
[Link];
end;
end;
tmp := BmpClone(bmp);
dst := [Link](bmp);
src := [Link](tmp);
[Link];
[Link];
[Link];
result := true;
end;
tmp := BmpClone(bmp);
[Link] := h;
[Link] := w;
src := [Link](bmp);
dst := [Link](tmp);
if plus then
begin
for iy := 0 to h-1 do
for ix := 0 to w-1 do
dst[h-1-iy,ix]^ := src[ix,iy]^;
end
else
begin
for iy := 0 to h-1 do
for ix := 0 to w-1 do
dst[iy,w-1-ix]^ := src[ix,iy]^;
end;
[Link];
[Link];
[Link];
bmp := tmp;
result := true;
end;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
pd := dst[ix,iy]; ps := src[ix,iy];
pd^.rgbtRed := 255 - ps^.rgbtRed;
pd^.rgbtGreen := 255 - ps^.rgbtGreen;
pd^.rgbtBlue := 255 - ps^.rgbtBlue;
end;
[Link];
[Link];
[Link];
result := true;
end;
with [Link] do
begin
[Link] := clGray;
for i := 0 to num-1 do
begin
[Link] := RGB(pe[i].peRed, pe[i].peGreen, pe[i].peBlue);
x := 14*(i mod 16)+1; y := 14*(i div 16)+1;
Rectangle(x-1, y-1, x+14, y+14);
end;
end;
end;
for i := 0 to num-1 do
begin
c := trunc(pe[i].peRed*0.299+pe[i].peGreen*0.587+pe[i].peBlue*0.114);
ct[i].rgbBlue := c;
ct[i].rgbGreen := c;
ct[i].rgbRed := c;
ct[i].rgbReserved := 0;
end;
SetDIBColorTable([Link],0,num,ct);
DeleteObject([Link]);
end;
function GrayScale4(var bmp: TBitmap):Boolean;
var
tmp8, bmp4:TBitmap;
w, h, ix, iy, i: integer;
src: TBmpData8;
dst: TBmpData4;
ct: array[0..15] of TRGBQuad;
v: Byte;
begin
result := false;
if [Link] <> pf24bit then exit;
w := [Link];
h := [Link];
tmp8 := BmpClone(bmp);
if not GrayScale(tmp8) then
begin
[Link];
exit;
end;
// if not HistoStretchGray(tmp8) then
if not HistoStretch(tmp8) then
begin
[Link];
exit;
end;
bmp4 := [Link];
[Link] := pf4bit;
[Link] := w;
[Link] := h;
for i := 0 to 15 do
begin
ct[i].rgbBlue := i shl 4;
ct[i].rgbGreen := i shl 4;
ct[i].rgbRed := i shl 4;
ct[i].rgbReserved := 0;
end;
SetDIBColorTable([Link],0,15,ct);
DeleteObject([Link]);
src := [Link](tmp8);
dst := [Link](bmp4);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
v := src[ix,iy]^ shr 4;
if (src[ix,iy]^ and $F) > 8 then Inc(v);
if v > $F then v := $F;
dst[ix, iy] := v;
end;
[Link];
[Link];
[Link];
[Link];
bmp := bmp4;
result := true;
end;
w := [Link];
h := [Link];
src := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := src[ix,iy]^;
inc(Hist[Trunc(0.299*[Link] + 0.587*[Link] + 0.114*[Link])]);
end;
[Link];
max := -1;
for i := 0 to 255 do if Hist[i] > max then max := Hist[i];
result := [Link];
[Link] := pf8bit;
[Link] := 275;
[Link] := 160;
with [Link] do
begin
[Link] := clGray;
for i := 0 to 255 do
begin
MoveTo(10+i,150);
LineTo(10+i,150-Hist[i]);
end;
[Link] := clBlack;
MoveTo(10, 150); LineTo(10, 10);
for i := 0 to 20 do
begin
MoveTo(10, 150-7*i);
if Odd(i) then LineTo(8, 150-7*i) else LineTo(6, 150-7*i);
end;
MoveTo(10, 150); LineTo(10+255, 150);
for i := 0 to 51 do
begin
MoveTo(10+5*i, 150);
if Odd(i) then LineTo(10+5*i, 152) else LineTo(10+5*i, 154);
end;
end;
end;
function RGBHistogram(bmp: TBitmap): TBitmap;
var
w, h, ix, iy, i, max: integer;
src: TBmpData24;
d: TRGBTriple;
L, R, G, B: array[0..255] of integer;
pt: array[0..255] of TPoint;
begin
for i := 0 to 255 do
begin
L[i] := 0; R[i] := 0; G[i] := 0; B[i] := 0;
end;
w := [Link];
h := [Link];
src := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := src[ix,iy]^;
inc(R[[Link]]);
inc(G[[Link]]);
inc(B[[Link]]);
inc(L[Trunc(0.299*[Link] + 0.587*[Link] + 0.114*[Link])]);
end;
[Link];
max := -1;
for i := 0 to 255 do
begin
if R[i] > max then max := R[i];
if G[i] > max then max := G[i];
if B[i] > max then max := B[i];
if L[i] > max then max := L[i];
end;
result := [Link];
[Link] := pf8bit;
[Link] := 275;
[Link] := 160;
with [Link] do
begin
[Link] := clSilver;
FillRect(Rect(0, 0, 275, 160));
[Link] := 2;
[Link] := 1;
[Link] := clBlack;
MoveTo(10, 150); LineTo(10, 10);
for i := 0 to 20 do
begin
MoveTo(10, 150-7*i);
if Odd(i) then LineTo(8, 150-7*i) else LineTo(6, 150-7*i);
end;
MoveTo(10, 150); LineTo(10+255, 150);
for i := 0 to 51 do
begin
MoveTo(10+5*i, 150);
if Odd(i) then LineTo(10+5*i, 152) else LineTo(10+5*i, 154);
end;
end;
end;
bmp8 := [Link];
[Link] := pf8bit;
[Link] := w;
[Link] := h;
SetGrayPalette(bmp8);
src := [Link](bmp);
dst := [Link](bmp8);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := src[ix,iy];
dst[ix, iy]^ := Trunc(0.299*d^.rgbtRed + 0.587*d^.rgbtGreen +
0.114*d^.rgbtBlue);
end;
[Link];
[Link];
[Link];
bmp := bmp8;
result := true;
end;
tmp8 := BmpClone(bmp);
if not GrayScale(tmp8) then
begin
[Link];
exit;
end;
if stretch then
// if not HistoStretchGray(tmp8) then
if not HistoStretch(tmp8) then
begin
[Link];
exit;
end;
bmp1 := [Link];
[Link] := pf1bit;
[Link] := w;
[Link] := h;
Dark := ColorToRGB(Dark);
ct[0].rgbBlue := GetBValue(Dark);
ct[0].rgbGreen := GetGValue(Dark);
ct[0].rgbRed := GetRValue(Dark);
ct[0].rgbReserved := 0;
Bright := ColorToRGB(Bright);
ct[1].rgbBlue := GetBValue(Bright);
ct[1].rgbGreen :=GetGValue(Bright);
ct[1].rgbRed := GetRValue(Bright);
ct[1].rgbReserved := 0;
SetDIBColorTable([Link],0,2,ct);
DeleteObject([Link]);
src := [Link](tmp8);
dst := [Link](bmp1);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
dst[ix, iy] := src[ix,iy]^ > threshold;
x := ix+1; y := iy;
if (x < w) then src[x,y]^ := AdjustByte(src[x,y]^+ dif*7/16);
x := ix-1; y := iy+1;
if (x > -1) and (y < h) then src[x,y]^ := AdjustByte(src[x,y]^+ dif*3/16);
x := ix; y := iy+1;
if (y < h) then src[x,y]^ := AdjustByte(src[x,y]^+ dif*5/16);
x := ix+1; y := iy+1;
if (x < w) and (y < h) then src[x,y]^ := AdjustByte(src[x,y]^+ dif/16);
end;
[Link];
[Link];
[Link];
[Link];
bmp := bmp1;
result := true;
end;
bd := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := bd[ix,iy];
d^.rgbtRed := AdjustByte(d^.rgbtRed + rr);
d^.rgbtGreen := AdjustByte(d^.rgbtGreen + rr);
d^.rgbtBlue := AdjustByte(d^.rgbtBlue + rr);
end;
[Link];
result := true;
end;
value := (100.0+nContrast)/100.0;
value := value*value;
w := [Link];
h := [Link];
bd := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := bd[ix,iy];
d^.rgbtRed := AdjustByte(((d^.rgbtRed/255.0 - 0.5)*value + 0.5)*255.0);
d^.rgbtGreen := AdjustByte(((d^.rgbtGreen/255.0 - 0.5)*value + 0.5)*255.0);
d^.rgbtBlue := AdjustByte(((d^.rgbtBlue/255.0 - 0.5)*value + 0.5)*255.0);
end;
[Link];
result := true;
end;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := src[ix,iy];
r := -d^.rgbtRed;
g := -d^.rgbtGreen;
b := -d^.rgbtBlue;
x := ix+1; y := iy+1;
if (x > w-1) then x := ix;
if (y > h-1) then y := iy;
d := src[x,y];
r := r - d^.rgbtRed;
g := g - d^.rgbtGreen;
b := b - d^.rgbtBlue;
x := ix-1; y := iy-1;
if (x < 0) then x := ix;
if (y < 0) then y := iy;
d := src[x,y];
r := r + 2*d^.rgbtRed;
g := g + 2*d^.rgbtGreen;
b := b + 2*d^.rgbtBlue;
d := dst[ix,iy];
d^.rgbtRed := AdjustByte(r+127);
d^.rgbtGreen := AdjustByte(g+127);
d^.rgbtBlue := AdjustByte(b+127);
end;
[Link];
[Link];
[Link];
result := true;
end;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := src[ix,iy];
r := d^.rgbtRed;
g := d^.rgbtGreen;
b := d^.rgbtBlue;
x := ix+1; y := iy+1;
if (x > w-1) then x := ix;
if (y > h-1) then y := iy;
d := src[x,y];
r := r - d^.rgbtRed;
g := g - d^.rgbtGreen;
b := b - d^.rgbtBlue;
d := dst[ix,iy];
d^.rgbtRed := AdjustByte(r+127);
d^.rgbtGreen := AdjustByte(g+127);
d^.rgbtBlue := AdjustByte(b+127);
end;
[Link];
[Link];
[Link];
result := true;
end;
tl := [Link];
try
[Link] := w * h;
for y := 0 to h-1 do
begin
for x := 0 to w-1 do
begin
pData := src[x, y];
c := RGB(pData^.rgbtRed, pData^.rgbtGreen, pData^.rgbtBlue);
[Link](pointer(c));
end;
end;
[Link](CompInt);
result := 1;
for i := 1 to [Link]-1 do
if integer(tl[i-1]) <> integer(tl[i]) then inc(result);
finally
[Link];
end;
[Link];
end;
bmp8 := [Link];
[Link] := pf8bit;
[Link] := w;
[Link] := h;
Dark := ColorToRGB(Dark);
Bright := ColorToRGB(Bright);
dr := GetRValue(Dark); dg := GetGValue(Dark); db := GetBValue(Dark);
br := GetRValue(Bright); bg := GetGValue(Bright); bb := GetBValue(Bright);
for i := 0 to 255 do
begin
ct[i].rgbRed := Round(dr+(br-dr)*i/255);
ct[i].rgbGreen := Round(dg+(bg-dg)*i/255);
ct[i].rgbBlue := Round(db+(bb-db)*i/255);
ct[i].rgbReserved := 0;
end;
SetDIBColorTable([Link],0,256,ct);
DeleteObject([Link]);
src := [Link](bmp);
dst := [Link](bmp8);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := src[ix,iy];
dst[ix, iy]^ := Trunc(0.299*d^.rgbtRed + 0.587*d^.rgbtGreen +
0.114*d^.rgbtBlue);
end;
[Link];
[Link];
[Link];
bmp := bmp8;
result := true;
end;
for i := 0 to 255 do
ga[i] := Trunc(Min(255.0, ( 255.0 * Power(i/255.0, 1.0/dGamma)) + 0.5));
bd := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := bd[ix, iy];
d^.rgbtRed := ga[d^.rgbtRed];
d^.rgbtGreen := ga[d^.rgbtGreen];
d^.rgbtBlue := ga[d^.rgbtBlue];
end;
[Link];
result := true;
end;
bd := [Link](bmp);
fRed := 1.0+fRed/100;
fGreen := 1.0+fGreen/100;
fBlue := 1.0+fBlue/100;
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := bd[ix,iy]^;
bd[ix,iy]^.rgbtRed := AdjustByte([Link]*fRed);
bd[ix,iy]^.rgbtGreen := AdjustByte([Link]*fGreen);
bd[ix,iy]^.rgbtBlue := AdjustByte([Link]*fBlue);
end;
[Link];
result := true;
end;
level := 1+percent/100;
SatComp := 1.0 - level;
SatCompR := 0.3086 * SatComp;
SatCompG := 0.6094 * SatComp;
SatCompB := 0.0820 * SatComp;
bd := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := bd[ix,iy]^;
bd[ix,iy]^.rgbtRed := AdjustByte([Link]*(SatCompR+level)+
[Link]*SatCompG+
[Link]*SatCompB);
bd[ix,iy]^.rgbtGreen := AdjustByte([Link]*SatCompR+
[Link]*(SatCompG+level)+
[Link]*SatCompB);
bd[ix,iy]^.rgbtBlue := AdjustByte([Link]*SatCompR+
[Link]*SatCompG+
[Link]*(SatCompB+level));
end;
[Link];
result := true;
end;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
rv := 0; gv := 0; bv := 0; rh := 0; gh := 0; bh := 0;
for y := iy-1 to iy+1 do
for x := ix-1 to ix+1 do
begin
if (y<0) or (y>h-1) then yy := iy else yy := y;
if (x<0) or (x>w-1) then xx := ix else xx := x;
d := src[xx,yy];
rv := rv + vmask[x-ix,y-iy]*d^.rgbtRed;
gv := gv + vmask[x-ix,y-iy]*d^.rgbtGreen;
bv := bv + vmask[x-ix,y-iy]*d^.rgbtBlue;
rh := rh + hmask[x-ix,y-iy]*d^.rgbtRed;
gh := gh + hmask[x-ix,y-iy]*d^.rgbtGreen;
bh := bh + hmask[x-ix,y-iy]*d^.rgbtBlue;
end;
d := dst[ix,iy];
d^.rgbtRed := AdjustByte(sqrt(rv*rv+rh*rh));
d^.rgbtGreen := AdjustByte(sqrt(gv*gv+gh*gh));
d^.rgbtBlue := AdjustByte(sqrt(bv*bv+bh*bh));
end;
[Link];
[Link];
[Link];
result := true;
end;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
r := 0; g := 0; b := 0;
for y := iy-1 to iy+1 do
for x := ix-1 to ix+1 do
begin
if (y<0) or (y>h-1) then yy := iy else yy := y;
if (x<0) or (x>w-1) then xx := ix else xx := x;
d := src[xx,yy];
r := r + mask[x-ix,y-iy]*d^.rgbtRed;
g := g + mask[x-ix,y-iy]*d^.rgbtGreen;
b := b + mask[x-ix,y-iy]*d^.rgbtBlue;
end;
d := dst[ix,iy];
d^.rgbtRed := AdjustByte(r+127);
d^.rgbtGreen := AdjustByte(g+127);
d^.rgbtBlue := AdjustByte(b+127)
end;
[Link];
[Link];
[Link];
if fGray then GrayScale(bmp);
result := true;
end;
rate := percent/100;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
r := 0; g := 0; b := 0;
for y := iy-1 to iy+1 do
for x := ix-1 to ix+1 do
begin
if (y<0) or (y>h-1) then yy := iy else yy := y;
if (x<0) or (x>w-1) then xx := ix else xx := x;
d := src[xx,yy];
r := r + mask[x-ix,y-iy]*d^.rgbtRed;
g := g + mask[x-ix,y-iy]*d^.rgbtGreen;
b := b + mask[x-ix,y-iy]*d^.rgbtBlue;
end;
d := dst[ix,iy];
[Link];
[Link];
[Link];
result := true;
end;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
r := 0; g := 0; b := 0;
for y := iy-1 to iy+1 do
for x := ix-1 to ix+1 do
begin
if (y<0) or (y>h-1) then yy := iy else yy := y;
if (x<0) or (x>w-1) then xx := ix else xx := x;
d := src[xx,yy];
r := r + mask[x-ix,y-iy]*d^.rgbtRed;
g := g + mask[x-ix,y-iy]*d^.rgbtGreen;
b := b + mask[x-ix,y-iy]*d^.rgbtBlue;
end;
d := dst[ix,iy];
d^.rgbtRed := AdjustByte(r+127);
d^.rgbtGreen := AdjustByte(g+127);
d^.rgbtBlue := AdjustByte(b+127)
end;
[Link];
[Link];
[Link];
result := true;
end;
rate := percent/100;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
r := 0; g := 0; b := 0;
for y := iy-1 to iy+1 do
for x := ix-1 to ix+1 do
begin
if (y<0) or (y>h-1) then yy := iy else yy := y;
if (x<0) or (x>w-1) then xx := ix else xx := x;
d := src[xx,yy];
r := r + mask[x-ix,y-iy]*d^.rgbtRed;
g := g + mask[x-ix,y-iy]*d^.rgbtGreen;
b := b + mask[x-ix,y-iy]*d^.rgbtBlue;
end;
d := dst[ix,iy];
[Link];
[Link];
[Link];
result := true;
end;
num := (2*area+1)*(2*area+1);
md := Round(num/2);
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
indx := 0;
for y := iy-area to iy+area do
for x := ix-area to ix+area do
begin
if (y<0) or (y>h-1) then yy := iy else yy := y;
if (x<0) or (x>w-1) then xx := ix else xx := x;
d := src[xx,yy];
rl[indx] := pointer(d^.rgbtRed);
gl[indx] := pointer(d^.rgbtGreen);
bl[indx] := pointer(d^.rgbtBlue);
inc(indx);
end;
[Link](ColorSort);
[Link](ColorSort);
[Link](ColorSort);
d := dst[ix,iy];
d^.rgbtRed := byte(rl[md]);
d^.rgbtGreen := byte(gl[md]);
d^.rgbtBlue := byte(bl[md]);
end;
[Link];
[Link];
[Link];
[Link];
[Link];
[Link];
result := true;
end;
maxc := Max(Max(r,g),b);
minc := Min(Min(r,g),b);
ll := (maxc+minc)/2;
cr := (maxc-r)/(maxc-minc);
cg := (maxc-g)/(maxc-minc);
cb := (maxc-b)/(maxc-minc);
if maxc=r then
hh := cb-cg
else
if maxc=g then
hh := 2+cr-cb
else
hh := 4+cg-cr;
hh := 60*hh;
if hh<0 then hh := hh+360;
end;
h := trunc(hh);
s := trunc(ss*100);
l := trunc(ll*100);
end;
r := 0; g := 0; b := 0;
if s = 0 then
begin
r := ll;
g := ll;
b := ll;
end
else
begin
if ll<=0.5 then
maxc := ll*(1+ss)
else
maxc := ll*(1-ss)+ss;
minc := 2*ll-maxc;
hhh := hh+120;
if hhh>=360 then hhh := hhh-360;
case hhh of
0..59 : r := minc+(maxc-minc)*hhh/60;
60..179 : r := maxc;
180..239: r := minc+(maxc-minc)*(240-hhh)/60;
240..359: r := minc;
end;
hhh := hh;
case hhh of
0..59 : g := minc+(maxc-minc)*hhh/60;
60..179 : g := maxc;
180..239: g := minc+(maxc-minc)*(240-hhh)/60;
240..359: g := minc;
end;
hhh := hh-120;
if hhh<0 then hhh := hhh+360;
case hhh of
0..59 : b := minc+(maxc-minc)*hhh/60;
60..179 : b := maxc;
180..239: b := minc+(maxc-minc)*(240-hhh)/60;
240..359: b := minc;
end;
end;
rgb^.rgbtRed := trunc(r*255);
rgb^.rgbtGreen := trunc(g*255);
rgb^.rgbtBlue := trunc(b*255);
end;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := src[ix,iy];
RGBToHSL(d^, hh, ss, ll);
hh := (hh+angle) mod 360;
HSLToRGB(dst[ix,iy],hh,ss,ll);
end;
[Link];
[Link];
[Link];
result := true;
end;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
d := src[ix,iy];
RGBToHSL(d^, hh, ss, ll);
ll := trunc(ll*(1+percent/100));
if ll>100 then ll := 100;
HSLToRGB(dst[ix,iy],hh,ss,ll);
end;
[Link];
[Link];
[Link];
result := true;
end;
stretchfactor := 1.00;
threshold := Round(w*h*0.015);
bd := [Link](grayBMP);
for y := 0 to h-1 do
for x := 0 to w-1 do
inc(hist[bd[x,y]^]);
lt := 0;
for i := 0 to 255 do
begin
lt := lt + hist[i];
if lt > threshold then
begin
lt := i;
break;
end;
end;
ht := 0;
for i := 255 downto 0 do
begin
ht := ht + hist[i];
if ht > threshold then
begin
ht := i;
break;
end;
end;
originalrange := ht - lt + 1;
stretchedrange := originalrange + Round(stretchfactor * (255 - originalrange));
scaleFactor := stretchedrange / originalrange;
for y := 0 to h-1 do
for x := 0 to w-1 do
bd[x,y]^ := AdjustByte(scalefactor * (bd[x,y]^ - lt));
[Link];
result := true;
end;
bmp1 := [Link];
[Link] := pf1bit;
[Link] := w;
[Link] := h;
GrayScale(bmp24);
src := [Link](bmp24);
dst := [Link](bmp1);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
dst[ix,iy] := src[ix,iy]^ > threshold;
[Link];
[Link];
[Link];
bmp24 := bmp1;
result := true;
end;
bmp1 := [Link];
[Link] := pf1bit;
[Link] := w;
[Link] := h;
Dark := ColorToRGB(Dark);
ct[0].rgbBlue := GetBValue(Dark);
ct[0].rgbGreen := GetGValue(Dark);
ct[0].rgbRed := GetRValue(Dark);
ct[0].rgbReserved := 0;
Bright := ColorToRGB(Bright);
ct[1].rgbBlue := GetBValue(Bright);
ct[1].rgbGreen :=GetGValue(Bright);
ct[1].rgbRed := GetRValue(Bright);
ct[1].rgbReserved := 0;
SetDIBColorTable([Link],0,2,ct);
DeleteObject([Link]);
GrayScale(bmp24);
Randomize;
mfactor := (256-randomness) div 2;
src := [Link](bmp24);
dst := [Link](bmp1);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
p8 := src[ix,iy];
d := p8^ > (Random(randomness)+mfactor);
dst[ix,iy] := d;
if ErrorDiffusion = edNone then continue;
case ErrorDiffusion of
edFloydSteinberg: begin
for yy := iy to iy+1 do
for xx := ix-1 to ix+1 do
begin
if FSmask[xx-ix,yy-iy] = 0 then continue;
if (xx<0) or (xx>w-1) then continue;
if yy>h-1 then continue;
p8 := src[xx,yy];
p8^ := AdjustByte(p8^ + err*FSmask[xx-ix,yy-iy]);
end;
end;
edStucki: begin
for yy := iy to iy+2 do
for xx := ix-2 to ix+2 do
begin
if STmask[xx-ix,yy-iy] = 0 then continue;
if (xx<0) or (xx>w-1) then continue;
if yy>h-1 then continue;
p8 := src[xx,yy];
p8^ := AdjustByte(p8^ + err*STmask[xx-ix,yy-iy]);
end;
end;
edSierra: begin
for yy := iy to iy+2 do
for xx := ix-2 to ix+2 do
begin
if SRmask[xx-ix,yy-iy] = 0 then continue;
if (xx<0) or (xx>w-1) then continue;
if yy>h-1 then continue;
p8 := src[xx,yy];
p8^ := AdjustByte(p8^ + err*SRmask[xx-ix,yy-iy]);
end;
end;
edJaJuNi: begin
for yy := iy to iy+2 do
for xx := ix-2 to ix+2 do
begin
if JJmask[xx-ix,yy-iy] = 0 then continue;
if (xx<0) or (xx>w-1) then continue;
if yy>h-1 then continue;
p8 := src[xx,yy];
p8^ := AdjustByte(p8^ + err*JJmask[xx-ix,yy-iy]);
end;
end;
end;
end;
[Link];
[Link];
[Link];
bmp24 := bmp1;
result := true;
end;
GrayScale(bmp24);
bmp1 := [Link];
[Link] := pf1bit;
[Link] := w;
[Link] := h;
Dark := ColorToRGB(Dark);
ct[0].rgbBlue := GetBValue(Dark);
ct[0].rgbGreen := GetGValue(Dark);
ct[0].rgbRed := GetRValue(Dark);
ct[0].rgbReserved := 0;
Bright := ColorToRGB(Bright);
ct[1].rgbBlue := GetBValue(Bright);
ct[1].rgbGreen :=GetGValue(Bright);
ct[1].rgbRed := GetRValue(Bright);
ct[1].rgbReserved := 0;
SetDIBColorTable([Link],0,2,ct);
DeleteObject([Link]);
//area := 2;
//area := 3;
area := 4;
src := [Link](bmp24);
dst := [Link](bmp1);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
p8 := src[ix, iy];
d := p8^ > ptn[ix mod area, iy mod area];
dst[ix,iy] := d;
case ErrorDiffusion of
edFloydSteinberg: begin
for yy := iy to iy+1 do
for xx := ix-1 to ix+1 do
begin
if FSmask[xx-ix,yy-iy] = 0 then continue;
if (xx<0) or (xx>w-1) then continue;
if yy>h-1 then continue;
p8 := src[xx,yy];
p8^ := AdjustByte(p8^ + err*FSmask[xx-ix,yy-iy]);
end;
end;
edStucki: begin
for yy := iy to iy+2 do
for xx := ix-2 to ix+2 do
begin
if STmask[xx-ix,yy-iy] = 0 then continue;
if (xx<0) or (xx>w-1) then continue;
if yy>h-1 then continue;
p8 := src[xx,yy];
p8^ := AdjustByte(p8^ + err*STmask[xx-ix,yy-iy]);
end;
end;
edSierra: begin
for yy := iy to iy+2 do
for xx := ix-2 to ix+2 do
begin
if SRmask[xx-ix,yy-iy] = 0 then continue;
if (xx<0) or (xx>w-1) then continue;
if yy>h-1 then continue;
p8 := src[xx,yy];
p8^ := AdjustByte(p8^ + err*SRmask[xx-ix,yy-iy]);
end;
end;
edJaJuNi: begin
for yy := iy to iy+2 do
for xx := ix-2 to ix+2 do
begin
if JJmask[xx-ix,yy-iy] = 0 then continue;
if (xx<0) or (xx>w-1) then continue;
if yy>h-1 then continue;
p8 := src[xx,yy];
p8^ := AdjustByte(p8^ + err*JJmask[xx-ix,yy-iy]);
end;
end;
end;
end;
[Link];
[Link];
[Link];
bmp24 := bmp1;
result := true;
end;
wfactor := w/rwidth;
hfactor := h/rheight;
tmp := BmpClone(bmp);
[Link] := rwidth;
[Link] := rheight;
src := [Link](bmp);
dst := [Link](tmp);
for iy := 0 to rheight-1 do
for ix := 0 to rwidth-1 do
case mode of
rmNearest:
begin
x0 := Round(wfactor*ix); if x0>w-1 then x0 := w-1;
y0 := Round(hfactor*iy); if y0>h-1 then y0 := h-1;
dst[ix,iy]^ := src[x0,y0]^;
end;
rmBilinear:
begin
xx := wfactor*ix;
yy := hfactor*iy;
d := dst[ix,iy];
d00 := src[x0, y0]; d10 := src[x1,y0];
d01 := src[x0, y1]; d11 := src[x1,y1];
r1 := d00^.rgbtRed*coefx00 + d10^.rgbtRed*coefx01;
r2 := d01^.rgbtRed*coefx00 + d11^.rgbtRed*coefx01;
d^.rgbtRed := AdjustByte(r1*coefy00 + r2*coefy01);
g1 := d00^.rgbtGreen*coefx00 + d10^.rgbtGreen*coefx01;
g2 := d01^.rgbtGreen*coefx00 + d11^.rgbtGreen*coefx01;
d^.rgbtGreen := AdjustByte(g1*coefy00 + g2*coefy01);
b1 := d00^.rgbtBlue*coefx00 + d10^.rgbtBlue*coefx01;
b2 := d01^.rgbtBlue*coefx00 + d11^.rgbtBlue*coefx01;
d^.rgbtBlue := AdjustByte(b1*coefy00 + b2*coefy01);
end;
rmBicubic:
begin
xx := wfactor*ix; x := trunc(xx);
yy := hfactor*iy; y := trunc(yy);
r := 0; g := 0; b := 0;
for fy := y-1 to y+2 do
for fx := x-1 to x+2 do
begin
dx := Abs(xx-fx);
dy := Abs(yy-fy);
if dx<1 then
wx := (dx-1)*(dx*dx-dx-1)
else
wx := -(dx-1)*(dx-2)*(dx-2);
if dy<1 then
wy := (dy-1)*(dy*dy-dy-1)
else
wy := -(dy-1)*(dy-2)*(dy-2);
d := src[x0,y0];
r := r + d^.rgbtRed*wx*wy;
g := g + d^.rgbtGreen*wx*wy;
b := b + d^.rgbtBlue*wx*wy;
end;
dst[ix,iy]^.rgbtRed := AdjustByte(r);
dst[ix,iy]^.rgbtGreen := AdjustByte(g);
dst[ix,iy]^.rgbtBlue := AdjustByte(b);
end;
rmMitchell:
begin
xx := wfactor*ix; x := trunc(xx);
yy := hfactor*iy; y := trunc(yy);
r := 0; g := 0; b := 0;
for fy := y-1 to y+2 do
for fx := x-1 to x+2 do
begin
dx := Abs(xx-fx);
dy := Abs(yy-fy);
if dx<1 then
wx := 7*dx*dx*dx/6-2*dx*dx+8/9
else
wx := 2*dx*dx-10*dx/3-7*dx*dx*dx/18+16/9;
if dy<1 then
wy := 7*dy*dy*dy/6-2*dy*dy+8/9
else
wy := 2*dy*dy-10*dy/3-7*dy*dy*dy/18+16/9;
r := r + src[x0,y0]^.rgbtRed*wx*wy;
g := g + src[x0,y0]^.rgbtGreen*wx*wy;
b := b + src[x0,y0]^.rgbtBlue*wx*wy;
end;
dst[ix,iy]^.rgbtRed := AdjustByte(r);
dst[ix,iy]^.rgbtGreen := AdjustByte(g);
dst[ix,iy]^.rgbtBlue := AdjustByte(b);
end;
rmLagrange:
begin
xx := wfactor*ix; x := trunc(xx);
yy := hfactor*iy; y := trunc(yy);
r := 0; g := 0; b := 0;
for fy := y-1 to y+2 do
for fx := x-1 to x+2 do
begin
dx := Abs(xx-fx);
dy := Abs(yy-fy);
if dx<1 then
wx := 0.5*(dx-2)*(dx+1)*(dx-1)
else
wx := -(dx-3)*(dx-2)*(dx-1)/6;
if dy<1 then
wy := 0.5*(dy-2)*(dy+1)*(dy-1)
else
wy := -(dy-3)*(dy-2)*(dy-1)/6;
r := r + src[x0,y0]^.rgbtRed*wx*wy;
g := g + src[x0,y0]^.rgbtGreen*wx*wy;
b := b + src[x0,y0]^.rgbtBlue*wx*wy;
end;
dst[ix,iy]^.rgbtRed := AdjustByte(r);
dst[ix,iy]^.rgbtGreen := AdjustByte(g);
dst[ix,iy]^.rgbtBlue := AdjustByte(b);
end;
rmBSpline:
begin
xx := wfactor*ix; x := trunc(xx);
yy := hfactor*iy; y := trunc(yy);
dxx := xx-x;
dyy := yy-y;
RX[-1] := dxn[1];
RX[0] := dxn[2]-4*dxn[1];
RX[1] := dxn[3]-4*dxn[2]+6*dxn[1];
RX[2] := dxn[4]-4*dxn[3]+6*dxn[2]-4*dxn[1];
RY[-1] := dyn[3]-4*dyn[2]+6*dyn[1]-4*dyn[0];
RY[0] := dyn[2]-4*dyn[1]+6*dyn[0];
RY[1] := dyn[1]-4*dyn[0];
RY[2] := dyn[0];
r := 0; g := 0; b := 0;
for fy := y-1 to y+2 do
for fx := x-1 to x+2 do
begin
x0 := fx; if (x0<0) or (x0>w-1) then x0 := x;
y0 := fy; if (y0<0) or (y0>h-1) then y0 := y;
r := r + src[x0,y0]^.rgbtRed*RX[fx-x]*RY[fy-y];
g := g + src[x0,y0]^.rgbtGreen*RX[fx-x]*RY[fy-y];
b := b + src[x0,y0]^.rgbtBlue*RX[fx-x]*RY[fy-y];
end;
dst[ix,iy]^.rgbtRed := AdjustByte(r);
dst[ix,iy]^.rgbtGreen := AdjustByte(g);
dst[ix,iy]^.rgbtBlue := AdjustByte(b);
end;
end;
[Link];
[Link];
[Link];
bmp := tmp;
result := true;
end;
w := [Link];
h := [Link];
bd := [Link](bmp24);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
c := bd[x,y]^;
RGBToHSL(c, hh, ss, ll);
inc(ht[hh]);
end;
[Link];
max := 0;
for i := 0 to 359 do
if ht[i] > max then max := ht[i];
result := [Link];
[Link] := pf24bit;
[Link] := 370;
[Link] := 160;
for i := 0 to 359 do
begin
HSLToRGB(@c, i, 60, 40);
[Link] := RGB([Link], [Link], [Link]);
[Link](5+i, 155);
[Link](5+i, 155-Round(ht[i]*150/max));
end;
end;
v := zone*2+1;
v := v*v;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
r := 0; g := 0; b := 0;
for y := iy-zone to iy+zone do
for x := ix-zone to ix+zone do
begin
if (y<0) or (y>h-1) then yy := iy else yy := y;
if (x<0) or (x>w-1) then xx := ix else xx := x;
d := src[xx,yy];
r := r + d^.rgbtRed;
g := g + d^.rgbtGreen;
b := b + d^.rgbtBlue;
end;
d := dst[ix,iy];
d^.rgbtRed := r div v;
d^.rgbtGreen := g div v;
d^.rgbtBlue := b div v;
end;
[Link];
[Link];
[Link];
result := true;
end;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
case mode of
rkMax: begin
r := 0; g := 0; b := 0;
end;
else begin
r := 255; g := 255; b := 255;
end;
end;
for y := iy-zone to iy+zone do
for x := ix-zone to ix+zone do
begin
if (y<0) or (y>h-1) then yy := iy else yy := y;
if (x<0) or (x>w-1) then xx := ix else xx := x;
d := src[xx,yy];
case mode of
rkMax: begin
if r<d^.rgbtRed then r := d^.rgbtRed;
if g<d^.rgbtGreen then g := d^.rgbtGreen;
if b<d^.rgbtBlue then b := d^.rgbtBlue;
end;
else begin
if r>d^.rgbtRed then r := d^.rgbtRed;
if g>d^.rgbtGreen then g := d^.rgbtGreen;
if b>d^.rgbtBlue then b := d^.rgbtBlue;
end;
end;
end;
d := dst[ix,iy];
d^.rgbtRed := r;
d^.rgbtGreen := g;
d^.rgbtBlue := b;
end;
[Link];
[Link];
[Link];
result := true;
end;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
rmax := 0; gmax := 0; bmax := 0;
rmin := 255; gmin := 255; bmin := 255;
for y := iy-zone to iy+zone do
for x := ix-zone to ix+zone do
begin
if (y<0) or (y>h-1) then continue;
if (x<0) or (x>w-1) then continue;
d := src[x,y];
d^.rgbtRed := rmax-rmin;
d^.rgbtGreen := gmax-gmin;
d^.rgbtBlue := bmax-bmin;
end;
[Link];
[Link];
[Link];
if Gray then
result := GrayScale(bmp)
else
result := true;
end;
tmp := [Link];
[Link] := pf24bit;
[Link] := w+2;
[Link] := h+2;
[Link] := bkColor;
[Link](Rect(0,0,w+2,h+2));
[Link](1, 1, bmp);
[Link];
bmp := tmp;
angle := -angle;
sn := sin(pi*angle/180);
cs := cos(pi*angle/180);
for i := 0 to 3 do
pts[i] := PointF(pts[i].X*cs+pts[i].Y*sn, -pts[i].X*sn+pts[i].Y*cs);
ww := Round(xmax-xmin+1);
hh := Round(ymax-ymin+1);
tmp := [Link];
[Link] := pf24bit;
[Link] := ww;
[Link] := hh;
[Link] := bkColor;
[Link](Rect(0,0,ww,hh));
angle := -angle;
sn := sin(pi*angle/180);
cs := cos(pi*angle/180);
src := [Link](bmp);
dst := [Link](tmp);
srcRect := Rect(0,0,w,h);
for iy := 0 to hh-1 do
for ix := 0 to ww-1 do
begin
rx := ix+xmin;
ry := iy+ymin;
sx := rx*cs+ry*sn;
sy := -rx*sn+ry*cs;
if PtInRect(srcRect, Point(Ceil(sx),Ceil(sy))) or
PtInRect(srcRect, Point(Floor(sx),Floor(sy)))
then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
g1 := src[x0+1, y0+1]^.rgbtGreen*coefx00 +
src[x1+1,y0+1]^.rgbtGreen*coefx01;
g2 := src[x0+1, y1+1]^.rgbtGreen*coefx00 +
src[x1+1,y1+1]^.rgbtGreen*coefx01;
dst[ix,iy]^.rgbtGreen := AdjustByte(g1*coefy00 + g2*coefy01);
[Link];
[Link];
[Link];
bmp := tmp;
result := true;
end;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
rmax := 0; gmax := 0; bmax := 0;
rind := 0; gind := 0; bind := 0;
for i := 0 to 15 do
begin
rh[i] := 0; gh[i] := 0; bh[i] := 0;
end;
for i := 0 to 15 do
begin
if rmax < rh[i] then begin rmax := rh[i]; rind := i; end;
if gmax < gh[i] then begin gmax := gh[i]; gind := i; end;
if bmax < bh[i] then begin bmax := bh[i]; bind := i; end;
end;
d := dst[ix,iy];
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
range := zone*3;
SetLength(gf,range+1);
for i := 0 to range do
gf[i] := exp(-i*i/(2*zone*zone));
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
[Link];
[Link];
[Link];
result := true;
end;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
case mt of
mtLeft: if ix >= w2 then dst[ix,iy]^ := src[w-1-ix,iy]^;
mtRight: if ix < w2 then dst[ix,iy]^ := src[w-1-ix,iy]^;
end;
[Link];
[Link];
[Link];
result := true;
end;
src := [Link](bmp);
nd := area-1;
nw := w div area; if (w mod area)<>0 then inc(nw);
nh := h div area; if (h mod area)<>0 then inc(nh);
for y := 0 to nh-1 do
begin
for x := 0 to nw-1 do
begin
b := 0; g := 0; r := 0; count := 0;
for iy := y*area to y*area+nd do
begin
if iy>h-1 then continue;
for ix := x*area to x*area+nd do
begin
if ix>w-1 then continue;
d := src[ix, iy];
b := b + d^.rgbtBlue;
g := g + d^.rgbtGreen;
r := r + d^.rgbtRed;
inc(count);
end;
end;
end;
end;
[Link];
result := true;
end;
src := [Link](bmp);
nd := area-1;
nw := w div area; if (w mod area)<>0 then inc(nw);
nh := h div area; if (h mod area)<>0 then inc(nh);
for y := 0 to nh-1 do
begin
for x := 0 to nw-1 do
begin
b := 0; g := 0; r := 0; count := 0;
for iy := y*area to y*area+nd do
begin
if iy>h-1 then continue;
for ix := x*area to x*area+nd do
begin
if ix>w-1 then continue;
d := src[[Link]+ix, [Link]+iy];
b := b + d^.rgbtBlue;
g := g + d^.rgbtGreen;
r := r + d^.rgbtRed;
inc(count);
end;
end;
end;
end;
[Link];
result := true;
end;
w := [Link];
h := [Link];
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
c := Round(w*factor);
for y := 0 to h-1 do
begin
for x := 0 to w-1 do
begin
xx := Round(x + w*cos((x-c)*2*pi*2/w)/6);
if (xx>=0) and (xx<w) then
dst[x,y]^ := src[xx,y]^;
end;
end;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
c := factor;
cx := w/2;
cy := h/2;
rct := Rect(0,0,w-1,h-1);
tmp := BmpClone(bmp);
[Link] := clGray;
[Link](Rect(0,0,w,h));
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
begin
for x := 0 to w-1 do
begin
r := Sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
a := ArcTan2(y-cy,x-cx); // radian
sx := Sqrt(r*c)*Cos(a) + cx;
sy := Sqrt(r*c)*Sin(a) + cy;
if PtFInRect(PointF(sx, sy), rct) then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
[Link];
result := true;
end;
w := [Link];
h := [Link];
c := factor;
cx := w/2;
cy := h/2;
rct := Rect(0,0,w-1,h-1);
rr := Sqrt(cx*cx+cy*cy);
tmp := BmpClone(bmp);
[Link] := clGray;
[Link](Rect(0,0,w,h));
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
begin
for x := 0 to w-1 do
begin
r := Sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
a := ArcTan2(y-cy,x-cx); // radian
sx := c*r*r/rr*Cos(a) + cx;
sy := c*r*r/rr*Sin(a) + cy;
if PtFInRect(PointF(sx, sy), rct) then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
c := factor;
cx := w/2;
cy := h/2;
rct := Rect(0,0,w-1,h-1);
rr := Sqrt(cx*cx+cy*cy);
tmp := BmpClone(bmp);
[Link] := clGray;
[Link](Rect(0,0,w,h));
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
begin
for x := 0 to w-1 do
begin
r := Sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
a := ArcTan2(y-cy,x-cx); // radian
a := a + c*r;
sx := r*Cos(a) + cx;
sy := r*Sin(a) + cy;
if PtFInRect(PointF(sx, sy), rct) then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
Randomize;
r := 0;
dr := entropy;
SetLength(yshift, w);
for x := 0 to w-1 do
begin
if Random(1001) > 500 then r := r+dr else r := r-dr;
yshift[x] := r;
end;
rct := Rect(0,0,w-2,h-2);
//r := 0;
tmp := BmpClone(bmp);
[Link] := clGray;
[Link](Rect(0,0,w,h));
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
begin
if Random(1001) > 500 then r := r+dr else r := r-dr;
for x := 0 to w-1 do
begin
sx := x+r;
sy := y+yshift[x];
if PtFInRect(PointF(sx, sy), rct) then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
rct := Rect(0,0,w,h);
tmp := BmpClone(bmp);
[Link] := clGray;
[Link](rct);
src := [Link](tmp);
dst := [Link](bmp);
if cd = cdVertical then
begin
r := w/2;
for x := 0 to w-1 do
begin
xx := x-r;
a := ArcTan2(sqrt(r*r-xx*xx),xx); // radian
sx := 2*r*(1-a/pi);
if (sx<0) or (sx>w-2) then continue;
for y := 0 to h-2 do
begin
sy := y;
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
for y := 0 to h-1 do
begin
yy := y-r;
a := ArcTan2(sqrt(r*r-yy*yy),yy); // radian
sy := 2*r*(1-a/pi);
if (sy<0) or (sy>h-2) then continue;
for x := 0 to w-2 do
begin
sx := x;
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
c := factor;
cx := w/2;
cy := h/2;
rr := Sqrt(cx*cx+cy*cy);
rct := Rect(0,0,w-2,h-2);
tmp := BmpClone(bmp);
[Link] := clGray;
[Link](Rect(0,0,w,h));
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
begin
for x := 0 to w-1 do
begin
r := Sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
a := ArcTan2(y-cy,x-cx); // radian
e := sin(c*r*pi/(2*rr)); e := sqrt(e)+0.1;
sx := r*e*Cos(a) + cx;
sy := r*e*Sin(a) + cy;
if PtFInRect(PointF(sx, sy), rct) then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
rnd := zone*2+1;
rct := Rect(0,0,w-1,h-1);
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
begin
for x := 0 to w-1 do
begin
xx := x; yy := y;
case mode of
bwVertical: xx := x + (x mod rnd) - zone;
bwHorizontal:yy := y + (y mod rnd) - zone;
bwBoth: begin
xx := x + (x mod rnd) - zone;
yy := y + (y mod rnd) - zone;
end;
end;
if PtInRect(rct,Point(xx,yy)) then dst[x,y]^ := src[xx,yy]^;
end;
end;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
rnd := zone*2+1;
cx := w/2;
cy := h/2;
rct := Rect(0,0,w-2,h-2);
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
begin
for x := 0 to w-1 do
begin
r := Sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
a := ArcTan2(y-cy,x-cx); // radian
sx := x + (Round(((a+pi)*180/pi+0.1*r)) mod rnd) + zone;
sy := y;
if PtFInRect(PointF(sx, sy), rct) then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
[Link];
[Link];
[Link];
result := true;
end;
cx := w/2;
cy := h/2;
rr := radius*radius;
tmp := BmpClone(bmp);
[Link] := clBlack;
[Link](Rect(0,0,w,h));
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
r := (x-cx)*(x-cx)+(y-cy)*(y-cy);
c :=1.1*(1-r/rr);
if c<0 then continue;
d := dst[x,y];
s := src[x,y];
d^.rgbtRed := AdjustByte(s^.rgbtRed*c);
d^.rgbtGreen := AdjustByte(s^.rgbtGreen*c);
d^.rgbtBlue := AdjustByte(s^.rgbtBlue*c);
end;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
tmp := BmpClone(bmp);
Invert(bmp);
nd := area-1;
ne := entropy*2+1;
nw := w div area; if (w mod area)<>0 then inc(nw);
nh := h div area; if (h mod area)<>0 then inc(nh);
Randomize;
for y := 0 to nh-1 do
begin
for x := 0 to nw-1 do
begin
ix := x*area;
iy := y*area;
xx := ix+Random(ne)-entropy;
yy := iy+Random(ne)-entropy;
[Link](Rect(xx, yy, xx+nd, yy+nd), [Link],
Rect(ix, iy, ix+nd, iy+nd));
end;
end;
[Link];
result := true;
end;
w := [Link];
h := [Link];
c := factor;
f := frequency;
cx := w/2;
cy := h/2;
rct := Rect(0,0,w-2,h-2);
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
begin
for x := 0 to w-1 do
begin
r := Sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
a := ArcTan2(y-cy,x-cx);
rr := r+c*sin(f*r*pi/180);
sx := rr*Cos(a) + cx;
sy := rr*Sin(a) + cy;
if PtFInRect(PointF(sx, sy), rct) then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
cx := w/2;
cy := h/2;
rct := Rect(0,0,w-1,h-1);
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
r := Sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
rr := (Trunc(r) div zone)*zone;
a := ArcTan2((y-cy),(x-cx))*180/pi; // degree
aa := (Trunc(a) div zone)*zone*pi/180; // radian
xx := Round(rr*cos(aa)+cx);
yy := Round(rr*sin(aa)+cy);
if PtInRect(rct,Point(xx,yy)) then
dst[x,y]^ := src[xx,yy]^;
end;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
c := factor;
f := frequency;
cx := w/2;
cy := h/2;
dst := [Link](bmp);
for y := 0 to h-1 do
begin
for x := 0 to w-1 do
begin
r := Sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
bb := 1+c*sin(f*r*pi/180);
d := dst[x,y];
d^.rgbtRed := AdjustByte(d^.rgbtRed*bb);
d^.rgbtGreen := AdjustByte(d^.rgbtGreen*bb);
d^.rgbtBlue := AdjustByte(d^.rgbtBlue*bb);
end;
end;
[Link];
result := true;
end;
w := [Link];
h := [Link];
c := factor;
f := frequency;
rct := Rect(0,0,w-2,h-2);
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
begin
for x := 0 to w-1 do
begin
sx := x;
sy := y;
case WaveType of
wtVertical : sx := x + c*sin(f*x*pi/180);
wtHorizontal: sy := y + c*sin(f*y*pi/180);
wtBoth : begin
sx := x + c*sin(f*x*pi/180);
sy := y + c*sin(f*y*pi/180);
end;
end;
if PtFInRect(PointF(sx, sy), rct) then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
cx := w/2;
cy := h/2;
rr := radius*radius;
dst := [Link](bmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
r := (x-cx)*(x-cx)+(y-cy)*(y-cy);
c :=1.1*(1-r/rr);
if c>0 then
begin
SatComp := 1.0 - c;
SatCompR := 0.3086 * SatComp;
SatCompG := 0.6094 * SatComp;
SatCompB := 0.0820 * SatComp;
d := dst[x,y]^;
bd := dst[x,y];
bd^.rgbtRed := AdjustByte([Link]*(SatCompR+c)+
[Link]*SatCompG+
[Link]*SatCompB);
bd^.rgbtGreen := AdjustByte([Link]*SatCompR+
[Link]*(SatCompG+c)+
[Link]*SatCompB);
bd^.rgbtBlue := AdjustByte([Link]*SatCompR+
[Link]*SatCompG+
[Link]*(SatCompB+c));
end
else
begin
d := dst[x,y]^;
bd := dst[x,y];
[Link];
result := true;
end;
w := [Link];
h := [Link];
cx := w/2;
cy := h/2;
rr := radius*radius;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
r := sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
z :=Round(0.3*r*r*r/rr);
if (z>1) then
begin
if z>10 then z := 10;
count := 0;
sr := 0; sg := 0; sb := 0;
for iy := y-z to y+z do
begin
if (iy<0) or (iy>h-1) then continue;
for ix := x-z to x+z do
begin
if (ix<0) or (ix>w-1) then continue;
s := src[ix,iy];
sr := sr + s^.rgbtRed;
sg := sg + s^.rgbtGreen;
sb := sb + s^.rgbtBlue;
inc(count);
end;
end;
d := dst[x,y];
d^.rgbtRed := sr div count;
d^.rgbtGreen := sg div count;
d^.rgbtBlue := sb div count;
end;
end;
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
cx := w/2;
cy := h/2;
rct := Rect(0,0,w,h);
rf := factor;
Randomize;
for x := -1 to 361 do sft[x] := Random(rf);
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
r := sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
a := ArcTan2((y-cy),(x-cx));
deg := (a+pi)*180/pi;
sss := Trunc(deg)-deg;
ss := (1-sss)*sft[Trunc(deg)]+sss*sft[Trunc(deg)+1];
if r<ss then continue;
r := r-ss;
xx := Round(r*cos(a)+cx);
yy := Round(r*sin(a)+cy);
if PtInRect(rct, Point(xx,yy)) then
begin
b := 1+(ss-rf/2)/(rf*4);
d := dst[x,y];
s := src[xx,yy];
d^.rgbtRed := AdjustByte(s^.rgbtRed*b);
d^.rgbtGreen := AdjustByte(s^.rgbtGreen*b);
d^.rgbtBlue := AdjustByte(s^.rgbtBlue*b);
end;
end;
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
tmp := [Link];
[Link] := pf24bit;
[Link] := w;
[Link] := h;
[Link] := RGB($ee,$ee,$ee);
[Link](Rect(0,0,w,h));
[Link](rct,[Link],rct);
[Link];
result := true;
end;
p: integer;
begin
w := [Link];
h := [Link];
ww := w + ShadowWidth+2+Margin*2;
hh := h + ShadowWidth+2+Margin*2;
tmp := [Link];
[Link] := pf24bit;
[Link] := ww;
[Link] := hh;
[Link] := backcolor;
[Link](Rect(0,0,ww,hh));
p := ShadowWidth+Margin;
if ShadowWidth > 5 then
[Link] := $606060
else
[Link] := $404040;
[Link](Rect(p, p, p+w, p+h));
GaussianBlur(tmp, 3);
[Link];
bmp := tmp;
end;
w := [Link];
h := [Link];
tmp := [Link];
[Link] := pf24bit;
[Link] := w;
[Link] := h;
src := [Link](bmp);
dst := [Link](tmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
s := src[x,y];
b := Trunc(0.299*s^.rgbtRed + 0.587*s^.rgbtGreen + 0.114*s^.rgbtBlue);
if b< threshold then dst[x,y]^ := s^;
end;
[Link];
[Link];
[Link];
bmp := tmp;
result := true;
end;
w := Min(dw-dstX, sw);
h := Min(dh-dstY, sh);
d := [Link](dst);
s := [Link](src);
m := [Link](mask);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
a := m[x,y]^;
if a = 0 then continue;
if (x+dstX<0) or (y+dstY<0) then continue;
pd := d[x+dstX,y+dstY];
ps := s[x,y];
pd^.rgbtRed := AdjustByte(((255-a)*pd^.rgbtRed + a*ps^.rgbtRed)/255);
pd^.rgbtGreen := AdjustByte(((255-a)*pd^.rgbtGreen + a*ps^.rgbtGreen)/255);
pd^.rgbtBlue := AdjustByte(((255-a)*pd^.rgbtBlue + a*ps^.rgbtBlue)/255);
end;
[Link];
[Link];
[Link];
end;
cx := w/2;
cy := h/2;
rr := Radius*Radius;
bd := [Link](result);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
r := (x-cx)*(x-cx)+(y-cy)*(y-cy);
c :=Round(255*(1-r/rr));
if c<0 then
bd[x,y]^ := 0
else
bd[x,y]^ := c;
end;
[Link];
end;
SetGrayPalette(result);
bd := [Link](result);
for y := 0 to h-1 do
for x := 0 to w-1 do
case mode of
smVert: bd[x,y]^ := Round(255*sin(x*pi/(w-1)));
smHorz: bd[x,y]^ := Round(255*sin(y*pi/(h-1)));
smBoth:bd[x,y]^ := Round(255*sin(x*pi/(w-1))*sin(y*pi/(h-1)));
end;
[Link];
end;
bd := [Link](bmp);
nd := area-1;
nw := w div area; if (w mod area)<>0 then inc(nw);
nh := h div area; if (h mod area)<>0 then inc(nh);
for y := 0 to nh-1 do
begin
for x := 0 to nw-1 do
begin
b := 0; g := 0; r := 0; count := 0;
for iy := y*area to y*area+nd do
begin
if iy>h-1 then continue;
for ix := x*area to x*area+nd do
begin
if ix>w-1 then continue;
d := bd[ix, iy]^;
b := b + [Link];
g := g + [Link];
r := r + [Link];
inc(count);
end;
end;
b := b div count;
g := g div count;
r := r div count;
[Link] := b;
[Link] := g;
[Link] := r;
[Link] := AdjustByte([Link]*1.2);
[Link] := AdjustByte([Link]*1.2);
[Link] := AdjustByte([Link]*1.2);
iy := y*area+nd;
if iy<=h-1 then
begin
for ix := x*area to x*area+nd do
begin
if ix>w-1 then continue;
bd[ix,iy]^ := e;
end;
end;
ix := x*area+nd;
if ix<=w-1 then
begin
for iy := y*area to y*area+nd-1 do
begin
if iy>h-1 then continue;
bd[ix,iy]^ := e;
end;
end;
end;
end;
[Link];
result := true;
end;
w := [Link];
h := [Link];
r := percent/100;
tmp := BmpClone(bmp);
GaussianBlur(tmp, 1);
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
d := dst[x,y];
s := src[x,y];
d^.rgbtRed := AdjustByte((1-r)*d^.rgbtRed + r*s^.rgbtRed);
d^.rgbtGreen := AdjustByte((1-r)*d^.rgbtGreen + r*s^.rgbtGreen);
d^.rgbtBlue := AdjustByte((1-r)*d^.rgbtBlue + r*s^.rgbtBlue);
end;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
tmp := [Link];
[Link] := pf1bit;
[Link] := w;
[Link] := h;
r3 := sqrt(3.0);
src := [Link](bmp);
dst := [Link](tmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
s := src[x,y];
if x+1>w-1 then
r1 := 0
else
begin
t := src[x+1,y];
bb := s^.rgbtBlue - t^.rgbtBlue;
gg := s^.rgbtGreen - t^.rgbtGreen;
rr := s^.rgbtRed - t^.rgbtRed;
r1 := trunc(sqrt(rr*rr+gg*gg+bb*bb)/r3);
end;
if y+1>h-1 then
r2 := 0
else
begin
t := src[x,y+1];
bb := s^.rgbtBlue - t^.rgbtBlue;
gg := s^.rgbtGreen - t^.rgbtGreen;
rr := s^.rgbtRed - t^.rgbtRed;
r2 := trunc(sqrt(rr*rr+gg*gg+bb*bb)/r3);
end;
[Link];
[Link];
[Link];
bmp := tmp;
result := true;
end;
tmp := [Link];
[Link] := pf8bit;
[Link] := w;
[Link] := h;
SetGrayPalette(tmp);
r3 := sqrt(3.0);
src := [Link](bmp);
dst := [Link](tmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
s := src[x,y];
if x+1>w-1 then
r1 := 0
else
begin
t := src[x+1,y];
bb := s^.rgbtBlue - t^.rgbtBlue;
gg := s^.rgbtGreen - t^.rgbtGreen;
rr := s^.rgbtRed - t^.rgbtRed;
r1 := trunc(sqrt(rr*rr+gg*gg+bb*bb)/r3);
end;
if y+1>h-1 then
r2 := 0
else
begin
t := src[x,y+1];
bb := s^.rgbtBlue - t^.rgbtBlue;
gg := s^.rgbtGreen - t^.rgbtGreen;
rr := s^.rgbtRed - t^.rgbtRed;
r2 := trunc(sqrt(rr*rr+gg*gg+bb*bb)/r3);
end;
dst[x,y]^ := AdjustByte(255-r1-r2);
end;
[Link];
[Link];
[Link];
bmp := tmp;
result := true;
end;
tmp := [Link];
[Link] := pf24bit;
[Link] := w+2;
[Link] := h+2;
[Link] := bkColor;
[Link](Rect(0,0,w+2,h+2));
[Link](1, 1, bmp);
[Link];
bmp := tmp;
ww := Round(w+Abs(deform));;
hh := h;
tmp := [Link];
[Link] := pf24bit;
[Link] := ww;
[Link] := hh;
[Link] := bkColor;
[Link](Rect(0,0,ww,hh));
src := [Link](bmp);
dst := [Link](tmp);
srcRect := Rect(0,0,w,h);
for iy := 0 to hh-1 do
for ix := 0 to ww-1 do
begin
if deform > 0 then
sx := ix+deform*iy/h-deform
else
sx := ix+deform*iy/h;
sy := iy;
if PtInRect(srcRect, Point(Ceil(sx),Ceil(sy))) or
PtInRect(srcRect, Point(Floor(sx),Floor(sy)))
then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
g1 := src[x0+1, y0+1]^.rgbtGreen*coefx00 +
src[x1+1,y0+1]^.rgbtGreen*coefx01;
g2 := src[x0+1, y1+1]^.rgbtGreen*coefx00 +
src[x1+1,y1+1]^.rgbtGreen*coefx01;
dst[ix,iy]^.rgbtGreen := AdjustByte(g1*coefy00 + g2*coefy01);
[Link];
[Link];
[Link];
bmp := tmp;
result := true;
end;
tmp := [Link];
[Link] := pf24bit;
[Link] := w+2;
[Link] := h+2;
[Link] := bkColor;
[Link](Rect(0,0,w+2,h+2));
[Link](1, 1, bmp);
[Link];
bmp := tmp;
ww := Round(w+Abs(deform));;
hh := h;
tmp := [Link];
[Link] := pf24bit;
[Link] := ww;
[Link] := hh;
[Link] := bkColor;
[Link](Rect(0,0,ww,hh));
src := [Link](bmp);
dst := [Link](tmp);
srcRect := Rect(0,0,w,h);
for iy := 0 to hh-1 do
for ix := 0 to ww-1 do
begin
if deform > 0 then
sx := ix+deform*iy/h-deform
else
sx := ix+deform*iy/h;
sy := iy;
if PtInRect(srcRect, Point(Ceil(sx),Ceil(sy))) or
PtInRect(srcRect, Point(Floor(sx),Floor(sy)))
then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
g1 := src[x0+1, y0+1]^.rgbtGreen*coefx00 +
src[x1+1,y0+1]^.rgbtGreen*coefx01;
g2 := src[x0+1, y1+1]^.rgbtGreen*coefx00 +
src[x1+1,y1+1]^.rgbtGreen*coefx01;
dst[ix,iy]^.rgbtGreen := AdjustByte(g1*coefy00 + g2*coefy01);
[Link];
[Link];
[Link];
bmp := tmp;
w := [Link];
h := [Link];
ww := Ceil(w/partition);
hh := Ceil(h/partition);
tmp1 := BmpClone(bmp);
BmpResize(tmp1, ww, hh, rmBicubic);
Invert(tmp1);
GrayScale(tmp1);
//HistoStretch(tmp1);
tmp2 := [Link];
[Link] := pf8bit;
[Link] := w;
[Link] := h;
SetGrayPalette(tmp2);
for x := 0 to partition-1 do
for y := 0 to partition-1 do
[Link](ww*x, hh*y, tmp1);
[Link];
dst := [Link];
[Link] := pf24bit;
[Link] := w;
[Link] := h;
src := [Link](bmp);
tgt := [Link](dst);
mask := [Link](tmp2);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
r := mask[x,y]^;
s := src[x,y];
d := tgt[x,y];
d^.rgbtRed := AdjustByte((255-r)*0.85+s^.rgbtRed*r/255);
d^.rgbtGreen := AdjustByte((255-r)*0.85+s^.rgbtGreen*r/255);
d^.rgbtBlue := AdjustByte((255-r)*0.85+s^.rgbtBlue*r/255);
end;
[Link];
[Link];
[Link];
[Link];
[Link];
bmp := dst;
result := true;
end;
w := [Link];
h := [Link];
ww := w div hdiv;
hh := h div vdiv;
www := ww + framewidth*2;
hhh := hh + framewidth*2;
tmp := [Link];
[Link] := pf24bit;
[Link] := www;
[Link] := hhh;
[Link](0,0,www, hhh);
dst := [Link];
[Link] := pf24bit;
[Link] := www*hdiv + margin*2;
[Link] := hhh*vdiv + margin*2;
Randomize;
for x := 0 to hdiv-1 do
for y := 0 to vdiv-1 do
begin
srcRct := Rect(ww*x, hh*y, ww*(x+1), hh*(y+1));
[Link](dstRct, [Link], srcRct);
[Link](margin+www*x+Random(5)-2, margin+hhh*y+Random(5)-2, tmp);
end;
[Link];
[Link];
bmp := dst;
result := true;
end;
w := [Link];
h := [Link];
cx := w/2;
cy := h/2;
rct := Rect(0,0,w-1,h-1);
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
rr := Round(Sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy)));
a := ArcTan2((y-cy),(x-cx)); // radian
count := 0; r := 0; g := 0; b := 0;
for i := rr-zone to rr+zone do
begin
if i<0 then continue;
xx := Round(i*cos(a)+cx);
yy := Round(i*sin(a)+cy);
if PtInRect(rct,Point(xx,yy)) then
begin
s := src[xx,yy];
r := r + s^.rgbtRed;
g := g + s^.rgbtGreen;
b := b + s^.rgbtBlue;
inc(count);
end;
end;
if count = 0 then continue;
d := dst[x,y];
d^.rgbtRed := r div count;
d^.rgbtGreen := g div count;
d^.rgbtBlue := b div count;
end;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
cx := w/2;
cy := h/2;
rct := Rect(0,0,w-1,h-1);
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
rr := Sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
a := Round(ArcTan2((y-cy),(x-cx))*180/pi); // degree
count := 0; r := 0; g := 0; b := 0;
for i := a-zone to a+zone do
begin
xx := Round(rr*cos(i*pi/180)+cx);
yy := Round(rr*sin(i*pi/180)+cy);
if PtInRect(rct,Point(xx,yy)) then
begin
s := src[xx,yy];
r := r + s^.rgbtRed;
g := g + s^.rgbtGreen;
b := b + s^.rgbtBlue;
inc(count);
end;
end;
if count = 0 then continue;
d := dst[x,y];
d^.rgbtRed := r div count;
d^.rgbtGreen := g div count;
d^.rgbtBlue := b div count;
end;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
p := percent/100;
src := [Link](bmp);
mdu := [Link](modu);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
m := mdu[x,y]^;
r := (1-p) + 2*p*m/255;
s := src[x,y];
s^.rgbtRed := AdjustByte(r*s^.rgbtRed);
s^.rgbtGreen := AdjustByte(r*s^.rgbtGreen);
s^.rgbtBlue := AdjustByte(r*s^.rgbtBlue);
end;
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
q := Round(Sqrt(w*w+h*h)/2)+3;
SetLength(rshift, q);
Randomize;
r := 0;
dr := rentropy;
for x := 0 to q-1 do
begin
p := Random(1500);
if p < 500 then r := r-dr
else
if p > 1000 then r := r+dr;
rshift[x] := r;
end;
r := 0;
dr := aentropy;
for x := 0 to 181 do
begin
p := Random(1500);
if p < 500 then r := r-dr
else
if p > 1000 then r := r+dr;
ashift[x] := r;
end;
cx := w/2;
cy := h/2;
rct := Rect(0,0,w-2,h-2);
tmp := BmpClone(bmp);
[Link] := clGray;
[Link](Rect(0,0,w,h));
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
rr := Sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
a := ArcTan2((y-cy),(x-cx))*180/pi; // degree
if bInterpolation then
begin
f := rr - Trunc(rr);
rr := rr + (1-f)*rshift[Trunc(rr)] + f*rshift[Trunc(rr)+1];
f := Abs(a) - Trunc(Abs(a));
a := a + (1-f)*ashift[Trunc(Abs(a))] + f*ashift[Trunc(Abs(a)+1)];
end
else
begin
rr := rr + rshift[Round(rr)];
a := a + ashift[Round(Abs(a))];
end;
sx := rr*cos(a*pi/180)+cx;
sy := rr*sin(a*pi/180)+cy;
if PtFInRect(PointF(sx, sy), rct) then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
[Link];
[Link];
[Link];
result := true;
end;
q := max(w,h);
BmpResize(bmp,q,q);
cx := q/2;
cy := q/2;
rct := Rect(0,0,q-2,q-2);
tmp := BmpClone(bmp);
[Link] := bkColor;
[Link](Rect(0,0,q,q));
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to q-1 do
for x := 0 to q-1 do
begin
rr := Sqrt((x-cx)*(x-cx)+(y-cy)*(y-cy));
a := ArcTan2((y-cy),(x-cx))*180/pi; // degree
if Abs(a)<45 then
c := 1/cos(a*pi/180)
else
if Abs(a)<135 then
c := 1/sin(Abs(a)*pi/180)
else
c := -1/cos(a*pi/180);
rr := rr*c;
sx := rr*cos(a*pi/180)+cx;
sy := rr*sin(a*pi/180)+cy;
if PtFInRect(PointF(sx, sy), rct) then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
q := max(w,h);
BmpResize(bmp,q,q);
r := q/2;
rct := Rect(0,0,q-2,q-2);
tmp := BmpClone(bmp);
[Link] := bkColor;
[Link](Rect(0,0,q,q));
src := [Link](tmp);
dst := [Link](bmp);
for y := 1 to q-1 do
for x := 0 to q-1 do
begin
l := sqrt(2*r*y-y*y);
if l = 0 then sx := 0 else sx := r*(x-r)/l+r;
sy := y;
[Link];
[Link];
[Link];
result := BmpResize(bmp, w, h);
end;
p := percent/100;
tmp := BmpClone(bmp);
src := [Link](tmp);
dst := [Link](bmp);
for iy := 0 to h-1 do
for ix := 0 to w-1 do
begin
r := 0; g := 0; b := 0;
for y := iy-1 to iy+1 do
for x := ix-1 to ix+1 do
begin
if mask[x-ix,y-iy] = 0 then continue;
if (y<0) or (y>h-1) then yy := iy else yy := y;
if (x<0) or (x>w-1) then xx := ix else xx := x;
d := src[xx,yy];
r := r + mask[x-ix,y-iy]*d^.rgbtRed;
g := g + mask[x-ix,y-iy]*d^.rgbtGreen;
b := b + mask[x-ix,y-iy]*d^.rgbtBlue;
end;
d := dst[ix,iy];
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
b := cy- a*cx;
rct := Rect(0,0,w,h);
tmp := [Link];
[Link] := pf24bit;
[Link] := w+2;
[Link] := h+2;
[Link] := bkColor;
[Link](Rect(0,0,w+2, h+2));
[Link](1,1,bmp);
[Link] := bkColor;
[Link](Rect(0,0,w, h));
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
begin
dd := Abs(y-a*x-b)/sqrt(1+a*a);
if PtInRect(rct, Point(Ceil(sx),Ceil(sy))) or
PtInRect(rct, Point(Floor(sx),Floor(sy))) then
begin
x0 := floor(sx);
x1 := x0+1;
y0 := floor(sy);
y1 := y0+1;
g1 := src[x0+1, y0+1]^.rgbtGreen*coefx00 +
src[x1+1,y0+1]^.rgbtGreen*coefx01;
g2 := src[x0+1, y1+1]^.rgbtGreen*coefx00 +
src[x1+1,y1+1]^.rgbtGreen*coefx01;
dst[x,y]^.rgbtGreen := AdjustByte(g1*coefy00 + g2*coefy01);
[Link];
[Link];
[Link];
result := true;
end;
w := [Link];
h := [Link];
pt[0] := Point(0,0);
pt[1] := Point(w,0);
pt[2] := Point(w,h);
pt[3] := Point(0,h);
sn := sin(angle*pi/180);
cs := cos(angle*pi/180);
cx := w/2;
cy := h/2;
if sn = 0 then
begin
if angle = 0 then
begin
pt[0] := Point(0, Round(cy));
pt[1] := Point(w, Round(cy));
end
else
begin
pt[2] := Point(w, Round(cy));
pt[3] := Point(0, Round(cy));
end;
end
else
if cs = 0 then
begin
if angle = 90 then
begin
pt[1] := Point(Round(cx), 0);
pt[2] := Point(Round(cx), h);
end
else
begin
pt[0] := Point(Round(cx), 0);
pt[3] := Point(Round(cx), h);
end;
end
else
begin
a := sn/cs;
b := cy-a*cx;
if (b >=0) and (b < h) then
begin
if (angle < 90) or (angle > 270) then
begin
pt[0] := Point(0, Round(b));
pt[1] := Point(w, Round(a*w+b));
end
else
begin
pt[3] := Point(0, Round(b));
pt[2] := Point(w, Round(a*w+b));
end;
end
else
begin
if angle < 180 then
begin
pt[1] := Point(Round(-b/a),0);
pt[2] := Point(Round((h-b)/a), h);
end
else
begin
pt[0] := Point(Round(-b/a),0);
pt[3] := Point(Round((h-b)/a), h);
end;
end;
end;
tmp := BmpClone(bmp);
LineInvert(tmp, cx, cy, angle, bkColor);
[Link];
result := true;
end;
function Mirror3(var bmp: TBitmap; cx, cy, angle: single; bkColor: TColor):
Boolean;
var
tmp: TBitmap;
w, h, x, y: integer;
src, dst: TBmpData24;
a, b, sn, cs: single;
fUp: Boolean;
begin
result := false;
if [Link] <> pf24bit then exit;
w := [Link];
h := [Link];
sn := sin(angle*pi/180);
cs := cos(angle*pi/180);
b := cy- a*cx;
tmp := BmpClone(bmp);
LineInvert(tmp, cx, cy, angle, bkColor);
src := [Link](tmp);
dst := [Link](bmp);
for y := 0 to h-1 do
for x := 0 to w-1 do
if fUp then
begin
if (a*x+b>y) then dst[x,y]^ := src[x,y]^;
end
else
begin
if (a*x+b<y) then dst[x,y]^ := src[x,y]^;
end;
[Link];
[Link];
[Link];
result := true;
end;
end.
The function AdjustByte plays a critical role in image transformations by ensuring that pixel intensity values stay within the valid range (0 to 255) after calculations. When modifying pixel components through algorithms that increase or decrease intensity, AdjustByte verifies and bounds these values to prevent overflow or underflow, which could result in display errors or artifacts. This step is essential in maintaining image data integrity after applying operations like contrast adjustment, filtering, and color alterations .
Although not explicitly stated in the provided document summaries, functions like those for edge detection (e.g., Sobel, Laplacian) implicitly rely on Fourier Transform principles. The Fourier Transform would decompose the image into frequency components, allowing analysis of high-frequency areas corresponding to edges. By applying convolution in the spatial domain, these methods exploit principles similar to those in frequency domain transformations but instead directly compute edge magnitude and direction .
The BlackWhiteFloydStucci2 function uses the Floyd-Steinberg dithering algorithm. It first converts the image to grayscale and applies histogram stretching. The function processes each pixel, comparing its intensity to a threshold to decide whether to set it to the dark or bright color. The error (difference between the original and converted value) is calculated and distributed to neighboring pixels using predefined coefficients (7/16, 5/16, 3/16, and 1/16) to ensure smoother transitions and reduce visual artifacts .
The Fisheye function distorts an image by applying a non-linear transformation that simulates the effect of a fisheye lens. The transformation is centered at the image's midpoint; each pixel is relocated based on its radial distance from the center. The new position is calculated using the square root of the distance and scaled by a constant factor, adjusting both x and y coordinates with trigonometric functions (cosine and sine) of the angle. This distortion compresses regions towards the center while expanding peripheral areas, creating a spherical appearance characteristic of fisheye effects .
The Swirl function applies a nonlinear transformation to an image, producing a swirling effect around its center. This distortion is achieved by adjusting the position of each pixel based on radial distance and angle. For each pixel, the angle is incremented proportional to its distance from the center, a factor that introduces a rotation while maintaining radial integrity. The transformation uses cosine and sine functions to compute new coordinates, resulting in a twisted appearance that visually spirals the image content .
The Laplacian function differs from the Sobel function as it uses a single convolution mask that detects edges by emphasizing regions where intensity values significantly diverge from the surrounding pixels. Unlike Sobel, which uses directional gradients, Laplacian focuses on areas with sharp intensity changes in all directions. It strengthens edges but can be more sensitive to noise. The output adds 127 to the calculated value for normalization, converting negative values for display purposes. The function can optionally convert the image to grayscale after processing .
The Grayscale function first checks if the image's pixel format is 24-bit. It then creates an 8-bit bitmap of the same dimensions as the original. The function uses the SetGrayPalette procedure to set the grayscale palette for the new image. It iterates over each pixel, calculates a weighted sum of the red, green, and blue components using the formula 0.299*Red + 0.587*Green + 0.114*Blue, and assigns this value to the corresponding pixel in the 8-bit image. This process ensures that the converted image maintains the luminance of the original colors .
The Contrast function adjusts the contrast of a bitmap by scaling pixel intensity based on a user-defined contrast value. The provided contrast level is transformed into a multiplication factor through the relation (100 + nContrast) / 100, which is then squared for increased sensitivity. The function iterates over each pixel, modifying its red, green, and blue components using the formula ((component/255 - 0.5) * factor + 0.5) * 255, which centers the pixel intensity, scales it, and re-centers it. This approach stretches or compresses the dynamic range around midtones to enhance or reduce contrast .
To enhance edges, the EdgeEnhance function applies a convolution mask that emphasizes the difference between each pixel and its neighbors. By attenuating the contributions of the central pixel and enhancing neighboring pixels, it increases contrast along edges. The resulting values are scaled by a factor derived from the input percentage to control enhancement intensity, modifying the original pixel values accordingly. The function iteratively applies this process to improve edge definition while reducing the impact on uniform regions of the image .
The Sobel function is an edge detection technique in image processing that emphasizes the edges by calculating the gradient magnitude of the bitmap. It applies horizontal and vertical convolution masks to identify changes in intensity, marking areas where there is a significant change. For each pixel, it calculates horizontal and vertical gradient components, combines them to determine edge strength, and assigns adjusted values to highlight edges. If fGray is true, the resulting image is converted to grayscale to simplify viewing of the detected edges .