123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- //---------------------------------------------------------------------------------
- //
- // Little Color Management System
- // Copyright (c) 1998-2023 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;
- static
- void Help(void)
- {
- fprintf(stderr, "usage: psicc [flags] [<Output file>]\n\n");
- fprintf(stderr, "flags:\n\n");
- fprintf(stderr, "-i<profile> - Input profile: Generates Color Space Array (CSA)\n");
- fprintf(stderr, "-o<profile> - Output profile: Generates Color Rendering Dictionary(CRD)\n");
- fprintf(stderr, "-t<0,1,2,3> - Intent (0=Perceptual, 1=Colorimetric, 2=Saturation, 3=Absolute)\n");
- fprintf(stderr, "-b - Black point compensation (CRD only)\n");
- fprintf(stderr, "-u - Do NOT generate resource name on CRD\n");
- fprintf(stderr, "-c<0,1,2> - Precision (0=LowRes, 1=Normal (default), 2=Hi-res) (CRD only)\n");
- fprintf(stderr, "-n<gridpoints> - Alternate way to set precision, number of CLUT points (CRD only)\n");
- 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 https://www.littlecms.com\n"
- "For suggestions, comments, bug reports etc. send mail to\n"
- "info@littlecms.com\n\n");
- exit(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 '-':
- if (strcmp(xoptarg, "help") == 0)
- {
- Help();
- }
- else
- {
- FatalError("Unknown option - run without args to see valid ones.\n");
- }
- break;
-
- 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 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);
- if (Buffer == NULL) return;
- 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;
- fprintf(stderr, "Little CMS ICC PostScript generator - v2.1 [LittleCMS %2.2f]\n", cmsGetEncodedCMMversion() / 1000.0);
- fprintf(stderr, "Copyright (c) 1998-2023 Marti Maria Saguer. See COPYING file for details.\n");
- fflush(stderr);
- // 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;
- }
|