type
TForm1 = class(TForm)
Image1: TImage;
BitBtn1: TBitBtn;
Image2: TImage;
ColorBox1: TColorBox;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type
cl= record
b,g,r : byte ;
end ;
a = array [0..$FFFF] of cl ;
procedure RGBtoHSV(const R,G,B:byte;var H,S,V:integer) ;
var
M, D : integer ;
begin
V := Max(R, Max(G, B)) ;
M := Min(R, Min(G, B)) ;
D := V-M ;
if V=0
then begin
S := 0 ;
H := 0 ;
end
else begin
S := Round(255*D/V) ;
if S=0
then H := 0
else begin
if R=V
then H := Round(60*(G-B)/D)
else if G=V
then H := Round(60*((B-R)/D+2))
else H := Round(60*((R-G)/D+4)) ;
H := (H+360) mod 360 ;
end ;
end ;
end ;
procedure HSVtoRGB(const H, S, V:integer;var R, G, B:byte) ;
var
p, q, t : integer ;
f : double ;
begin
if S=0
then begin
R := V ;
G := V ;
B := V ;
end
else begin
f := Frac(H/60) ;
p := Round(V*(1-S/255)) ;
q := Round(V*(1-S/255*f)) ;
t := Round(V*(1-S/255*(1-f))) ;
case Round(H/60) of
0 : begin
R := V ;
G := t ;
B := p ;
end ;
1 : begin
R := q ;
G := v ;
B := p ;
end ;
2 : begin
R := p ;
G := v ;
B := t ;
end ;
3 : begin
R := p ;
G := q ;
B := v ;
end ;
4 : begin
R := t ;
G := p ;
B := v ;
end ;
5 : begin
R := V ;
G := p ;
B := q ;
end ;
end ;
end ;
end ;
procedure TForm1.BitBtn1Click(Sender: TObject);
var
l,t : ^a ;
i,j, H,S,V, c, p, q : integer ;
begin
c := ColorBox1.Selected ; //c:tcolor
RGBtoHSV(c and $FF, (c shr 8) and $FF, c shr 16, p, q, V) ;
for i:=0 to image1.Height-1 do
begin
l := image1.Picture.Bitmap.ScanLine ; //ÓÃScanLine±ÈÓÃPixels[j,i]¿ìµÃ¶à
t := image2.Picture.Bitmap.ScanLine ;
for j:=0 to image1.Width-1 do
begin
RGBtoHSV(l^[j].r, l^[j].g, l^[j].b, H, S, V) ;
S := q ;
H := p ;
HSVtoRGB(H, S, V, t^[j].r, t^[j].g, t^[j].b) ;
end ;
end ;
image2.Refresh ;
end;