Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/lcms2/utils/psicc/psicc.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 //--------------------------------------------------------------------------------- | |
| 2 // | |
| 3 // Little Color Management System | |
| 4 // Copyright (c) 1998-2023 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: | |
| 12 // | |
| 13 // The above copyright notice and this permission notice shall be included in | |
| 14 // all copies or substantial portions of the Software. | |
| 15 // | |
| 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. | |
| 23 // | |
| 24 //--------------------------------------------------------------------------------- | |
| 25 | |
| 26 #include "utils.h" | |
| 27 | |
| 28 // ------------------------------------------------------------------------ | |
| 29 | |
| 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; | |
| 38 | |
| 39 | |
| 40 | |
| 41 static | |
| 42 void Help(void) | |
| 43 { | |
| 44 fprintf(stderr, "usage: psicc [flags] [<Output file>]\n\n"); | |
| 45 | |
| 46 fprintf(stderr, "flags:\n\n"); | |
| 47 | |
| 48 fprintf(stderr, "-i<profile> - Input profile: Generates Color Space Array (CSA)\n"); | |
| 49 fprintf(stderr, "-o<profile> - Output profile: Generates Color Rendering Dictionary(CRD)\n"); | |
| 50 | |
| 51 fprintf(stderr, "-t<0,1,2,3> - Intent (0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute)\n"); | |
| 52 | |
| 53 fprintf(stderr, "-b - Black point compensation (CRD only)\n"); | |
| 54 fprintf(stderr, "-u - Do NOT generate resource name on CRD\n"); | |
| 55 fprintf(stderr, "-c<0,1,2> - Precision (0=LowRes, 1=Normal (default), 2=Hi-res) (CRD only)\n"); | |
| 56 fprintf(stderr, "-n<gridpoints> - Alternate way to set precision, number of CLUT points (CRD only)\n"); | |
| 57 | |
| 58 fprintf(stderr, "\n"); | |
| 59 fprintf(stderr, "If no output file is specified, output goes to stdout.\n\n"); | |
| 60 fprintf(stderr, "This program is intended to be a demo of the little cms\n" | |
| 61 "engine. Both lcms and this program are freeware. You can\n" | |
| 62 "obtain both in source code at https://www.littlecms.com\n" | |
| 63 "For suggestions, comments, bug reports etc. send mail to\n" | |
| 64 "info@littlecms.com\n\n"); | |
| 65 | |
| 66 exit(0); | |
| 67 } | |
| 68 | |
| 69 // The toggles stuff | |
| 70 | |
| 71 static | |
| 72 void HandleSwitches(int argc, char *argv[]) | |
| 73 { | |
| 74 int s; | |
| 75 | |
| 76 while ((s = xgetopt(argc,argv,"uUbBI:i:O:o:T:t:c:C:n:N:-:")) != EOF) { | |
| 77 | |
| 78 switch (s) | |
| 79 { | |
| 80 | |
| 81 case '-': | |
| 82 if (strcmp(xoptarg, "help") == 0) | |
| 83 { | |
| 84 Help(); | |
| 85 } | |
| 86 else | |
| 87 { | |
| 88 FatalError("Unknown option - run without args to see valid ones.\n"); | |
| 89 } | |
| 90 break; | |
| 91 | |
| 92 case 'i': | |
| 93 case 'I': | |
| 94 cInProf = xoptarg; | |
| 95 break; | |
| 96 | |
| 97 case 'o': | |
| 98 case 'O': | |
| 99 cOutProf = xoptarg; | |
| 100 break; | |
| 101 | |
| 102 case 'b': | |
| 103 case 'B': BlackPointCompensation =TRUE; | |
| 104 break; | |
| 105 | |
| 106 | |
| 107 case 't': | |
| 108 case 'T': | |
| 109 Intent = atoi(xoptarg); | |
| 110 if (Intent > 3) Intent = 3; | |
| 111 if (Intent < 0) Intent = 0; | |
| 112 break; | |
| 113 | |
| 114 case 'U': | |
| 115 case 'u': | |
| 116 Undecorated = TRUE; | |
| 117 break; | |
| 118 | |
| 119 case 'c': | |
| 120 case 'C': | |
| 121 PrecalcMode = atoi(xoptarg); | |
| 122 if (PrecalcMode < 0 || PrecalcMode > 2) | |
| 123 FatalError("ERROR: Unknown precalc mode '%d'", PrecalcMode); | |
| 124 break; | |
| 125 | |
| 126 | |
| 127 case 'n': | |
| 128 case 'N': | |
| 129 if (PrecalcMode != 1) | |
| 130 FatalError("Precalc mode already specified"); | |
| 131 NumOfGridPoints = atoi(xoptarg); | |
| 132 break; | |
| 133 | |
| 134 | |
| 135 default: | |
| 136 | |
| 137 FatalError("Unknown option - run without args to see valid ones.\n"); | |
| 138 } | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 static | |
| 146 void GenerateCSA(cmsContext ContextID) | |
| 147 { | |
| 148 cmsHPROFILE hProfile = OpenStockProfile(ContextID, cInProf); | |
| 149 size_t n; | |
| 150 char* Buffer; | |
| 151 | |
| 152 if (hProfile == NULL) return; | |
| 153 | |
| 154 n = cmsGetPostScriptCSA(ContextID, hProfile, Intent, 0, NULL, 0); | |
| 155 if (n == 0) return; | |
| 156 | |
| 157 Buffer = (char*) malloc(n + 1); | |
| 158 if (Buffer != NULL) { | |
| 159 | |
| 160 cmsGetPostScriptCSA(ContextID, hProfile, Intent, 0, Buffer, (cmsUInt32Number) n); | |
| 161 Buffer[n] = 0; | |
| 162 | |
| 163 fprintf(OutFile, "%s", Buffer); | |
| 164 | |
| 165 free(Buffer); | |
| 166 } | |
| 167 | |
| 168 cmsCloseProfile(ContextID, hProfile); | |
| 169 } | |
| 170 | |
| 171 | |
| 172 static | |
| 173 void GenerateCRD(cmsContext ContextID) | |
| 174 { | |
| 175 cmsHPROFILE hProfile = OpenStockProfile(ContextID, cOutProf); | |
| 176 size_t n; | |
| 177 char* Buffer; | |
| 178 cmsUInt32Number dwFlags = 0; | |
| 179 | |
| 180 if (hProfile == NULL) return; | |
| 181 | |
| 182 if (BlackPointCompensation) dwFlags |= cmsFLAGS_BLACKPOINTCOMPENSATION; | |
| 183 if (Undecorated) dwFlags |= cmsFLAGS_NODEFAULTRESOURCEDEF; | |
| 184 | |
| 185 switch (PrecalcMode) { | |
| 186 | |
| 187 case 0: dwFlags |= cmsFLAGS_LOWRESPRECALC; break; | |
| 188 case 2: dwFlags |= cmsFLAGS_HIGHRESPRECALC; break; | |
| 189 case 1: | |
| 190 if (NumOfGridPoints > 0) | |
| 191 dwFlags |= cmsFLAGS_GRIDPOINTS(NumOfGridPoints); | |
| 192 break; | |
| 193 | |
| 194 default: FatalError("ERROR: Unknown precalculation mode '%d'", PrecalcMode); | |
| 195 } | |
| 196 | |
| 197 n = cmsGetPostScriptCRD(ContextID, hProfile, Intent, dwFlags, NULL, 0); | |
| 198 if (n == 0) return; | |
| 199 | |
| 200 Buffer = (char*) malloc(n + 1); | |
| 201 if (Buffer == NULL) return; | |
| 202 cmsGetPostScriptCRD(ContextID, hProfile, Intent, dwFlags, Buffer, (cmsUInt32Number) n); | |
| 203 Buffer[n] = 0; | |
| 204 | |
| 205 fprintf(OutFile, "%s", Buffer); | |
| 206 free(Buffer); | |
| 207 cmsCloseProfile(ContextID, hProfile); | |
| 208 } | |
| 209 | |
| 210 | |
| 211 int main(int argc, char *argv[]) | |
| 212 { | |
| 213 int nargs; | |
| 214 cmsContext ContextID = NULL; | |
| 215 | |
| 216 fprintf(stderr, "Little CMS ICC PostScript generator - v2.1 [LittleCMS %2.2f]\n", cmsGetEncodedCMMversion() / 1000.0); | |
| 217 fprintf(stderr, "Copyright (c) 1998-2023 Marti Maria Saguer. See COPYING file for details.\n"); | |
| 218 fflush(stderr); | |
| 219 | |
| 220 // Initialize | |
| 221 InitUtils(NULL, "psicc"); | |
| 222 | |
| 223 HandleSwitches(argc, argv); | |
| 224 | |
| 225 nargs = (argc - xoptind); | |
| 226 if (nargs != 0 && nargs != 1) | |
| 227 Help(); | |
| 228 | |
| 229 if (cInProf == NULL && cOutProf == NULL) | |
| 230 Help(); | |
| 231 | |
| 232 if (nargs == 0) | |
| 233 OutFile = stdout; | |
| 234 else | |
| 235 OutFile = fopen(argv[xoptind], "wt"); | |
| 236 | |
| 237 if (cInProf != NULL) | |
| 238 GenerateCSA(ContextID); | |
| 239 | |
| 240 if (cOutProf != NULL) | |
| 241 GenerateCRD(ContextID); | |
| 242 | |
| 243 if (nargs == 1) { | |
| 244 fclose(OutFile); | |
| 245 } | |
| 246 | |
| 247 return 0; | |
| 248 } |
