Cazax
2009-01-21 15:40:07
I made a color debugger for all your coloring needs :):
Debugs RGB,HSL and XYZ min, max and middle values, tolerance, Sat mod and hue mod for CTS 2. I just need the formula for sensitivity to debug it :(
program Color_Debugger;
//By Cazax
Type
TRGB = Record
MinR, MinG, MinB : Integer;
MaxR, MaxG, MaxB : Integer;
MiddleColor : Integer;
End;
THSL = Record
MinH, MinS, MinL : Extended;
MaxH, MaxS, MaxL : Extended;
MiddleColor : Integer;
End;
TXYZ = Record
MinX, MinY, MinZ : Extended;
MaxX, MaxY, MaxZ : Extended;
MiddleColor : Integer;
End;
TColorSpace = (RGBcts, HSLcts, XYZcts);
Var
Colors : TIntegerArray;
RGB : TRGB;
HSL : THSL;
XYZ : TXYZ;
Procedure SetColors;
Begin
Colors := [{---------}]; // PUT COLORS HERE!
//Example: Colors := [14184135, 7516841, 94516525, 6843218];
End;
Function GetTolerance(Col1, Col2 : TColor; CTS : TColorSpace): Integer;
Var
V : Variant;
Begin
V := CTS;
ColorToleranceSpeed(V);
While Not SimilarColors(Col1, Col2, Result) Do
Inc(Result);
ColorToleranceSpeed(1);
End;
Procedure GetValues;
Var
I, H2, R, G, B : Integer;
H, S, L, X, Y, Z : Extended;
Begin
H2 := High(Colors);
For I := 0 To H2 Do
Begin
ColorToRGB(Colors[I], R, G, B);
ColorToHSL(Colors[I], H, S, L);
ColorToXYZ(Colors[I], X, Y, Z);
If I = 0 Then
Begin
RGB.MinR := R;
RGB.MinG := G;
RGB.MinB := B;
HSL.MinH := H;
HSL.MinS := S;
HSL.MinL := L;
XYZ.MinX := X;
XYZ.MinY := Y;
XYZ.MinZ := Z;
RGB.MaxR := R;
RGB.MaxG := G;
RGB.MaxB := B;
HSL.MaxH := H;
HSL.MaxS := S;
HSL.MaxL := L;
XYZ.MaxX := X;
XYZ.MaxY := Y;
XYZ.MaxZ := Z;
End;
RGB.MinR := Min(RGB.MinR, R);
RGB.MinG := Min(RGB.MinG, G);
RGB.MinB := Min(RGB.MinB, B);
HSL.MinH := MinE(HSL.MinH, H);
HSL.MinS := MinE(HSL.MinS, S);
HSL.MinL := MinE(HSL.MinL, L);
XYZ.MinX := MinE(XYZ.MinX, X);
XYZ.MinY := MinE(XYZ.MinY, Y);
XYZ.MinZ := MinE(XYZ.MinZ, Z);
RGB.MaxR := Max(RGB.MaxR, R);
RGB.MaxG := Max(RGB.MaxG, G);
RGB.MaxB := Max(RGB.MaxB, B);
HSL.MaxH := MaxE(HSL.MaxH, H);
HSL.MaxS := MaxE(HSL.MaxS, S);
HSL.MaxL := MaxE(HSL.MaxL, L);
XYZ.MaxX := MaxE(XYZ.MaxX, X);
XYZ.MaxY := MaxE(XYZ.MaxY, Y);
XYZ.MaxZ := MaxE(XYZ.MaxZ, Z);
End;
RGB.MiddleColor := RGBToColor((RGB.MinR + RGB.MaxR) Shr 1, (RGB.MinG + RGB.MaxG) Shr 1, (RGB.MinB + RGB.MaxB) Shr 1);
HSL.MiddleColor := HSLToColor((HSL.MinH + HSL.MaxH) / 2, (HSL.MinS + HSL.MaxS) / 2, (HSL.MinL + HSL.MaxL) / 2);
XYZ.MiddleColor := XYZToColor((XYZ.MinX + XYZ.MaxX) / 2, (XYZ.MinY + XYZ.MaxY) / 2, (XYZ.MinZ + XYZ.MaxZ) / 2);
End;
Procedure Debug;
Begin
Writeln('RGB Information:');
Writeln('Min Values: |R:' + IntToStr(RGB.MinR) + '|G:' + IntToStr(RGB.MinG) + '|B:' + IntToStr(RGB.MinB));
Writeln('Max Values: |R:' + IntToStr(RGB.MaxR) + '|G:' + IntToStr(RGB.MaxG) + '|B:' + IntToStr(RGB.MaxB));
Writeln('Mid Values: |R:' + IntToStr((RGB.MaxR + RGB.MinR) Shr 1) + '|G:' + IntToStr((RGB.MaxG + RGB.MinB) Shr 1) + '|B:' + IntToStr((RGB.MaxB + RGB.MinB) Shr 1));
Writeln('RGB Mid Color: ' + IntToStr(RGB.MiddleColor));
Writeln('RGB Tolerance: ' + IntToStr(GetTolerance(RGBToColor(RGB.MinR, RGB.MinG, RGB.MinB), RGBToColor(RGB.MaxR, RGB.MaxG, RGB.MaxB), RGBcts)));
Writeln('');
Writeln('HSL Information:');
Writeln('Min Values: |H:' + FloatToStr(HSL.MinH) + '|S:' + FloatToStr(HSL.MinS) + '|L:' + FloatToStr(HSL.MinL));
Writeln('Max Values: |H:' + FloatToStr(HSL.MaxH) + '|S:' + FloatToStr(HSL.MaxS) + '|L:' + FloatToStr(HSL.MaxL));
Writeln('Mid Values: |H:' + FloatToStr((HSL.MaxH + HSL.MinH) / 2) + '|S:' + FloatToStr((HSL.MaxS + HSL.MinS) / 2) + '|L:' + FloatToStr((HSL.MaxL + HSL.MinL) / 2));
Writeln('HSL Mid Color: ' + IntToStr(HSL.MiddleColor));
Writeln('Smod/HMod: ' + FloatToStr(Abs(HSL.MaxS - HSL.MinS) / Abs(HSL.MaxL - HSL.MinL)) + ' / ' + FloatToStr(Abs(HSL.MaxH - HSL.MinH) / Abs(HSL.MaxL - HSL.MinL)));
Writeln('HSL Tolerance: ' + IntToStr(GetTolerance(HSLToColor(HSL.MinH, HSL.MinS, HSL.MinL), HSLToColor(HSL.MaxH, HSL.MaxS, HSL.MaxL), HSLcts)));
Writeln('');
Writeln('XYZ Information:');
Writeln('Min Values: |X:' + FloatToStr(XYZ.MinX) + '|Y:' + FloatToStr(XYZ.MinY) + '|Z:' + FloatToStr(XYZ.MinZ));
Writeln('Max Values: |X:' + FloatToStr(XYZ.MaxX) + '|Y:' + FloatToStr(XYZ.MaxY) + '|Z:' + FloatToStr(XYZ.MaxZ));
Writeln('Mid Values: |X:' + FloatToStr((XYZ.MaxX + XYZ.MinX) / 2) + '|Y:' + FloatToStr((XYZ.MaxY + XYZ.MinY) / 2) + '|Z:' + FloatToStr((XYZ.MaxZ + XYZ.MinZ) / 2));
Writeln('XYZ Mid Color: ' + IntToStr(XYZ.MiddleColor));
Writeln('XYZ Tolerance: ' + IntToStr(GetTolerance(XYZToColor(XYZ.Minx, XYZ.MinY, XYZ.MinZ), XYZToColor(XYZ.MaxX, XYZ.MaxY, XYZ.MaxZ), XYZcts)));
Writeln('Sensitivity: ' + '?');
Writeln('');
End;
begin
SetColors;
GetValues;
Debug;
end.Debugs RGB,HSL and XYZ min, max and middle values, tolerance, Sat mod and hue mod for CTS 2. I just need the formula for sensitivity to debug it :(