121 |
|
WARP3D *wcor = NULL; /* color space warp */ |
122 |
|
|
123 |
|
FILE *debugfp = NULL; /* debug output picture */ |
124 |
– |
char *progname; |
124 |
|
|
125 |
|
static void init(void); |
126 |
|
static int chartndx(int x, int y, int *np); |
127 |
|
static void getpicture(void); |
128 |
|
static void getcolors(void); |
129 |
|
static void bresp(COLOR y, COLOR x); |
130 |
+ |
static void ibresp(COLOR y, COLOR x); |
131 |
|
static void compute(void); |
132 |
|
static void putmapping(void); |
133 |
|
static void compsoln(COLOR cin[], COLOR cout[], int n); |
149 |
|
{ |
150 |
|
int i; |
151 |
|
|
152 |
< |
progname = argv[0]; |
152 |
> |
fixargv0(argv[0]); /* sets global progname */ |
153 |
|
for (i = 1; i < argc && argv[i][0] == '-'; i++) |
154 |
|
switch (argv[i][1]) { |
155 |
|
case 'd': /* debug output */ |
434 |
|
|
435 |
|
static void |
436 |
|
bresp( /* piecewise linear interpolation of primaries */ |
437 |
< |
COLOR y, |
438 |
< |
COLOR x |
437 |
> |
COLOR y, /* y is linear output */ |
438 |
> |
COLOR x /* x is non-linear input */ |
439 |
|
) |
440 |
|
{ |
441 |
|
int i, n; |
454 |
|
|
455 |
|
|
456 |
|
static void |
457 |
+ |
ibresp( /* inverse mapping (delinearization) */ |
458 |
+ |
COLOR x, /* x is non-linear output */ |
459 |
+ |
COLOR y /* y is linear input */ |
460 |
+ |
) |
461 |
+ |
{ |
462 |
+ |
int i, n; |
463 |
+ |
|
464 |
+ |
for (i = 0; i < 3; i++) { |
465 |
+ |
for (n = 0; n < NMBNEU-2; n++) |
466 |
+ |
if (colval(y,i) < colval(bramp[n+1][1],i)) |
467 |
+ |
break; |
468 |
+ |
colval(x,i) = ((colval(bramp[n+1][1],i) - colval(y,i)) * |
469 |
+ |
colval(bramp[n][0],i) + |
470 |
+ |
(colval(y,i) - colval(bramp[n][1],i)) * |
471 |
+ |
colval(bramp[n+1][0],i)) / |
472 |
+ |
(colval(bramp[n+1][1],i) - colval(bramp[n][1],i)); |
473 |
+ |
} |
474 |
+ |
} |
475 |
+ |
|
476 |
+ |
|
477 |
+ |
static void |
478 |
|
compute(void) /* compute color mapping */ |
479 |
|
{ |
480 |
|
COLOR clrin[24], clrout[24]; |
500 |
|
copycolor(bramp[i][1], mbRGB[mbneu[i]]); |
501 |
|
} |
502 |
|
/* compute color space gamut */ |
503 |
< |
if (scanning) { |
504 |
< |
copycolor(colmin, cblack); |
505 |
< |
copycolor(colmax, cwhite); |
506 |
< |
scalecolor(colmax, irrad); |
507 |
< |
} else |
508 |
< |
for (i = 0; i < 3; i++) { |
509 |
< |
colval(colmin,i) = colval(bramp[0][0],i) - |
489 |
< |
colval(bramp[0][1],i) * |
490 |
< |
(colval(bramp[1][0],i)-colval(bramp[0][0],i)) / |
491 |
< |
(colval(bramp[1][1],i)-colval(bramp[0][1],i)); |
492 |
< |
colval(colmax,i) = colval(bramp[NMBNEU-2][0],i) + |
493 |
< |
(1.-colval(bramp[NMBNEU-2][1],i)) * |
494 |
< |
(colval(bramp[NMBNEU-1][0],i) - |
495 |
< |
colval(bramp[NMBNEU-2][0],i)) / |
496 |
< |
(colval(bramp[NMBNEU-1][1],i) - |
497 |
< |
colval(bramp[NMBNEU-2][1],i)); |
498 |
< |
} |
503 |
> |
copycolor(colmin, cblack); |
504 |
> |
copycolor(colmax, cwhite); |
505 |
> |
scalecolor(colmax, irrad); |
506 |
> |
if (!scanning) { |
507 |
> |
ibresp(colmin, colmin); |
508 |
> |
ibresp(colmax, colmax); |
509 |
> |
} |
510 |
|
/* compute color mapping */ |
511 |
|
do { |
512 |
|
cflags = inpflags & ~gmtflags; |
513 |
|
n = 0; /* compute transform matrix */ |
514 |
< |
for (i = 0; i < 24; i++) |
515 |
< |
if (cflags & 1L<<i) { |
514 |
> |
for (i = 0; i < 24; i++) { |
515 |
> |
if (!(cflags & 1L<<i)) |
516 |
> |
continue; |
517 |
> |
if (scanning) { |
518 |
|
bresp(clrin[n], inpRGB[i]); |
519 |
|
copycolor(clrout[n], mbRGB[i]); |
520 |
< |
n++; |
520 |
> |
} else { |
521 |
> |
copycolor(clrin[n], inpRGB[i]); |
522 |
> |
ibresp(clrout[n], mbRGB[i]); |
523 |
|
} |
524 |
+ |
n++; |
525 |
+ |
} |
526 |
|
compsoln(clrin, clrout, n); |
527 |
|
for (i = 0; i < 24; i++) /* check gamut */ |
528 |
|
if (cflags & 1L<<i && cvtcolor(ctmp, inpRGB[i])) |
529 |
|
gmtflags |= 1L<<i; |
530 |
|
} while (cflags & gmtflags); |
531 |
+ |
|
532 |
|
if (gmtflags & MODFLGS) |
533 |
|
fprintf(stderr, |
534 |
|
"%s: warning - some moderate colors are out of gamut\n", |