1
0
mirror of https://github.com/moparisthebest/Simba synced 2025-01-30 14:50:18 -05:00

Fixed the color conversions (RGB-values should be Bytes, not integers.. IMO), oh and it was taking the wrong methods (from graphics.pas instead of colour_conv.pas)

Added testscript for colour conversions, but I cbf to finnish it.
Changed the export limit! We are already exporting more than 200 methods, win!

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@427 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Raymond 2010-01-18 13:38:45 +00:00
parent 212e41ecd1
commit 1e1c08e5a4
5 changed files with 37 additions and 73 deletions

View File

@ -42,7 +42,7 @@ uses
ColorBox, about, framefunctionlist, ocr, updateform, simbasettings;
const
SimbaVersion = 423;
SimbaVersion = 427;
type
@ -201,7 +201,6 @@ type
TB_SelectClient: TToolButton;
ToolButton8: TToolButton;
MTrayIcon: TTrayIcon;
ColorListBox1: TColorListBox;
procedure ActionClearDebugExecute(Sender: TObject);
procedure ActionCloseTabExecute(Sender: TObject);
procedure ActionCopyExecute(Sender: TObject);

View File

@ -0,0 +1,9 @@
program new;
var
R,G,B : byte;
begin
ColorToRGB(clwhite,r,g,b);
Writeln([r,g,b]);
Writeln(RGBToColor(50,150,250));//16422450
writeln(XYZToColor(0.5,0.7,0.9));//1513219
end.

View File

@ -118,16 +118,16 @@ AddFunction(@ps_GetPage,'function GetPage(url : string): string;');
{ Color Conversions and Speed }
SetCurrSection('Color Convert');
AddFunction(@ColorToRGB, 'procedure ColorToRGB(Color: integer; out r, g, b: Integer);');
AddFunction(@RGBToColor, 'function RGBtoColor(r, g, b: integer): TColor;');
AddFunction(@ColorToHSL, 'procedure ColorToHSL(Color: Integer; out h, s, l: Extended);');
AddFunction(@HSLToColor, 'function HSLToColor(H, S, L: Extended): TColor;');
AddFunction(@ColorToXYZ, 'procedure ColorToXYZ(Color: Integer; out x, y, z: Extended);');
AddFunction(@XYZToColor, 'function XYZToColor(X, Y, Z: Extended): TColor;');
AddFunction(@RGBToHSL, 'procedure RGBToHSL(R, G, B: Integer; out h, s, l: Extended);');
AddFunction(@HSLToRGB, 'procedure HSLtoRGB(H, S, L: extended; out R, G ,B: Integer);');
AddFunction(@RGBToXYZ, 'procedure RGBToXYZ(R, G, B: Integer;out x, y ,z: Extended);');
AddFunction(@XYZToRGB, 'procedure XYZToRGB(X, Y, Z: Extended; out R, G, B: integer);');
AddFunction(@Colour_Conv.ColorToRGB, 'procedure ColorToRGB(Color: integer; out r, g, b: Byte);');
AddFunction(@Colour_conv.RGBToColor, 'function RGBtoColor(r, g, b: Byte): TColor;');
AddFunction(@Colour_conv.ColorToHSL, 'procedure ColorToHSL(Color: Integer; out h, s, l: Extended);');
AddFunction(@Colour_conv.HSLToColor, 'function HSLToColor(H, S, L: Extended): TColor;');
AddFunction(@Colour_conv.ColorToXYZ, 'procedure ColorToXYZ(Color: Integer; out x, y, z: Extended);');
AddFunction(@Colour_conv.XYZToColor, 'function XYZToColor(X, Y, Z: Extended): TColor;');
AddFunction(@Colour_conv.RGBToHSL, 'procedure RGBToHSL(R, G, B: Byte; out h, s, l: Extended);');
AddFunction(@Colour_conv.HSLToRGB, 'procedure HSLtoRGB(H, S, L: extended; out R, G ,B: Byte);');
AddFunction(@Colour_conv.RGBToXYZ, 'procedure RGBToXYZ(R, G, B: Byte;out x, y ,z: Extended);');
AddFunction(@Colour_conv.XYZToRGB, 'procedure XYZToRGB(X, Y, Z: Extended; out R, G, B: Byte);');
{ Color Finding }
SetCurrSection('Color');

View File

@ -515,8 +515,8 @@ end;
procedure AddFunction( Ptr : Pointer; DeclStr : String);
begin;
// SetLength(ExportedMethods,c+1);
if c >= 200 then
raise exception.create('PSThread.LoadMethods: Exported more than 200 functions');
if c >= 300 then
raise exception.create('PSThread.LoadMethods: Exported more than 300 functions');
Result[c].FuncDecl:= DeclStr;
Result[c].FuncPtr:= Ptr;
Result[c].Section:= CurrSection;
@ -526,7 +526,7 @@ end;
begin
c := 0;
CurrSection := 'Other';
SetLength(Result,200);
SetLength(Result,300);
{$i PSInc/psexportedmethods.inc}
SetLength(Result,c);

View File

