1 //---------------------------------------------------------------------------------
3 // Little Color Management System
4 // Copyright (c) 1998-2010 Marti Maria Saguer
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the Software
11 // is furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
18 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 //---------------------------------------------------------------------------------
28 // ------------------------------------------------------------------------
30 static char *cInProf
= NULL
;
31 static char *cOutProf
= NULL
;
32 static int Intent
= INTENT_PERCEPTUAL
;
34 static int BlackPointCompensation
= FALSE
;
35 static int Undecorated
= FALSE
;
36 static int PrecalcMode
= 1;
37 static int NumOfGridPoints
= 0;
43 void HandleSwitches(int argc
, char *argv
[])
47 while ((s
= xgetopt(argc
,argv
,"uUbBI:i:O:o:T:t:c:C:n:N:")) != EOF
) {
63 case 'B': BlackPointCompensation
=TRUE
;
69 Intent
= atoi(xoptarg
);
70 if (Intent
> 3) Intent
= 3;
71 if (Intent
< 0) Intent
= 0;
81 PrecalcMode
= atoi(xoptarg
);
82 if (PrecalcMode
< 0 || PrecalcMode
> 2)
83 FatalError("ERROR: Unknown precalc mode '%d'", PrecalcMode
);
90 FatalError("Precalc mode already specified");
91 NumOfGridPoints
= atoi(xoptarg
);
97 FatalError("Unknown option - run without args to see valid ones.\n");
105 fprintf(stderr
, "little cms ICC PostScript generator - v2.0 [LittleCMS %2.2f]\n", LCMS_VERSION
/ 1000.0);
107 fprintf(stderr
, "usage: psicc [flags]\n\n");
109 fprintf(stderr
, "flags:\n\n");
111 fprintf(stderr
, "%ci<profile> - Input profile: Generates Color Space Array (CSA)\n", SW
);
112 fprintf(stderr
, "%co<profile> - Output profile: Generates Color Rendering Dictionary(CRD)\n", SW
);
114 fprintf(stderr
, "%ct<0,1,2,3> - Intent (0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute)\n", SW
);
116 fprintf(stderr
, "%cb - Black point compensation (CRD only)\n", SW
);
117 fprintf(stderr
, "%cu - Do NOT generate resource name on CRD\n", SW
);
118 fprintf(stderr
, "%cc<0,1,2> - Precision (0=LowRes, 1=Normal (default), 2=Hi-res) (CRD only)\n", SW
);
119 fprintf(stderr
, "%cn<gridpoints> - Alternate way to set precission, number of CLUT points (CRD only)\n", SW
);
121 fprintf(stderr
, "\n");
122 fprintf(stderr
, "This program is intended to be a demo of the little cms\n"
123 "engine. Both lcms and this program are freeware. You can\n"
124 "obtain both in source code at http://www.littlecms.com\n"
125 "For suggestions, comments, bug reports etc. send mail to\n"
126 "info@littlecms.com\n\n");
132 void GenerateCSA(void)
134 cmsHPROFILE hProfile
= OpenStockProfile(0, cInProf
);
138 if (hProfile
== NULL
) return;
140 n
= cmsGetPostScriptCSA(0, hProfile
, Intent
, 0, NULL
, 0);
143 Buffer
= (char*) malloc(n
+ 1);
144 if (Buffer
!= NULL
) {
146 cmsGetPostScriptCSA(0, hProfile
, Intent
, 0, Buffer
, n
);
149 fprintf(OutFile
, "%s", Buffer
);
154 cmsCloseProfile(hProfile
);
159 void GenerateCRD(void)
161 cmsHPROFILE hProfile
= OpenStockProfile(0, cOutProf
);
164 cmsUInt32Number dwFlags
= 0;
166 if (hProfile
== NULL
) return;
168 if (BlackPointCompensation
) dwFlags
|= cmsFLAGS_BLACKPOINTCOMPENSATION
;
169 if (Undecorated
) dwFlags
|= cmsFLAGS_NODEFAULTRESOURCEDEF
;
171 switch (PrecalcMode
) {
173 case 0: dwFlags
|= cmsFLAGS_LOWRESPRECALC
; break;
174 case 2: dwFlags
|= cmsFLAGS_HIGHRESPRECALC
; break;
176 if (NumOfGridPoints
> 0)
177 dwFlags
|= cmsFLAGS_GRIDPOINTS(NumOfGridPoints
);
180 default: FatalError("ERROR: Unknown precalculation mode '%d'", PrecalcMode
);
183 n
= cmsGetPostScriptCRD(0, hProfile
, Intent
, dwFlags
, NULL
, 0);
186 Buffer
= (char*) malloc(n
+ 1);
187 cmsGetPostScriptCRD(0, hProfile
, Intent
, dwFlags
, Buffer
, n
);
190 fprintf(OutFile
, "%s", Buffer
);
192 cmsCloseProfile(hProfile
);
196 int main(int argc
, char *argv
[])
203 HandleSwitches(argc
, argv
);
205 nargs
= (argc
- xoptind
);
206 if (nargs
!= 0 && nargs
!= 1)
212 OutFile
= fopen(argv
[xoptind
], "wt");
215 if (cInProf
== NULL
&& cOutProf
== NULL
)
222 if (cOutProf
!= NULL
)