// Get input from user static void GetLine(char* Buffer, const char* frm, ...) { int res; va_list args; va_start(args, frm); do { if (xisatty(stdin)) vfprintf(stderr, frm, args); res = scanf("%4095s", Buffer); if (res < 0 || toupper(Buffer[0]) == 'Q') { // Quit? CloseTransforms(); if (xisatty(stdin)) fprintf(stderr, "Done.\n"); exit(0); } } while (res == 0); va_end(args); }
int main(int argc, char *argv[]) { WORD Input[MAXCHANNELS], Output[MAXCHANNELS], PCSLab[MAXCHANNELS], PCSxyz[MAXCHANNELS]; fprintf(stderr, "little cms ColorSpace conversion calculator - v1.8\n\n"); if (argc == 1) Help(); HandleSwitches(argc, argv); cmsSetErrorHandler(MyErrorHandler); OpenTransforms(); for(;;) { if (xisatty(stdin)) printf("\nEnter values, 'q' to quit\n"); if (feof(stdin)) break; TakeValues(Input); cmsDoTransform(hTrans, Input, Output, 1); if (Verbose) { if (hTransXYZ) cmsDoTransform(hTransXYZ, Input, PCSxyz, 1); if (hTransLab) cmsDoTransform(hTransLab, Input, PCSLab, 1); } if (xisatty(stdin)) printf("\n"); PrintResults(Output, OutputColorSpace); printf("\n"); if (Verbose && hTransXYZ && hTransLab) { PrintResults(PCSxyz, icSigXYZData); printf("\n"); PrintResults(PCSLab, icSigLabData); printf("\n"); } } return 0; }
static double GetAnswer(const char* Prompt, double Range) { char Buffer[4096]; double val = 0.0; if (Range == 0.0) { // Range 0 means double value if (xisatty(stdin)) printf("%s? ", Prompt); GetLine(Buffer); return atof(Buffer); } else { if (InHexa) { // Hexadecimal int hexa; if (Width16) Range = 0xFFFF; else Range = 0xFF; if (xisatty(stdin)) printf("%s (0..%X)? ", Prompt, (int) Range); GetLine(Buffer); sscanf(Buffer, "%x", &hexa); val = hexa; } else { // Normal usage if (xisatty(stdin)) printf("%s (0..%d)? ", Prompt, (int) Range); GetLine(Buffer); sscanf(Buffer, "%lf", &val); } // Normalize to 0..0xffff return floor((val * 65535.0) / Range + 0.5); } }
// Read values from a text file or terminal static void TakeFloatValues(cmsFloat64Number Float[]) { cmsUInt32Number i, n; char ChannelName[cmsMAX_PATH]; char Buffer[4096]; if (xisatty(stdin)) fprintf(stderr, "\nEnter values, 'q' to quit\n"); if (InputNamedColor) { // This is named color index, which is always cmsUInt16Number cmsUInt16Number index = GetIndex(); memcpy(Float, &index, sizeof(cmsUInt16Number)); return; } n = cmsChannelsOf(InputColorSpace); for (i=0; i < n; i++) { if (InputColorant) { cmsNamedColorInfo(InputColorant, i, ChannelName, NULL, NULL, NULL, NULL); } else { InputRange = 1; sprintf(ChannelName, "Channel #%u", i+1); } GetLine(Buffer, "%s? ", ChannelName); Float[i] = (cmsFloat64Number) atof(Buffer) / InputRange; } if (xisatty(stdin)) fprintf(stderr, "\n"); }
static void GetLine(char* Buffer) { scanf("%s", Buffer); if (toupper(Buffer[0]) == 'Q') { // Quit? CloseTransforms(); if (xisatty(stdin)) printf("Done.\n"); exit(0); } }
static WORD GetIndex(void) { char Buffer[4096], Name[40], Prefix[40], Suffix[40]; int index, max; max = cmsNamedColorCount(hTrans)-1; if (xisatty(stdin)) printf("Color index (0..%d)? ", max); GetLine(Buffer); index = atoi(Buffer); if (index > max) FatalError("Named color %d out of range!", index); cmsNamedColorInfo(hTrans, index, Name, Prefix, Suffix); printf("\n%s %s %s: ", Prefix, Name, Suffix); return index; }