52 |
|
} r; /* Radiance scanline */ |
53 |
|
union { |
54 |
|
uint8 *bp; /* byte pointer */ |
55 |
+ |
uint16 *wp; /* word pointer */ |
56 |
|
float *fp; /* float pointer */ |
57 |
|
char *p; /* generic pointer */ |
58 |
|
} t; /* TIFF scanline */ |
69 |
|
|
70 |
|
int Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr(); |
71 |
|
int Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry(); |
72 |
+ |
int RRGGBB2Color(), GGry2Color(); |
73 |
|
|
74 |
|
short ortab[8] = { /* orientation conversion table */ |
75 |
|
YMAJOR|YDECR, |
263 |
|
quiterr("unsupported photometric type"); |
264 |
|
/* fall through */ |
265 |
|
case PHOTOMETRIC_RGB: |
266 |
< |
SET(C_GAMMA|C_GAMUT); |
266 |
> |
SET(C_GAMMA); |
267 |
|
setcolrgam(cvts.gamcor); |
268 |
|
if (CHK(C_XYZE)) { |
269 |
|
comprgb2xyzmat(cvts.cmat, |
274 |
|
hi != 3) |
275 |
|
quiterr("unsupported samples per pixel for RGB"); |
276 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi) || |
277 |
< |
hi != 8) |
277 |
> |
hi != 8 & hi != 16) |
278 |
|
quiterr("unsupported bits per sample for RGB"); |
279 |
< |
cvts.tf = RGB2Colr; |
279 |
> |
if (hi == 8) |
280 |
> |
cvts.tf = RGB2Colr; |
281 |
> |
else { |
282 |
> |
cvts.tf = RRGGBB2Color; |
283 |
> |
SET(C_RFLT); |
284 |
> |
} |
285 |
|
break; |
286 |
|
case PHOTOMETRIC_MINISBLACK: |
287 |
< |
SET(C_GRY|C_GAMMA|C_GAMUT); |
287 |
> |
SET(C_GRY|C_GAMMA); |
288 |
> |
setcolrgam(cvts.gamcor); |
289 |
|
cvts.pconf = PLANARCONFIG_CONTIG; |
290 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_SAMPLESPERPIXEL, &hi) || |
291 |
|
hi != 1) |
292 |
|
quiterr("unsupported samples per pixel for greyscale"); |
293 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi) || |
294 |
< |
hi != 8) |
294 |
> |
hi != 8 & hi != 16) |
295 |
|
quiterr("unsupported bits per sample for greyscale"); |
296 |
< |
cvts.tf = Gry2Colr; |
296 |
> |
if (hi == 8) |
297 |
> |
cvts.tf = Gry2Colr; |
298 |
> |
else { |
299 |
> |
cvts.tf = GGry2Color; |
300 |
> |
SET(C_RFLT); |
301 |
> |
} |
302 |
|
break; |
303 |
|
default: |
304 |
|
quiterr("unsupported photometric type"); |
372 |
|
SET(C_XYZE); |
373 |
|
else |
374 |
|
quiterr("unrecognized input picture format"); |
375 |
< |
return; |
375 |
> |
return(1); |
376 |
|
} |
377 |
|
if (isexpos(s)) { |
378 |
|
cvts.stonits /= exposval(s); |
379 |
< |
return; |
379 |
> |
return(1); |
380 |
|
} |
381 |
|
if (isaspect(s)) { |
382 |
|
cvts.pixrat *= aspectval(s); |
383 |
< |
return; |
383 |
> |
return(1); |
384 |
|
} |
385 |
|
if (isprims(s)) { |
386 |
|
primsval(cvts.prims, s); |
387 |
|
SET(C_PRIM); |
388 |
< |
return; |
388 |
> |
return(1); |
389 |
|
} |
390 |
+ |
return(0); |
391 |
|
} |
392 |
|
|
393 |
|
|
521 |
|
{ |
522 |
|
register int x; |
523 |
|
|
524 |
< |
if (CHK(C_RFLT|C_TFLT) != (C_RFLT|C_TFLT) | CHK(C_GRY)) |
524 |
> |
if (CHK(C_RFLT|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
525 |
|
quiterr("internal error 1 in Luv2Color"); |
526 |
|
|
527 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
528 |
|
quiterr("error reading TIFF input"); |
529 |
|
|
530 |
|
for (x = cvts.xmax; x--; ) { |
531 |
< |
cvts.r.colors[x][RED] = cvts.t.fp[3*x]; |
532 |
< |
cvts.r.colors[x][GRN] = cvts.t.fp[3*x + 1]; |
533 |
< |
cvts.r.colors[x][BLU] = cvts.t.fp[3*x + 2]; |
531 |
> |
colval(cvts.r.colors[x],CIEX) = cvts.t.fp[3*x]; |
532 |
> |
colval(cvts.r.colors[x],CIEY) = cvts.t.fp[3*x + 1]; |
533 |
> |
colval(cvts.r.colors[x],CIEZ) = cvts.t.fp[3*x + 2]; |
534 |
|
if (CHK(C_CXFM)) |
535 |
|
colortrans(cvts.r.colors[x], cvts.cmat, |
536 |
|
cvts.r.colors[x]); |
550 |
|
|
551 |
|
|
552 |
|
int |
553 |
+ |
RRGGBB2Color(y) /* read/convert/write RGB16->COLOR scanline */ |
554 |
+ |
uint32 y; |
555 |
+ |
{ |
556 |
+ |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
557 |
+ |
register double d; |
558 |
+ |
register int x; |
559 |
+ |
|
560 |
+ |
if (CHK(C_RFLT|C_TFLT|C_GRY) != C_RFLT) |
561 |
+ |
quiterr("internal error 1 in RRGGBB2Color"); |
562 |
+ |
|
563 |
+ |
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
564 |
+ |
quiterr("error reading TIFF input"); |
565 |
+ |
|
566 |
+ |
for (x = cvts.xmax; x--; ) { |
567 |
+ |
d = (cvts.t.wp[3*x] + 0.5)*(1./(1L<<16)); |
568 |
+ |
if (dogamma) d = pow(d, cvts.gamcor); |
569 |
+ |
colval(cvts.r.colors[x],RED) = d; |
570 |
+ |
d = (cvts.t.wp[3*x + 1] + 0.5)*(1./(1L<<16)); |
571 |
+ |
if (dogamma) d = pow(d, cvts.gamcor); |
572 |
+ |
colval(cvts.r.colors[x],GRN) = d; |
573 |
+ |
d = (cvts.t.wp[3*x + 2] + 0.5)*(1./(1L<<16)); |
574 |
+ |
if (dogamma) d = pow(d, cvts.gamcor); |
575 |
+ |
colval(cvts.r.colors[x],BLU) = d; |
576 |
+ |
if (CHK(C_CXFM)) |
577 |
+ |
colortrans(cvts.r.colors[x], cvts.cmat, |
578 |
+ |
cvts.r.colors[x]); |
579 |
+ |
if (CHK(C_GAMUT)) |
580 |
+ |
clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1], |
581 |
+ |
CGAMUT_LOWER, cblack, cwhite); |
582 |
+ |
} |
583 |
+ |
if (cvts.bradj) { |
584 |
+ |
d = pow(2.,(double)cvts.bradj); |
585 |
+ |
for (x = cvts.xmax; x--; ) |
586 |
+ |
scalecolor(cvts.r.colors[x], d); |
587 |
+ |
} |
588 |
+ |
|
589 |
+ |
if (fwritescan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
590 |
+ |
quiterr("error writing Radiance picture"); |
591 |
+ |
} |
592 |
+ |
|
593 |
+ |
|
594 |
+ |
int |
595 |
|
L2Color(y) /* read/convert/write L16->COLOR scanline */ |
596 |
|
uint32 y; |
597 |
|
{ |
604 |
|
quiterr("error reading TIFF input"); |
605 |
|
|
606 |
|
for (x = cvts.xmax; x--; ) |
607 |
< |
cvts.r.colors[x][RED] = |
608 |
< |
cvts.r.colors[x][GRN] = |
609 |
< |
cvts.r.colors[x][BLU] = cvts.t.fp[x] > 0. ? cvts.t.fp[x] : 0.; |
607 |
> |
colval(cvts.r.colors[x],RED) = |
608 |
> |
colval(cvts.r.colors[x],GRN) = |
609 |
> |
colval(cvts.r.colors[x],BLU) = |
610 |
> |
cvts.t.fp[x] > 0. ? cvts.t.fp[x] : 0.; |
611 |
|
|
612 |
|
if (fwritescan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
613 |
|
quiterr("error writing Radiance picture"); |
676 |
|
{ |
677 |
|
register int x; |
678 |
|
|
679 |
< |
if (CHK(C_RFLT|C_TFLT) | !CHK(C_GRY)) |
679 |
> |
if (CHK(C_RFLT|C_TFLT|C_GRY) != C_GRY) |
680 |
|
quiterr("internal error 1 in Gry2Colr"); |
681 |
|
|
682 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
697 |
|
|
698 |
|
|
699 |
|
int |
700 |
+ |
GGry2Color(y) /* read/convert/write G16->COLOR scanline */ |
701 |
+ |
uint32 y; |
702 |
+ |
{ |
703 |
+ |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
704 |
+ |
double m; |
705 |
+ |
register double d; |
706 |
+ |
register int x; |
707 |
+ |
|
708 |
+ |
if (CHK(C_TFLT|C_GRY|C_RFLT) != (C_GRY|C_RFLT)) |
709 |
+ |
quiterr("internal error 1 in GGry2Color"); |
710 |
+ |
|
711 |
+ |
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
712 |
+ |
quiterr("error reading TIFF input"); |
713 |
+ |
|
714 |
+ |
if (cvts.bradj) |
715 |
+ |
m = pow(2., (double)cvts.bradj); |
716 |
+ |
for (x = cvts.xmax; x--; ) { |
717 |
+ |
d = (cvts.t.wp[x] + 0.5)*(1./(1L<<16)); |
718 |
+ |
if (dogamma) d = pow(d, cvts.gamcor); |
719 |
+ |
if (cvts.bradj) d *= m; |
720 |
+ |
colval(cvts.r.colors[x],RED) = |
721 |
+ |
colval(cvts.r.colors[x],GRN) = |
722 |
+ |
colval(cvts.r.colors[x],BLU) = d; |
723 |
+ |
} |
724 |
+ |
if (fwritescan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
725 |
+ |
quiterr("error writing Radiance picture"); |
726 |
+ |
} |
727 |
+ |
|
728 |
+ |
|
729 |
+ |
int |
730 |
|
Color2L(y) /* read/convert/write COLOR->L16 scanline */ |
731 |
|
uint32 y; |
732 |
|
{ |
754 |
|
{ |
755 |
|
register int x; |
756 |
|
|
757 |
< |
if (CHK(C_RFLT|C_TFLT) != (C_RFLT|C_TFLT) | CHK(C_GRY)) |
757 |
> |
if (CHK(C_RFLT|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
758 |
|
quiterr("internal error 1 in Color2Luv"); |
759 |
|
|
760 |
|
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
771 |
|
} |
772 |
|
|
773 |
|
for (x = cvts.xmax; x--; ) { |
774 |
< |
cvts.t.fp[3*x] = colval(cvts.r.colors[x],RED); |
775 |
< |
cvts.t.fp[3*x+1] = colval(cvts.r.colors[x],GRN); |
776 |
< |
cvts.t.fp[3*x+2] = colval(cvts.r.colors[x],BLU); |
774 |
> |
cvts.t.fp[3*x] = colval(cvts.r.colors[x],CIEX); |
775 |
> |
cvts.t.fp[3*x+1] = colval(cvts.r.colors[x],CIEY); |
776 |
> |
cvts.t.fp[3*x+2] = colval(cvts.r.colors[x],CIEZ); |
777 |
|
} |
778 |
|
|
779 |
|
if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
787 |
|
{ |
788 |
|
register int x; |
789 |
|
|
790 |
< |
if (CHK(C_RFLT|C_TFLT) | !CHK(C_GRY)) |
790 |
> |
if (CHK(C_RFLT|C_TFLT|C_GRY) != C_GRY) |
791 |
|
quiterr("internal error 1 in Colr2Gry"); |
792 |
|
|
793 |
|
if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0) |