BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RGB<->HSL

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM
View previous topic :: View next topic  
Author Message
Roberto Della Pasqua
Guest





PostPosted: Sun May 22, 2005 2:34 pm    Post subject: RGB<->HSL Reply with quote



kind group,

I like ask if somebody can help to rewrite these SLOW GR32 routines using
PCasting and pointers, then I'll forward to the *smart* gr32 community.

THANK YOU ANYWAY!

Regards,

Roberto

function HSLtoRGB(H, S, L: Single): TColor32;
const
OneOverThree = 1 / 3;
var
M1, M2: Single;
R, G, B: Byte;

function HueToColor(Hue: Single): Byte;
var
V: Double;
begin
Hue := Hue - Floor(Hue);
if 6 * Hue < 1 then
V := M1 + (M2 - M1) * Hue * 6
else
if 2 * Hue < 1 then
V := M2
else
if 3 * Hue < 2 then
V := M1 + (M2 - M1) * (2 / 3 - Hue) * 6
else
V := M1;
Result := Round(255 * V);
end;

begin
if S = 0 then begin
R := Round(255 * L);
G := R;
B := R;
end
else begin
if L <= 0.5 then
M2 := L * (1 + S)
else
M2 := L + S - L * S;
M1 := 2 * L - M2;
R := HueToColor(H + OneOverThree);
G := HueToColor(H);
B := HueToColor(H - OneOverThree)
end;
Result := Color32(R, G, B, 255);
end;

procedure RGBtoHSL(RGB: TColor32; out H, S, L: Single);
var
R, G, B, D, Cmax, Cmin: Single;
begin
R := RedComponent(RGB) / 255;
G := GreenComponent(RGB) / 255;
B := BlueComponent(RGB) / 255;
Cmax := Max(R, Max(G, B));
Cmin := Min(R, Min(G, B));
L := (Cmax + Cmin) / 2;

if Cmax = Cmin then begin
H := 0;
S := 0
end
else begin
D := Cmax - Cmin;
if L < 0.5 then
S := D / (Cmax + Cmin)
else
S := D / (2 - Cmax - Cmin);
if R = Cmax then
H := (G - B) / D
else
if G = Cmax then
H := 2 + (B - R) / D
else
H := 4 + (R - G) / D;
H := H / 6;
if H < 0 then
H := H + 1
end;
end;


Back to top
Mr. X
Guest





PostPosted: Sun May 22, 2005 3:33 pm    Post subject: Re: RGB<->HSL Reply with quote



Hey
You should also forward this to the GR32 newsgroup Smile
X

"Roberto Della Pasqua" <roberto AT dellapasqua.com> wrote

Quote:
kind group,

I like ask if somebody can help to rewrite these SLOW GR32 routines using
PCasting and pointers, then I'll forward to the *smart* gr32 community.

THANK YOU ANYWAY!

Regards,

Roberto

function HSLtoRGB(H, S, L: Single): TColor32;
const
OneOverThree = 1 / 3;
var
M1, M2: Single;
R, G, B: Byte;

function HueToColor(Hue: Single): Byte;
var
V: Double;
begin
Hue := Hue - Floor(Hue);
if 6 * Hue < 1 then
V := M1 + (M2 - M1) * Hue * 6
else
if 2 * Hue < 1 then
V := M2
else
if 3 * Hue < 2 then
V := M1 + (M2 - M1) * (2 / 3 - Hue) * 6
else
V := M1;
Result := Round(255 * V);
end;

begin
if S = 0 then begin
R := Round(255 * L);
G := R;
B := R;
end
else begin
if L <= 0.5 then
M2 := L * (1 + S)
else
M2 := L + S - L * S;
M1 := 2 * L - M2;
R := HueToColor(H + OneOverThree);
G := HueToColor(H);
B := HueToColor(H - OneOverThree)
end;
Result := Color32(R, G, B, 255);
end;

procedure RGBtoHSL(RGB: TColor32; out H, S, L: Single);
var
R, G, B, D, Cmax, Cmin: Single;
begin
R := RedComponent(RGB) / 255;
G := GreenComponent(RGB) / 255;
B := BlueComponent(RGB) / 255;
Cmax := Max(R, Max(G, B));
Cmin := Min(R, Min(G, B));
L := (Cmax + Cmin) / 2;

if Cmax = Cmin then begin
H := 0;
S := 0
end
else begin
D := Cmax - Cmin;
if L < 0.5 then
S := D / (Cmax + Cmin)
else
S := D / (2 - Cmax - Cmin);
if R = Cmax then
H := (G - B) / D
else
if G = Cmax then
H := 2 + (B - R) / D
else
H := 4 + (R - G) / D;
H := H / 6;
if H < 0 then
H := H + 1
end;
end;





