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