28 |
|
#define C_XYZE 0x10 /* Radiance is XYZE */ |
29 |
|
#define C_RFLT 0x20 /* Radiance data is float */ |
30 |
|
#define C_TFLT 0x40 /* TIFF data is float */ |
31 |
< |
#define C_PRIM 0x80 /* has assigned primaries */ |
31 |
> |
#define C_TWRD 0x80 /* TIFF data is 16-bit */ |
32 |
> |
#define C_PRIM 0x100 /* has assigned primaries */ |
33 |
|
|
34 |
|
struct { |
35 |
|
uint16 flags; /* conversion flags (defined above) */ |
53 |
|
} r; /* Radiance scanline */ |
54 |
|
union { |
55 |
|
uint8 *bp; /* byte pointer */ |
56 |
+ |
uint16 *wp; /* word pointer */ |
57 |
|
float *fp; /* float pointer */ |
58 |
|
char *p; /* generic pointer */ |
59 |
|
} t; /* TIFF scanline */ |
70 |
|
|
71 |
|
int Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr(); |
72 |
|
int Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry(); |
73 |
+ |
int RRGGBB2Color(), GGry2Color(); |
74 |
|
|
75 |
|
short ortab[8] = { /* orientation conversion table */ |
76 |
|
YMAJOR|YDECR, |
187 |
|
int rsiz, tsiz; |
188 |
|
|
189 |
|
rsiz = CHK(C_RFLT) ? sizeof(COLOR) : sizeof(COLR); |
190 |
< |
tsiz = (CHK(C_TFLT) ? sizeof(float) : sizeof(uint8)) * |
190 |
> |
tsiz = (CHK(C_TFLT) ? sizeof(float) : |
191 |
> |
CHK(C_TWRD) ? sizeof(uint16) : sizeof(uint8)) * |
192 |
|
(CHK(C_GRY) ? 1 : 3); |
193 |
|
cvts.r.p = (char *)malloc(rsiz*cvts.xmax); |
194 |
|
cvts.t.p = (char *)malloc(tsiz*cvts.xmax); |
265 |
|
quiterr("unsupported photometric type"); |
266 |
|
/* fall through */ |
267 |
|
case PHOTOMETRIC_RGB: |
268 |
< |
SET(C_GAMMA|C_GAMUT); |
268 |
> |
SET(C_GAMMA); |
269 |
|
setcolrgam(cvts.gamcor); |
270 |
|
if (CHK(C_XYZE)) { |
271 |
|
comprgb2xyzmat(cvts.cmat, |
276 |
|
hi != 3) |
277 |
|
quiterr("unsupported samples per pixel for RGB"); |
278 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi) || |
279 |
< |
hi != 8) |
279 |
> |
hi != 8 & hi != 16) |
280 |
|
quiterr("unsupported bits per sample for RGB"); |
281 |
< |
cvts.tf = RGB2Colr; |
281 |
> |
if (hi == 8) |
282 |
> |
cvts.tf = RGB2Colr; |
283 |
> |
else { |
284 |
> |
cvts.tf = RRGGBB2Color; |
285 |
> |
SET(C_RFLT|C_TWRD); |
286 |
> |
} |
287 |
|
break; |
288 |
|
case PHOTOMETRIC_MINISBLACK: |
289 |
< |
SET(C_GRY|C_GAMMA|C_GAMUT); |
289 |
> |
SET(C_GRY|C_GAMMA); |
290 |
> |
setcolrgam(cvts.gamcor); |
291 |
|
cvts.pconf = PLANARCONFIG_CONTIG; |
292 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_SAMPLESPERPIXEL, &hi) || |
293 |
|
hi != 1) |
294 |
|
quiterr("unsupported samples per pixel for greyscale"); |
295 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi) || |
296 |
< |
hi != 8) |
296 |
> |
hi != 8 & hi != 16) |
297 |
|
quiterr("unsupported bits per sample for greyscale"); |
298 |
< |
cvts.tf = Gry2Colr; |
298 |
> |
if (hi == 8) |
299 |
> |
cvts.tf = Gry2Colr; |
300 |
> |
else { |
301 |
> |
cvts.tf = GGry2Color; |
302 |
> |
SET(C_RFLT|C_TWRD); |
303 |
> |
} |
304 |
|
break; |
305 |
|
default: |
306 |
|
quiterr("unsupported photometric type"); |
374 |
|
SET(C_XYZE); |
375 |
|
else |
376 |
|
quiterr("unrecognized input picture format"); |
377 |
< |
return; |
377 |
> |
return(1); |
378 |
|
} |
379 |
|
if (isexpos(s)) { |
380 |
|
cvts.stonits /= exposval(s); |
381 |
< |
return; |
381 |
> |
return(1); |
382 |
|
} |
383 |
|
if (isaspect(s)) { |
384 |
|
cvts.pixrat *= aspectval(s); |
385 |
< |
return; |
385 |
> |
return(1); |
386 |
|
} |
387 |
|
if (isprims(s)) { |
388 |
|
primsval(cvts.prims, s); |
389 |
|
SET(C_PRIM); |
390 |
< |
return; |
390 |
> |
return(1); |
391 |
|
} |
392 |
+ |
return(0); |
393 |
|
} |
394 |
|
|
395 |
|
|
523 |
|
{ |
524 |
|
register int x; |
525 |
|
|
526 |
< |
if (CHK(C_RFLT|C_TFLT) != (C_RFLT|C_TFLT) | CHK(C_GRY)) |
526 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
527 |
|
quiterr("internal error 1 in Luv2Color"); |
528 |
|
|
529 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
530 |
|
quiterr("error reading TIFF input"); |
531 |
|
|
532 |
|
for (x = cvts.xmax; x--; ) { |
533 |
< |
cvts.r.colors[x][RED] = cvts.t.fp[3*x]; |
534 |
< |
cvts.r.colors[x][GRN] = cvts.t.fp[3*x + 1]; |
535 |
< |
cvts.r.colors[x][BLU] = cvts.t.fp[3*x + 2]; |
533 |
> |
colval(cvts.r.colors[x],CIEX) = cvts.t.fp[3*x]; |
534 |
> |
colval(cvts.r.colors[x],CIEY) = cvts.t.fp[3*x + 1]; |
535 |
> |
colval(cvts.r.colors[x],CIEZ) = cvts.t.fp[3*x + 2]; |
536 |
|
if (CHK(C_CXFM)) |
537 |
|
colortrans(cvts.r.colors[x], cvts.cmat, |
538 |
|
cvts.r.colors[x]); |
552 |
|
|
553 |
|
|
554 |
|
int |
555 |
+ |
RRGGBB2Color(y) /* read/convert/write RGB16->COLOR scanline */ |
556 |
+ |
uint32 y; |
557 |
+ |
{ |
558 |
+ |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
559 |
+ |
register double d; |
560 |
+ |
register int x; |
561 |
+ |
|
562 |
+ |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_TWRD|C_RFLT)) |
563 |
+ |
quiterr("internal error 1 in RRGGBB2Color"); |
564 |
+ |
|
565 |
+ |
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
566 |
+ |
quiterr("error reading TIFF input"); |
567 |
+ |
|
568 |
+ |
for (x = cvts.xmax; x--; ) { |
569 |
+ |
d = (cvts.t.wp[3*x] + 0.5)*(1./(1L<<16)); |
570 |
+ |
if (dogamma) d = pow(d, cvts.gamcor); |
571 |
+ |
colval(cvts.r.colors[x],RED) = d; |
572 |
+ |
d = (cvts.t.wp[3*x + 1] + 0.5)*(1./(1L<<16)); |
573 |
+ |
if (dogamma) d = pow(d, cvts.gamcor); |
574 |
+ |
colval(cvts.r.colors[x],GRN) = d; |
575 |
+ |
d = (cvts.t.wp[3*x + 2] + 0.5)*(1./(1L<<16)); |
576 |
+ |
if (dogamma) d = pow(d, cvts.gamcor); |
577 |
+ |
colval(cvts.r.colors[x],BLU) = d; |
578 |
+ |
if (CHK(C_CXFM)) |
579 |
+ |
colortrans(cvts.r.colors[x], cvts.cmat, |
580 |
+ |
cvts.r.colors[x]); |
581 |
+ |
if (CHK(C_GAMUT)) |
582 |
+ |
clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1], |
583 |
+ |
CGAMUT_LOWER, cblack, cwhite); |
584 |
+ |
} |
585 |
+ |
if (cvts.bradj) { |
586 |
+ |
d = pow(2.,(double)cvts.bradj); |
587 |
+ |
for (x = cvts.xmax; x--; ) |
588 |
+ |
scalecolor(cvts.r.colors[x], d); |
589 |
+ |
} |
590 |
+ |
|
591 |
+ |
if (fwritescan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
592 |
+ |
quiterr("error writing Radiance picture"); |
593 |
+ |
} |
594 |
+ |
|
595 |
+ |
|
596 |
+ |
int |
597 |
|
L2Color(y) /* read/convert/write L16->COLOR scanline */ |
598 |
|
uint32 y; |
599 |
|
{ |
600 |
|
register int x; |
601 |
|
|
602 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
602 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
603 |
|
quiterr("internal error 1 in L2Color"); |
604 |
|
|
605 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
606 |
|
quiterr("error reading TIFF input"); |
607 |
|
|
608 |
|
for (x = cvts.xmax; x--; ) |
609 |
< |
cvts.r.colors[x][RED] = |
610 |
< |
cvts.r.colors[x][GRN] = |
611 |
< |
cvts.r.colors[x][BLU] = cvts.t.fp[x] > 0. ? cvts.t.fp[x] : 0.; |
609 |
> |
colval(cvts.r.colors[x],RED) = |
610 |
> |
colval(cvts.r.colors[x],GRN) = |
611 |
> |
colval(cvts.r.colors[x],BLU) = |
612 |
> |
cvts.t.fp[x] > 0. ? cvts.t.fp[x] : 0.; |
613 |
|
|
614 |
|
if (fwritescan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
615 |
|
quiterr("error writing Radiance picture"); |
623 |
|
COLOR ctmp; |
624 |
|
register int x; |
625 |
|
|
626 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY)) |
626 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY)) |
627 |
|
quiterr("internal error 1 in RGB2Colr"); |
628 |
|
|
629 |
|
if (cvts.pconf == PLANARCONFIG_CONTIG) { |
678 |
|
{ |
679 |
|
register int x; |
680 |
|
|
681 |
< |
if (CHK(C_RFLT|C_TFLT) | !CHK(C_GRY)) |
681 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY) |
682 |
|
quiterr("internal error 1 in Gry2Colr"); |
683 |
|
|
684 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
699 |
|
|
700 |
|
|
701 |
|
int |
702 |
+ |
GGry2Color(y) /* read/convert/write G16->COLOR scanline */ |
703 |
+ |
uint32 y; |
704 |
+ |
{ |
705 |
+ |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
706 |
+ |
double m; |
707 |
+ |
register double d; |
708 |
+ |
register int x; |
709 |
+ |
|
710 |
+ |
if (CHK(C_TFLT|C_TWRD|C_GRY|C_RFLT) != (C_GRY|C_RFLT|C_TWRD)) |
711 |
+ |
quiterr("internal error 1 in GGry2Color"); |
712 |
+ |
|
713 |
+ |
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
714 |
+ |
quiterr("error reading TIFF input"); |
715 |
+ |
|
716 |
+ |
if (cvts.bradj) |
717 |
+ |
m = pow(2., (double)cvts.bradj); |
718 |
+ |
for (x = cvts.xmax; x--; ) { |
719 |
+ |
d = (cvts.t.wp[x] + 0.5)*(1./(1L<<16)); |
720 |
+ |
if (dogamma) d = pow(d, cvts.gamcor); |
721 |
+ |
if (cvts.bradj) d *= m; |
722 |
+ |
colval(cvts.r.colors[x],RED) = |
723 |
+ |
colval(cvts.r.colors[x],GRN) = |
724 |
+ |
colval(cvts.r.colors[x],BLU) = d; |
725 |
+ |
} |
726 |
+ |
if (fwritescan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
727 |
+ |
quiterr("error writing Radiance picture"); |
728 |
+ |
} |
729 |
+ |
|
730 |
+ |
|
731 |
+ |
int |
732 |
|
Color2L(y) /* read/convert/write COLOR->L16 scanline */ |
733 |
|
uint32 y; |
734 |
|
{ |
735 |
|
double m = pow(2.,(double)cvts.bradj); |
736 |
|
register int x; |
737 |
|
|
738 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
738 |
> |
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
739 |
|
quiterr("internal error 1 in Color2L"); |
740 |
|
|
741 |
|
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
756 |
|
{ |
757 |
|
register int x; |
758 |
|
|
759 |
< |
if (CHK(C_RFLT|C_TFLT) != (C_RFLT|C_TFLT) | CHK(C_GRY)) |
759 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
760 |
|
quiterr("internal error 1 in Color2Luv"); |
761 |
|
|
762 |
|
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
773 |
|
} |
774 |
|
|
775 |
|
for (x = cvts.xmax; x--; ) { |
776 |
< |
cvts.t.fp[3*x] = colval(cvts.r.colors[x],RED); |
777 |
< |
cvts.t.fp[3*x+1] = colval(cvts.r.colors[x],GRN); |
778 |
< |
cvts.t.fp[3*x+2] = colval(cvts.r.colors[x],BLU); |
776 |
> |
cvts.t.fp[3*x] = colval(cvts.r.colors[x],CIEX); |
777 |
> |
cvts.t.fp[3*x+1] = colval(cvts.r.colors[x],CIEY); |
778 |
> |
cvts.t.fp[3*x+2] = colval(cvts.r.colors[x],CIEZ); |
779 |
|
} |
780 |
|
|
781 |
|
if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
789 |
|
{ |
790 |
|
register int x; |
791 |
|
|
792 |
< |
if (CHK(C_RFLT|C_TFLT) | !CHK(C_GRY)) |
792 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY) |
793 |
|
quiterr("internal error 1 in Colr2Gry"); |
794 |
|
|
795 |
|
if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0) |
816 |
|
COLOR ctmp; |
817 |
|
register int x; |
818 |
|
|
819 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY)) |
819 |
> |
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY)) |
820 |
|
quiterr("internal error 1 in Colr2RGB"); |
821 |
|
|
822 |
|
if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0) |