1 |
– |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Program to convert between RADIANCE and TIFF files. |
6 |
< |
* Added experimental LogLuv encodings 7/97 (GWL). |
6 |
> |
* Added LogLuv encodings 7/97 (GWL). |
7 |
> |
* Added white-balance adjustment 10/01 (GW). |
8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdio.h> |
11 |
|
#include <math.h> |
12 |
+ |
#include <time.h> |
13 |
|
#include "tiffio.h" |
14 |
|
#include "color.h" |
15 |
|
#include "resolu.h" |
16 |
|
|
17 |
|
#define GAMCOR 2.2 /* default gamma */ |
18 |
|
|
20 |
– |
#ifndef malloc |
21 |
– |
extern char *malloc(); |
22 |
– |
#endif |
19 |
|
/* conversion flags */ |
20 |
|
#define C_CXFM 0x1 /* needs color transformation */ |
21 |
|
#define C_GAMUT 0x2 /* needs gamut mapping */ |
24 |
|
#define C_XYZE 0x10 /* Radiance is XYZE */ |
25 |
|
#define C_RFLT 0x20 /* Radiance data is float */ |
26 |
|
#define C_TFLT 0x40 /* TIFF data is float */ |
27 |
< |
#define C_PRIM 0x80 /* has assigned primaries */ |
27 |
> |
#define C_TWRD 0x80 /* TIFF data is 16-bit */ |
28 |
> |
#define C_PRIM 0x100 /* has assigned primaries */ |
29 |
|
|
30 |
|
struct { |
31 |
|
uint16 flags; /* conversion flags (defined above) */ |
32 |
|
uint16 comp; /* TIFF compression type */ |
33 |
+ |
uint16 phot; /* TIFF photometric type */ |
34 |
|
uint16 pconf; /* TIFF planar configuration */ |
35 |
|
float gamcor; /* gamma correction value */ |
36 |
|
short bradj; /* Radiance exposure adjustment (stops) */ |
37 |
|
uint16 orient; /* visual orientation (TIFF spec.) */ |
38 |
< |
float stonits; /* input conversion to nits */ |
38 |
> |
double stonits; /* input conversion to nits */ |
39 |
|
float pixrat; /* pixel aspect ratio */ |
40 |
|
FILE *rfp; /* Radiance stream pointer */ |
41 |
|
TIFF *tif; /* TIFF pointer */ |
49 |
|
} r; /* Radiance scanline */ |
50 |
|
union { |
51 |
|
uint8 *bp; /* byte pointer */ |
52 |
+ |
uint16 *wp; /* word pointer */ |
53 |
|
float *fp; /* float pointer */ |
54 |
|
char *p; /* generic pointer */ |
55 |
|
} t; /* TIFF scanline */ |
56 |
|
int (*tf)(); /* translation procedure */ |
57 |
|
} cvts = { /* conversion structure */ |
58 |
< |
0, COMPRESSION_NONE, PLANARCONFIG_CONTIG, GAMCOR, 0, |
58 |
> |
0, COMPRESSION_NONE, PHOTOMETRIC_RGB, |
59 |
> |
PLANARCONFIG_CONTIG, GAMCOR, 0, 1, 1., 1., |
60 |
|
}; |
61 |
|
|
62 |
|
#define CHK(f) (cvts.flags & (f)) |
66 |
|
|
67 |
|
int Luv2Color(), L2Color(), RGB2Colr(), Gry2Colr(); |
68 |
|
int Color2Luv(), Color2L(), Colr2RGB(), Colr2Gry(); |
69 |
+ |
int RRGGBB2Color(), GGry2Color(); |
70 |
|
|
71 |
|
short ortab[8] = { /* orientation conversion table */ |
72 |
|
YMAJOR|YDECR, |
106 |
|
cvts.comp = COMPRESSION_LZW; |
107 |
|
break; |
108 |
|
case 'L': /* LogLuv 32-bit output */ |
109 |
< |
cvts.comp = COMPRESSION_LOGLUV32; |
109 |
> |
cvts.comp = COMPRESSION_SGILOG; |
110 |
> |
cvts.phot = PHOTOMETRIC_LOGLUV; |
111 |
|
break; |
112 |
|
case 'l': /* LogLuv 24-bit output */ |
113 |
< |
cvts.comp = COMPRESSION_LOGLUV24; |
113 |
> |
cvts.comp = COMPRESSION_SGILOG24; |
114 |
> |
cvts.phot = PHOTOMETRIC_LOGLUV; |
115 |
|
break; |
116 |
|
case 'b': /* greyscale output? */ |
117 |
|
TGL(C_GRY); |
144 |
|
if (i != argc-2) |
145 |
|
goto userr; |
146 |
|
|
147 |
< |
if (CHK(C_GRY) && (cvts.comp == COMPRESSION_LOGLUV24 || |
148 |
< |
cvts.comp == COMPRESSION_LOGLUV32)) |
149 |
< |
cvts.comp = COMPRESSION_LOGL16; |
147 |
> |
if (CHK(C_GRY)) /* consistency corrections */ |
148 |
> |
if (cvts.phot == PHOTOMETRIC_RGB) |
149 |
> |
cvts.phot = PHOTOMETRIC_MINISBLACK; |
150 |
> |
else { |
151 |
> |
cvts.phot = PHOTOMETRIC_LOGL; |
152 |
> |
cvts.comp = COMPRESSION_SGILOG; |
153 |
> |
} |
154 |
|
|
155 |
|
ra2tiff(i, argv); |
156 |
|
} |
183 |
|
int rsiz, tsiz; |
184 |
|
|
185 |
|
rsiz = CHK(C_RFLT) ? sizeof(COLOR) : sizeof(COLR); |
186 |
< |
tsiz = (CHK(C_TFLT) ? sizeof(float) : sizeof(uint8)) * |
186 |
> |
tsiz = (CHK(C_TFLT) ? sizeof(float) : |
187 |
> |
CHK(C_TWRD) ? sizeof(uint16) : sizeof(uint8)) * |
188 |
|
(CHK(C_GRY) ? 1 : 3); |
189 |
|
cvts.r.p = (char *)malloc(rsiz*cvts.xmax); |
190 |
|
cvts.t.p = (char *)malloc(tsiz*cvts.xmax); |
224 |
|
if (TIFFGetField(cvts.tif, TIFFTAG_XRESOLUTION, &f1) && |
225 |
|
TIFFGetField(cvts.tif, TIFFTAG_YRESOLUTION, &f2)) |
226 |
|
cvts.pixrat = f1/f2; |
219 |
– |
else |
220 |
– |
cvts.pixrat = 1.; |
227 |
|
|
228 |
< |
if (!TIFFGetFieldDefaulted(cvts.tif, TIFFTAG_ORIENTATION, &cvts.orient)) |
223 |
< |
cvts.orient = 1; |
228 |
> |
TIFFGetFieldDefaulted(cvts.tif, TIFFTAG_ORIENTATION, &cvts.orient); |
229 |
|
|
230 |
< |
switch (cvts.comp) { |
231 |
< |
case COMPRESSION_LOGL16: |
232 |
< |
SET(C_GRY|C_RFLT|C_TFLT|C_GAMUT); |
233 |
< |
cvts.pconf = PLANARCONFIG_CONTIG; |
234 |
< |
TIFFSetField(cvts.tif, TIFFTAG_LOGLUVDATAFMT, |
230 |
< |
LOGLUVDATAFMT_FLTY); |
231 |
< |
TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, |
232 |
< |
SAMPLEFORMAT_IEEEFP); |
233 |
< |
cvts.tf = L2Color; |
234 |
< |
break; |
235 |
< |
case COMPRESSION_LOGLUV24: |
236 |
< |
case COMPRESSION_LOGLUV32: |
230 |
> |
if (!TIFFGetFieldDefaulted(cvts.tif, TIFFTAG_PHOTOMETRIC, &cvts.phot)) |
231 |
> |
quiterr("TIFF has unspecified photometric type"); |
232 |
> |
|
233 |
> |
switch (cvts.phot) { |
234 |
> |
case PHOTOMETRIC_LOGLUV: |
235 |
|
SET(C_RFLT|C_TFLT); |
236 |
|
if (!CHK(C_XYZE)) { |
237 |
|
cpcolormat(cvts.cmat, xyz2rgbmat); |
238 |
|
SET(C_CXFM|C_GAMUT); |
239 |
< |
} else if (cvts.comp == COMPRESSION_LOGLUV32) |
239 |
> |
} else if (cvts.comp == COMPRESSION_SGILOG) |
240 |
|
SET(C_GAMUT); |
241 |
|
if (cvts.pconf != PLANARCONFIG_CONTIG) |
242 |
|
quiterr("cannot handle separate Luv planes"); |
243 |
< |
TIFFSetField(cvts.tif, TIFFTAG_LOGLUVDATAFMT, |
244 |
< |
LOGLUVDATAFMT_FLTXYZ); |
247 |
< |
TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, |
248 |
< |
SAMPLEFORMAT_IEEEFP); |
243 |
> |
TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT, |
244 |
> |
SGILOGDATAFMT_FLOAT); |
245 |
|
cvts.tf = Luv2Color; |
246 |
|
break; |
247 |
< |
default: |
248 |
< |
SET(C_GAMMA|C_GAMUT); |
247 |
> |
case PHOTOMETRIC_LOGL: |
248 |
> |
SET(C_GRY|C_RFLT|C_TFLT|C_GAMUT); |
249 |
> |
cvts.pconf = PLANARCONFIG_CONTIG; |
250 |
> |
TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT, |
251 |
> |
SGILOGDATAFMT_FLOAT); |
252 |
> |
cvts.tf = L2Color; |
253 |
> |
break; |
254 |
> |
case PHOTOMETRIC_YCBCR: |
255 |
> |
if (cvts.comp == COMPRESSION_JPEG && |
256 |
> |
cvts.pconf == PLANARCONFIG_CONTIG) { |
257 |
> |
TIFFSetField(cvts.tif, TIFFTAG_JPEGCOLORMODE, |
258 |
> |
JPEGCOLORMODE_RGB); |
259 |
> |
cvts.phot = PHOTOMETRIC_RGB; |
260 |
> |
} else |
261 |
> |
quiterr("unsupported photometric type"); |
262 |
> |
/* fall through */ |
263 |
> |
case PHOTOMETRIC_RGB: |
264 |
> |
SET(C_GAMMA); |
265 |
|
setcolrgam(cvts.gamcor); |
266 |
|
if (CHK(C_XYZE)) { |
267 |
< |
comprgb2xyzmat(cvts.cmat, |
267 |
> |
comprgb2xyzWBmat(cvts.cmat, |
268 |
|
CHK(C_PRIM) ? cvts.prims : stdprims); |
269 |
|
SET(C_CXFM); |
270 |
|
} |
271 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_SAMPLESPERPIXEL, &hi) || |
272 |
< |
(hi != 1 && hi != 3)) |
273 |
< |
quiterr("unsupported samples per pixel"); |
274 |
< |
if (hi == 1) { |
275 |
< |
SET(C_GRY); |
276 |
< |
cvts.pconf = PLANARCONFIG_CONTIG; |
277 |
< |
cvts.tf = Gry2Colr; |
266 |
< |
} else |
272 |
> |
hi != 3) |
273 |
> |
quiterr("unsupported samples per pixel for RGB"); |
274 |
> |
if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi) || |
275 |
> |
hi != 8 & hi != 16) |
276 |
> |
quiterr("unsupported bits per sample for RGB"); |
277 |
> |
if (hi == 8) |
278 |
|
cvts.tf = RGB2Colr; |
279 |
+ |
else { |
280 |
+ |
cvts.tf = RRGGBB2Color; |
281 |
+ |
SET(C_RFLT|C_TWRD); |
282 |
+ |
} |
283 |
+ |
break; |
284 |
+ |
case PHOTOMETRIC_MINISBLACK: |
285 |
+ |
SET(C_GRY|C_GAMMA); |
286 |
+ |
setcolrgam(cvts.gamcor); |
287 |
+ |
cvts.pconf = PLANARCONFIG_CONTIG; |
288 |
+ |
if (!TIFFGetField(cvts.tif, TIFFTAG_SAMPLESPERPIXEL, &hi) || |
289 |
+ |
hi != 1) |
290 |
+ |
quiterr("unsupported samples per pixel for greyscale"); |
291 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, &hi) || |
292 |
< |
hi != 8) |
293 |
< |
quiterr("unsupported bits per sample"); |
292 |
> |
hi != 8 & hi != 16) |
293 |
> |
quiterr("unsupported bits per sample for greyscale"); |
294 |
> |
if (hi == 8) |
295 |
> |
cvts.tf = Gry2Colr; |
296 |
> |
else { |
297 |
> |
cvts.tf = GGry2Color; |
298 |
> |
SET(C_RFLT|C_TWRD); |
299 |
> |
} |
300 |
|
break; |
301 |
+ |
default: |
302 |
+ |
quiterr("unsupported photometric type"); |
303 |
+ |
break; |
304 |
|
} |
305 |
|
|
274 |
– |
if (TIFFGetField(cvts.tif, TIFFTAG_PHOTOMETRIC, &hi) && |
275 |
– |
hi != (CHK(C_GRY) ? PHOTOMETRIC_MINISBLACK : PHOTOMETRIC_RGB)) |
276 |
– |
quiterr("unsupported photometric interpretation"); |
277 |
– |
|
306 |
|
if (!TIFFGetField(cvts.tif, TIFFTAG_IMAGEWIDTH, &cvts.xmax) || |
307 |
|
!TIFFGetField(cvts.tif, TIFFTAG_IMAGELENGTH, &cvts.ymax)) |
308 |
|
quiterr("unknown input image resolution"); |
370 |
|
SET(C_XYZE); |
371 |
|
else |
372 |
|
quiterr("unrecognized input picture format"); |
373 |
< |
return; |
373 |
> |
return(1); |
374 |
|
} |
375 |
|
if (isexpos(s)) { |
376 |
|
cvts.stonits /= exposval(s); |
377 |
< |
return; |
377 |
> |
return(1); |
378 |
|
} |
379 |
|
if (isaspect(s)) { |
380 |
|
cvts.pixrat *= aspectval(s); |
381 |
< |
return; |
381 |
> |
return(1); |
382 |
|
} |
383 |
|
if (isprims(s)) { |
384 |
|
primsval(cvts.prims, s); |
385 |
|
SET(C_PRIM); |
386 |
< |
return; |
386 |
> |
return(1); |
387 |
|
} |
388 |
+ |
return(0); |
389 |
|
} |
390 |
|
|
391 |
|
|
414 |
|
cvts.stonits *= WHTEFFICACY; |
415 |
|
/* set up conversion */ |
416 |
|
TIFFSetField(cvts.tif, TIFFTAG_COMPRESSION, cvts.comp); |
417 |
+ |
TIFFSetField(cvts.tif, TIFFTAG_PHOTOMETRIC, cvts.phot); |
418 |
|
|
419 |
< |
switch (cvts.comp) { |
420 |
< |
case COMPRESSION_LOGL16: |
391 |
< |
SET(C_GRY|C_RFLT|C_TFLT); |
392 |
< |
TIFFSetField(cvts.tif, TIFFTAG_LOGLUVDATAFMT, |
393 |
< |
LOGLUVDATAFMT_FLTY); |
394 |
< |
TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, |
395 |
< |
SAMPLEFORMAT_IEEEFP); |
396 |
< |
cvts.tf = Color2L; |
397 |
< |
break; |
398 |
< |
case COMPRESSION_LOGLUV24: |
399 |
< |
case COMPRESSION_LOGLUV32: |
419 |
> |
switch (cvts.phot) { |
420 |
> |
case PHOTOMETRIC_LOGLUV: |
421 |
|
SET(C_RFLT|C_TFLT); |
422 |
|
CLR(C_GRY); |
423 |
|
if (!CHK(C_XYZE)) { |
424 |
< |
cpcolormat(cvts.cmat, rgb2xyzmat); |
424 |
> |
comprgb2xyzWBmat(cvts.cmat, |
425 |
> |
CHK(C_PRIM) ? cvts.prims : stdprims); |
426 |
|
SET(C_CXFM); |
427 |
|
} |
428 |
< |
TIFFSetField(cvts.tif, TIFFTAG_LOGLUVDATAFMT, |
429 |
< |
LOGLUVDATAFMT_FLTXYZ); |
430 |
< |
TIFFSetField(cvts.tif, TIFFTAG_SAMPLEFORMAT, |
431 |
< |
SAMPLEFORMAT_IEEEFP); |
428 |
> |
if (cvts.comp != COMPRESSION_SGILOG && |
429 |
> |
cvts.comp != COMPRESSION_SGILOG24) |
430 |
> |
quiterr("internal error 2 in initfromrad"); |
431 |
> |
TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT, |
432 |
> |
SGILOGDATAFMT_FLOAT); |
433 |
|
cvts.tf = Color2Luv; |
434 |
|
break; |
435 |
< |
default: |
435 |
> |
case PHOTOMETRIC_LOGL: |
436 |
> |
SET(C_GRY|C_RFLT|C_TFLT); |
437 |
> |
if (cvts.comp != COMPRESSION_SGILOG) |
438 |
> |
quiterr("internal error 3 in initfromrad"); |
439 |
> |
TIFFSetField(cvts.tif, TIFFTAG_SGILOGDATAFMT, |
440 |
> |
SGILOGDATAFMT_FLOAT); |
441 |
> |
cvts.tf = Color2L; |
442 |
> |
break; |
443 |
> |
case PHOTOMETRIC_RGB: |
444 |
|
SET(C_GAMMA|C_GAMUT); |
445 |
+ |
CLR(C_GRY); |
446 |
|
setcolrgam(cvts.gamcor); |
447 |
|
if (CHK(C_XYZE)) { |
448 |
< |
compxyz2rgbmat(cvts.cmat, |
448 |
> |
compxyz2rgbWBmat(cvts.cmat, |
449 |
|
CHK(C_PRIM) ? cvts.prims : stdprims); |
450 |
|
SET(C_CXFM); |
451 |
|
} |
420 |
– |
if (CHK(C_GRY)) |
421 |
– |
cvts.tf = Colr2Gry; |
422 |
– |
else |
423 |
– |
cvts.tf = Colr2RGB; |
452 |
|
if (CHK(C_PRIM)) { |
453 |
|
TIFFSetField(cvts.tif, TIFFTAG_PRIMARYCHROMATICITIES, |
454 |
|
(float *)cvts.prims); |
455 |
|
TIFFSetField(cvts.tif, TIFFTAG_WHITEPOINT, |
456 |
|
(float *)cvts.prims[WHT]); |
457 |
|
} |
458 |
+ |
cvts.tf = Colr2RGB; |
459 |
|
break; |
460 |
+ |
case PHOTOMETRIC_MINISBLACK: |
461 |
+ |
SET(C_GRY|C_GAMMA|C_GAMUT); |
462 |
+ |
setcolrgam(cvts.gamcor); |
463 |
+ |
cvts.tf = Colr2Gry; |
464 |
+ |
break; |
465 |
+ |
default: |
466 |
+ |
quiterr("internal error 4 in initfromrad"); |
467 |
+ |
break; |
468 |
|
} |
469 |
|
/* set other TIFF fields */ |
470 |
|
TIFFSetField(cvts.tif, TIFFTAG_IMAGEWIDTH, cvts.xmax); |
471 |
|
TIFFSetField(cvts.tif, TIFFTAG_IMAGELENGTH, cvts.ymax); |
472 |
|
TIFFSetField(cvts.tif, TIFFTAG_SAMPLESPERPIXEL, CHK(C_GRY) ? 1 : 3); |
473 |
|
TIFFSetField(cvts.tif, TIFFTAG_BITSPERSAMPLE, CHK(C_TFLT) ? 32 : 8); |
437 |
– |
TIFFSetField(cvts.tif, TIFFTAG_PHOTOMETRIC, |
438 |
– |
CHK(C_GRY) ? PHOTOMETRIC_MINISBLACK : PHOTOMETRIC_RGB); |
474 |
|
TIFFSetField(cvts.tif, TIFFTAG_XRESOLUTION, 72.); |
475 |
|
TIFFSetField(cvts.tif, TIFFTAG_YRESOLUTION, 72./cvts.pixrat); |
476 |
|
TIFFSetField(cvts.tif, TIFFTAG_ORIENTATION, cvts.orient); |
478 |
|
TIFFSetField(cvts.tif, TIFFTAG_PLANARCONFIG, cvts.pconf); |
479 |
|
TIFFSetField(cvts.tif, TIFFTAG_STONITS, |
480 |
|
cvts.stonits/pow(2.,(double)cvts.bradj)); |
481 |
< |
i1 = TIFFScanlineSize(cvts.tif); |
481 |
> |
if (cvts.comp == COMPRESSION_NONE) |
482 |
> |
i1 = TIFFScanlineSize(cvts.tif); |
483 |
> |
else |
484 |
> |
i1 = 3*cvts.xmax; /* conservative guess */ |
485 |
|
i2 = 8192/i1; /* compute good strip size */ |
486 |
|
if (i2 < 1) i2 = 1; |
487 |
|
TIFFSetField(cvts.tif, TIFFTAG_ROWSPERSTRIP, (uint32)i2); |
520 |
|
{ |
521 |
|
register int x; |
522 |
|
|
523 |
< |
if (CHK(C_RFLT|C_TFLT) != (C_RFLT|C_TFLT) | CHK(C_GRY)) |
523 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
524 |
|
quiterr("internal error 1 in Luv2Color"); |
525 |
|
|
526 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
527 |
|
quiterr("error reading TIFF input"); |
528 |
|
|
529 |
|
for (x = cvts.xmax; x--; ) { |
530 |
< |
cvts.r.colors[x][RED] = cvts.t.fp[3*x]; |
531 |
< |
cvts.r.colors[x][GRN] = cvts.t.fp[3*x + 1]; |
532 |
< |
cvts.r.colors[x][BLU] = cvts.t.fp[3*x + 2]; |
530 |
> |
colval(cvts.r.colors[x],CIEX) = cvts.t.fp[3*x]; |
531 |
> |
colval(cvts.r.colors[x],CIEY) = cvts.t.fp[3*x + 1]; |
532 |
> |
colval(cvts.r.colors[x],CIEZ) = cvts.t.fp[3*x + 2]; |
533 |
|
if (CHK(C_CXFM)) |
534 |
|
colortrans(cvts.r.colors[x], cvts.cmat, |
535 |
|
cvts.r.colors[x]); |
549 |
|
|
550 |
|
|
551 |
|
int |
552 |
+ |
RRGGBB2Color(y) /* read/convert/write RGB16->COLOR scanline */ |
553 |
+ |
uint32 y; |
554 |
+ |
{ |
555 |
+ |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
556 |
+ |
register double d; |
557 |
+ |
register int x; |
558 |
+ |
|
559 |
+ |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_TWRD|C_RFLT)) |
560 |
+ |
quiterr("internal error 1 in RRGGBB2Color"); |
561 |
+ |
|
562 |
+ |
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
563 |
+ |
quiterr("error reading TIFF input"); |
564 |
+ |
|
565 |
+ |
for (x = cvts.xmax; x--; ) { |
566 |
+ |
d = (cvts.t.wp[3*x] + 0.5)*(1./(1L<<16)); |
567 |
+ |
if (dogamma) d = pow(d, cvts.gamcor); |
568 |
+ |
colval(cvts.r.colors[x],RED) = d; |
569 |
+ |
d = (cvts.t.wp[3*x + 1] + 0.5)*(1./(1L<<16)); |
570 |
+ |
if (dogamma) d = pow(d, cvts.gamcor); |
571 |
+ |
colval(cvts.r.colors[x],GRN) = d; |
572 |
+ |
d = (cvts.t.wp[3*x + 2] + 0.5)*(1./(1L<<16)); |
573 |
+ |
if (dogamma) d = pow(d, cvts.gamcor); |
574 |
+ |
colval(cvts.r.colors[x],BLU) = d; |
575 |
+ |
if (CHK(C_CXFM)) |
576 |
+ |
colortrans(cvts.r.colors[x], cvts.cmat, |
577 |
+ |
cvts.r.colors[x]); |
578 |
+ |
if (CHK(C_GAMUT)) |
579 |
+ |
clipgamut(cvts.r.colors[x], cvts.t.fp[3*x + 1], |
580 |
+ |
CGAMUT_LOWER, cblack, cwhite); |
581 |
+ |
} |
582 |
+ |
if (cvts.bradj) { |
583 |
+ |
d = pow(2.,(double)cvts.bradj); |
584 |
+ |
for (x = cvts.xmax; x--; ) |
585 |
+ |
scalecolor(cvts.r.colors[x], d); |
586 |
+ |
} |
587 |
+ |
|
588 |
+ |
if (fwritescan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
589 |
+ |
quiterr("error writing Radiance picture"); |
590 |
+ |
} |
591 |
+ |
|
592 |
+ |
|
593 |
+ |
int |
594 |
|
L2Color(y) /* read/convert/write L16->COLOR scanline */ |
595 |
|
uint32 y; |
596 |
|
{ |
597 |
|
register int x; |
598 |
|
|
599 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
599 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
600 |
|
quiterr("internal error 1 in L2Color"); |
601 |
|
|
602 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
603 |
|
quiterr("error reading TIFF input"); |
604 |
|
|
605 |
|
for (x = cvts.xmax; x--; ) |
606 |
< |
cvts.r.colors[x][RED] = |
607 |
< |
cvts.r.colors[x][GRN] = |
608 |
< |
cvts.r.colors[x][BLU] = cvts.t.fp[x] > 0. ? cvts.t.fp[x] : 0.; |
606 |
> |
colval(cvts.r.colors[x],RED) = |
607 |
> |
colval(cvts.r.colors[x],GRN) = |
608 |
> |
colval(cvts.r.colors[x],BLU) = |
609 |
> |
cvts.t.fp[x] > 0. ? cvts.t.fp[x] : 0.; |
610 |
|
|
611 |
|
if (fwritescan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
612 |
|
quiterr("error writing Radiance picture"); |
620 |
|
COLOR ctmp; |
621 |
|
register int x; |
622 |
|
|
623 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY)) |
623 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY)) |
624 |
|
quiterr("internal error 1 in RGB2Colr"); |
625 |
|
|
626 |
|
if (cvts.pconf == PLANARCONFIG_CONTIG) { |
635 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
636 |
|
goto readerr; |
637 |
|
if (TIFFReadScanline(cvts.tif, |
638 |
< |
(tidata_t)(cvts.t.bp + cvts.xmax), y, 1) < 0) |
638 |
> |
(tdata_t)(cvts.t.bp + cvts.xmax), y, 1) < 0) |
639 |
|
goto readerr; |
640 |
|
if (TIFFReadScanline(cvts.tif, |
641 |
< |
(tidata_t)(cvts.t.bp + 2*cvts.xmax), y, 2) < 0) |
641 |
> |
(tdata_t)(cvts.t.bp + 2*cvts.xmax), y, 2) < 0) |
642 |
|
goto readerr; |
643 |
|
for (x = cvts.xmax; x--; ) { |
644 |
|
cvts.r.colrs[x][RED] = cvts.t.bp[x]; |
675 |
|
{ |
676 |
|
register int x; |
677 |
|
|
678 |
< |
if (CHK(C_RFLT|C_TFLT) | !CHK(C_GRY)) |
678 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY) |
679 |
|
quiterr("internal error 1 in Gry2Colr"); |
680 |
|
|
681 |
|
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
696 |
|
|
697 |
|
|
698 |
|
int |
699 |
+ |
GGry2Color(y) /* read/convert/write G16->COLOR scanline */ |
700 |
+ |
uint32 y; |
701 |
+ |
{ |
702 |
+ |
int dogamma = cvts.gamcor < 0.99 | cvts.gamcor > 1.01; |
703 |
+ |
double m; |
704 |
+ |
register double d; |
705 |
+ |
register int x; |
706 |
+ |
|
707 |
+ |
if (CHK(C_TFLT|C_TWRD|C_GRY|C_RFLT) != (C_GRY|C_RFLT|C_TWRD)) |
708 |
+ |
quiterr("internal error 1 in GGry2Color"); |
709 |
+ |
|
710 |
+ |
if (TIFFReadScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
711 |
+ |
quiterr("error reading TIFF input"); |
712 |
+ |
|
713 |
+ |
if (cvts.bradj) |
714 |
+ |
m = pow(2., (double)cvts.bradj); |
715 |
+ |
for (x = cvts.xmax; x--; ) { |
716 |
+ |
d = (cvts.t.wp[x] + 0.5)*(1./(1L<<16)); |
717 |
+ |
if (dogamma) d = pow(d, cvts.gamcor); |
718 |
+ |
if (cvts.bradj) d *= m; |
719 |
+ |
colval(cvts.r.colors[x],RED) = |
720 |
+ |
colval(cvts.r.colors[x],GRN) = |
721 |
+ |
colval(cvts.r.colors[x],BLU) = d; |
722 |
+ |
} |
723 |
+ |
if (fwritescan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
724 |
+ |
quiterr("error writing Radiance picture"); |
725 |
+ |
} |
726 |
+ |
|
727 |
+ |
|
728 |
+ |
int |
729 |
|
Color2L(y) /* read/convert/write COLOR->L16 scanline */ |
730 |
|
uint32 y; |
731 |
|
{ |
732 |
|
double m = pow(2.,(double)cvts.bradj); |
733 |
|
register int x; |
734 |
|
|
735 |
< |
if (CHK(C_RFLT|C_TFLT) != (C_RFLT|C_TFLT) | !CHK(C_GRY)) |
735 |
> |
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY) != (C_RFLT|C_TFLT|C_GRY)) |
736 |
|
quiterr("internal error 1 in Color2L"); |
737 |
|
|
738 |
|
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
753 |
|
{ |
754 |
|
register int x; |
755 |
|
|
756 |
< |
if (CHK(C_RFLT|C_TFLT) != (C_RFLT|C_TFLT) | CHK(C_GRY)) |
756 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != (C_RFLT|C_TFLT)) |
757 |
|
quiterr("internal error 1 in Color2Luv"); |
758 |
|
|
759 |
|
if (freadscan(cvts.r.colors, cvts.xmax, cvts.rfp) < 0) |
770 |
|
} |
771 |
|
|
772 |
|
for (x = cvts.xmax; x--; ) { |
773 |
< |
cvts.t.fp[3*x] = colval(cvts.r.colors[x],RED); |
774 |
< |
cvts.t.fp[3*x+1] = colval(cvts.r.colors[x],GRN); |
775 |
< |
cvts.t.fp[3*x+2] = colval(cvts.r.colors[x],BLU); |
773 |
> |
cvts.t.fp[3*x] = colval(cvts.r.colors[x],CIEX); |
774 |
> |
cvts.t.fp[3*x+1] = colval(cvts.r.colors[x],CIEY); |
775 |
> |
cvts.t.fp[3*x+2] = colval(cvts.r.colors[x],CIEZ); |
776 |
|
} |
777 |
|
|
778 |
|
if (TIFFWriteScanline(cvts.tif, cvts.t.p, y, 0) < 0) |
786 |
|
{ |
787 |
|
register int x; |
788 |
|
|
789 |
< |
if (CHK(C_RFLT|C_TFLT) | !CHK(C_GRY)) |
789 |
> |
if (CHK(C_RFLT|C_TWRD|C_TFLT|C_GRY) != C_GRY) |
790 |
|
quiterr("internal error 1 in Colr2Gry"); |
791 |
|
|
792 |
|
if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0) |
813 |
|
COLOR ctmp; |
814 |
|
register int x; |
815 |
|
|
816 |
< |
if (CHK(C_RFLT|C_TFLT|C_GRY)) |
816 |
> |
if (CHK(C_RFLT|C_TFLT|C_TWRD|C_GRY)) |
817 |
|
quiterr("internal error 1 in Colr2RGB"); |
818 |
|
|
819 |
|
if (freadcolrs(cvts.r.colrs, cvts.xmax, cvts.rfp) < 0) |