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 |
|
* |
15 |
|
#ifdef MSDOS |
16 |
|
#include <fcntl.h> |
17 |
|
#endif |
18 |
+ |
#include <time.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; |
160 |
|
bounds[3][1] = atoi(argv[++i]); |
161 |
|
scanning = 2; |
162 |
|
break; |
163 |
+ |
case 'P': /* pick position */ |
164 |
+ |
scanning = 3; |
165 |
+ |
break; |
166 |
|
case 'i': /* irradiance factor */ |
167 |
|
i++; |
168 |
|
if (badarg(argc-i, argv+i, "f")) |
196 |
|
fprintf(stderr, "%s: bad input picture\n", progname); |
197 |
|
exit(1); |
198 |
|
} |
199 |
+ |
if (scanning == 3) { |
200 |
+ |
if (i >= argc) |
201 |
+ |
goto userr; |
202 |
+ |
pickchartpos(argv[i]); |
203 |
+ |
scanning = 2; |
204 |
+ |
} |
205 |
|
} else { /* else set default xmax and ymax */ |
206 |
|
xmax = 512; |
207 |
|
ymax = 2*512/3; |
223 |
|
|
224 |
|
printf("# Color correspondence produced by:\n#\t\t"); |
225 |
|
printargs(argc, argv, stdout); |
226 |
< |
printf("#\tUsage: pcwarp -m %s uncorrected.pic > corrected.pic\n", |
226 |
> |
printf("#\tUsage: pcwarp %s uncorrected.pic > corrected.pic\n", |
227 |
|
i+1 < argc ? argv[i+1] : "{this_file}"); |
228 |
|
printf("#\t Or: pcond [options] -m %s orig.pic > output.pic\n", |
229 |
|
i+1 < argc ? argv[i+1] : "{this_file}"); |
254 |
|
exit(0); |
255 |
|
userr: |
256 |
|
fprintf(stderr, |
257 |
< |
"Usage: %s [-d dbg.pic][-p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.pic [output.{cal|cwp}]\n", |
257 |
> |
"Usage: %s [-d dbg.pic][-P | -p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.pic [output.{cal|cwp}]\n", |
258 |
|
progname); |
259 |
|
fprintf(stderr, " or: %s [-d dbg.pic][-i irrad][-m] -c [xyY.dat [output.{cal|cwp}]]\n", |
260 |
|
progname); |
358 |
|
scalecolor(inpRGB[i], d); |
359 |
|
inpflags |= 1L<<i; |
360 |
|
} |
361 |
< |
free((char *)scanln); |
361 |
> |
free((void *)scanln); |
362 |
|
} |
363 |
|
|
364 |
|
|
708 |
|
} |
709 |
|
/* clean up */ |
710 |
|
fclose(debugfp); |
711 |
< |
free((char *)scan); |
711 |
> |
free((void *)scan); |
712 |
|
} |
713 |
|
|
714 |
|
|
778 |
|
} |
779 |
|
/* clean up */ |
780 |
|
fclose(debugfp); |
781 |
< |
free((char *)scan); |
781 |
> |
free((void *)scan); |
782 |
> |
} |
783 |
> |
|
784 |
> |
|
785 |
> |
getpos(name, bnds, fp) /* get boundary position */ |
786 |
> |
char *name; |
787 |
> |
int bnds[2]; |
788 |
> |
FILE *fp; |
789 |
> |
{ |
790 |
> |
char buf[64]; |
791 |
> |
|
792 |
> |
fprintf(stderr, "\tSelect corner: %s\n", name); |
793 |
> |
if (fgets(buf, sizeof(buf), fp) == NULL || |
794 |
> |
sscanf(buf, "%d %d", &bnds[0], &bnds[1]) != 2) { |
795 |
> |
fprintf(stderr, "%s: read error from display process\n", |
796 |
> |
progname); |
797 |
> |
exit(1); |
798 |
> |
} |
799 |
> |
} |
800 |
> |
|
801 |
> |
|
802 |
> |
pickchartpos(pfn) /* display picture and pick chart location */ |
803 |
> |
char *pfn; |
804 |
> |
{ |
805 |
> |
char combuf[512]; |
806 |
> |
FILE *pfp; |
807 |
> |
|
808 |
> |
sprintf(combuf, DISPCOM, pfn); |
809 |
> |
if ((pfp = popen(combuf, "r")) == NULL) { |
810 |
> |
perror(combuf); |
811 |
> |
exit(1); |
812 |
> |
} |
813 |
> |
fputs("Use middle mouse button to select chart corners:\n", stderr); |
814 |
> |
getpos("upper left (dark skin)", bounds[0], pfp); |
815 |
> |
getpos("upper right (bluish green)", bounds[1], pfp); |
816 |
> |
getpos("lower left (white)", bounds[2], pfp); |
817 |
> |
getpos("lower right (black)", bounds[3], pfp); |
818 |
> |
fputs("Got it -- quit display program.\n", stderr); |
819 |
> |
pclose(pfp); |
820 |
|
} |