6 Windows
, SysUtils
, Classes
, Graphics
, Controls
, Forms
, Dialogs
,
7 ExtCtrls
, StdCtrls
, ExtDlgs
, lcms2dll
, ComCtrls
;
17 ComboBoxInput
: TComboBox
;
18 ComboBoxOutput
: TComboBox
;
21 WBCompensation
: TCheckBox
;
22 NoTransform
: TCheckBox
;
23 RadioGroup1
: TRadioGroup
;
24 OpenPictureDialog1
: TOpenPictureDialog
;
26 ProgressBar1
: TProgressBar
;
27 ComboBoxIntent
: TComboBox
;
31 OpenDialog1
: TOpenDialog
;
33 ScrollBar1
: TScrollBar
;
35 procedure Button2Click(Sender
: TObject
);
36 procedure Button1Click(Sender
: TObject
);
37 procedure Button3Click(Sender
: TObject
);
38 procedure Button4Click(Sender
: TObject
);
39 procedure ComboBoxIntentChange(Sender
: TObject
);
40 procedure ScrollBar1Change(Sender
: TObject
);
42 { Private declarations }
43 function ComputeFlags
: DWORD
;
46 constructor Create(Owner
: TComponent
); Override;
47 { Public declarations }
65 IntentCodes
: array [0 .. 20] of cmsUInt32Number
;
67 FUNCTION InSignatures(Signature
: cmsProfileClassSignature
; dwFlags
: DWORD
): Boolean;
70 if (((dwFlags
AND IS_DISPLAY
) <> 0) AND (Signature
= cmsSigDisplayClass
)) then
72 else if (((dwFlags
AND IS_OUTPUT
) <> 0) AND (Signature
= cmsSigOutputClass
))
75 else if (((dwFlags
AND IS_INPUT
) <> 0) AND (Signature
= cmsSigInputClass
))
78 else if (((dwFlags
AND IS_COLORSPACE
) <> 0) AND
79 (Signature
= cmsSigColorSpaceClass
)) then
81 else if (((dwFlags
AND IS_ABSTRACT
) <> 0) AND
82 (Signature
= cmsSigAbstractClass
)) then
88 PROCEDURE FillCombo(var Combo
: TComboBox
; Signatures
: DWORD
);
90 Files
, Descriptions
: TStringList
;
92 SearchRec
: TSearchRec
;
93 Path
, Profile
: String;
94 Dir
: ARRAY [0 .. 1024] OF Char;
95 hProfile
: cmsHPROFILE
;
96 Descrip
: array [0 .. 256] of Char;
98 Files
:= TStringList
.Create
;
99 Descriptions
:= TStringList
.Create
;
100 GetSystemDirectory(Dir
, 1023);
101 Path
:= String(Dir
) + '\SPOOL\DRIVERS\COLOR\';
102 Found
:= FindFirst(Path
+ '*.ic?', faAnyFile
, SearchRec
);
105 Profile
:= Path
+ SearchRec
.Name
;
106 hProfile
:= cmsOpenProfileFromFile(PAnsiChar(AnsiString(Profile
)), 'r');
107 if (hProfile
<> NIL) THEN
110 if ((cmsGetColorSpace(hProfile
) = cmsSigRgbData
) AND InSignatures
111 (cmsGetDeviceClass(hProfile
), Signatures
)) then
113 cmsGetProfileInfo(hProfile
, cmsInfoDescription
, 'EN', 'us', Descrip
,
115 Descriptions
.Add(Descrip
);
118 cmsCloseProfile(hProfile
);
121 Found
:= FindNext(SearchRec
);
124 FindClose(SearchRec
);
125 Combo
.Items
:= Descriptions
;
126 Combo
.Tag
:= Integer(Files
);
129 // A rather simple Logger... note the "cdecl" convention
130 PROCEDURE ErrorLogger(ContextID
: cmsContext
; ErrorCode
: cmsUInt32Number
;
131 Text: PAnsiChar
); Cdecl;
133 MessageBox(0, PWideChar(WideString(Text)), 'Something is going wrong...',
134 MB_OK
OR MB_ICONWARNING
or MB_TASKMODAL
);
137 constructor TForm1
.Create(Owner
: TComponent
);
139 IntentNames
: array [0 .. 20] of PAnsiChar
;
142 inherited Create(Owner
);
145 cmsSetLogErrorHandler(ErrorLogger
);
148 ScrollBar1
.Max
:= 100;
150 FillCombo(ComboBoxInput
, IS_INPUT
OR IS_COLORSPACE
OR IS_DISPLAY
);
151 FillCombo(ComboBoxOutput
, $FFFF );
154 // Get the supported intents
155 n
:= cmsGetSupportedIntents(20, @IntentCodes
, @IntentNames
);
158 ComboBoxIntent
.Items
.BeginUpdate
;
159 ComboBoxIntent
.Items
.Clear
;
160 for i
:= 0 TO n
- 1 DO
161 ComboBoxIntent
.Items
.Add(String(IntentNames
[i
]));
163 ComboBoxIntent
.ItemIndex
:= 0;
164 ComboBoxIntent
.Items
.EndUpdate
;
169 procedure TForm1
.ScrollBar1Change(Sender
: TObject
);
173 d
:= ScrollBar1
.Position
;
175 Label4
.Caption
:= 'Adaptation state '+s
+ '% (Abs. col only)';
178 procedure TForm1
.Button2Click(Sender
: TObject
);
180 if OpenPictureDialog1
.Execute
then
182 Image1
.Picture
.LoadFromFile(OpenPictureDialog1
.FileName
);
183 Image1
.Picture
.Bitmap
.PixelFormat
:= pf24bit
;
185 Image2
.Picture
.LoadFromFile(OpenPictureDialog1
.FileName
);
186 Image2
.Picture
.Bitmap
.PixelFormat
:= pf24bit
;
191 function SelectedFile(var Combo
: TComboBox
): string;
197 List
:= TStringList(Combo
.Tag
);
198 n
:= Combo
.ItemIndex
;
200 SelectedFile
:= List
.Strings
[n
]
202 SelectedFile
:= Combo
.Text;
205 procedure TForm1
.ComboBoxIntentChange(Sender
: TObject
);
207 ScrollBar1
.Enabled
:= (ComboBoxIntent
.itemIndex
= 3);
210 function TForm1
.ComputeFlags
: DWORD
;
215 if (WBCompensation
.Checked
) then
217 dwFlags
:= dwFlags
OR cmsFLAGS_BLACKPOINTCOMPENSATION
220 if (NoTransform
.Checked
) then
222 dwFlags
:= dwFlags
OR cmsFLAGS_NULLTRANSFORM
225 case RadioGroup1
.ItemIndex
of
227 dwFlags
:= dwFlags
OR cmsFLAGS_NOOPTIMIZE
;
229 dwFlags
:= dwFlags
OR cmsFLAGS_HIGHRESPRECALC
;
231 dwFlags
:= dwFlags
OR cmsFLAGS_LOWRESPRECALC
;
234 ComputeFlags
:= dwFlags
237 procedure TForm1
.Button1Click(Sender
: TObject
);
239 Source
, Dest
: String;
240 hSrc
, hDest
: cmsHPROFILE
;
241 xform
: cmsHTRANSFORM
;
242 i
, PicW
, PicH
: Integer;
247 Source
:= SelectedFile(ComboBoxInput
);
248 Dest
:= SelectedFile(ComboBoxOutput
);
250 dwFlags
:= ComputeFlags
;
252 Intent
:= IntentCodes
[ComboBoxIntent
.ItemIndex
];
254 cmsSetAdaptationState( ScrollBar1
.Position
/ 100.0 );
256 if (Source
<> '') AND (Dest
<> '') then
258 hSrc
:= cmsOpenProfileFromFile(PAnsiChar(AnsiString(Source
)), 'r');
259 hDest
:= cmsOpenProfileFromFile(PAnsiChar(AnsiString(Dest
)), 'r');
261 if (hSrc
<> Nil) and (hDest
<> Nil) then
263 xform
:= cmsCreateTransform(hSrc
, TYPE_BGR_8
, hDest
, TYPE_BGR_8
, Intent
,
273 cmsCloseProfile(hSrc
);
278 cmsCloseProfile(hDest
);
281 if (xform
<> nil) then
284 PicW
:= Image2
.Picture
.width
;
285 PicH
:= Image2
.Picture
.height
;
286 ProgressBar1
.Min
:= 0;
287 ProgressBar1
.Max
:= PicH
;
288 ProgressBar1
.Step
:= 1;
290 for i
:= 0 TO (PicH
- 1) do
292 if ((i
MOD 100) = 0) then
293 ProgressBar1
.Position
:= i
;
295 cmsDoTransform(xform
, Image1
.Picture
.Bitmap
.Scanline
[i
],
296 Image2
.Picture
.Bitmap
.Scanline
[i
], PicW
);
299 ProgressBar1
.Position
:= PicH
;
301 cmsDeleteTransform(xform
);
306 ProgressBar1
.Position
:= 0;
310 procedure TForm1
.Button3Click(Sender
: TObject
);
312 if OpenDialog1
.Execute
then
313 ComboBoxInput
.Text := OpenDialog1
.FileName
;
316 procedure TForm1
.Button4Click(Sender
: TObject
);
318 if OpenDialog1
.Execute
then
319 ComboBoxOutput
.Text := OpenDialog1
.FileName
;