📄 jvqfullcolorspaces.pas
字号:
Result := inherited ConvertToColor(JoinColorParts(Red, Green, Blue));
end;
function TJvYUVColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte;
begin
Result := 128;
end;
function TJvYUVColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte;
begin
Result := YUV_MAX;
end;
function TJvYUVColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte;
begin
Result := YUV_MIN;
end;
function TJvYUVColorSpace.GetAxisName(Index: TJvAxisIndex): string;
begin
case Index of
axIndex0:
Result := RsYUV_Y;
axIndex1:
Result := RsYUV_U;
axIndex2:
Result := RsYUV_V;
else
Result := inherited GetAxisName(Index);
end;
end;
function TJvYUVColorSpace.GetName: string;
begin
Result := RsYUV_FullName;
end;
function TJvYUVColorSpace.GetShortName: string;
begin
Result := RsYUV_ShortName;
end;
//=== { TJvHSVColorSpace } ===================================================
function TJvHSVColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor;
var
Hue, Saturation, Value: Integer;
Red, Green, Blue: Integer;
ColorMax, ColorMin, ColorDelta: Integer;
begin
SplitColorParts(AColor, Red, Green, Blue);
if Red > Green then
ColorMax := Red
else
ColorMax := Green;
if Blue > ColorMax then
ColorMax := Blue;
if Red < Green then
ColorMin := Red
else
ColorMin := Green;
if Blue < ColorMin then
ColorMin := Blue;
ColorDelta := ColorMax - ColorMin;
Value := ColorMax;
if Value = 0 then
Saturation := 0
else
Saturation := (255 * ColorDelta) div Value;
if Saturation = 0 then
Hue := 0
else
begin
Hue := 0;
if Value = Red then
Hue := (40 * (Green - Blue) div ColorDelta);
if Value = Green then
Hue := (HSV_MAX div 3) + (40 * (Blue - Red) div ColorDelta);
if Value = Blue then
Hue := ((HSV_MAX * 2) div 3) + (40 * (Red - Green) div ColorDelta);
end;
if Hue < 0 then
Hue := Hue + HSV_MAX;
if Hue > HSV_MAX then
Hue := Hue - HSV_MAX;
Result := inherited ConvertFromColor(JoinColorParts(Hue, Saturation, Value));
end;
function TJvHSVColorSpace.ConvertToColor(AColor: TJvFullColor): TColor;
var
Hue, Saturation, Value: Integer;
Red, Green, Blue: Integer;
P, Q, T, Summ, Rest: Integer;
begin
SplitColorParts(AColor, Hue, Saturation, Value);
if Saturation = 0 then
begin
Red := Value;
Green := Value;
Blue := Value;
end
else
begin
if Hue = HSV_MAX then
Hue := 0;
Rest := Hue mod (HSV_MAX div 6);
Hue := Hue div (HSV_MAX div 6);
Summ := Value * Saturation;
P := Value - Summ div RGB_MAX;
Q := Value - (Summ * Rest) div (RGB_MAX * (HSV_MAX div 6));
T := Value - (Summ * ((HSV_MAX div 6) - Rest)) div (RGB_MAX * (HSV_MAX div 6));
case Hue of
0:
begin
Red := Value;
Green := T;
Blue := P;
end;
1:
begin
Red := Q;
Green := Value;
Blue := P;
end;
2:
begin
Red := P;
Green := Value;
Blue := T;
end;
3:
begin
Red := P;
Green := Q;
Blue := Value;
end;
4:
begin
Red := T;
Green := P;
Blue := Value;
end;
else
Red := Value;
Green := P;
Blue := Q;
end;
end;
Result := inherited ConvertToColor(JoinColorParts(Red, Green, Blue));
end;
function TJvHSVColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte;
begin
case Index of
axIndex0:
Result := 120;
axIndex1:
Result := 240;
else
Result := 150;
end;
end;
function TJvHSVColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte;
begin
case Index of
axIndex0:
Result := HSV_MAX;
else
Result := RGB_MAX;
end;
end;
function TJvHSVColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte;
begin
Result := HSV_MIN;
end;
function TJvHSVColorSpace.GetAxisName(Index: TJvAxisIndex): string;
begin
case Index of
axIndex0:
Result := RsHSV_Hue;
axIndex1:
Result := RsHSV_Saturation;
axIndex2:
Result := RsHSV_Value;
else
Result := inherited GetAxisName(Index);
end;
end;
function TJvHSVColorSpace.GetName: string;
begin
Result := RsHSV_FullName;
end;
function TJvHSVColorSpace.GetShortName: string;
begin
Result := RsHSV_ShortName;
end;
//=== { TJvYIQColorSpace } ===================================================
function TJvYIQColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor;
var
Y, I, Q: Integer;
Red, Green, Blue: Integer;
begin
SplitColorParts(AColor, Red, Green, Blue);
Y := Round(0.299*Red + 0.587*Green + 0.114*Blue);
I := Round(0.596*Red - 0.275*Green - 0.321*Blue) + 128;
Q := Round(0.212*Red - 0.523*Green + 0.311*Blue) + 128;
Y := EnsureRange(Y, YIQ_MIN, YIQ_MAX);
I := EnsureRange(I, YIQ_MIN, YIQ_MAX);
Q := EnsureRange(Q, YIQ_MIN, YIQ_MAX);
Result := inherited ConvertFromColor(JoinColorParts(Y, I, Q));
end;
function TJvYIQColorSpace.ConvertToColor(AColor: TJvFullColor): TColor;
var
Red, Green, Blue: Integer;
Y, I, Q: Integer;
begin
SplitColorParts(AColor, Y, I, Q);
//Y := Y;
I := I - 128;
Q := Q - 128;
Red := Round(Y + 0.956*I + 0.620*Q);
Green := Round(Y - 0.272*I - 0.647*Q);
Blue := Round(Y - 1.108*I + 1.705*Q);
Red := EnsureRange(Red , RGB_MIN, RGB_MAX);
Green := EnsureRange(Green, RGB_MIN, RGB_MAX);
Blue := EnsureRange(Blue, RGB_MIN, RGB_MAX);
Result := inherited ConvertToColor(JoinColorParts(Red, Green, Blue));
end;
function TJvYIQColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte;
begin
Result := 128;
end;
function TJvYIQColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte;
begin
Result := YIQ_MAX;
end;
function TJvYIQColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte;
begin
Result := YIQ_MIN;
end;
function TJvYIQColorSpace.GetAxisName(Index: TJvAxisIndex): string;
begin
case Index of
axIndex0:
Result := RsYIQ_Y;
axIndex1:
Result := RsYIQ_I;
axIndex2:
Result := RsYIQ_Q;
else
Result := inherited GetAxisName(Index);
end;
end;
function TJvYIQColorSpace.GetName: string;
begin
Result := RsYIQ_FullName;
end;
function TJvYIQColorSpace.GetShortName: string;
begin
Result := RsYIQ_ShortName;
end;
//=== { TJvYCCColorSpace } ===================================================
function TJvYCCColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor;
var
Y, Cr, Cb: Integer;
Red, Green, Blue: Integer;
begin
SplitColorParts(AColor, Red, Green, Blue);
Y := Round( 0.299*Red + 0.587*Green + 0.114*Blue);
Cr := Round(-0.150*Red - 0.293*Green + 0.443*Blue) + 128;
Cb := Round( 0.438*Red - 0.367*Green - 0.071*Blue) + 128;
Y := EnsureRange(Y, YCC_MIN, YCC_MAX);
Cr := EnsureRange(Cr, YCC_MIN, YCC_MAX);
Cb := EnsureRange(Cb, YCC_MIN, YCC_MAX);
Result := inherited ConvertFromColor(JoinColorParts(Y, Cr, Cb));
end;
function TJvYCCColorSpace.ConvertToColor(AColor: TJvFullColor): TColor;
var
Red, Green, Blue: Integer;
Y, Cr, Cb: Integer;
begin
SplitColorParts(AColor, Y, Cr, Cb);
Y := Y;
Cr := Cr - 128;
Cb := Cb - 128;
Red := Round(Y - 0.001*Cr + 1.600*Cb);
Green := Round(Y - 0.388*Cr - 0.816*Cb);
Blue := Round(Y + 2.000*Cr + 0.002*Cb);
Red := EnsureRange(Red , RGB_MIN, RGB_MAX);
Green := EnsureRange(Green, RGB_MIN, RGB_MAX);
Blue := EnsureRange(Blue, RGB_MIN, RGB_MAX);
Result := inherited ConvertToColor(JoinColorParts(Red, Green, Blue));
end;
function TJvYCCColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte;
begin
Result := 128;
end;
function TJvYCCColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte;
begin
Result := YCC_MAX;
end;
function TJvYCCColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte;
begin
Result := YCC_MIN;
end;
function TJvYCCColorSpace.GetAxisName(Index: TJvAxisIndex): string;
begin
case Index of
axIndex0:
Result := RsYCC_Y;
axIndex1:
Result := RsYCC_Cr;
axIndex2:
Result := RsYCC_Cb;
else
Result := inherited GetAxisName(Index);
end;
end;
function TJvYCCColorSpace.GetName: string;
begin
Result := RsYCC_FullName;
end;
function TJvYCCColorSpace.GetShortName: string;
begin
Result := RsYCC_ShortName;
end;
//=== { TJvXYZColorSpace } ===================================================
function TJvXYZColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor;
var
X, Y, Z: Integer;
Red, Green, Blue: Integer;
begin
SplitColorParts(AColor, Red, Green, Blue);
X := Round( 0.618*Red + 0.177*Green + 0.205*Blue);
Y := Round( 0.299*Red + 0.587*Green + 0.114*Blue);
Z := Round( 0.056*Green + 0.944*Blue);
X := EnsureRange(X, XYZ_MIN, XYZ_MAX);
Y := EnsureRange(Y, XYZ_MIN, XYZ_MAX);
Z := EnsureRange(Z, XYZ_MIN, XYZ_MAX);
Result := inherited ConvertFromColor(JoinColorParts(X, Y, Z));
end;
function TJvXYZColorSpace.ConvertToColor(AColor: TJvFullColor): TColor;
var
Red, Green, Blue: Integer;
X, Y, Z: Integer;
begin
SplitColorParts(AColor, X, Y, Z);
Red := Round( 1.876*X - 0.533*Y - 0.343*Z);
Green := Round(-0.967*X + 1.998*Y - 0.031*Z);
Blue := Round( 0.057*X - 0.118*Y + 1.061*Z);
Red := EnsureRange(Red , RGB_MIN, RGB_MAX);
Green := EnsureRange(Green, RGB_MIN, RGB_MAX);
Blue := EnsureRange(Blue, RGB_MIN, RGB_MAX);
Result := inherited ConvertToColor(JoinColorParts(Red, Green, Blue));
end;
function TJvXYZColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte;
begin
Result := 128;
end;
function TJvXYZColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -