grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / lcms2 / utils / psicc / psicc.c
blob3716177b9c1f0637874960da17dbf42ee0bbb4f1
1 //---------------------------------------------------------------------------------
2 //
3 // Little Color Management System
4 // Copyright (c) 1998-2010 Marti Maria Saguer
5 //
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 //---------------------------------------------------------------------------------
26 #include "utils.h"
28 // ------------------------------------------------------------------------
30 static char *cInProf = NULL;
31 static char *cOutProf = NULL;
32 static int Intent = INTENT_PERCEPTUAL;
33 static FILE* OutFile;
34 static int BlackPointCompensation = FALSE;
35 static int Undecorated = FALSE;
36 static int PrecalcMode = 1;
37 static int NumOfGridPoints = 0;
40 // The toggles stuff
42 static
43 void HandleSwitches(int argc, char *argv[])
45 int s;
47 while ((s = xgetopt(argc,argv,"uUbBI:i:O:o:T:t:c:C:n:N:")) != EOF) {
49 switch (s){
52 case 'i':
53 case 'I':
54 cInProf = xoptarg;
55 break;
57 case 'o':
58 case 'O':
59 cOutProf = xoptarg;
60 break;
62 case 'b':
63 case 'B': BlackPointCompensation =TRUE;
64 break;
67 case 't':
68 case 'T':
69 Intent = atoi(xoptarg);
70 if (Intent > 3) Intent = 3;
71 if (Intent < 0) Intent = 0;
72 break;
74 case 'U':
75 case 'u':
76 Undecorated = TRUE;
77 break;
79 case 'c':
80 case 'C':
81 PrecalcMode = atoi(xoptarg);
82 if (PrecalcMode < 0 || PrecalcMode > 2)
83 FatalError("ERROR: Unknown precalc mode '%d'", PrecalcMode);
84 break;
87 case 'n':
88 case 'N':
89 if (PrecalcMode != 1)
90 FatalError("Precalc mode already specified");
91 NumOfGridPoints = atoi(xoptarg);
92 break;
95 default:
97 FatalError("Unknown option - run without args to see valid ones.\n");
102 static
103 void Help(void)
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");
127 exit(0);
131 static
132 void GenerateCSA(void)
134 cmsHPROFILE hProfile = OpenStockProfile(0, cInProf);
135 size_t n;
136 char* Buffer;
138 if (hProfile == NULL) return;
140 n = cmsGetPostScriptCSA(0, hProfile, Intent, 0, NULL, 0);
141 if (n == 0) return;
143 Buffer = (char*) malloc(n + 1);
144 if (Buffer != NULL) {
146 cmsGetPostScriptCSA(0, hProfile, Intent, 0, Buffer, n);
147 Buffer[n] = 0;
149 fprintf(OutFile, "%s", Buffer);
151 free(Buffer);
154 cmsCloseProfile(hProfile);
158 static
159 void GenerateCRD(void)
161 cmsHPROFILE hProfile = OpenStockProfile(0, cOutProf);
162 size_t n;
163 char* Buffer;
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;
175 case 1:
176 if (NumOfGridPoints > 0)
177 dwFlags |= cmsFLAGS_GRIDPOINTS(NumOfGridPoints);
178 break;
180 default: FatalError("ERROR: Unknown precalculation mode '%d'", PrecalcMode);
183 n = cmsGetPostScriptCRD(0, hProfile, Intent, dwFlags, NULL, 0);
184 if (n == 0) return;
186 Buffer = (char*) malloc(n + 1);
187 cmsGetPostScriptCRD(0, hProfile, Intent, dwFlags, Buffer, n);
188 Buffer[n] = 0;
190 fprintf(OutFile, "%s", Buffer);
191 free(Buffer);
192 cmsCloseProfile(hProfile);
196 int main(int argc, char *argv[])
198 int nargs;
200 // Initialize
201 InitUtils("psicc");
203 HandleSwitches(argc, argv);
205 nargs = (argc - xoptind);
206 if (nargs != 0 && nargs != 1)
207 Help();
209 if (nargs == 0)
210 OutFile = stdout;
211 else
212 OutFile = fopen(argv[xoptind], "wt");
215 if (cInProf == NULL && cOutProf == NULL)
216 Help();
219 if (cInProf != NULL)
220 GenerateCSA();
222 if (cOutProf != NULL)
223 GenerateCRD();
225 if (nargs == 1) {
226 fclose(OutFile);
229 return 0;