@ -37,12 +37,11 @@ Function RGBtoColor(r,g,b : byte) : TColor; overload; inline;
Function RGBtoColor(r,g,b : integer) : TColor; overload; inline;
Procedure ColorToRGB(Color : integer;out r,g,b : byte); overload; inline;
Procedure ColorToRGB(Color : integer;out r,g,b : integer); overload; inline;
Procedure RGBToXYZ(R,G,B : integer;out x,y,z : Extended); inline;
Procedure XYZToRGB(X,Y,Z : Extended;out R,G,B: integer); inline;
Procedure RGBToHSL(RR,GG,BB : integer;out H,S,L : Extended); inline;
Procedure RGBToHSLNonFixed(RR,GG,BB : integer;out H,S,L : Extended); inline;
Procedure HSLtoRGB(H,S,L : extended;out R,G,B : Byte); inline;overload;
Procedure HSLtoRGB(H,S,L : extended;out R,G,B : Integer); inline;overload;
Procedure RGBToXYZ(R,G,B : byte;out x,y,z : Extended); inline;
Procedure XYZToRGB(X,Y,Z : Extended;out R,G,B: byte); inline;
Procedure RGBToHSL(RR,GG,BB : byte;out H,S,L : Extended); inline;
Procedure RGBToHSLNonFixed(RR,GG,BB : byte;out H,S,L : Extended); inline;
Procedure HSLtoRGB(H,S,L : extended;out R,G,B : Byte); inline;
Procedure ColorToHSL(Col: Integer; out h, s, l: Extended); inline;
procedure ColorToXYZ(color: Integer; out X, Y, Z: Extended); inline;
function XYZToColor(X, Y, Z: Extended): TColor; inline;
@ -100,7 +99,7 @@ end;
X, Y and Z components.
/\}
Procedure RGBToXYZ(R,G,B : integer;out x,y,z : Extended); inline;
Procedure RGBToXYZ(R,G,B : byte;out x,y,z : Extended); inline;
var
Red,Green,Blue : Extended;
begin;
@ -129,7 +128,7 @@ end;
Red (R), Green (G) and Blue (B) components.
/\}
Procedure XYZToRGB(X,Y,Z : Extended;out R,G,B: integer); inline;
Procedure XYZToRGB(X,Y,Z : Extended;out R,G,B: byte); inline;
var
TempR,TempG,TempB,Tempx,tempy,tempz : Extended;
begin;
@ -161,7 +160,7 @@ end;
H (Hue), S (Saturation) and L (Luminance) components.
/\}
Procedure RGBToHSL(RR,GG,BB : integer;out H,S,L : Extended); inline;
Procedure RGBToHSL(RR,GG,BB : byte;out H,S,L : Extended); inline;
var
R, G, B, D, Cmax, Cmin: Extended;
begin
@ -208,7 +207,7 @@ end;
This function does not multiply it by 100.
/\}
Procedure RGBToHSLNonFixed(RR,GG,BB : integer;out H,S,L : Extended); inline;
Procedure RGBToHSLNonFixed(RR,GG,BB : byte;out H,S,L : Extended); inline;
var
R, G, B, D, Cmax, Cmin: Extended;
begin
@ -251,7 +250,7 @@ end;
Red (R), Green (G) and Blue (B) components.
/\}
procedure HSLtoRGB(H, S, L: extended; out R, G, B: Byte); inline; overload;
procedure HSLtoRGB(H, S, L: extended; out R, G, B: Byte); inline;
var
Temp,Temp2 : Extended;
//begin
@ -294,56 +293,13 @@ begin;
end;
end;
Procedure HSLtoRGB(H,S,L : extended;out R,G,B : Integer); inline;
var
Temp,Temp2 : Extended;
//begin
Function Hue2RGB(TempHue : Extended) : integer;
begin;
if TempHue < 0 then
TempHue := TempHue + 1
else if TempHue > 1 then
TempHue := TempHue - 1;
if ( ( 6 * TempHue ) < 1 ) then
Result :=Round(255 * (( Temp + ( Temp2 - Temp ) * 6 * TempHue )))
else if ( ( 2 * TempHue ) < 1 ) then
Result :=Round(255 * Temp2)
else if ( ( 3 * TempHue ) < 2 ) then
Result :=Round(255 * (Temp + ( Temp2 - Temp ) * ( ( TwoDivThree ) - TempHue ) * 6))
else
Result :=Round(255 * Temp);
end;
begin;
H := H / 100;
S := S / 100;
L := L / 100;
if s = 0 then
begin;
R := Round(L * 255);
G := R;
B := R;
end else
begin;
if (L < 0.5) then
Temp2 := L * ( 1 + S )
else
Temp2 := (L + S) - ( S * L);
Temp := 2 * L - Temp2;
R := Hue2RGB( H + ( OneDivThree ) );
G := Hue2RGB( H );
B := Hue2RGB( H - ( OneDivThree ) );
end;
end;
{/\
Split the Given Color col in H, S, L components.
/\}
Procedure ColorToHSL(Col: Integer; out h, s, l: Extended); inline;
Var
R, G, B: Integer;
R, G, B: byte;
Begin
ColorToRGB(Col, R, G, B);
RGBToHSL(R, G, B, H, S, L);
@ -351,7 +307,7 @@ End;
procedure ColorToXYZ(color: Integer; out X, Y, Z: Extended); inline;
var
R, G, B: Integer;
R, G, B: byte;
begin
ColorToRGB(Color, R, G, B);
RGBToXYZ(R, G, B, X, Y, Z);
@ -359,7 +315,7 @@ end;
function HSLToColor(H, S, L: Extended): TColor; inline;
var
r, g, b: Integer;
r, g, b: byte;
begin
HSLToRGB(H, S, L, r, g, b);
Result := RGBToColor(r, g, b);
@ -367,7 +323,7 @@ end;
function XYZToColor(X, Y, Z: Extended): TColor; inline;
var
r, g, b: Integer;
r, g, b: byte;
begin
XYZToRGB(X, Y, Z, r, g, b);
Result := RGBToColor(r, g, b);