unit ColorMixer;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TColorMixer=class(TComponent)
private
FColor1_Original: TColor;
FColor2_Added: TColor;
FMixStrengthPercentage: Byte;
FColor3_Result: TColor;
protected
procedure SetColor1_Original(Value: TColor);
procedure SetColor2_Added(Value: TColor);
procedure SetMixStrengthPercentage(Value: Byte);
procedure SetColor3_Result(Value: TColor);
function Colorize: TColor;
public
constructor Create( AOwner: TComponent);
override;
published
property Color1_Original: TColor
read FColor1_Original
write SetColor1_Original
stored true
default $00000000;
property Color2_Added: TColor
read FColor2_Added
write SetColor2_Added
stored true
default $00FFFFFF;
property MixStrengthPercentage: Byte
read FMixStrengthPercentage
write SetMixStrengthPercentage
stored true
default 50;
property Color3_Result: TColor
read FColor3_Result
default $00888888;
end;
procedure Register;
//{$R ColorMixer.res}
//{$R ColorMixer.dcr}
implementation
constructor TColorMixer.Create(AOwner: TComponent);
var Filename, s:
String;
begin
inherited Create(AOwner);
FColor1_Original:=$00000000;
FColor2_Added:=$00FFFFFF;
FMixStrengthPercentage:=50;
if not (csDesigning
in ComponentState)
then
begin
if (Filename='
')
or(Filename='
.')
then
begin
s:=Application.ExeName;
Filename:=ChangeFileExt(s,'
.ini');
end;
end;
end;
procedure TColorMixer.SetColor1_Original(Value: TColor);
begin
if Value<>FColor1_Original
then
begin
FColor1_Original:=Value;
end;
end;
procedure TColorMixer.SetColor2_Added(Value: TColor);
begin
if Value<>FColor2_Added
then
begin
FColor2_Added:=Value;
end;
end;
procedure TColorMixer.SetMixStrengthPercentage(Value: Byte);
begin
if Value<>FMixStrengthPercentage
then
begin
FMixStrengthPercentage:=Value;
end;
end;
procedure TColorMixer.SetColor3_Result(Value: TColor);
var
Color1, Color2: LongInt;
ValueR, ValueG, ValueB, Value1, Value2: Byte;
begin
if Value<>FColor3_Result
then
begin
FColor3_Result:=Colorize;
end;
end;
function TColorMixer.Colorize: TColor;
var
Color1, Color2: LongInt;
ValueR, ValueG, ValueB, Value1, Value2: Byte;
begin
FMixStrengthPercentage:=Round(2.55*FMixStrengthPercentage);
Color1:=ColorToRGB(FColor1_Original);
Color2:=ColorToRGB(FColor2_Added);
Value1:=Byte(Color1);
Value2:=Byte(Color2);
ValueR:=FMixStrengthPercentage*(Value1-Value2)
shr 8+Value2;
Value1:=Byte(Color1
shr 8);
Value2:=Byte(Color2
shr 8);
ValueG:=FMixStrengthPercentage*(Value1-Value2)
shr 8+Value2;
Value1:=Byte(Color1
shr 16);
Value2:=Byte(Color2
shr 16);
ValueB:=FMixStrengthPercentage*(Value1-Value2)
shr 8+Value2;
result:=(ValueB
shl 16)+(ValueG
shl 8)+ValueR;
end;
procedure Register;
begin
RegisterComponents('
Sven Littkowski`s Best',[TColorMixer]);
end;
end.