1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* pvalue.c - program to print pixel values. |
6 |
|
* |
8 |
|
*/ |
9 |
|
|
10 |
|
#include "standard.h" |
11 |
< |
|
11 |
> |
#include "platform.h" |
12 |
|
#include "color.h" |
16 |
– |
|
13 |
|
#include "resolu.h" |
14 |
|
|
15 |
|
#define min(a,b) ((a)<(b)?(a):(b)) |
18 |
|
#define ALL 3 |
19 |
|
#define BRIGHT 4 |
20 |
|
|
25 |
– |
#define brightonly (putprim==BRIGHT) |
26 |
– |
|
21 |
|
RESOLU picres; /* resolution of picture */ |
22 |
|
|
23 |
|
int uniq = 0; /* print only unique values? */ |
37 |
|
|
38 |
|
long skipbytes = 0; /* skip bytes in input? */ |
39 |
|
|
40 |
+ |
int swapbytes = 0; /* swap bytes? */ |
41 |
+ |
|
42 |
+ |
int interleave = 1; /* file is interleaved? */ |
43 |
+ |
|
44 |
|
int resolution = 1; /* put/get resolution string? */ |
45 |
|
|
46 |
|
int original = 0; /* convert to original values? */ |
61 |
|
|
62 |
|
int (*getval)(), (*putval)(); |
63 |
|
|
64 |
+ |
double |
65 |
+ |
rgb_bright(clr) |
66 |
+ |
COLOR clr; |
67 |
+ |
{ |
68 |
+ |
return(bright(clr)); |
69 |
+ |
} |
70 |
|
|
71 |
+ |
double |
72 |
+ |
xyz_bright(clr) |
73 |
+ |
COLOR clr; |
74 |
+ |
{ |
75 |
+ |
return(clr[CIEY]); |
76 |
+ |
} |
77 |
+ |
|
78 |
+ |
double (*mybright)() = &rgb_bright; |
79 |
+ |
|
80 |
+ |
|
81 |
|
main(argc, argv) |
82 |
|
int argc; |
83 |
|
char **argv; |
133 |
|
case 'r': /* reverse conversion */ |
134 |
|
reverse = argv[i][0] == '-'; |
135 |
|
break; |
136 |
+ |
case 'n': /* non-interleaved RGB */ |
137 |
+ |
interleave = argv[i][0] == '+'; |
138 |
+ |
break; |
139 |
|
case 'b': /* brightness values */ |
140 |
|
putprim = argv[i][0] == '-' ? BRIGHT : ALL; |
141 |
|
break; |
164 |
|
format = 'b'; |
165 |
|
fmtid = "byte"; |
166 |
|
break; |
167 |
+ |
case 'W': /* 16-bit swapped */ |
168 |
+ |
swapbytes = 1; |
169 |
+ |
case 'w': /* 16-bit */ |
170 |
+ |
dataonly = 1; |
171 |
+ |
format = 'w'; |
172 |
+ |
fmtid = "16-bit"; |
173 |
+ |
break; |
174 |
+ |
case 'F': /* swapped floats */ |
175 |
+ |
swapbytes = 1; |
176 |
|
case 'f': /* float */ |
177 |
|
dataonly = 1; |
178 |
|
format = 'f'; |
179 |
|
fmtid = "float"; |
180 |
|
break; |
181 |
+ |
case 'D': /* swapped doubles */ |
182 |
+ |
swapbytes = 1; |
183 |
|
case 'd': /* double */ |
184 |
|
dataonly = 1; |
185 |
|
format = 'd'; |
193 |
|
case 'X': /* x resolution */ |
194 |
|
resolution = 0; |
195 |
|
if (argv[i][0] == '-') |
196 |
< |
picres.or |= XDECR; |
196 |
> |
picres.rt |= XDECR; |
197 |
|
picres.xr = atoi(argv[++i]); |
198 |
|
break; |
199 |
|
case 'y': /* y resolution */ |
200 |
|
case 'Y': /* y resolution */ |
201 |
|
resolution = 0; |
202 |
|
if (argv[i][0] == '-') |
203 |
< |
picres.or |= YDECR; |
203 |
> |
picres.rt |= YDECR; |
204 |
|
if (picres.xr == 0) |
205 |
< |
picres.or |= YMAJOR; |
205 |
> |
picres.rt |= YMAJOR; |
206 |
|
picres.yr = atoi(argv[++i]); |
207 |
|
break; |
208 |
|
default: |
215 |
|
else |
216 |
|
break; |
217 |
|
/* recognize special formats */ |
218 |
< |
if (dataonly && format == 'b') |
219 |
< |
if (brightonly) |
218 |
> |
if (dataonly && format == 'b') { |
219 |
> |
if (putprim == ALL) |
220 |
> |
fmtid = "24-bit_rgb"; |
221 |
> |
else |
222 |
|
fmtid = "8-bit_grey"; |
223 |
+ |
} |
224 |
+ |
if (dataonly && format == 'w') { |
225 |
+ |
if (putprim == ALL) |
226 |
+ |
fmtid = "48-bit_rgb"; |
227 |
|
else |
228 |
< |
fmtid = "24-bit_rgb"; |
228 |
> |
fmtid = "16-bit_grey"; |
229 |
> |
} |
230 |
|
/* assign reverse ordering */ |
231 |
|
rord[ord[0]] = 0; |
232 |
|
rord[ord[1]] = 1; |
240 |
|
progname, argv[i]); |
241 |
|
quit(1); |
242 |
|
} |
243 |
< |
if (skipbytes && fseek(fin, skipbytes, 0)) |
209 |
< |
goto seekerr; |
210 |
< |
if (reverse && !brightonly && i == argc-3) { |
243 |
> |
if (reverse && putprim != BRIGHT && i == argc-3) { |
244 |
|
if ((fin2 = fopen(argv[i+1], "r")) == NULL) { |
245 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
246 |
|
progname, argv[i+1]); |
251 |
|
progname, argv[i+2]); |
252 |
|
quit(1); |
253 |
|
} |
254 |
< |
if (skipbytes && (fseek(fin2, skipbytes, 0) || |
222 |
< |
fseek(fin3, skipbytes, 0))) |
223 |
< |
goto seekerr; |
254 |
> |
interleave = -1; |
255 |
|
} else if (i != argc-1) |
256 |
|
fin = NULL; |
257 |
+ |
if (reverse && putprim != BRIGHT && !interleave) { |
258 |
+ |
fin2 = fopen(argv[i], "r"); |
259 |
+ |
fin3 = fopen(argv[i], "r"); |
260 |
+ |
} |
261 |
+ |
if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL && |
262 |
+ |
(fseek(fin2, skipbytes, 0) || |
263 |
+ |
fseek(fin3, skipbytes, 0))))) { |
264 |
+ |
fprintf(stderr, "%s: cannot skip %ld bytes on input\n", |
265 |
+ |
progname, skipbytes); |
266 |
+ |
quit(1); |
267 |
+ |
} |
268 |
|
} |
269 |
|
if (fin == NULL) { |
270 |
|
fprintf(stderr, "%s: bad # file arguments\n", progname); |
271 |
|
quit(1); |
272 |
|
} |
273 |
|
|
232 |
– |
set_io(); |
233 |
– |
|
274 |
|
if (reverse) { |
275 |
< |
#ifdef MSDOS |
276 |
< |
setmode(fileno(stdout), O_BINARY); |
275 |
> |
#ifdef _WIN32 |
276 |
> |
SET_FILE_BINARY(stdout); |
277 |
|
if (format != 'a' && format != 'i') |
278 |
< |
setmode(fileno(fin), O_BINARY); |
278 |
> |
SET_FILE_BINARY(fin); |
279 |
|
#endif |
280 |
|
/* get header */ |
281 |
|
if (header) { |
299 |
|
if (resolution && fin2 != NULL) { |
300 |
|
RESOLU pres2; |
301 |
|
if (!fgetsresolu(&pres2, fin2) || |
302 |
< |
pres2.or != picres.or || |
302 |
> |
pres2.rt != picres.rt || |
303 |
|
pres2.xr != picres.xr || |
304 |
|
pres2.yr != picres.yr || |
305 |
|
!fgetsresolu(&pres2, fin3) || |
306 |
< |
pres2.or != picres.or || |
306 |
> |
pres2.rt != picres.rt || |
307 |
|
pres2.xr != picres.xr || |
308 |
|
pres2.yr != picres.yr) { |
309 |
|
fprintf(stderr, "%s: resolution mismatch\n", |
320 |
|
fputsresolu(&picres, stdout); /* always put resolution */ |
321 |
|
valtopix(); |
322 |
|
} else { |
323 |
< |
#ifdef MSDOS |
324 |
< |
setmode(fileno(fin), O_BINARY); |
323 |
> |
#ifdef _WIN32 |
324 |
> |
SET_FILE_BINARY(fin); |
325 |
|
if (format != 'a' && format != 'i') |
326 |
< |
setmode(fileno(stdout), O_BINARY); |
326 |
> |
SET_FILE_BINARY(stdout); |
327 |
|
#endif |
328 |
|
/* get header */ |
329 |
|
getheader(fin, checkhead, NULL); |
330 |
|
if (wrongformat) { |
331 |
< |
fprintf(stderr, "%s: input not a Radiance picture\n", |
331 |
> |
fprintf(stderr, |
332 |
> |
"%s: input not a Radiance RGBE picture\n", |
333 |
|
progname); |
334 |
|
quit(1); |
335 |
|
} |
350 |
|
} |
351 |
|
|
352 |
|
quit(0); |
312 |
– |
seekerr: |
313 |
– |
fprintf(stderr, "%s: cannot skip %ld bytes on input\n", |
314 |
– |
progname, skipbytes); |
315 |
– |
quit(1); |
353 |
|
} |
354 |
|
|
355 |
|
|
356 |
+ |
int |
357 |
|
checkhead(line) /* deal with line from header */ |
358 |
|
char *line; |
359 |
|
{ |
361 |
|
double d; |
362 |
|
COLOR ctmp; |
363 |
|
|
364 |
< |
if (formatval(fmt, line)) |
365 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
366 |
< |
else if (original && isexpos(line)) { |
364 |
> |
if (formatval(fmt, line)) { |
365 |
> |
if (!strcmp(fmt, CIEFMT)) { |
366 |
> |
mybright = &xyz_bright; |
367 |
> |
if (original) { |
368 |
> |
scalecolor(exposure, 1./WHTEFFICACY); |
369 |
> |
doexposure++; |
370 |
> |
} |
371 |
> |
} else if (!strcmp(fmt, COLRFMT)) |
372 |
> |
mybright = &rgb_bright; |
373 |
> |
else |
374 |
> |
wrongformat++; |
375 |
> |
} else if (original && isexpos(line)) { |
376 |
|
d = 1.0/exposval(line); |
377 |
|
scalecolor(exposure, d); |
378 |
|
doexposure++; |
384 |
|
doexposure++; |
385 |
|
} else if (header) |
386 |
|
fputs(line, stdout); |
387 |
+ |
return(0); |
388 |
|
} |
389 |
|
|
390 |
|
|
393 |
|
register COLOR *scanln; |
394 |
|
int dogamma; |
395 |
|
COLOR lastc; |
396 |
< |
FLOAT hv[2]; |
396 |
> |
RREAL hv[2]; |
397 |
> |
int startprim, endprim; |
398 |
> |
long startpos; |
399 |
|
int y; |
400 |
|
register int x; |
401 |
|
|
405 |
|
quit(1); |
406 |
|
} |
407 |
|
dogamma = gamcor < .95 || gamcor > 1.05; |
408 |
< |
setcolor(lastc, 0.0, 0.0, 0.0); |
409 |
< |
for (y = 0; y < numscans(&picres); y++) { |
410 |
< |
if (freadscan(scanln, scanlen(&picres), fin) < 0) { |
411 |
< |
fprintf(stderr, "%s: read error\n", progname); |
408 |
> |
if (putprim == ALL && !interleave) { |
409 |
> |
startprim = RED; endprim = BLU; |
410 |
> |
startpos = ftell(fin); |
411 |
> |
} else { |
412 |
> |
startprim = putprim; endprim = putprim; |
413 |
> |
} |
414 |
> |
for (putprim = startprim; putprim <= endprim; putprim++) { |
415 |
> |
if (putprim != startprim && fseek(fin, startpos, 0)) { |
416 |
> |
fprintf(stderr, "%s: seek error on input file\n", |
417 |
> |
progname); |
418 |
|
quit(1); |
419 |
|
} |
420 |
< |
for (x = 0; x < scanlen(&picres); x++) { |
421 |
< |
if (uniq) |
422 |
< |
if ( colval(scanln[x],RED) == |
423 |
< |
colval(lastc,RED) && |
424 |
< |
colval(scanln[x],GRN) == |
369 |
< |
colval(lastc,GRN) && |
370 |
< |
colval(scanln[x],BLU) == |
371 |
< |
colval(lastc,BLU) ) |
372 |
< |
continue; |
373 |
< |
else |
374 |
< |
copycolor(lastc, scanln[x]); |
375 |
< |
if (doexposure) |
376 |
< |
multcolor(scanln[x], exposure); |
377 |
< |
if (dogamma) |
378 |
< |
setcolor(scanln[x], |
379 |
< |
pow(colval(scanln[x],RED), 1.0/gamcor), |
380 |
< |
pow(colval(scanln[x],GRN), 1.0/gamcor), |
381 |
< |
pow(colval(scanln[x],BLU), 1.0/gamcor)); |
382 |
< |
if (!dataonly) { |
383 |
< |
pix2loc(hv, &picres, x, y); |
384 |
< |
printf("%7d %7d ", (int)(hv[0]*picres.xr), |
385 |
< |
(int)(hv[1]*picres.yr)); |
386 |
< |
} |
387 |
< |
if ((*putval)(scanln[x]) < 0) { |
388 |
< |
fprintf(stderr, "%s: write error\n", progname); |
420 |
> |
set_io(); |
421 |
> |
setcolor(lastc, 0.0, 0.0, 0.0); |
422 |
> |
for (y = 0; y < numscans(&picres); y++) { |
423 |
> |
if (freadscan(scanln, scanlen(&picres), fin) < 0) { |
424 |
> |
fprintf(stderr, "%s: read error\n", progname); |
425 |
|
quit(1); |
426 |
|
} |
427 |
+ |
for (x = 0; x < scanlen(&picres); x++) { |
428 |
+ |
if (uniq) { |
429 |
+ |
if ( colval(scanln[x],RED) == |
430 |
+ |
colval(lastc,RED) && |
431 |
+ |
colval(scanln[x],GRN) == |
432 |
+ |
colval(lastc,GRN) && |
433 |
+ |
colval(scanln[x],BLU) == |
434 |
+ |
colval(lastc,BLU) ) |
435 |
+ |
continue; |
436 |
+ |
else |
437 |
+ |
copycolor(lastc, scanln[x]); |
438 |
+ |
} |
439 |
+ |
if (doexposure) |
440 |
+ |
multcolor(scanln[x], exposure); |
441 |
+ |
if (dogamma) |
442 |
+ |
setcolor(scanln[x], |
443 |
+ |
pow(colval(scanln[x],RED), 1.0/gamcor), |
444 |
+ |
pow(colval(scanln[x],GRN), 1.0/gamcor), |
445 |
+ |
pow(colval(scanln[x],BLU), 1.0/gamcor)); |
446 |
+ |
if (!dataonly) { |
447 |
+ |
pix2loc(hv, &picres, x, y); |
448 |
+ |
printf("%7d %7d ", |
449 |
+ |
(int)(hv[0]*picres.xr), |
450 |
+ |
(int)(hv[1]*picres.yr)); |
451 |
+ |
} |
452 |
+ |
if ((*putval)(scanln[x]) < 0) { |
453 |
+ |
fprintf(stderr, "%s: write error\n", |
454 |
+ |
progname); |
455 |
+ |
quit(1); |
456 |
+ |
} |
457 |
+ |
} |
458 |
|
} |
459 |
|
} |
460 |
< |
free((char *)scanln); |
460 |
> |
free((void *)scanln); |
461 |
|
} |
462 |
|
|
463 |
|
|
474 |
|
quit(1); |
475 |
|
} |
476 |
|
dogamma = gamcor < .95 || gamcor > 1.05; |
477 |
+ |
set_io(); |
478 |
|
for (y = 0; y < numscans(&picres); y++) { |
479 |
|
for (x = 0; x < scanlen(&picres); x++) { |
480 |
|
if (!dataonly) { |
501 |
|
quit(1); |
502 |
|
} |
503 |
|
} |
504 |
< |
free((char *)scanln); |
504 |
> |
free((void *)scanln); |
505 |
|
} |
506 |
|
|
507 |
|
|
508 |
+ |
void |
509 |
|
quit(code) |
510 |
|
int code; |
511 |
|
{ |
513 |
|
} |
514 |
|
|
515 |
|
|
516 |
+ |
swap16(wp, n) /* swap n 16-bit words */ |
517 |
+ |
register uint16 *wp; |
518 |
+ |
int n; |
519 |
+ |
{ |
520 |
+ |
while (n-- > 0) { |
521 |
+ |
*wp = *wp << 8 | ((*wp >> 8) & 0xff); |
522 |
+ |
wp++; |
523 |
+ |
} |
524 |
+ |
} |
525 |
+ |
|
526 |
+ |
|
527 |
+ |
swap32(wp, n) /* swap n 32-bit words */ |
528 |
+ |
register uint32 *wp; |
529 |
+ |
int n; |
530 |
+ |
{ |
531 |
+ |
while (n-- > 0) { |
532 |
+ |
*wp = *wp << 24 | ((*wp >> 24) & 0xff) | |
533 |
+ |
(*wp & 0xff00) << 8 | (*wp & 0xff0000) >> 8; |
534 |
+ |
wp++; |
535 |
+ |
} |
536 |
+ |
} |
537 |
+ |
|
538 |
+ |
|
539 |
+ |
swap64(wp, n) /* swap n 64-bit words */ |
540 |
+ |
register char *wp; |
541 |
+ |
int n; |
542 |
+ |
{ |
543 |
+ |
register int t; |
544 |
+ |
|
545 |
+ |
while (n-- > 0) { |
546 |
+ |
t = wp[0]; wp[0] = wp[7]; wp[7] = t; |
547 |
+ |
t = wp[1]; wp[1] = wp[6]; wp[6] = t; |
548 |
+ |
t = wp[2]; wp[2] = wp[5]; wp[5] = t; |
549 |
+ |
t = wp[3]; wp[3] = wp[4]; wp[4] = t; |
550 |
+ |
wp += 8; |
551 |
+ |
} |
552 |
+ |
} |
553 |
+ |
|
554 |
+ |
|
555 |
|
getcascii(col) /* get an ascii color value from stream(s) */ |
556 |
|
COLOR col; |
557 |
|
{ |
585 |
|
fread((char *)(vd+2), sizeof(double), 1, fin3) != 1) |
586 |
|
return(-1); |
587 |
|
} |
588 |
+ |
if (swapbytes) |
589 |
+ |
swap64((char *)vd, 3); |
590 |
|
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
591 |
|
return(0); |
592 |
|
} |
606 |
|
fread((char *)(vf+2), sizeof(float), 1, fin3) != 1) |
607 |
|
return(-1); |
608 |
|
} |
609 |
+ |
if (swapbytes) |
610 |
+ |
swap32((uint32 *)vf, 3); |
611 |
|
setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]); |
612 |
|
return(0); |
613 |
|
} |
653 |
|
} |
654 |
|
|
655 |
|
|
656 |
+ |
getcword(col) /* get a 16-bit color value from stream(s) */ |
657 |
+ |
COLOR col; |
658 |
+ |
{ |
659 |
+ |
uint16 vw[3]; |
660 |
+ |
|
661 |
+ |
if (fin2 == NULL) { |
662 |
+ |
if (fread((char *)vw, sizeof(uint16), 3, fin) != 3) |
663 |
+ |
return(-1); |
664 |
+ |
} else { |
665 |
+ |
if (fread((char *)vw, sizeof(uint16), 1, fin) != 1 || |
666 |
+ |
fread((char *)(vw+1), sizeof(uint16), 1, fin2) != 1 || |
667 |
+ |
fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1) |
668 |
+ |
return(-1); |
669 |
+ |
} |
670 |
+ |
if (swapbytes) |
671 |
+ |
swap16(vw, 3); |
672 |
+ |
setcolor(col, (vw[rord[RED]]+.5)/65536., |
673 |
+ |
(vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.); |
674 |
+ |
return(0); |
675 |
+ |
} |
676 |
+ |
|
677 |
+ |
|
678 |
|
getbascii(col) /* get an ascii brightness value from fin */ |
679 |
|
COLOR col; |
680 |
|
{ |
694 |
|
|
695 |
|
if (fread((char *)&vd, sizeof(double), 1, fin) != 1) |
696 |
|
return(-1); |
697 |
+ |
if (swapbytes) |
698 |
+ |
swap64((char *)&vd, 1); |
699 |
|
setcolor(col, vd, vd, vd); |
700 |
|
return(0); |
701 |
|
} |
708 |
|
|
709 |
|
if (fread((char *)&vf, sizeof(float), 1, fin) != 1) |
710 |
|
return(-1); |
711 |
+ |
if (swapbytes) |
712 |
+ |
swap32((uint32 *)&vf, 1); |
713 |
|
setcolor(col, vf, vf, vf); |
714 |
|
return(0); |
715 |
|
} |
743 |
|
} |
744 |
|
|
745 |
|
|
746 |
+ |
getbword(col) /* get a 16-bit brightness value from fin */ |
747 |
+ |
COLOR col; |
748 |
+ |
{ |
749 |
+ |
uint16 vw; |
750 |
+ |
double d; |
751 |
+ |
|
752 |
+ |
if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1) |
753 |
+ |
return(-1); |
754 |
+ |
if (swapbytes) |
755 |
+ |
swap16(&vw, 1); |
756 |
+ |
d = (vw+.5)/65536.; |
757 |
+ |
setcolor(col, d, d, d); |
758 |
+ |
return(0); |
759 |
+ |
} |
760 |
+ |
|
761 |
+ |
|
762 |
|
putcascii(col) /* put an ascii color to stdout */ |
763 |
|
COLOR col; |
764 |
|
{ |
779 |
|
vf[0] = colval(col,ord[0]); |
780 |
|
vf[1] = colval(col,ord[1]); |
781 |
|
vf[2] = colval(col,ord[2]); |
782 |
+ |
if (swapbytes) |
783 |
+ |
swap32((uint32 *)vf, 3); |
784 |
|
fwrite((char *)vf, sizeof(float), 3, stdout); |
785 |
|
|
786 |
|
return(ferror(stdout) ? -1 : 0); |
795 |
|
vd[0] = colval(col,ord[0]); |
796 |
|
vd[1] = colval(col,ord[1]); |
797 |
|
vd[2] = colval(col,ord[2]); |
798 |
+ |
if (swapbytes) |
799 |
+ |
swap64((char *)vd, 3); |
800 |
|
fwrite((char *)vd, sizeof(double), 3, stdout); |
801 |
|
|
802 |
|
return(ferror(stdout) ? -1 : 0); |
818 |
|
putcbyte(col) /* put a byte color to stdout */ |
819 |
|
COLOR col; |
820 |
|
{ |
821 |
< |
register int i; |
821 |
> |
long i; |
822 |
|
BYTE vb[3]; |
823 |
|
|
824 |
|
i = colval(col,ord[0])*256.; |
833 |
|
} |
834 |
|
|
835 |
|
|
836 |
+ |
putcword(col) /* put a 16-bit color to stdout */ |
837 |
+ |
COLOR col; |
838 |
+ |
{ |
839 |
+ |
long i; |
840 |
+ |
uint16 vw[3]; |
841 |
+ |
|
842 |
+ |
i = colval(col,ord[0])*65536.; |
843 |
+ |
vw[0] = min(i,65535); |
844 |
+ |
i = colval(col,ord[1])*65536.; |
845 |
+ |
vw[1] = min(i,65535); |
846 |
+ |
i = colval(col,ord[2])*65536.; |
847 |
+ |
vw[2] = min(i,65535); |
848 |
+ |
if (swapbytes) |
849 |
+ |
swap16(vw, 3); |
850 |
+ |
fwrite((char *)vw, sizeof(uint16), 3, stdout); |
851 |
+ |
|
852 |
+ |
return(ferror(stdout) ? -1 : 0); |
853 |
+ |
} |
854 |
+ |
|
855 |
+ |
|
856 |
|
putbascii(col) /* put an ascii brightness to stdout */ |
857 |
|
COLOR col; |
858 |
|
{ |
859 |
< |
fprintf(stdout, "%15.3e\n", bright(col)); |
859 |
> |
fprintf(stdout, "%15.3e\n", (*mybright)(col)); |
860 |
|
|
861 |
|
return(ferror(stdout) ? -1 : 0); |
862 |
|
} |
867 |
|
{ |
868 |
|
float vf; |
869 |
|
|
870 |
< |
vf = bright(col); |
870 |
> |
vf = (*mybright)(col); |
871 |
> |
if (swapbytes) |
872 |
> |
swap32((uint32 *)&vf, 1); |
873 |
|
fwrite((char *)&vf, sizeof(float), 1, stdout); |
874 |
|
|
875 |
|
return(ferror(stdout) ? -1 : 0); |
881 |
|
{ |
882 |
|
double vd; |
883 |
|
|
884 |
< |
vd = bright(col); |
884 |
> |
vd = (*mybright)(col); |
885 |
> |
if (swapbytes) |
886 |
> |
swap64((char *)&vd, 1); |
887 |
|
fwrite((char *)&vd, sizeof(double), 1, stdout); |
888 |
|
|
889 |
|
return(ferror(stdout) ? -1 : 0); |
893 |
|
putbint(col) /* put an int brightness to stdout */ |
894 |
|
COLOR col; |
895 |
|
{ |
896 |
< |
fprintf(stdout, "%d\n", (int)(bright(col)*256.)); |
896 |
> |
fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.)); |
897 |
|
|
898 |
|
return(ferror(stdout) ? -1 : 0); |
899 |
|
} |
905 |
|
register int i; |
906 |
|
BYTE vb; |
907 |
|
|
908 |
< |
i = bright(col)*256.; |
908 |
> |
i = (*mybright)(col)*256.; |
909 |
|
vb = min(i,255); |
910 |
|
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
911 |
|
|
913 |
|
} |
914 |
|
|
915 |
|
|
916 |
+ |
putbword(col) /* put a 16-bit brightness to stdout */ |
917 |
+ |
COLOR col; |
918 |
+ |
{ |
919 |
+ |
long i; |
920 |
+ |
uint16 vw; |
921 |
+ |
|
922 |
+ |
i = (*mybright)(col)*65536.; |
923 |
+ |
vw = min(i,65535); |
924 |
+ |
if (swapbytes) |
925 |
+ |
swap16(&vw, 1); |
926 |
+ |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
927 |
+ |
|
928 |
+ |
return(ferror(stdout) ? -1 : 0); |
929 |
+ |
} |
930 |
+ |
|
931 |
+ |
|
932 |
|
putpascii(col) /* put an ascii primary to stdout */ |
933 |
|
COLOR col; |
934 |
|
{ |
944 |
|
float vf; |
945 |
|
|
946 |
|
vf = colval(col,putprim); |
947 |
+ |
if (swapbytes) |
948 |
+ |
swap32((uint32 *)&vf, 1); |
949 |
|
fwrite((char *)&vf, sizeof(float), 1, stdout); |
950 |
|
|
951 |
|
return(ferror(stdout) ? -1 : 0); |
958 |
|
double vd; |
959 |
|
|
960 |
|
vd = colval(col,putprim); |
961 |
+ |
if (swapbytes) |
962 |
+ |
swap64((char *)&vd, 1); |
963 |
|
fwrite((char *)&vd, sizeof(double), 1, stdout); |
964 |
|
|
965 |
|
return(ferror(stdout) ? -1 : 0); |
978 |
|
putpbyte(col) /* put a byte primary to stdout */ |
979 |
|
COLOR col; |
980 |
|
{ |
981 |
< |
register int i; |
981 |
> |
long i; |
982 |
|
BYTE vb; |
983 |
|
|
984 |
|
i = colval(col,putprim)*256.; |
989 |
|
} |
990 |
|
|
991 |
|
|
992 |
+ |
putpword(col) /* put a 16-bit primary to stdout */ |
993 |
+ |
COLOR col; |
994 |
+ |
{ |
995 |
+ |
long i; |
996 |
+ |
uint16 vw; |
997 |
+ |
|
998 |
+ |
i = colval(col,putprim)*65536.; |
999 |
+ |
vw = min(i,65535); |
1000 |
+ |
if (swapbytes) |
1001 |
+ |
swap16(&vw, 1); |
1002 |
+ |
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
1003 |
+ |
|
1004 |
+ |
return(ferror(stdout) ? -1 : 0); |
1005 |
+ |
} |
1006 |
+ |
|
1007 |
+ |
|
1008 |
|
set_io() /* set put and get functions */ |
1009 |
|
{ |
1010 |
|
switch (format) { |
1018 |
|
} else { |
1019 |
|
getval = getcascii; |
1020 |
|
putval = putcascii; |
1021 |
+ |
if (reverse && !interleave) { |
1022 |
+ |
fprintf(stderr, |
1023 |
+ |
"%s: ASCII input files must be interleaved\n", |
1024 |
+ |
progname); |
1025 |
+ |
quit(1); |
1026 |
+ |
} |
1027 |
|
} |
1028 |
|
return; |
1029 |
|
case 'f': /* binary float */ |
1036 |
|
} else { |
1037 |
|
getval = getcfloat; |
1038 |
|
putval = putcfloat; |
1039 |
+ |
if (reverse && !interleave) { |
1040 |
+ |
if (fin2 == NULL) |
1041 |
+ |
goto namerr; |
1042 |
+ |
if (fseek(fin2, |
1043 |
+ |
(long)sizeof(float)*picres.xr*picres.yr, 1)) |
1044 |
+ |
goto seekerr; |
1045 |
+ |
if (fseek(fin3, |
1046 |
+ |
(long)sizeof(float)*2*picres.xr*picres.yr, 1)) |
1047 |
+ |
goto seekerr; |
1048 |
+ |
} |
1049 |
|
} |
1050 |
|
return; |
1051 |
|
case 'd': /* binary double */ |
1058 |
|
} else { |
1059 |
|
getval = getcdouble; |
1060 |
|
putval = putcdouble; |
1061 |
+ |
if (reverse && !interleave) { |
1062 |
+ |
if (fin2 == NULL) |
1063 |
+ |
goto namerr; |
1064 |
+ |
if (fseek(fin2, |
1065 |
+ |
(long)sizeof(double)*picres.xr*picres.yr, 1)) |
1066 |
+ |
goto seekerr; |
1067 |
+ |
if (fseek(fin3, |
1068 |
+ |
(long)sizeof(double)*2*picres.xr*picres.yr, 1)) |
1069 |
+ |
goto seekerr; |
1070 |
+ |
} |
1071 |
|
} |
1072 |
|
return; |
1073 |
|
case 'i': /* integer */ |
1080 |
|
} else { |
1081 |
|
getval = getcint; |
1082 |
|
putval = putcint; |
1083 |
+ |
if (reverse && !interleave) { |
1084 |
+ |
fprintf(stderr, |
1085 |
+ |
"%s: integer input files must be interleaved\n", |
1086 |
+ |
progname); |
1087 |
+ |
quit(1); |
1088 |
+ |
} |
1089 |
|
} |
1090 |
|
return; |
1091 |
|
case 'b': /* byte */ |
1098 |
|
} else { |
1099 |
|
getval = getcbyte; |
1100 |
|
putval = putcbyte; |
1101 |
+ |
if (reverse && !interleave) { |
1102 |
+ |
if (fin2 == NULL) |
1103 |
+ |
goto namerr; |
1104 |
+ |
if (fseek(fin2, |
1105 |
+ |
(long)sizeof(BYTE)*picres.xr*picres.yr, 1)) |
1106 |
+ |
goto seekerr; |
1107 |
+ |
if (fseek(fin3, |
1108 |
+ |
(long)sizeof(BYTE)*2*picres.xr*picres.yr, 1)) |
1109 |
+ |
goto seekerr; |
1110 |
+ |
} |
1111 |
|
} |
1112 |
|
return; |
1113 |
+ |
case 'w': /* 16-bit */ |
1114 |
+ |
if (putprim == BRIGHT) { |
1115 |
+ |
getval = getbword; |
1116 |
+ |
putval = putbword; |
1117 |
+ |
} else if (putprim != ALL) { |
1118 |
+ |
getval = getbword; |
1119 |
+ |
putval = putpword; |
1120 |
+ |
} else { |
1121 |
+ |
getval = getcword; |
1122 |
+ |
putval = putcword; |
1123 |
+ |
if (reverse && !interleave) { |
1124 |
+ |
if (fin2 == NULL) |
1125 |
+ |
goto namerr; |
1126 |
+ |
if (fseek(fin2, |
1127 |
+ |
(long)sizeof(uint16)*picres.xr*picres.yr, 1)) |
1128 |
+ |
goto seekerr; |
1129 |
+ |
if (fseek(fin3, |
1130 |
+ |
(long)sizeof(uint16)*2*picres.xr*picres.yr, 1)) |
1131 |
+ |
goto seekerr; |
1132 |
+ |
} |
1133 |
+ |
} |
1134 |
+ |
return; |
1135 |
|
} |
1136 |
+ |
badopt: |
1137 |
+ |
fprintf(stderr, "%s: botched file type\n", progname); |
1138 |
+ |
quit(1); |
1139 |
+ |
namerr: |
1140 |
+ |
fprintf(stderr, "%s: non-interleaved file(s) must be named\n", |
1141 |
+ |
progname); |
1142 |
+ |
quit(1); |
1143 |
+ |
seekerr: |
1144 |
+ |
fprintf(stderr, "%s: cannot seek on interleaved input file\n", |
1145 |
+ |
progname); |
1146 |
+ |
quit(1); |
1147 |
|
} |