Back to top
Roberto Della Pasqua
Guest





PostPosted: Sun May 22, 2005 3:49 pm    Post subject: Re: RGB<->HSL Reply with quote



I'll forward the received help,

Soumitra nobody can help in GR32, is GR32 asking help here :)

Bye ^^

"Mr. X" <no (AT) mail (DOT) here> wrote

Quote:
Hey
You should also forward this to the GR32 newsgroup Smile
X

"Roberto Della Pasqua" <roberto AT dellapasqua.com> wrote in message
news:4290975d$1 (AT) newsgroups (DOT) borland.com...
kind group,

I like ask if somebody can help to rewrite these SLOW GR32 routines using
PCasting and pointers, then I'll forward to the *smart* gr32 community.

THANK YOU ANYWAY!

Regards,

Roberto

function HSLtoRGB(H, S, L: Single): TColor32;
const
OneOverThree = 1 / 3;
var
M1, M2: Single;
R, G, B: Byte;

function HueToColor(Hue: Single): Byte;
var
V: Double;
begin
Hue := Hue - Floor(Hue);
if 6 * Hue < 1 then
V := M1 + (M2 - M1) * Hue * 6
else
if 2 * Hue < 1 then
V := M2
else
if 3 * Hue < 2 then
V := M1 + (M2 - M1) * (2 / 3 - Hue) * 6
else
V := M1;
Result := Round(255 * V);
end;

begin
if S = 0 then begin
R := Round(255 * L);
G := R;
B := R;
end
else begin
if L <= 0.5 then
M2 := L * (1 + S)
else
M2 := L + S - L * S;
M1 := 2 * L - M2;
R := HueToColor(H + OneOverThree);
G := HueToColor(H);
B := HueToColor(H - OneOverThree)
end;
Result := Color32(R, G, B, 255);
end;

procedure RGBtoHSL(RGB: TColor32; out H, S, L: Single);
var
R, G, B, D, Cmax, Cmin: Single;
begin
R := RedComponent(RGB) / 255;
G := GreenComponent(RGB) / 255;
B := BlueComponent(RGB) / 255;
Cmax := Max(R, Max(G, B));
Cmin := Min(R, Min(G, B));
L := (Cmax + Cmin) / 2;

if Cmax = Cmin then begin
H := 0;
S := 0
end
else begin
D := Cmax - Cmin;
if L < 0.5 then
S := D / (Cmax + Cmin)
else
S := D / (2 - Cmax - Cmin);
if R = Cmax then
H := (G - B) / D
else
if G = Cmax then
H := 2 + (B - R) / D
else
H := 4 + (R - G) / D;
H := H / 6;
if H < 0 then
H := H + 1
end;
end;







Back to top
Frank
Guest





PostPosted: Mon May 23, 2005 7:32 am    Post subject: Re: RGB<->HSL Reply with quote

Quote:
I like ask if somebody can help to rewrite these SLOW GR32 routines using
PCasting and pointers, then I'll forward to the *smart* gr32 community.

The slowdown is in other things.
Replace the multiplications with shifts and adds/subtracts (eg 255 * n = (n
shl Cool - n , inline the function calls, replace divisions with
multiplications (but shifts&adds are even much faster). Max & Min should be
replaced by (inlined) Fastcode versions.

The speedup will be around 10 times. No pointers/casts required.




Back to top
Mr. X
Guest





PostPosted: Wed May 25, 2005 6:23 am    Post subject: Re: RGB<->HSL Reply with quote

Hey
Im working on the reverse method ... ill send you in a day or two.,
Please be patient till then
Regards
X :)

"Roberto Della Pasqua" <roberto AT dellapasqua.com> wrote

Quote:
I'll forward the received help,

Soumitra nobody can help in GR32, is GR32 asking help here :)

Bye ^^

"Mr. X" <no (AT) mail (DOT) here> wrote in message
news:4290a65a (AT) newsgroups (DOT) borland.com...
Hey
You should also forward this to the GR32 newsgroup Smile
X

"Roberto Della Pasqua" <roberto AT dellapasqua.com> wrote in message
news:4290975d$1 (AT) newsgroups (DOT) borland.com...
kind group,

I like ask if somebody can help to rewrite these SLOW GR32 routines
using
PCasting and pointers, then I'll forward to the *smart* gr32 community.

THANK YOU ANYWAY!

Regards,

Roberto

function HSLtoRGB(H, S, L: Single): TColor32;
const
OneOverThree = 1 / 3;
var
M1, M2: Single;
R, G, B: Byte;

