90 |
|
#define REQFLGS NEUFLGS /* need these colors */ |
91 |
|
#define MODFLGS (NEUFLGS|UNSFLGS) /* should be in gamut */ |
92 |
|
|
93 |
< |
#define CENTCVG 0.3 /* measured coverage of square sample */ |
94 |
< |
#define FULLCVG 0.9 /* coverage of entire square */ |
93 |
> |
#define RG_BORD 0 /* patch border */ |
94 |
> |
#define RG_CENT 01 /* central region of patch */ |
95 |
> |
#define RG_ORIG 02 /* original color region */ |
96 |
> |
#define RG_CORR 04 /* corrected color region */ |
97 |
|
|
98 |
|
int xmax, ymax; /* input image dimensions */ |
99 |
|
int bounds[4][2]; /* image coordinates of chart corners */ |
235 |
|
|
236 |
|
|
237 |
|
int |
238 |
< |
chartndx(x, y, cvg) /* find color number for position */ |
238 |
> |
chartndx(x, y, np) /* find color number for position */ |
239 |
|
int x, y; |
240 |
< |
double cvg; |
240 |
> |
int *np; |
241 |
|
{ |
242 |
|
double ipos[3], cpos[3]; |
243 |
|
int ix, iy; |
244 |
|
double fx, fy; |
243 |
– |
double cmin, cmax; |
245 |
|
|
246 |
|
ipos[0] = x; |
247 |
|
ipos[1] = y; |
250 |
|
cpos[0] /= cpos[2]; |
251 |
|
cpos[1] /= cpos[2]; |
252 |
|
if (cpos[0] < 0. || cpos[0] >= 6. || cpos[1] < 0. || cpos[1] >= 4.) |
253 |
< |
return(-1); |
253 |
> |
return(RG_BORD); |
254 |
|
ix = cpos[0]; |
255 |
|
iy = cpos[1]; |
256 |
|
fx = cpos[0] - ix; |
257 |
|
fy = cpos[1] - iy; |
258 |
< |
cmin = .5*(1.-cvg); |
259 |
< |
cmax = 1. - cmin; |
260 |
< |
if (fx < cmin || fx >= cmax || fy < cmin || fy >= cmax) |
261 |
< |
return(-1); |
262 |
< |
return(iy*6 + ix); |
258 |
> |
*np = iy*6 + ix; |
259 |
> |
if (fx >= 0.35 && fx < 0.65 && fy >= 0.35 && fy < 0.65) |
260 |
> |
return(RG_CENT); |
261 |
> |
if (fx < 0.05 || fx >= 0.95 || fy < 0.05 || fy >= 0.95) |
262 |
> |
return(RG_BORD); |
263 |
> |
if (fx >= 0.5) /* right side is corrected */ |
264 |
> |
return(RG_CORR); |
265 |
> |
return(RG_ORIG); /* left side is original */ |
266 |
|
} |
267 |
|
|
268 |
|
|
272 |
|
COLOR pval; |
273 |
|
int ccount[24]; |
274 |
|
double d; |
275 |
< |
int y; |
276 |
< |
register int x, i; |
275 |
> |
int y, i; |
276 |
> |
register int x; |
277 |
|
|
278 |
|
scanln = (COLR *)malloc(xmax*sizeof(COLR)); |
279 |
|
if (scanln == NULL) { |
290 |
|
progname); |
291 |
|
exit(1); |
292 |
|
} |
293 |
< |
for (x = 0; x < xmax; x++) { |
294 |
< |
i = chartndx(x, y, CENTCVG); |
291 |
< |
if (i >= 0) { |
293 |
> |
for (x = 0; x < xmax; x++) |
294 |
> |
if (chartndx(x, y, &i) == RG_CENT) { |
295 |
|
colr_color(pval, scanln[x]); |
296 |
|
addcolor(inpRGB[i], pval); |
297 |
|
ccount[i]++; |
298 |
|
} |
296 |
– |
} |
299 |
|
} |
300 |
|
for (i = 0; i < 24; i++) { /* compute averages */ |
301 |
|
if (ccount[i] == 0) |
569 |
|
{ |
570 |
|
static COLOR blkcol = BLKCOLOR; |
571 |
|
COLOR *scan; |
572 |
< |
int y; |
573 |
< |
register int x, i; |
572 |
> |
int y, i; |
573 |
> |
register int x, rg; |
574 |
|
|
575 |
|
if (fseek(stdin, 0L, 0) == EOF) { |
576 |
|
fprintf(stderr, "%s: cannot seek on input picture\n", progname); |
596 |
|
exit(1); |
597 |
|
} |
598 |
|
for (x = 0; x < xmax; x++) { |
599 |
< |
i = chartndx(x, y, CENTCVG); |
600 |
< |
if (i < 0) |
599 |
> |
rg = chartndx(x, y, &i); |
600 |
> |
if (rg == RG_CENT) { |
601 |
> |
if (!(1L<<i & gmtflags) || (x+y)&07) |
602 |
> |
copycolor(scan[x], mbRGB[i]); |
603 |
> |
else |
604 |
> |
copycolor(scan[x], blkcol); |
605 |
> |
} else if (rg == RG_CORR) |
606 |
|
cvtcolor(scan[x], scan[x]); |
607 |
< |
else if (!(1L<<i & gmtflags) || (x+y)&07) |
601 |
< |
copycolor(scan[x], mbRGB[i]); |
602 |
< |
else |
607 |
> |
else if (rg != RG_ORIG) |
608 |
|
copycolor(scan[x], blkcol); |
609 |
|
} |
610 |
|
if (fwritescan(scan, xmax, debugfp) < 0) { |
622 |
|
clrdebug() /* put out debug picture from color input */ |
623 |
|
{ |
624 |
|
static COLR blkclr = BLKCOLR; |
625 |
< |
COLR mbclr[24], cvclr[24]; |
625 |
> |
COLR mbclr[24], cvclr[24], orclr[24]; |
626 |
|
COLR *scan; |
627 |
|
COLOR ctmp; |
628 |
< |
int y; |
629 |
< |
register int i, x; |
628 |
> |
int y, i; |
629 |
> |
register int x, rg; |
630 |
|
/* convert colors */ |
631 |
|
for (i = 0; i < 24; i++) { |
632 |
|
setcolr(mbclr[i], colval(mbRGB[i],RED), |
633 |
|
colval(mbRGB[i],GRN), colval(mbRGB[i],BLU)); |
634 |
|
if (inpflags & 1L<<i) { |
635 |
+ |
setcolr(orclr[i], colval(inpRGB[i],RED), |
636 |
+ |
colval(inpRGB[i],GRN), |
637 |
+ |
colval(inpRGB[i],BLU)); |
638 |
|
cvtcolor(ctmp, inpRGB[i]); |
639 |
|
setcolr(cvclr[i], colval(ctmp,RED), |
640 |
|
colval(ctmp,GRN), colval(ctmp,BLU)); |
652 |
|
fprtresolu(xmax, ymax, debugfp); |
653 |
|
/* write debug picture */ |
654 |
|
for (y = ymax-1; y >= 0; y--) { |
655 |
< |
for (x = 0; x < xmax; x++) |
656 |
< |
if ((i = chartndx(x, y, CENTCVG)) >= 0) { |
655 |
> |
for (x = 0; x < xmax; x++) { |
656 |
> |
rg = chartndx(x, y, &i); |
657 |
> |
if (rg == RG_CENT) { |
658 |
|
if (!(1L<<i & gmtflags) || (x+y)&07) |
659 |
|
copycolr(scan[x], mbclr[i]); |
660 |
|
else |
661 |
|
copycolr(scan[x], blkclr); |
662 |
< |
} else if ((i = chartndx(x, y, FULLCVG)) >= 0 && |
654 |
< |
inpflags & 1L<<i) |
655 |
< |
copycolr(scan[x], cvclr[i]); |
656 |
< |
else |
662 |
> |
} else if (rg == RG_BORD || !(1L<<i & inpflags)) |
663 |
|
copycolr(scan[x], blkclr); |
664 |
+ |
else if (rg == RG_ORIG) |
665 |
+ |
copycolr(scan[x], orclr[i]); |
666 |
+ |
else /* rg == RG_CORR */ |
667 |
+ |
copycolr(scan[x], cvclr[i]); |
668 |
+ |
} |
669 |
|
if (fwritecolrs(scan, xmax, debugfp) < 0) { |
670 |
|
fprintf(stderr, "%s: error writing debugging picture\n", |
671 |
|
progname); |