1 |
– |
/* Copyright (c) 1997 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Calibrate a scanned MacBeth Color Checker Chart |
6 |
|
* |
12 |
|
|
13 |
|
#include <stdio.h> |
14 |
|
#include <math.h> |
15 |
< |
#ifdef MSDOS |
16 |
< |
#include <fcntl.h> |
17 |
< |
#endif |
15 |
> |
#include <time.h> |
16 |
> |
|
17 |
> |
#include "platform.h" |
18 |
> |
#include "rtprocess.h" |
19 |
|
#include "color.h" |
20 |
|
#include "resolu.h" |
21 |
|
#include "pmap.h" |
98 |
|
#define RG_ORIG 02 /* original color region */ |
99 |
|
#define RG_CORR 04 /* corrected color region */ |
100 |
|
|
101 |
+ |
#ifndef DISPCOM |
102 |
+ |
#define DISPCOM "ximage -op %s" |
103 |
+ |
#endif |
104 |
+ |
|
105 |
|
int scanning = 1; /* scanned input (or recorded output)? */ |
106 |
|
double irrad = 1.0; /* irradiance multiplication factor */ |
107 |
|
int rawmap = 0; /* put out raw color mapping? */ |
123 |
|
FILE *debugfp = NULL; /* debug output picture */ |
124 |
|
char *progname; |
125 |
|
|
124 |
– |
extern char *malloc(); |
126 |
|
|
126 |
– |
|
127 |
|
main(argc, argv) |
128 |
|
int argc; |
129 |
|
char **argv; |
141 |
|
perror(argv[i]); |
142 |
|
exit(1); |
143 |
|
} |
144 |
< |
#ifdef MSDOS |
145 |
< |
setmode(fileno(debugfp), O_BINARY); |
146 |
< |
#endif |
144 |
> |
SET_FILE_BINARY(debugfp); |
145 |
|
newheader("RADIANCE", debugfp); /* start */ |
146 |
|
printargs(argc, argv, debugfp); /* header */ |
147 |
|
break; |
158 |
|
bounds[3][1] = atoi(argv[++i]); |
159 |
|
scanning = 2; |
160 |
|
break; |
161 |
+ |
case 'P': /* pick position */ |
162 |
+ |
scanning = 3; |
163 |
+ |
break; |
164 |
|
case 'i': /* irradiance factor */ |
165 |
|
i++; |
166 |
|
if (badarg(argc-i, argv+i, "f")) |
186 |
|
exit(1); |
187 |
|
} |
188 |
|
if (scanning) { /* load input picture header */ |
189 |
< |
#ifdef MSDOS |
189 |
< |
setmode(fileno(stdin), O_BINARY); |
190 |
< |
#endif |
189 |
> |
SET_FILE_BINARY(stdin); |
190 |
|
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
191 |
|
fgetresolu(&xmax, &ymax, stdin) < 0) { |
192 |
|
fprintf(stderr, "%s: bad input picture\n", progname); |
193 |
|
exit(1); |
194 |
|
} |
195 |
+ |
if (scanning == 3) { |
196 |
+ |
if (i >= argc) |
197 |
+ |
goto userr; |
198 |
+ |
pickchartpos(argv[i]); |
199 |
+ |
scanning = 2; |
200 |
+ |
} |
201 |
|
} else { /* else set default xmax and ymax */ |
202 |
|
xmax = 512; |
203 |
|
ymax = 2*512/3; |
219 |
|
|
220 |
|
printf("# Color correspondence produced by:\n#\t\t"); |
221 |
|
printargs(argc, argv, stdout); |
222 |
< |
printf("#\tUsage: pcwarp -m %s uncorrected.pic > corrected.pic\n", |
222 |
> |
printf("#\tUsage: pcwarp %s uncorrected.pic > corrected.pic\n", |
223 |
|
i+1 < argc ? argv[i+1] : "{this_file}"); |
224 |
|
printf("#\t Or: pcond [options] -m %s orig.pic > output.pic\n", |
225 |
|
i+1 < argc ? argv[i+1] : "{this_file}"); |
242 |
|
printf("}\n"); |
243 |
|
putmapping(); /* put out color mapping */ |
244 |
|
} |
245 |
< |
if (debugfp != NULL) /* put out debug picture */ |
245 |
> |
if (debugfp != NULL) { /* put out debug picture */ |
246 |
|
if (scanning) |
247 |
|
picdebug(); |
248 |
|
else |
249 |
|
clrdebug(); |
250 |
+ |
} |
251 |
|
exit(0); |
252 |
|
userr: |
253 |
|
fprintf(stderr, |
254 |
< |
"Usage: %s [-d dbg.pic][-p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.pic [output.{cal|cwp}]\n", |
254 |
> |
"Usage: %s [-d dbg.pic][-P | -p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.pic [output.{cal|cwp}]\n", |
255 |
|
progname); |
256 |
|
fprintf(stderr, " or: %s [-d dbg.pic][-i irrad][-m] -c [xyY.dat [output.{cal|cwp}]]\n", |
257 |
|
progname); |
355 |
|
scalecolor(inpRGB[i], d); |
356 |
|
inpflags |= 1L<<i; |
357 |
|
} |
358 |
< |
free((char *)scanln); |
358 |
> |
free((void *)scanln); |
359 |
|
} |
360 |
|
|
361 |
|
|
367 |
|
float xyYin[3]; |
368 |
|
|
369 |
|
while (fgetval(stdin, 'i', &n) == 1) { /* read colors */ |
370 |
< |
if (n < 0 | n > 24 || |
370 |
> |
if ((n < 0) | (n > 24) || |
371 |
|
fgetval(stdin, 'f', &xyYin[0]) != 1 || |
372 |
|
fgetval(stdin, 'f', &xyYin[1]) != 1 || |
373 |
|
fgetval(stdin, 'f', &xyYin[2]) != 1 || |
374 |
< |
xyYin[0] < 0. | xyYin[1] < 0. || |
374 |
> |
(xyYin[0] < 0.) | (xyYin[1] < 0.) || |
375 |
|
xyYin[0] + xyYin[1] > 1.) { |
376 |
|
fprintf(stderr, "%s: bad color input data\n", |
377 |
|
progname); |
705 |
|
} |
706 |
|
/* clean up */ |
707 |
|
fclose(debugfp); |
708 |
< |
free((char *)scan); |
708 |
> |
free((void *)scan); |
709 |
|
} |
710 |
|
|
711 |
|
|
775 |
|
} |
776 |
|
/* clean up */ |
777 |
|
fclose(debugfp); |
778 |
< |
free((char *)scan); |
778 |
> |
free((void *)scan); |
779 |
> |
} |
780 |
> |
|
781 |
> |
|
782 |
> |
getpos(name, bnds, fp) /* get boundary position */ |
783 |
> |
char *name; |
784 |
> |
int bnds[2]; |
785 |
> |
FILE *fp; |
786 |
> |
{ |
787 |
> |
char buf[64]; |
788 |
> |
|
789 |
> |
fprintf(stderr, "\tSelect corner: %s\n", name); |
790 |
> |
if (fgets(buf, sizeof(buf), fp) == NULL || |
791 |
> |
sscanf(buf, "%d %d", &bnds[0], &bnds[1]) != 2) { |
792 |
> |
fprintf(stderr, "%s: read error from display process\n", |
793 |
> |
progname); |
794 |
> |
exit(1); |
795 |
> |
} |
796 |
> |
} |
797 |
> |
|
798 |
> |
|
799 |
> |
pickchartpos(pfn) /* display picture and pick chart location */ |
800 |
> |
char *pfn; |
801 |
> |
{ |
802 |
> |
char combuf[512]; |
803 |
> |
FILE *pfp; |
804 |
> |
|
805 |
> |
sprintf(combuf, DISPCOM, pfn); |
806 |
> |
if ((pfp = popen(combuf, "r")) == NULL) { |
807 |
> |
perror(combuf); |
808 |
> |
exit(1); |
809 |
> |
} |
810 |
> |
fputs("Use middle mouse button to select chart corners:\n", stderr); |
811 |
> |
getpos("upper left (dark skin)", bounds[0], pfp); |
812 |
> |
getpos("upper right (bluish green)", bounds[1], pfp); |
813 |
> |
getpos("lower left (white)", bounds[2], pfp); |
814 |
> |
getpos("lower right (black)", bounds[3], pfp); |
815 |
> |
fputs("Got it -- quit display program.\n", stderr); |
816 |
> |
pclose(pfp); |
817 |
|
} |