function HueToColor(Hue: Single): Byte;
var
V: Double;
begin
Hue := Hue - Floor(Hue);
if 6 * Hue < 1 then
V := M1 + (M2 - M1) * Hue * 6
else
if 2 * Hue < 1 then
V := M2
else
if 3 * Hue < 2 then
V := M1 + (M2 - M1) * (2 / 3 - Hue) * 6
else
V := M1;
Result := Round(255 * V);
end;

begin
if S = 0 then begin
R := Round(255 * L);
G := R;
B := R;
end
else begin
if L <= 0.5 then
M2 := L * (1 + S)
else
M2 := L + S - L * S;
M1 := 2 * L - M2;
R := HueToColor(H + OneOverThree);
G := HueToColor(H);
B := HueToColor(H - OneOverThree)
end;
Result := Color32(R, G, B, 255);
end;

procedure RGBtoHSL(RGB: TColor32; out H, S, L: Single);
var
R, G, B, D, Cmax, Cmin: Single;
begin
R := RedComponent(RGB) / 255;
G := GreenComponent(RGB) / 255;
B := BlueComponent(RGB) / 255;
Cmax := Max(R, Max(G, B));
Cmin := Min(R, Min(G, B));
L := (Cmax + Cmin) / 2;

if Cmax = Cmin then begin
H := 0;
S := 0
end
else begin
D := Cmax - Cmin;
if L < 0.5 then
S := D / (Cmax + Cmin)
else
S := D / (2 - Cmax - Cmin);
if R = Cmax then
H := (G - B) / D
else
if G = Cmax then
H := 2 + (B - R) / D
else
H := 4 + (R - G) / D;
H := H / 6;
if H < 0 then
H := H + 1
end;
end;









Back to top
Roberto Della Pasqua
Guest





PostPosted: Wed May 25, 2005 9:03 am    Post subject: Re: RGB<->HSL Reply with quote

you are so kind, thank you!

"Mr. X" <no (AT) mail (DOT) here> wrote

Quote:
Hey
Im working on the reverse method ... ill send you in a day or two.,
Please be patient till then
Regards
X :)

"Roberto Della Pasqua" <roberto AT dellapasqua.com> wrote in message
news:4290a8ea (AT) newsgroups (DOT) borland.com...
I'll forward the received help,

Soumitra nobody can help in GR32, is GR32 asking help here :)

Bye ^^

"Mr. X" <no (AT) mail (DOT) here> wrote in message
news:4290a65a (AT) newsgroups (DOT) borland.com...
Hey
You should also forward this to the GR32 newsgroup Smile
X

"Roberto Della Pasqua" <roberto AT dellapasqua.com> wrote in message
news:4290975d$1 (AT) newsgroups (DOT) borland.com...
kind group,

I like ask if somebody can help to rewrite these SLOW GR32 routines
using
PCasting and pointers, then I'll forward to the *smart* gr32
community.

THANK YOU ANYWAY!

Regards,

Roberto

function HSLtoRGB(H, S, L: Single): TColor32;
const
OneOverThree = 1 / 3;
var
M1, M2: Single;
R, G, B: Byte;

function HueToColor(Hue: Single): Byte;
var
V: Double;
begin
Hue := Hue - Floor(Hue);
if 6 * Hue < 1 then
V := M1 + (M2 - M1) * Hue * 6
else
if 2 * Hue < 1 then
V := M2
else
if 3 * Hue < 2 then
V := M1 + (M2 - M1) * (2 / 3 - Hue) * 6
else
V := M1;
Result := Round(255 * V);
end;

begin
if S = 0 then begin
R := Round(255 * L);
G := R;
B := R;
end
else begin
if L <= 0.5 then
M2 := L * (1 + S)
else
M2 := L + S - L * S;
M1 := 2 * L - M2;
R := HueToColor(H + OneOverThree);
G := HueToColor(H);
B := HueToColor(H - OneOverThree)
end;
Result := Color32(R, G, B, 255);
end;

procedure RGBtoHSL(RGB: TColor32; out H, S, L: Single);
var
R, G, B, D, Cmax, Cmin: Single;
begin
R := RedComponent(RGB) / 255;
G := GreenComponent(RGB) / 255;
B := BlueComponent(RGB) / 255;
Cmax := Max(R, Max(G, B));
Cmin := Min(R, Min(G, B));
L := (Cmax + Cmin) / 2;

if Cmax = Cmin then begin
H := 0;
S := 0
end
else begin
D := Cmax - Cmin;
if L < 0.5 then
S := D / (Cmax + Cmin)
else
S := D / (2 - Cmax - Cmin);
if R = Cmax then
H := (G - B) / D
else
if G = Cmax then
H := 2 + (B - R) / D
else
H := 4 + (R - G) / D;
H := H / 6;
if H < 0 then
H := H + 1
end;
end;











Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.