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
default $00000000;
property Color2_Added: TColor
read FColor2_Added
write SetColor2_Added
default $00FFFFFF;
property MixStrengthPercentage: Byte
read FMixStrengthPercentage
write SetMixStrengthPercentage
default 50;
property Color3_Result: TColor
read FColor3_Result
write SetColor3_Result
default $00888888;
end;
procedure Register;
implementation
constructor TColorMixer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
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);
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
MixStrengthPercentage:=Round(2.55*MixStrengthPercentage);
Color1:=ColorToRGB(Color1_Original);
Color2:=ColorToRGB(Color2_Added);
Value1:=Byte(Color1);
Value2:=Byte(Color2);
ValueR:=MixStrengthPercentage*(Value1-Value2)
shr 8+Value2;
Value1:=Byte(Color1
shr 8);
Value2:=Byte(Color2
shr 8);
ValueG:=MixStrengthPercentage*(Value1-Value2)
shr 8+Value2;
Value1:=Byte(Color1
shr 16);
Value2:=Byte(Color2
shr 16);
ValueB:=MixStrengthPercentage*(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.