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;
SetColor3_Result: TColor;
protected
function Colorize(Sender: TObject; ColorOriginal, ColorAdded: TColor; PercentageStrength: Byte): TColor;
public
constructor Create( AOwner: TComponent); override;
published
property Color1_Original: TColor read FColor1_Original write SetColor1_Original default clBlack;
property Color2_Added: TColor read FColor2_Added write SetColor2_Added default clWhite;
property MixStrengthPercentage: Byte read FMixStrengthPercentage write SetFMixStrengthPercentage default 50;
property Color3_Result: TColor read FColor3_Result default clGray ;
end;
procedure Register;
implementation
constructor TColorMixer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
function TColorMixer.Colorize(Sender: TObject; ColorOriginal, ColorAdded: TColor; PercentageStrength: Byte): TColor;
var
Color1, Color2: LongInt;
ValueR, ValueG, ValueB, Value1, Value2: Byte;
begin
PercentageStrength:=Round(2.55*PercentageStrength);
Color1:=ColorToRGB(ColorOriginal);
Color2:=ColorToRGB(ColorAdded);
Value1:=Byte(Color1);
Value2:=Byte(Color2);
ValueR:=PercentageStrength*(Value1-Value2) shr 8+Value2;
Value1:=Byte(Color1 shr 8);
Value2:=Byte(Color2 shr 8);
ValueG:=PercentageStrength*(Value1-Value2) shr 8+Value2;
Value1:=Byte(Color1 shr 16);
Value2:=Byte(Color2 shr 16);
ValueB:=PercentageStrength*(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.