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 "color.h" |
19 |
|
#include "resolu.h" |
20 |
|
#include "pmap.h" |
97 |
|
#define RG_ORIG 02 /* original color region */ |
98 |
|
#define RG_CORR 04 /* corrected color region */ |
99 |
|
|
100 |
+ |
#ifndef DISPCOM |
101 |
+ |
#define DISPCOM "ximage -op %s" |
102 |
+ |
#endif |
103 |
+ |
|
104 |
|
int scanning = 1; /* scanned input (or recorded output)? */ |
105 |
|
double irrad = 1.0; /* irradiance multiplication factor */ |
106 |
|
int rawmap = 0; /* put out raw color mapping? */ |
122 |
|
FILE *debugfp = NULL; /* debug output picture */ |
123 |
|
char *progname; |
124 |
|
|
124 |
– |
extern char *malloc(); |
125 |
|
|
126 |
– |
|
126 |
|
main(argc, argv) |
127 |
|
int argc; |
128 |
|
char **argv; |
140 |
|
perror(argv[i]); |
141 |
|
exit(1); |
142 |
|
} |
143 |
< |
#ifdef MSDOS |
145 |
< |
setmode(fileno(debugfp), O_BINARY); |
146 |
< |
#endif |
143 |
> |
SET_FILE_BINARY(debugfp); |
144 |
|
newheader("RADIANCE", debugfp); /* start */ |
145 |
|
printargs(argc, argv, debugfp); /* header */ |
146 |
|
break; |
157 |
|
bounds[3][1] = atoi(argv[++i]); |
158 |
|
scanning = 2; |
159 |
|
break; |
160 |
+ |
case 'P': /* pick position */ |
161 |
+ |
scanning = 3; |
162 |
+ |
break; |
163 |
|
case 'i': /* irradiance factor */ |
164 |
|
i++; |
165 |
|
if (badarg(argc-i, argv+i, "f")) |
185 |
|
exit(1); |
186 |
|
} |
187 |
|
if (scanning) { /* load input picture header */ |
188 |
< |
#ifdef MSDOS |
189 |
< |
setmode(fileno(stdin), O_BINARY); |
190 |
< |
#endif |
188 |
> |
SET_FILE_BINARY(stdin); |
189 |
|
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
190 |
|
fgetresolu(&xmax, &ymax, stdin) < 0) { |
191 |
|
fprintf(stderr, "%s: bad input picture\n", progname); |
192 |
|
exit(1); |
193 |
|
} |
194 |
+ |
if (scanning == 3) { |
195 |
+ |
if (i >= argc) |
196 |
+ |
goto userr; |
197 |
+ |
pickchartpos(argv[i]); |
198 |
+ |
scanning = 2; |
199 |
+ |
} |
200 |
|
} else { /* else set default xmax and ymax */ |
201 |
|
xmax = 512; |
202 |
|
ymax = 2*512/3; |
249 |
|
exit(0); |
250 |
|
userr: |
251 |
|
fprintf(stderr, |
252 |
< |
"Usage: %s [-d dbg.pic][-p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.pic [output.{cal|cwp}]\n", |
252 |
> |
"Usage: %s [-d dbg.pic][-P | -p xul yul xur yur xll yll xlr ylr][-i irrad][-m] input.pic [output.{cal|cwp}]\n", |
253 |
|
progname); |
254 |
|
fprintf(stderr, " or: %s [-d dbg.pic][-i irrad][-m] -c [xyY.dat [output.{cal|cwp}]]\n", |
255 |
|
progname); |
353 |
|
scalecolor(inpRGB[i], d); |
354 |
|
inpflags |= 1L<<i; |
355 |
|
} |
356 |
< |
free((char *)scanln); |
356 |
> |
free((void *)scanln); |
357 |
|
} |
358 |
|
|
359 |
|
|
703 |
|
} |
704 |
|
/* clean up */ |
705 |
|
fclose(debugfp); |
706 |
< |
free((char *)scan); |
706 |
> |
free((void *)scan); |
707 |
|
} |
708 |
|
|
709 |
|
|
773 |
|
} |
774 |
|
/* clean up */ |
775 |
|
fclose(debugfp); |
776 |
< |
free((char *)scan); |
776 |
> |
free((void *)scan); |
777 |
> |
} |
778 |
> |
|
779 |
> |
|
780 |
> |
getpos(name, bnds, fp) /* get boundary position */ |
781 |
> |
char *name; |
782 |
> |
int bnds[2]; |
783 |
> |
FILE *fp; |
784 |
> |
{ |
785 |
> |
char buf[64]; |
786 |
> |
|
787 |
> |
fprintf(stderr, "\tSelect corner: %s\n", name); |
788 |
> |
if (fgets(buf, sizeof(buf), fp) == NULL || |
789 |
> |
sscanf(buf, "%d %d", &bnds[0], &bnds[1]) != 2) { |
790 |
> |
fprintf(stderr, "%s: read error from display process\n", |
791 |
> |
progname); |
792 |
> |
exit(1); |
793 |
> |
} |
794 |
> |
} |
795 |
> |
|
796 |
> |
|
797 |
> |
pickchartpos(pfn) /* display picture and pick chart location */ |
798 |
> |
char *pfn; |
799 |
> |
{ |
800 |
> |
char combuf[512]; |
801 |
> |
FILE *pfp; |
802 |
> |
|
803 |
> |
sprintf(combuf, DISPCOM, pfn); |
804 |
> |
if ((pfp = popen(combuf, "r")) == NULL) { |
805 |
> |
perror(combuf); |
806 |
> |
exit(1); |
807 |
> |
} |
808 |
> |
fputs("Use middle mouse button to select chart corners:\n", stderr); |
809 |
> |
getpos("upper left (dark skin)", bounds[0], pfp); |
810 |
> |
getpos("upper right (bluish green)", bounds[1], pfp); |
811 |
> |
getpos("lower left (white)", bounds[2], pfp); |
812 |
> |
getpos("lower right (black)", bounds[3], pfp); |
813 |
> |
fputs("Got it -- quit display program.\n", stderr); |
814 |
> |
pclose(pfp); |
815 |
|
} |