1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
//---------------------------------------------------------------------------------
//
// Little Color Management System
// Copyright (c) 1998-2010 Marti Maria Saguer
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//---------------------------------------------------------------------------------
#include "utils.h"
// ------------------------------------------------------------------------
static char *cInProf = NULL;
static char *cOutProf = NULL;
static int Intent = INTENT_PERCEPTUAL;
static FILE* OutFile;
static int BlackPointCompensation = FALSE;
static int Undecorated = FALSE;
static int PrecalcMode = 1;
static int NumOfGridPoints = 0;
// The toggles stuff
static
void HandleSwitches(int argc, char *argv[])
{
int s;
while ((s = xgetopt(argc,argv,"uUbBI:i:O:o:T:t:c:C:n:N:")) != EOF) {
switch (s){
case 'i':
case 'I':
cInProf = xoptarg;
break;
case 'o':
case 'O':
cOutProf = xoptarg;
break;
case 'b':
case 'B': BlackPointCompensation =TRUE;
break;
case 't':
case 'T':
Intent = atoi(xoptarg);
if (Intent > 3) Intent = 3;
if (Intent < 0) Intent = 0;
break;
case 'U':
case 'u':
Undecorated = TRUE;
break;
case 'c':
case 'C':
PrecalcMode = atoi(xoptarg);
if (PrecalcMode < 0 || PrecalcMode > 2)
FatalError("ERROR: Unknown precalc mode '%d'", PrecalcMode);
break;
case 'n':
case 'N':
if (PrecalcMode != 1)
FatalError("Precalc mode already specified");
NumOfGridPoints = atoi(xoptarg);
break;
default:
FatalError("Unknown option - run without args to see valid ones.\n");
}
}
}
static
void Help(void)
{
fprintf(stderr, "little CMS ICC PostScript generator - v2.1 [LittleCMS %2.2f]\n", LCMS_VERSION / 1000.0);
fprintf(stderr, "usage: psicc [flags] [<Output file>]\n\n");
fprintf(stderr, "flags:\n\n");
fprintf(stderr, "%ci<profile> - Input profile: Generates Color Space Array (CSA)\n", SW);
fprintf(stderr, "%co<profile> - Output profile: Generates Color Rendering Dictionary(CRD)\n", SW);
fprintf(stderr, "%ct<0,1,2,3> - Intent (0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute)\n", SW);
fprintf(stderr, "%cb - Black point compensation (CRD only)\n", SW);
fprintf(stderr, "%cu - Do NOT generate resource name on CRD\n", SW);
fprintf(stderr, "%cc<0,1,2> - Precision (0=LowRes, 1=Normal (default), 2=Hi-res) (CRD only)\n", SW);
fprintf(stderr, "%cn<gridpoints> - Alternate way to set precission, number of CLUT points (CRD only)\n", SW);
fprintf(stderr, "\n");
fprintf(stderr, "If no output file is specified, output goes to stdout.\n\n");
fprintf(stderr, "This program is intended to be a demo of the little cms\n"
"engine. Both lcms and this program are freeware. You can\n"
"obtain both in source code at http://www.littlecms.com\n"
"For suggestions, comments, bug reports etc. send mail to\n"
"info@littlecms.com\n\n");
exit(0);
}
static
void GenerateCSA(void)
{
cmsHPROFILE hProfile = OpenStockProfile(0, cInProf);
size_t n;
char* Buffer;
if (hProfile == NULL) return;
n = cmsGetPostScriptCSA(0, hProfile, Intent, 0, NULL, 0);
if (n == 0) return;
Buffer = (char*) malloc(n + 1);
if (Buffer != NULL) {
cmsGetPostScriptCSA(0, hProfile, Intent, 0, Buffer, (cmsUInt32Number) n);
Buffer[n] = 0;
fprintf(OutFile, "%s", Buffer);
free(Buffer);
}
cmsCloseProfile(hProfile);
}
static
void GenerateCRD(void)
{
cmsHPROFILE hProfile = OpenStockProfile(0, cOutProf);
size_t n;
char* Buffer;
cmsUInt32Number dwFlags = 0;
if (hProfile == NULL) return;
if (BlackPointCompensation) dwFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
if (Undecorated) dwFlags |= cmsFLAGS_NODEFAULTRESOURCEDEF;
switch (PrecalcMode) {
case 0: dwFlags |= cmsFLAGS_LOWRESPRECALC; break;
case 2: dwFlags |= cmsFLAGS_HIGHRESPRECALC; break;
case 1:
if (NumOfGridPoints > 0)
dwFlags |= cmsFLAGS_GRIDPOINTS(NumOfGridPoints);
break;
default: FatalError("ERROR: Unknown precalculation mode '%d'", PrecalcMode);
}
n = cmsGetPostScriptCRD(0, hProfile, Intent, dwFlags, NULL, 0);
if (n == 0) return;
Buffer = (char*) malloc(n + 1);
cmsGetPostScriptCRD(0, hProfile, Intent, dwFlags, Buffer, (cmsUInt32Number) n);
Buffer[n] = 0;
fprintf(OutFile, "%s", Buffer);
free(Buffer);
cmsCloseProfile(hProfile);
}
int main(int argc, char *argv[])
{
int nargs;
// Initialize
InitUtils("psicc");
HandleSwitches(argc, argv);
nargs = (argc - xoptind);
if (nargs != 0 && nargs != 1)
Help();
if (cInProf == NULL && cOutProf == NULL)
Help();
if (nargs == 0)
OutFile = stdout;
else
OutFile = fopen(argv[xoptind], "wt");
if (cInProf != NULL)
GenerateCSA();
if (cOutProf != NULL)
GenerateCRD();
if (nargs == 1) {
fclose(OutFile);
}
return 0;
}
|