mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-30 12:52:16 -05:00
9b3694f105
Touches pretty much all the functions in finder.pas, so I expect a lot of functions to break. Tests will have to be written and results will have to be compared with Simba 0.97. Still, I think it's ready for merging to simba-next. Squashed commit of the following: commitef3bfa6410
Merge:d1e3645
5b3e2a8
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Aug 4 00:44:01 2011 +0200 Merge branch 'simba-next' into cts-rework commit5b3e2a864b
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Aug 4 00:41:00 2011 +0200 Merge new CTS/Finder system. Touches pretty much all the functions in finder.pas, so I expect a lot of functions to break. Tests will have to be written and results will have to be compared with Simba 0.97. Still, I think it's ready for merging to simba-next. Squashed commit of the following: commitd1e3645ee5
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 19:08:23 2011 +0200 MML/Finder: Fix all compiler hints + bug. commitf159f20bc2
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 19:05:03 2011 +0200 MML/Finder: Fix FindDTMsRotated. commit1fc33752e4
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 19:04:16 2011 +0200 MML/Finder: FindDTMsRotated rework. commita621a6e8da
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 18:13:36 2011 +0200 MML/Finder: FindDTMs rework done. commit0b592eef86
Merge:56e01c6
aaafd6b
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 16:48:09 2011 +0200 Merge branch 'master' into cts-rework Conflicts: Units/MMLCore/finder.pas commit56e01c67fa
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 16:16:19 2011 +0200 MML/Finder: CTS: Bitmap+Color functions done. Only DTM to go. commit464b90d42b
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 13:58:49 2011 +0200 MMLCore/finder: Small cleanup. commit2414f60c08
Merge:55b0435
a20a31a
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jul 31 18:12:41 2011 +0200 Merge branch 'master' into cts-rework commit55b0435a4e
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 20:27:54 2011 +0200 Tests: Update BmpBench. commit013daccf07
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 20:09:31 2011 +0200 MML/Core: Cleanup. commit6f32e21291
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 20:08:17 2011 +0200 MML/Core: FindBitmapToleranceIn seems to work. commit3b939443e8
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 19:10:10 2011 +0200 MML/Core: FindBitmapToleranceIn is nearly finished. Speed is nice, results are not accurate yet. I probably missed something when pre-loading the data. commit0422f0eb5a
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 15:53:48 2011 +0200 MML/Core: Fixes for FindBitmapToleranceIn. commit65f4ae16ed
Merge:daff307
353d1f3
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 14:32:46 2011 +0200 Merge branch 'master' into cts-rework commitdaff307f3d
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 13:46:10 2011 +0200 Tests: Add BmpBench. commitcdb89a1802
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 13:12:21 2011 +0200 MMLCore: FindBitmapToleranceIn cts rewrite. commitd0bd81c2e9
Merge:3282636
da0de6e
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 00:15:50 2011 +0200 Merge branch 'master' into cts-rework commit3282636178
Merge:7c86003
a8cdf77
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jul 25 16:50:43 2011 +0200 Merge branch 'master' into cts-rework commit7c8600311c
Merge:153025f
e0767cb
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jul 24 00:14:53 2011 +0200 Merge branch 'master' into cts-rework Conflicts: Doc/sphinx/conf.py Doc/sphinx/libmml/intro.rst commit153025f080
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jul 17 19:51:16 2011 +0200 libMML: Changed the indentation. commit8abd502580
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jul 17 19:37:33 2011 +0200 Documentation: Bump version to 820. commit031654b3d1
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jul 17 19:36:21 2011 +0200 Documentation: Initial libMML documentation. commitf91c9ffb0e
Merge:f5c9690
989d077
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jul 7 12:00:58 2011 +0200 Merge branch 'master' into cts-rework commitf5c9690bee
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jul 7 11:59:15 2011 +0200 Finder: More rework and cleanups. commit79021409d0
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 21:34:03 2011 +0200 Finder: CTS 2 fix. commitcda571dcb0
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 21:06:17 2011 +0200 Finder: Remote tolerance param. Cleanups. commit733a8cbf32
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 20:39:44 2011 +0200 Finder: More fixes. :-) commite6b005b61f
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 18:34:49 2011 +0200 Finder: CTS-rework fixes. commit6f896b56a2
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 18:15:33 2011 +0200 Finder: Start CTS rework. commita630399148
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 13:01:22 2011 +0200 Small TODO update. commit0e6bf83a5c
Merge:f19fd6b
f2873b1
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 12:59:09 2011 +0200 Merge branch 'master' into cts-rework commitf19fd6bf8d
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jul 3 20:42:14 2011 +0200 Simba/Doc: Add Raymond to doc. commit451ab89db3
Merge:37183f5
35026bc
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 2 14:48:43 2011 +0200 Merge branch 'master' into cts-rework commit37183f5fd0
Merge:cca7b05
6873e72
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Tue Jun 28 22:10:02 2011 +0200 Merge branch 'master' into cts-rework commitcca7b05213
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jun 16 17:03:14 2011 +0200 Add CTS 3 to FindColorsTolerance. Conflicts: Units/MMLCore/finder.pas commitc837d9b960
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jun 16 16:33:25 2011 +0200 CTS 3: Fix typo. commit52db461f84
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 6 16:06:17 2011 +0200 CTS 3: Now implement the formula properly. commit7a0db25416
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jun 5 19:44:52 2011 +0200 Add L*a*b CTS (3). commit2e1e786d0e
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jun 16 15:11:17 2011 +0200 FindBitmapToleranceIn now works. commit58ea6021cd
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jun 16 14:26:20 2011 +0200 CTS work. CTS 2 is still broken for bitmaps. commit91d952d33a
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jun 16 12:52:10 2011 +0200 CTS cleanups. commitd9836a251c
Merge:5bf7d8b
bfc3f86
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 13 20:44:08 2011 +0200 Merge branch 'master' into cts-rework commit5bf7d8beea
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 13 20:38:00 2011 +0200 Completed first CTS rework. commit7a412d1670
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 13 20:21:23 2011 +0200 CTS: Cleanups. commit14474a84ab
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 13 18:16:59 2011 +0200 CTS rework for FindColorsTolerance. commitb87a123701
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 13 17:44:04 2011 +0200 More cleanups to CTS. commit9415d08100
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 13 17:41:06 2011 +0200 Finder: Trying a different CTS approach. commitd1e3645ee5
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 19:08:23 2011 +0200 MML/Finder: Fix all compiler hints + bug. commitf159f20bc2
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 19:05:03 2011 +0200 MML/Finder: Fix FindDTMsRotated. commit1fc33752e4
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 19:04:16 2011 +0200 MML/Finder: FindDTMsRotated rework. commita621a6e8da
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 18:13:36 2011 +0200 MML/Finder: FindDTMs rework done. commit0b592eef86
Merge:56e01c6
aaafd6b
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 16:48:09 2011 +0200 Merge branch 'master' into cts-rework Conflicts: Units/MMLCore/finder.pas commit56e01c67fa
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 16:16:19 2011 +0200 MML/Finder: CTS: Bitmap+Color functions done. Only DTM to go. commit464b90d42b
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Aug 1 13:58:49 2011 +0200 MMLCore/finder: Small cleanup. commit2414f60c08
Merge:55b0435
a20a31a
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jul 31 18:12:41 2011 +0200 Merge branch 'master' into cts-rework commit55b0435a4e
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 20:27:54 2011 +0200 Tests: Update BmpBench. commit013daccf07
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 20:09:31 2011 +0200 MML/Core: Cleanup. commit6f32e21291
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 20:08:17 2011 +0200 MML/Core: FindBitmapToleranceIn seems to work. commit3b939443e8
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 19:10:10 2011 +0200 MML/Core: FindBitmapToleranceIn is nearly finished. Speed is nice, results are not accurate yet. I probably missed something when pre-loading the data. commit0422f0eb5a
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 15:53:48 2011 +0200 MML/Core: Fixes for FindBitmapToleranceIn. commit65f4ae16ed
Merge:daff307
353d1f3
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 14:32:46 2011 +0200 Merge branch 'master' into cts-rework commitdaff307f3d
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 13:46:10 2011 +0200 Tests: Add BmpBench. commitcdb89a1802
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 13:12:21 2011 +0200 MMLCore: FindBitmapToleranceIn cts rewrite. commitd0bd81c2e9
Merge:3282636
da0de6e
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 30 00:15:50 2011 +0200 Merge branch 'master' into cts-rework commit3282636178
Merge:7c86003
a8cdf77
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jul 25 16:50:43 2011 +0200 Merge branch 'master' into cts-rework commit7c8600311c
Merge:153025f
e0767cb
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jul 24 00:14:53 2011 +0200 Merge branch 'master' into cts-rework Conflicts: Doc/sphinx/conf.py Doc/sphinx/libmml/intro.rst commit153025f080
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jul 17 19:51:16 2011 +0200 libMML: Changed the indentation. commit8abd502580
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jul 17 19:37:33 2011 +0200 Documentation: Bump version to 820. commit031654b3d1
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jul 17 19:36:21 2011 +0200 Documentation: Initial libMML documentation. commitf91c9ffb0e
Merge:f5c9690
989d077
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jul 7 12:00:58 2011 +0200 Merge branch 'master' into cts-rework commitf5c9690bee
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jul 7 11:59:15 2011 +0200 Finder: More rework and cleanups. commit79021409d0
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 21:34:03 2011 +0200 Finder: CTS 2 fix. commitcda571dcb0
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 21:06:17 2011 +0200 Finder: Remote tolerance param. Cleanups. commit733a8cbf32
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 20:39:44 2011 +0200 Finder: More fixes. :-) commite6b005b61f
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 18:34:49 2011 +0200 Finder: CTS-rework fixes. commit6f896b56a2
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 18:15:33 2011 +0200 Finder: Start CTS rework. commita630399148
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 13:01:22 2011 +0200 Small TODO update. commit0e6bf83a5c
Merge:f19fd6b
f2873b1
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Wed Jul 6 12:59:09 2011 +0200 Merge branch 'master' into cts-rework commitf19fd6bf8d
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jul 3 20:42:14 2011 +0200 Simba/Doc: Add Raymond to doc. commit451ab89db3
Merge:37183f5
35026bc
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sat Jul 2 14:48:43 2011 +0200 Merge branch 'master' into cts-rework commit37183f5fd0
Merge:cca7b05
6873e72
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Tue Jun 28 22:10:02 2011 +0200 Merge branch 'master' into cts-rework commitcca7b05213
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jun 16 17:03:14 2011 +0200 Add CTS 3 to FindColorsTolerance. Conflicts: Units/MMLCore/finder.pas commitc837d9b960
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jun 16 16:33:25 2011 +0200 CTS 3: Fix typo. commit52db461f84
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 6 16:06:17 2011 +0200 CTS 3: Now implement the formula properly. commit7a0db25416
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Sun Jun 5 19:44:52 2011 +0200 Add L*a*b CTS (3). commit2e1e786d0e
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jun 16 15:11:17 2011 +0200 FindBitmapToleranceIn now works. commit58ea6021cd
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jun 16 14:26:20 2011 +0200 CTS work. CTS 2 is still broken for bitmaps. commit91d952d33a
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Thu Jun 16 12:52:10 2011 +0200 CTS cleanups. commitd9836a251c
Merge:5bf7d8b
bfc3f86
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 13 20:44:08 2011 +0200 Merge branch 'master' into cts-rework commit5bf7d8beea
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 13 20:38:00 2011 +0200 Completed first CTS rework. commit7a412d1670
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 13 20:21:23 2011 +0200 CTS: Cleanups. commit14474a84ab
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 13 18:16:59 2011 +0200 CTS rework for FindColorsTolerance. commitb87a123701
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 13 17:44:04 2011 +0200 More cleanups to CTS. commit9415d08100
Author: Merlijn Wajer <merlijn@wizzup.org> Date: Mon Jun 13 17:41:06 2011 +0200 Finder: Trying a different CTS approach.
390 lines
9.5 KiB
ObjectPascal
390 lines
9.5 KiB
ObjectPascal
{
|
|
This file is part of the Mufasa Macro Library (MML)
|
|
Copyright (c) 2009 by Raymond van Venetië and Merlijn Wajer
|
|
|
|
MML is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
MML is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with MML. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
See the file COPYING, included in this distribution,
|
|
for details about the copyright.
|
|
|
|
Colour Conversion Utilities for the Mufasa Macro Library
|
|
}
|
|
|
|
unit colour_conv;
|
|
|
|
{$mode objfpc}{$H+}
|
|
{$Inline on}
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, SysUtils,
|
|
Graphics, mufasatypes,
|
|
Math;
|
|
|
|
|
|
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 : 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;
|
|
function HSLToColor(H, S, L: Extended): TColor; inline;
|
|
function BGRToRGB(BGR : TRGB32) : TColor;inline;
|
|
procedure XYZtoCIELab(X, Y, Z: Extended; out L, a, b: Extended);
|
|
procedure CIELabtoXYZ(L, a, b: Extended; out X, Y, Z: Extended);
|
|
|
|
|
|
implementation
|
|
|
|
Const
|
|
OneDivThree = 1/3.0;
|
|
TwoDivThree = 2 / 3.0;
|
|
OneDivTwoPointFour = 1 / 2.4;
|
|
function BGRToRGB(BGR : TRGB32) : TColor;inline;
|
|
begin;
|
|
Result := BGR.R or BGR.g shl 8 or BGR.b shl 16;
|
|
end;
|
|
|
|
Function RGBtoColor(r,g,b : byte): TColor; overload; inline;
|
|
begin;
|
|
Result := R or g shl 8 or b shl 16;
|
|
end;
|
|
|
|
{/\
|
|
Translates the given Red (R), Green (G) and Blue (B) components to a TColor.
|
|
R, G and B are integers.
|
|
/\}
|
|
|
|
Function RGBtoColor(r,g,b : integer): TColor; overload; inline;
|
|
begin;
|
|
Result := R or g shl 8 or b shl 16;
|
|
end;
|
|
|
|
{/\
|
|
Translates the given win-32 color in the Red (R), Green (G) and Blue (B)
|
|
components. R, G and B are bytes.
|
|
/\}
|
|
|
|
Procedure ColorToRGB(Color : integer;out r,g,b : byte); overload; inline;
|
|
begin
|
|
R := Color and $ff;
|
|
G := Color shr 8 and $ff;
|
|
B := Color shr 16 and $ff;
|
|
end;
|
|
|
|
{/\
|
|
Translates the given win-32 color in the Red (R), Green (G) and Blue (B)
|
|
components. R, G and B are integers.
|
|
/\}
|
|
|
|
Procedure ColorToRGB(Color : integer;out r,g,b : integer); overload; inline;
|
|
begin
|
|
R := Color and $ff;
|
|
G := Color shr 8 and $ff;
|
|
B := Color shr 16 and $ff;
|
|
end;
|
|
|
|
{/\
|
|
Translates the given Red (R), Green (G) and Blue (B) components to
|
|
X, Y and Z components.
|
|
/\}
|
|
|
|
Procedure RGBToXYZ(R,G,B : byte;out x,y,z : Extended); inline;
|
|
var
|
|
Red,Green,Blue : Extended;
|
|
begin;
|
|
Red := R / 255;
|
|
Green := G / 255;
|
|
Blue := B / 255;
|
|
if Red > 0.04045 then
|
|
Red := Power( ( Red + 0.055 ) / 1.055 , 2.4) * 100
|
|
else
|
|
Red := Red * 7.73993808;
|
|
if Green > 0.04045 then
|
|
Green := Power( ( Green + 0.055 ) / 1.055 , 2.4) * 100
|
|
else
|
|
Green := Green * 7.73993808;
|
|
if Blue > 0.04045 then
|
|
Blue := Power( ( Blue + 0.055 ) / 1.055 , 2.4) * 100
|
|
else
|
|
Blue := Blue * 7.73993808;
|
|
X := Red * 0.4124 + Green * 0.3576 + Blue * 0.1805;
|
|
Y := Red * 0.2126 + Green * 0.7152 + Blue * 0.0722;
|
|
Z := Red * 0.0193 + Green * 0.1192 + Blue * 0.9505;
|
|
end;
|
|
|
|
{/\
|
|
Translates the given X, Y and Z components to
|
|
Red (R), Green (G) and Blue (B) components.
|
|
/\}
|
|
|
|
Procedure XYZToRGB(X,Y,Z : Extended;out R,G,B: byte); inline;
|
|
var
|
|
TempR,TempG,TempB,Tempx,tempy,tempz : Extended;
|
|
begin;
|
|
Tempx := X / 100;
|
|
tempy := Y / 100;
|
|
tempz := Z / 100;
|
|
TempR := Tempx * 3.2406 + tempy * -1.5372 + tempz * -0.4986;
|
|
TempG := Tempx * -0.9689 + tempy * 1.8758 + tempz * 0.0415;
|
|
TempB := Tempx * 0.0557 + tempy * -0.2040 + tempz * 1.0570;
|
|
if TempR > 0.0031308 then
|
|
TempR := 1.055 * ( Power(TempR, (OneDivTwoPointFour)) ) - 0.055
|
|
else
|
|
TempR := 12.92 * TempR;
|
|
if TempG > 0.0031308 then
|
|
TempG := 1.055 * ( Power(TempG, ( OneDivTwoPointFour)) ) - 0.055
|
|
else
|
|
TempG := 12.92 * TempG;
|
|
if TempB > 0.0031308 then
|
|
TempB := 1.055 * ( Power(TempB , ( OneDivTwoPointFour )) ) - 0.055
|
|
else
|
|
TempB := 12.92 * TempB;
|
|
R := Round(TempR * 255);
|
|
G := Round(TempG * 255);
|
|
B := Round(TempB * 255);
|
|
end;
|
|
|
|
{/\
|
|
Translates the given Red (R), Green (G) and Blue (B) components to
|
|
H (Hue), S (Saturation) and L (Luminance) components.
|
|
/\}
|
|
|
|
Procedure RGBToHSL(RR,GG,BB : byte;out H,S,L : Extended); inline;
|
|
var
|
|
R, G, B, D, Cmax, Cmin: Extended;
|
|
begin
|
|
R := RR / 255;
|
|
G := GG / 255;
|
|
B := BB / 255;
|
|
CMin := R;
|
|
if G < Cmin then Cmin := G;
|
|
if B < Cmin then Cmin := B;
|
|
CMax := R;
|
|
if G > Cmax then Cmax := G;
|
|
if B > Cmax then Cmax := B;
|
|
L := 0.5 * (Cmax + Cmin);
|
|
if Cmax = Cmin then
|
|
begin
|
|
H := 0;
|
|
S := 0;
|
|
end else
|
|
begin;
|
|
D := Cmax - Cmin;
|
|
if L < 0.5 then
|
|
S := D / (Cmax + Cmin)
|
|
else
|
|
S := D / (2 - Cmax - Cmin);
|
|
if R = Cmax then
|
|
H := (G - B) / D
|
|
else
|
|
if G = Cmax then
|
|
H := 2 + (B - R) / D
|
|
else
|
|
H := 4 + (R - G) / D;
|
|
H := H / 6;
|
|
if H < 0 then
|
|
H := H + 1;
|
|
end;
|
|
H := H * 100;
|
|
S := S * 100;
|
|
L := L * 100;
|
|
end;
|
|
|
|
{/\
|
|
Translates the given Red (R), Green (G) and Blue (B) components to
|
|
H (Hue), S (Saturation) and L (Luminance) components.
|
|
This function does not multiply it by 100.
|
|
/\}
|
|
|
|
Procedure RGBToHSLNonFixed(RR,GG,BB : byte;out H,S,L : Extended); inline;
|
|
var
|
|
R, G, B, D, Cmax, Cmin: Extended;
|
|
begin
|
|
R := RR / 255;
|
|
G := GG / 255;
|
|
B := BB / 255;
|
|
CMin := R;
|
|
if G < Cmin then Cmin := G;
|
|
if B < Cmin then Cmin := B;
|
|
CMax := R;
|
|
if G > Cmax then Cmax := G;
|
|
if B > Cmax then Cmax := B;
|
|
L := 0.5 * (Cmax + Cmin);
|
|
if Cmax = Cmin then
|
|
begin
|
|
H := 0;
|
|
S := 0;
|
|
end else
|
|
begin;
|
|
D := Cmax - Cmin;
|
|
if L < 0.5 then
|
|
S := D / (Cmax + Cmin)
|
|
else
|
|
S := D / (2 - Cmax - Cmin);
|
|
if R = Cmax then
|
|
H := (G - B) / D
|
|
else
|
|
if G = Cmax then
|
|
H := 2 + (B - R) / D
|
|
else
|
|
H := 4 + (R - G) / D;
|
|
H := H / 6;
|
|
if H < 0 then
|
|
H := H + 1;
|
|
end;
|
|
end;
|
|
|
|
{/\
|
|
Translates the given H (Hue), S (Saturation) and L (Luminance) components to
|
|
Red (R), Green (G) and Blue (B) components.
|
|
/\}
|
|
|
|
procedure HSLtoRGB(H, S, L: extended; out R, G, B: Byte); 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 := Byte(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: byte;
|
|
Begin
|
|
ColorToRGB(Col, R, G, B);
|
|
RGBToHSL(R, G, B, H, S, L);
|
|
End;
|
|
|
|
procedure ColorToXYZ(color: Integer; out X, Y, Z: Extended); inline;
|
|
var
|
|
R, G, B: byte;
|
|
begin
|
|
ColorToRGB(Color, R, G, B);
|
|
RGBToXYZ(R, G, B, X, Y, Z);
|
|
end;
|
|
|
|
function HSLToColor(H, S, L: Extended): TColor; inline;
|
|
var
|
|
r, g, b: byte;
|
|
begin
|
|
HSLToRGB(H, S, L, r, g, b);
|
|
Result := RGBToColor(r, g, b);
|
|
end;
|
|
|
|
function XYZToColor(X, Y, Z: Extended): TColor; inline;
|
|
var
|
|
r, g, b: byte;
|
|
begin
|
|
XYZToRGB(X, Y, Z, r, g, b);
|
|
Result := RGBToColor(r, g, b);
|
|
end;
|
|
|
|
procedure XYZtoCIELab(X, Y, Z: Extended; out L, a, b: Extended);
|
|
begin
|
|
X := X / 95.047;
|
|
Y := Y / 100.000;
|
|
Z := Z / 108.883;
|
|
|
|
if ( X > 0.008856 ) then
|
|
X := Power(X, 1.0/3.0)
|
|
else
|
|
X := ( 7.787 * X ) + ( 16.0 / 116.0 );
|
|
if ( Y > 0.008856 ) then
|
|
Y := Power(Y, 1.0/3.0)
|
|
else
|
|
Y := ( 7.787 * Y ) + ( 16.0 / 116.0 );
|
|
if ( Z > 0.008856 ) then
|
|
Z := Power(Z, 1.0/3.0)
|
|
else
|
|
Z := ( 7.787 * Z ) + ( 16.0 / 116.0 );
|
|
|
|
L := (116.0 * Y ) - 16.0;
|
|
a := 500.0 * ( X - Y );
|
|
b := 200.0 * ( Y - Z );
|
|
end;
|
|
|
|
procedure CIELabtoXYZ(L, a, b: Extended; out X, Y, Z: Extended);
|
|
begin
|
|
Y := ( L + 16 ) / 116.0;
|
|
X := ( a / 500.0 )+ Y;
|
|
Z := Y - ( b / 200.0 );
|
|
|
|
if ( Power(Y, 3) > 0.008856 ) then
|
|
Y := Power(Y, 3)
|
|
else
|
|
Y := ( Y - (16.0 / 116.0 )) / 7.787;
|
|
if ( Power(X, 3) > 0.008856 ) then
|
|
X := Power(X, 3)
|
|
else
|
|
X := ( X - (16.0 / 116.0) ) / 7.787;
|
|
if ( Power(Z, 3) > 0.008856 ) then
|
|
Z := Power(Z, 3)
|
|
else
|
|
Z := ( Z - (16.0 / 116.0) ) / 7.787;
|
|
|
|
|
|
X := 95.047 * X;
|
|
Y := 100.000 * Y;
|
|
Z := 108.883 * Z;
|
|
end;
|
|
|
|
end.
|