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