Bramble
2007-01-24 20:33:15
this version of hsl splitter, will also return rgb values if you wish,
note:: to do this just edit the writeln(blahblahblah) in the main loop
edit:: this version will now find maxs and mins of hsl values and rgb values
note:: to do this just edit the writeln(blahblahblah) in the main loop
edit:: this version will now find maxs and mins of hsl values and rgb values
program rgb2hsl;
type rgbcolor =record
red,green,blue:integer;
end;
var var_min,Var_max,var_r,var_b,var_g,L,H,S,sixty,threesixty,onetwenty,twoforty,zero:extended;
a,b,c,I,maxofarray,rgbrange,hslrange:integer;color:Array[0..24] of integer;color2:rgbcolor;
rangeofvalues,maxofoutput,minofoutput:array[0..5] of integer;
procedure setup;
begin
Color[0]:=2972255;
Color[1]:=3694710;
Color[2]:=2906462;
Color[3]:=3498354;
Color[4]:=2905438;
Color[5]:=3697526;
Color[6]:=3169639;
Color[7]:=3565682;
Color[8]:=3233130;
Color[9]:=3500657;
Color[10]:=3564660;
Color[11]:=3237484;
Color[12]:=2576726;
Color[13]:=2639191;
Color[14]:=2510675;
Color[15]:=2840411;
Color[16]:=2770778;
Color[17]:=3233130;
Color[18]:=3104870;
Color[19]:=3036516;
Color[20]:=3167079;
Color[21]:=3562610;
Color[22]:=3103332;
Color[23]:=3231336;
Color[24]:=2772058;
maxofarray:=24;
end;
function color2rgb(color:integer):rgbcolor;
begin
result.red:=(color mod 256);
result.green:=((color/256) mod 256);
result.blue:=((color/256) / 256);
end;
function rgb2color(rgb:rgbcolor):integer;
begin
result:=(((rgb.blue*256)+rgb.green)*256)+rgb.red
end;
Procedure minmax;
var test1,test2:integer;
begin
Var_r:=color2.Red/255;
Var_g:=color2.Green/255;
Var_b:=color2.Blue/255;
test1:=min(color2.red,color2.green);
test2:=min(color2.green,color2.blue);
var_min:= min(test1,test2)/255;
test1:=max(color2.red,color2.green);
test2:=max(color2.green,color2.blue);
var_max:=max(test1,test2)/255;
zero:=0.0;
threesixty:=1.0;
sixty:=0.16666666666666666666666666666667;
onetwenty:=0.33333333333333333333333333333333;
twoforty:=0.66666666666666666666666666666667;
end;
Procedure Converter;
begin
L:= (Var_max+Var_min)/2
if (L<0.5) or (L=0.5) then
S:=(Var_max-Var_min)/(2*L)
else if L=0 then
S:=0
else
s:=(var_max-var_min)/(2-(var_max+var_min));
if (var_max = Var_r) and (var_b=Var_min) then
H:=(sixty*((var_g-Var_b)/(var_max-Var_min)))+zero;
if (var_max=Var_r) and (var_g<Var_b) then
h:=(sixty*((var_g-Var_b)/(var_max-Var_min))+threesixty);
if (var_max=Var_g) then
H:=sixty*((var_b-Var_r)/(var_max-Var_min))+onetwenty;
if (var_max = var_b) then
h:=sixty*((var_r-Var_g)/(var_max-Var_min))+ twoforty;
if (var_Max=Var_min) then
H:=0;
end;
procedure getmaxmin;
begin
if I=0 then
begin
maxofoutput[0]:=A;
maxofoutput[1]:=B;
maxofoutput[2]:=C;
maxofoutput[3]:=color2.red;
maxofoutput[4]:=color2.green;
maxofoutput[5]:=color2.blue;
minofoutput[0]:=A;
minofoutput[1]:=B;
minofoutput[2]:=C;
minofoutput[3]:=color2.red;
minofoutput[4]:=color2.green;
minofoutput[5]:=color2.blue;
end
else
begin
maxofoutput[0]:=max(maxofoutput[0],A);
maxofoutput[1]:=max(maxofoutput[1],b);
maxofoutput[2]:=max(maxofoutput[2],C);
maxofoutput[3]:=max(maxofoutput[3],color2.red);
maxofoutput[4]:=max(maxofoutput[4],color2.green);
maxofoutput[5]:=max(maxofoutput[5],color2.blue);
minofoutput[0]:=Min(minofoutput[0],A);
minofoutput[1]:=Min(minofoutput[1],B);
minofoutput[2]:=Min(minofoutput[2],C);
minofoutput[3]:=Min(minofoutput[3],color2.red);
minofoutput[4]:=Min(minofoutput[4],color2.green);
minofoutput[5]:=Min(minofoutput[5],color2.blue);
end;
end;
procedure rangeofvalue;
begin
rangeofvalues[0]:=maxofoutput[0]-minofoutput[0];
rangeofvalues[1]:=maxofoutput[1]-minofoutput[1];
rangeofvalues[2]:=maxofoutput[2]-minofoutput[2];
rangeofvalues[3]:=maxofoutput[3]-minofoutput[3];
rangeofvalues[4]:=maxofoutput[4]-minofoutput[4];
rangeofvalues[5]:=maxofoutput[5]-minofoutput[5];
rgbrange:=rangeofvalues[3]*rangeofvalues[4]*rangeofvalues[5];
hslrange:=rangeofvalues[0]*rangeofvalues[1]*rangeofvalues[2];
end;
begin
setup;
repeat
color2:=color2rgb(color[i]);
minmax;
converter;
a:=trunc(H*240);
b:=trunc(s*240);
c:=trunc(L*240);
getmaxmin;
//notes: A is Hue, B is Saturation, L is lightness or luminosity
// color2.red/color2.green/color2.blue is the rgb values
// color[i] is the current color
writeln (inttostr(a)+' = H '+inttostr(b)+' = s '+inttostr(c)+' = L');
if (I=maxofarray) then
begin
rangeofvalue;
//notes: for maxofoutput and minofoutput arrays, 0 is hue, 1 is saturation,
// 2 is luminosity, 3 is red, 4 is green, 5 is blue.
//this if statement will find max or min of hsl/rgb vars, u select which to output
writeLn(inttostr(maxofoutput[0])+' = max of Hue | '+inttostr(minofoutput[0])+ ' = min of Hue');
writeLn(inttostr(maxofoutput[1])+' = max of Saturation | '+inttostr(minofoutput[1])+ ' = min of Saturation');
writeLn(inttostr(maxofoutput[2])+' = max of Luminosity | '+inttostr(minofoutput[2])+ ' = min of Luminosity');
//note: rangeofvalues is like max/minofoutput with array,
// but it displays the range of the values
writeLn(inttostr(rangeofvalues[0])+' = H range | '+inttostr(rangeofvalues[1])+' = S range | '+inttostr(rangeofvalues[2])+' = L range');
// note: hslrange = total amount of colors in hsl range, same with rgbrange except
// it does rgb range
writeLn(inttostr(hslrange)+' = total colors possible between ranges');
end;
i:=i+1;
until (i=(maxofarray+1))
end.