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 |
|
* |
7 |
|
* 4/23/86 |
8 |
|
*/ |
9 |
|
|
10 |
+ |
#include "platform.h" |
11 |
|
#include "standard.h" |
14 |
– |
|
12 |
|
#include "color.h" |
16 |
– |
|
13 |
|
#include "resolu.h" |
14 |
+ |
#include "view.h" |
15 |
|
|
16 |
|
#define min(a,b) ((a)<(b)?(a):(b)) |
17 |
|
|
19 |
|
#define ALL 3 |
20 |
|
#define BRIGHT 4 |
21 |
|
|
25 |
– |
#define brightonly (putprim==BRIGHT) |
26 |
– |
|
22 |
|
RESOLU picres; /* resolution of picture */ |
28 |
– |
|
23 |
|
int uniq = 0; /* print only unique values? */ |
30 |
– |
|
24 |
|
int doexposure = 0; /* exposure change? (>100 to print) */ |
32 |
– |
|
25 |
|
int dataonly = 0; /* data only format? */ |
34 |
– |
|
26 |
|
int putprim = ALL; /* what to put out */ |
36 |
– |
|
27 |
|
int reverse = 0; /* reverse conversion? */ |
38 |
– |
|
28 |
|
int format = 'a'; /* input/output format */ |
29 |
|
char *fmtid = "ascii"; /* format identifier for header */ |
41 |
– |
|
30 |
|
int header = 1; /* do header? */ |
43 |
– |
|
31 |
|
long skipbytes = 0; /* skip bytes in input? */ |
32 |
< |
|
32 |
> |
int swapbytes = 0; /* swap bytes? */ |
33 |
|
int interleave = 1; /* file is interleaved? */ |
47 |
– |
|
34 |
|
int resolution = 1; /* put/get resolution string? */ |
49 |
– |
|
35 |
|
int original = 0; /* convert to original values? */ |
51 |
– |
|
36 |
|
int wrongformat = 0; /* wrong input format? */ |
53 |
– |
|
37 |
|
double gamcor = 1.0; /* gamma correction */ |
38 |
|
|
39 |
+ |
RGBPRIMP outprims = stdprims; /* output primaries for reverse conversion */ |
40 |
+ |
RGBPRIMS myprims; |
41 |
+ |
|
42 |
|
int ord[3] = {RED, GRN, BLU}; /* RGB ordering */ |
43 |
|
int rord[4]; /* reverse ordering */ |
44 |
|
|
49 |
|
FILE *fin; |
50 |
|
FILE *fin2 = NULL, *fin3 = NULL; /* for other color channels */ |
51 |
|
|
66 |
– |
int (*getval)(), (*putval)(); |
52 |
|
|
53 |
+ |
typedef int getfunc_t(COLOR col); |
54 |
+ |
typedef int putfunc_t(COLOR col); |
55 |
+ |
typedef double brightfunc_t(COLOR col); |
56 |
|
|
57 |
< |
main(argc, argv) |
58 |
< |
int argc; |
59 |
< |
char **argv; |
57 |
> |
getfunc_t *getval; |
58 |
> |
putfunc_t *putval; |
59 |
> |
brightfunc_t *mybright; |
60 |
> |
|
61 |
> |
static gethfunc checkhead; |
62 |
> |
static brightfunc_t rgb_bright, xyz_bright; |
63 |
> |
static getfunc_t getbascii, getbint, getbdouble, getbfloat, getbbyte, getbword; |
64 |
> |
static getfunc_t getcascii, getcint, getcdouble, getcfloat, getcbyte, getcword; |
65 |
> |
static putfunc_t putbascii, putbint, putbdouble, putbfloat, putbbyte, putbword; |
66 |
> |
static putfunc_t putcascii, putcint, putcdouble, putcfloat, putcbyte, putcword; |
67 |
> |
static putfunc_t putpascii, putpint, putpdouble, putpfloat, putpbyte, putpword; |
68 |
> |
|
69 |
> |
static void set_io(void); |
70 |
> |
static void pixtoval(void); |
71 |
> |
static void valtopix(void); |
72 |
> |
|
73 |
> |
|
74 |
> |
static double |
75 |
> |
rgb_bright( |
76 |
> |
COLOR clr |
77 |
> |
) |
78 |
|
{ |
79 |
< |
extern int checkhead(); |
80 |
< |
extern long atol(); |
75 |
< |
double d, expval = 1.0; |
76 |
< |
int i; |
79 |
> |
return(bright(clr)); |
80 |
> |
} |
81 |
|
|
82 |
+ |
static double |
83 |
+ |
xyz_bright( |
84 |
+ |
COLOR clr |
85 |
+ |
) |
86 |
+ |
{ |
87 |
+ |
return(clr[CIEY]); |
88 |
+ |
} |
89 |
+ |
|
90 |
+ |
int |
91 |
+ |
main( |
92 |
+ |
int argc, |
93 |
+ |
char **argv |
94 |
+ |
) |
95 |
+ |
{ |
96 |
+ |
const char *inpmode = "r"; |
97 |
+ |
double d, expval = 1.0; |
98 |
+ |
int i; |
99 |
+ |
|
100 |
|
progname = argv[0]; |
101 |
+ |
mybright = &rgb_bright; /* default */ |
102 |
|
|
103 |
|
for (i = 1; i < argc; i++) |
104 |
|
if (argv[i][0] == '-' || argv[i][0] == '+') |
118 |
|
case 'o': /* original values */ |
119 |
|
original = argv[i][0] == '-'; |
120 |
|
break; |
121 |
+ |
case 'O': /* original watts/sr/m^2 */ |
122 |
+ |
original = -(argv[i][0] == '-'); |
123 |
+ |
break; |
124 |
|
case 'g': /* gamma correction */ |
125 |
|
gamcor = atof(argv[i+1]); |
126 |
|
if (argv[i][0] == '+') |
153 |
|
case 'b': /* brightness values */ |
154 |
|
putprim = argv[i][0] == '-' ? BRIGHT : ALL; |
155 |
|
break; |
156 |
< |
case 'p': /* put primary */ |
156 |
> |
case 'p': /* primary controls */ |
157 |
|
switch (argv[i][2]) { |
158 |
+ |
/* these two options affect -r conversion */ |
159 |
+ |
case '\0': |
160 |
+ |
myprims[RED][CIEX] = atof(argv[++i]); |
161 |
+ |
myprims[RED][CIEY] = atof(argv[++i]); |
162 |
+ |
myprims[GRN][CIEX] = atof(argv[++i]); |
163 |
+ |
myprims[GRN][CIEY] = atof(argv[++i]); |
164 |
+ |
myprims[BLU][CIEX] = atof(argv[++i]); |
165 |
+ |
myprims[BLU][CIEY] = atof(argv[++i]); |
166 |
+ |
myprims[WHT][CIEX] = atof(argv[++i]); |
167 |
+ |
myprims[WHT][CIEY] = atof(argv[++i]); |
168 |
+ |
outprims = myprims; |
169 |
+ |
break; |
170 |
+ |
case 'x': case 'X': outprims = NULL; break; |
171 |
+ |
/* the following options affect +r only */ |
172 |
|
case 'r': case 'R': putprim = RED; break; |
173 |
|
case 'g': case 'G': putprim = GRN; break; |
174 |
|
case 'b': case 'B': putprim = BLU; break; |
176 |
|
} |
177 |
|
break; |
178 |
|
case 'd': /* data only (no indices) */ |
179 |
< |
dataonly = argv[i][0] == '-'; |
179 |
> |
dataonly = (argv[i][0] == '-'); |
180 |
|
switch (argv[i][2]) { |
181 |
|
case '\0': |
182 |
|
case 'a': /* ascii */ |
192 |
|
format = 'b'; |
193 |
|
fmtid = "byte"; |
194 |
|
break; |
195 |
+ |
case 'W': /* 16-bit swapped */ |
196 |
+ |
swapbytes = 1; |
197 |
+ |
case 'w': /* 16-bit */ |
198 |
+ |
dataonly = 1; |
199 |
+ |
format = 'w'; |
200 |
+ |
fmtid = "16-bit"; |
201 |
+ |
break; |
202 |
+ |
case 'F': /* swapped floats */ |
203 |
+ |
swapbytes = 1; |
204 |
|
case 'f': /* float */ |
205 |
|
dataonly = 1; |
206 |
|
format = 'f'; |
207 |
|
fmtid = "float"; |
208 |
|
break; |
209 |
+ |
case 'D': /* swapped doubles */ |
210 |
+ |
swapbytes = 1; |
211 |
|
case 'd': /* double */ |
212 |
|
dataonly = 1; |
213 |
|
format = 'd'; |
221 |
|
case 'X': /* x resolution */ |
222 |
|
resolution = 0; |
223 |
|
if (argv[i][0] == '-') |
224 |
< |
picres.or |= XDECR; |
224 |
> |
picres.rt |= XDECR; |
225 |
|
picres.xr = atoi(argv[++i]); |
226 |
|
break; |
227 |
|
case 'y': /* y resolution */ |
228 |
|
case 'Y': /* y resolution */ |
229 |
|
resolution = 0; |
230 |
|
if (argv[i][0] == '-') |
231 |
< |
picres.or |= YDECR; |
231 |
> |
picres.rt |= YDECR; |
232 |
|
if (picres.xr == 0) |
233 |
< |
picres.or |= YMAJOR; |
233 |
> |
picres.rt |= YMAJOR; |
234 |
|
picres.yr = atoi(argv[++i]); |
235 |
|
break; |
236 |
|
default: |
243 |
|
else |
244 |
|
break; |
245 |
|
/* recognize special formats */ |
246 |
< |
if (dataonly && format == 'b') |
247 |
< |
if (brightonly) |
246 |
> |
if (dataonly && format == 'b') { |
247 |
> |
if (putprim == ALL) |
248 |
> |
fmtid = "24-bit_rgb"; |
249 |
> |
else |
250 |
|
fmtid = "8-bit_grey"; |
251 |
+ |
} |
252 |
+ |
if (dataonly && format == 'w') { |
253 |
+ |
if (putprim == ALL) |
254 |
+ |
fmtid = "48-bit_rgb"; |
255 |
|
else |
256 |
< |
fmtid = "24-bit_rgb"; |
256 |
> |
fmtid = "16-bit_grey"; |
257 |
> |
} |
258 |
> |
if (!reverse || (format != 'a') & (format != 'i')) |
259 |
> |
inpmode = "rb"; |
260 |
|
/* assign reverse ordering */ |
261 |
|
rord[ord[0]] = 0; |
262 |
|
rord[ord[1]] = 1; |
263 |
|
rord[ord[2]] = 2; |
264 |
|
/* get input */ |
265 |
|
if (i == argc) { |
266 |
+ |
long n = skipbytes; |
267 |
+ |
if (inpmode[1] == 'b') |
268 |
+ |
SET_FILE_BINARY(stdin); |
269 |
+ |
while (n-- > 0) |
270 |
+ |
if (getchar() == EOF) { |
271 |
+ |
fprintf(stderr, |
272 |
+ |
"%s: cannot skip %ld bytes on standard input\n", |
273 |
+ |
progname, skipbytes); |
274 |
+ |
quit(1); |
275 |
+ |
} |
276 |
|
fin = stdin; |
277 |
|
} else if (i < argc) { |
278 |
< |
if ((fin = fopen(argv[i], "r")) == NULL) { |
278 |
> |
if ((fin = fopen(argv[i], inpmode)) == NULL) { |
279 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
280 |
|
progname, argv[i]); |
281 |
|
quit(1); |
282 |
|
} |
283 |
< |
if (reverse && !brightonly && i == argc-3) { |
284 |
< |
if ((fin2 = fopen(argv[i+1], "r")) == NULL) { |
283 |
> |
if (reverse && putprim != BRIGHT && i == argc-3) { |
284 |
> |
if ((fin2 = fopen(argv[i+1], inpmode)) == NULL) { |
285 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
286 |
|
progname, argv[i+1]); |
287 |
|
quit(1); |
288 |
|
} |
289 |
< |
if ((fin3 = fopen(argv[i+2], "r")) == NULL) { |
289 |
> |
if ((fin3 = fopen(argv[i+2], inpmode)) == NULL) { |
290 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
291 |
|
progname, argv[i+2]); |
292 |
|
quit(1); |
294 |
|
interleave = -1; |
295 |
|
} else if (i != argc-1) |
296 |
|
fin = NULL; |
297 |
< |
if (reverse && !brightonly && !interleave) { |
298 |
< |
fin2 = fopen(argv[i], "r"); |
299 |
< |
fin3 = fopen(argv[i], "r"); |
297 |
> |
if (reverse && putprim != BRIGHT && !interleave) { |
298 |
> |
fin2 = fopen(argv[i], inpmode); |
299 |
> |
fin3 = fopen(argv[i], inpmode); |
300 |
|
} |
301 |
< |
if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL && |
302 |
< |
(fseek(fin2, skipbytes, 0) || |
303 |
< |
fseek(fin3, skipbytes, 0))))) { |
301 |
> |
if (skipbytes && (fseek(fin, skipbytes, SEEK_SET) || (fin2 != NULL && |
302 |
> |
fseek(fin2, skipbytes, SEEK_SET) | |
303 |
> |
fseek(fin3, skipbytes, SEEK_SET)))) { |
304 |
|
fprintf(stderr, "%s: cannot skip %ld bytes on input\n", |
305 |
|
progname, skipbytes); |
306 |
|
quit(1); |
312 |
|
} |
313 |
|
|
314 |
|
if (reverse) { |
315 |
< |
#ifdef MSDOS |
246 |
< |
setmode(fileno(stdout), O_BINARY); |
247 |
< |
if (format != 'a' && format != 'i') |
248 |
< |
setmode(fileno(fin), O_BINARY); |
249 |
< |
#endif |
315 |
> |
SET_FILE_BINARY(stdout); |
316 |
|
/* get header */ |
317 |
|
if (header) { |
318 |
< |
if (checkheader(fin, fmtid, stdout) < 0) { |
319 |
< |
fprintf(stderr, "%s: wrong input format\n", |
320 |
< |
progname); |
318 |
> |
getheader(fin, checkhead, stdout); |
319 |
> |
if (wrongformat) { |
320 |
> |
fprintf(stderr, "%s: wrong input format (expected %s)\n", |
321 |
> |
progname, fmtid); |
322 |
|
quit(1); |
323 |
|
} |
324 |
|
if (fin2 != NULL) { |
336 |
|
if (resolution && fin2 != NULL) { |
337 |
|
RESOLU pres2; |
338 |
|
if (!fgetsresolu(&pres2, fin2) || |
339 |
< |
pres2.or != picres.or || |
339 |
> |
pres2.rt != picres.rt || |
340 |
|
pres2.xr != picres.xr || |
341 |
|
pres2.yr != picres.yr || |
342 |
|
!fgetsresolu(&pres2, fin3) || |
343 |
< |
pres2.or != picres.or || |
343 |
> |
pres2.rt != picres.rt || |
344 |
|
pres2.xr != picres.xr || |
345 |
|
pres2.yr != picres.yr) { |
346 |
|
fprintf(stderr, "%s: resolution mismatch\n", |
352 |
|
printargs(i, argv, stdout); |
353 |
|
if (expval < .99 || expval > 1.01) |
354 |
|
fputexpos(expval, stdout); |
355 |
< |
fputformat(COLRFMT, stdout); |
355 |
> |
if (outprims != NULL) { |
356 |
> |
if (outprims != stdprims) |
357 |
> |
fputprims(outprims, stdout); |
358 |
> |
fputformat(COLRFMT, stdout); |
359 |
> |
} else { /* XYZ data */ |
360 |
> |
if (original < 0) { |
361 |
> |
scalecolor(exposure, WHTEFFICACY); |
362 |
> |
doexposure++; |
363 |
> |
} |
364 |
> |
fputformat(CIEFMT, stdout); |
365 |
> |
} |
366 |
|
putchar('\n'); |
367 |
|
fputsresolu(&picres, stdout); /* always put resolution */ |
368 |
|
valtopix(); |
369 |
|
} else { |
370 |
< |
#ifdef MSDOS |
371 |
< |
setmode(fileno(fin), O_BINARY); |
295 |
< |
if (format != 'a' && format != 'i') |
296 |
< |
setmode(fileno(stdout), O_BINARY); |
297 |
< |
#endif |
370 |
> |
if ((format != 'a') & (format != 'i')) |
371 |
> |
SET_FILE_BINARY(stdout); |
372 |
|
/* get header */ |
373 |
< |
getheader(fin, checkhead, NULL); |
373 |
> |
getheader(fin, checkhead, header ? stdout : (FILE *)NULL); |
374 |
|
if (wrongformat) { |
375 |
< |
fprintf(stderr, "%s: input not a Radiance picture\n", |
375 |
> |
fprintf(stderr, |
376 |
> |
"%s: input not a Radiance RGBE picture\n", |
377 |
|
progname); |
378 |
|
quit(1); |
379 |
|
} |
381 |
|
fprintf(stderr, "%s: missing resolution\n", progname); |
382 |
|
quit(1); |
383 |
|
} |
384 |
+ |
if (original < 0 && mybright == &xyz_bright) { |
385 |
+ |
scalecolor(exposure, 1./WHTEFFICACY); |
386 |
+ |
doexposure++; |
387 |
+ |
} |
388 |
|
if (header) { |
389 |
|
printargs(i, argv, stdout); |
390 |
+ |
printf("NCOMP=%d\n", putprim==ALL ? 3 : 1); |
391 |
+ |
if (!resolution && dataonly && !uniq) |
392 |
+ |
printf("NCOLS=%d\nNROWS=%d\n", scanlen(&picres), |
393 |
+ |
numscans(&picres)); |
394 |
|
if (expval < .99 || expval > 1.01) |
395 |
|
fputexpos(expval, stdout); |
396 |
+ |
if (swapbytes) { |
397 |
+ |
if (nativebigendian()) |
398 |
+ |
puts("BigEndian=0"); |
399 |
+ |
else |
400 |
+ |
puts("BigEndian=1"); |
401 |
+ |
} else if ((format != 'a') & (format != 'i') & |
402 |
+ |
(format != 'b')) |
403 |
+ |
fputendian(stdout); |
404 |
|
fputformat(fmtid, stdout); |
405 |
|
putchar('\n'); |
406 |
|
} |
410 |
|
} |
411 |
|
|
412 |
|
quit(0); |
413 |
+ |
return 0; /* pro forma return */ |
414 |
|
} |
415 |
|
|
416 |
|
|
417 |
< |
checkhead(line) /* deal with line from header */ |
418 |
< |
char *line; |
417 |
> |
static int |
418 |
> |
checkhead( /* deal with line from header */ |
419 |
> |
char *line, |
420 |
> |
void *p |
421 |
> |
) |
422 |
|
{ |
423 |
< |
char fmt[32]; |
423 |
> |
FILE *fout = (FILE *)p; |
424 |
> |
char fmt[MAXFMTLEN]; |
425 |
|
double d; |
426 |
|
COLOR ctmp; |
427 |
+ |
int rv; |
428 |
|
|
429 |
< |
if (formatval(fmt, line)) |
430 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
431 |
< |
else if (original && isexpos(line)) { |
429 |
> |
if (formatval(fmt, line)) { |
430 |
> |
if (reverse) |
431 |
> |
wrongformat = strcmp(fmt, fmtid); |
432 |
> |
else if (!strcmp(fmt, CIEFMT)) |
433 |
> |
mybright = &xyz_bright; |
434 |
> |
else if (!strcmp(fmt, COLRFMT)) |
435 |
> |
mybright = &rgb_bright; |
436 |
> |
else |
437 |
> |
wrongformat++; |
438 |
> |
return(1); |
439 |
> |
} |
440 |
> |
if (original && isexpos(line)) { |
441 |
|
d = 1.0/exposval(line); |
442 |
|
scalecolor(exposure, d); |
443 |
|
doexposure++; |
444 |
< |
} else if (original && iscolcor(line)) { |
444 |
> |
return(1); |
445 |
> |
} |
446 |
> |
if (original && iscolcor(line)) { |
447 |
|
colcorval(ctmp, line); |
448 |
|
setcolor(exposure, colval(exposure,RED)/colval(ctmp,RED), |
449 |
|
colval(exposure,GRN)/colval(ctmp,GRN), |
450 |
|
colval(exposure,BLU)/colval(ctmp,BLU)); |
451 |
|
doexposure++; |
452 |
< |
} else if (header) |
453 |
< |
fputs(line, stdout); |
452 |
> |
return(1); |
453 |
> |
} |
454 |
> |
if ((rv = isbigendian(line)) >= 0) { |
455 |
> |
if (reverse) |
456 |
> |
swapbytes = (nativebigendian() != rv); |
457 |
> |
return(1); |
458 |
> |
} |
459 |
> |
if (fout != NULL) |
460 |
> |
fputs(line, fout); |
461 |
> |
return(0); |
462 |
|
} |
463 |
|
|
464 |
|
|
465 |
< |
pixtoval() /* convert picture to values */ |
465 |
> |
static void |
466 |
> |
pixtoval(void) /* convert picture to values */ |
467 |
|
{ |
468 |
< |
register COLOR *scanln; |
468 |
> |
COLOR *scanln; |
469 |
|
int dogamma; |
470 |
|
COLOR lastc; |
471 |
< |
FLOAT hv[2]; |
471 |
> |
RREAL hv[2]; |
472 |
|
int startprim, endprim; |
473 |
|
long startpos; |
474 |
< |
int y; |
358 |
< |
register int x; |
474 |
> |
int x, y; |
475 |
|
|
476 |
|
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
477 |
|
if (scanln == NULL) { |
479 |
|
quit(1); |
480 |
|
} |
481 |
|
dogamma = gamcor < .95 || gamcor > 1.05; |
482 |
< |
if (putprim == ALL && !interleave) { |
482 |
> |
if ((putprim == ALL) & !interleave) { |
483 |
|
startprim = RED; endprim = BLU; |
484 |
|
startpos = ftell(fin); |
485 |
|
} else { |
486 |
|
startprim = putprim; endprim = putprim; |
487 |
|
} |
488 |
|
for (putprim = startprim; putprim <= endprim; putprim++) { |
489 |
< |
if (putprim != startprim && fseek(fin, startpos, 0)) { |
489 |
> |
if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) { |
490 |
|
fprintf(stderr, "%s: seek error on input file\n", |
491 |
|
progname); |
492 |
|
quit(1); |
499 |
|
quit(1); |
500 |
|
} |
501 |
|
for (x = 0; x < scanlen(&picres); x++) { |
502 |
< |
if (uniq) |
502 |
> |
if (uniq) { |
503 |
|
if ( colval(scanln[x],RED) == |
504 |
|
colval(lastc,RED) && |
505 |
|
colval(scanln[x],GRN) == |
509 |
|
continue; |
510 |
|
else |
511 |
|
copycolor(lastc, scanln[x]); |
512 |
+ |
} |
513 |
|
if (doexposure) |
514 |
|
multcolor(scanln[x], exposure); |
515 |
|
if (dogamma) |
531 |
|
} |
532 |
|
} |
533 |
|
} |
534 |
< |
free((char *)scanln); |
534 |
> |
free((void *)scanln); |
535 |
|
} |
536 |
|
|
537 |
|
|
538 |
< |
valtopix() /* convert values to a pixel file */ |
538 |
> |
static void |
539 |
> |
valtopix(void) /* convert values to a pixel file */ |
540 |
|
{ |
541 |
< |
int dogamma; |
542 |
< |
register COLOR *scanln; |
543 |
< |
int y; |
544 |
< |
register int x; |
541 |
> |
int dogamma; |
542 |
> |
COLOR *scanln; |
543 |
> |
COLR rgbe; |
544 |
> |
int x, y; |
545 |
|
|
546 |
|
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
547 |
|
if (scanln == NULL) { |
570 |
|
pow(colval(scanln[x],BLU), gamcor)); |
571 |
|
if (doexposure) |
572 |
|
multcolor(scanln[x], exposure); |
573 |
+ |
if (uniq) { /* uncompressed? */ |
574 |
+ |
setcolr(rgbe, scanln[x][RED], |
575 |
+ |
scanln[x][GRN], |
576 |
+ |
scanln[x][BLU]); |
577 |
+ |
if (putbinary(rgbe, sizeof(COLR), 1, stdout) != 1) |
578 |
+ |
goto writerr; |
579 |
+ |
} |
580 |
|
} |
581 |
< |
if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { |
582 |
< |
fprintf(stderr, "%s: write error\n", progname); |
583 |
< |
quit(1); |
459 |
< |
} |
581 |
> |
/* write scan if compressed */ |
582 |
> |
if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0) |
583 |
> |
goto writerr; |
584 |
|
} |
585 |
< |
free((char *)scanln); |
585 |
> |
free((void *)scanln); |
586 |
> |
return; |
587 |
> |
writerr: |
588 |
> |
fprintf(stderr, "%s: write error\n", progname); |
589 |
> |
quit(1); |
590 |
|
} |
591 |
|
|
592 |
|
|
593 |
+ |
void |
594 |
|
quit(code) |
595 |
|
int code; |
596 |
|
{ |
598 |
|
} |
599 |
|
|
600 |
|
|
601 |
< |
getcascii(col) /* get an ascii color value from stream(s) */ |
602 |
< |
COLOR col; |
601 |
> |
static int |
602 |
> |
getcascii( /* get an ascii color value from stream(s) */ |
603 |
> |
COLOR col |
604 |
> |
) |
605 |
|
{ |
606 |
|
double vd[3]; |
607 |
|
|
619 |
|
} |
620 |
|
|
621 |
|
|
622 |
< |
getcdouble(col) /* get a double color value from stream(s) */ |
623 |
< |
COLOR col; |
622 |
> |
static int |
623 |
> |
getcdouble( /* get a double color value from stream(s) */ |
624 |
> |
COLOR col |
625 |
> |
) |
626 |
|
{ |
627 |
|
double vd[3]; |
628 |
|
|
629 |
|
if (fin2 == NULL) { |
630 |
< |
if (fread((char *)vd, sizeof(double), 3, fin) != 3) |
630 |
> |
if (getbinary(vd, sizeof(double), 3, fin) != 3) |
631 |
|
return(-1); |
632 |
|
} else { |
633 |
< |
if (fread((char *)vd, sizeof(double), 1, fin) != 1 || |
634 |
< |
fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 || |
635 |
< |
fread((char *)(vd+2), sizeof(double), 1, fin3) != 1) |
633 |
> |
if (getbinary(vd, sizeof(double), 1, fin) != 1 || |
634 |
> |
getbinary(vd+1, sizeof(double), 1, fin2) != 1 || |
635 |
> |
getbinary(vd+2, sizeof(double), 1, fin3) != 1) |
636 |
|
return(-1); |
637 |
|
} |
638 |
+ |
if (swapbytes) |
639 |
+ |
swap64((char *)vd, 3); |
640 |
|
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
641 |
|
return(0); |
642 |
|
} |
643 |
|
|
644 |
|
|
645 |
< |
getcfloat(col) /* get a float color value from stream(s) */ |
646 |
< |
COLOR col; |
645 |
> |
static int |
646 |
> |
getcfloat( /* get a float color value from stream(s) */ |
647 |
> |
COLOR col |
648 |
> |
) |
649 |
|
{ |
650 |
|
float vf[3]; |
651 |
|
|
652 |
|
if (fin2 == NULL) { |
653 |
< |
if (fread((char *)vf, sizeof(float), 3, fin) != 3) |
653 |
> |
if (getbinary(vf, sizeof(float), 3, fin) != 3) |
654 |
|
return(-1); |
655 |
|
} else { |
656 |
< |
if (fread((char *)vf, sizeof(float), 1, fin) != 1 || |
657 |
< |
fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 || |
658 |
< |
fread((char *)(vf+2), sizeof(float), 1, fin3) != 1) |
656 |
> |
if (getbinary(vf, sizeof(float), 1, fin) != 1 || |
657 |
> |
getbinary(vf+1, sizeof(float), 1, fin2) != 1 || |
658 |
> |
getbinary(vf+2, sizeof(float), 1, fin3) != 1) |
659 |
|
return(-1); |
660 |
|
} |
661 |
+ |
if (swapbytes) |
662 |
+ |
swap32((char *)vf, 3); |
663 |
|
setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]); |
664 |
|
return(0); |
665 |
|
} |
666 |
|
|
667 |
|
|
668 |
< |
getcint(col) /* get an int color value from stream(s) */ |
669 |
< |
COLOR col; |
668 |
> |
static int |
669 |
> |
getcint( /* get an int color value from stream(s) */ |
670 |
> |
COLOR col |
671 |
> |
) |
672 |
|
{ |
673 |
|
int vi[3]; |
674 |
|
|
687 |
|
} |
688 |
|
|
689 |
|
|
690 |
< |
getcbyte(col) /* get a byte color value from stream(s) */ |
691 |
< |
COLOR col; |
690 |
> |
static int |
691 |
> |
getcbyte( /* get a byte color value from stream(s) */ |
692 |
> |
COLOR col |
693 |
> |
) |
694 |
|
{ |
695 |
< |
BYTE vb[3]; |
695 |
> |
uby8 vb[3]; |
696 |
|
|
697 |
|
if (fin2 == NULL) { |
698 |
< |
if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3) |
698 |
> |
if (getbinary(vb, sizeof(uby8), 3, fin) != 3) |
699 |
|
return(-1); |
700 |
|
} else { |
701 |
< |
if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 || |
702 |
< |
fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 || |
703 |
< |
fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1) |
701 |
> |
if (getbinary(vb, sizeof(uby8), 1, fin) != 1 || |
702 |
> |
getbinary(vb+1, sizeof(uby8), 1, fin2) != 1 || |
703 |
> |
getbinary(vb+2, sizeof(uby8), 1, fin3) != 1) |
704 |
|
return(-1); |
705 |
|
} |
706 |
|
setcolor(col, (vb[rord[RED]]+.5)/256., |
709 |
|
} |
710 |
|
|
711 |
|
|
712 |
< |
getbascii(col) /* get an ascii brightness value from fin */ |
713 |
< |
COLOR col; |
712 |
> |
static int |
713 |
> |
getcword( /* get a 16-bit color value from stream(s) */ |
714 |
> |
COLOR col |
715 |
> |
) |
716 |
|
{ |
717 |
+ |
uint16 vw[3]; |
718 |
+ |
|
719 |
+ |
if (fin2 == NULL) { |
720 |
+ |
if (getbinary(vw, sizeof(uint16), 3, fin) != 3) |
721 |
+ |
return(-1); |
722 |
+ |
} else { |
723 |
+ |
if (getbinary(vw, sizeof(uint16), 1, fin) != 1 || |
724 |
+ |
getbinary(vw+1, sizeof(uint16), 1, fin2) != 1 || |
725 |
+ |
getbinary(vw+2, sizeof(uint16), 1, fin3) != 1) |
726 |
+ |
return(-1); |
727 |
+ |
} |
728 |
+ |
if (swapbytes) |
729 |
+ |
swap16((char *)vw, 3); |
730 |
+ |
setcolor(col, (vw[rord[RED]]+.5)/65536., |
731 |
+ |
(vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.); |
732 |
+ |
return(0); |
733 |
+ |
} |
734 |
+ |
|
735 |
+ |
|
736 |
+ |
static int |
737 |
+ |
getbascii( /* get an ascii brightness value from fin */ |
738 |
+ |
COLOR col |
739 |
+ |
) |
740 |
+ |
{ |
741 |
|
double vd; |
742 |
|
|
743 |
|
if (fscanf(fin, "%lf", &vd) != 1) |
747 |
|
} |
748 |
|
|
749 |
|
|
750 |
< |
getbdouble(col) /* get a double brightness value from fin */ |
751 |
< |
COLOR col; |
750 |
> |
static int |
751 |
> |
getbdouble( /* get a double brightness value from fin */ |
752 |
> |
COLOR col |
753 |
> |
) |
754 |
|
{ |
755 |
|
double vd; |
756 |
|
|
757 |
< |
if (fread((char *)&vd, sizeof(double), 1, fin) != 1) |
757 |
> |
if (getbinary(&vd, sizeof(double), 1, fin) != 1) |
758 |
|
return(-1); |
759 |
+ |
if (swapbytes) |
760 |
+ |
swap64((char *)&vd, 1); |
761 |
|
setcolor(col, vd, vd, vd); |
762 |
|
return(0); |
763 |
|
} |
764 |
|
|
765 |
|
|
766 |
< |
getbfloat(col) /* get a float brightness value from fin */ |
767 |
< |
COLOR col; |
766 |
> |
static int |
767 |
> |
getbfloat( /* get a float brightness value from fin */ |
768 |
> |
COLOR col |
769 |
> |
) |
770 |
|
{ |
771 |
|
float vf; |
772 |
|
|
773 |
< |
if (fread((char *)&vf, sizeof(float), 1, fin) != 1) |
773 |
> |
if (getbinary(&vf, sizeof(float), 1, fin) != 1) |
774 |
|
return(-1); |
775 |
+ |
if (swapbytes) |
776 |
+ |
swap32((char *)&vf, 1); |
777 |
|
setcolor(col, vf, vf, vf); |
778 |
|
return(0); |
779 |
|
} |
780 |
|
|
781 |
|
|
782 |
< |
getbint(col) /* get an int brightness value from fin */ |
783 |
< |
COLOR col; |
782 |
> |
static int |
783 |
> |
getbint( /* get an int brightness value from fin */ |
784 |
> |
COLOR col |
785 |
> |
) |
786 |
|
{ |
787 |
|
int vi; |
788 |
|
double d; |
795 |
|
} |
796 |
|
|
797 |
|
|
798 |
< |
getbbyte(col) /* get a byte brightness value from fin */ |
799 |
< |
COLOR col; |
798 |
> |
static int |
799 |
> |
getbbyte( /* get a byte brightness value from fin */ |
800 |
> |
COLOR col |
801 |
> |
) |
802 |
|
{ |
803 |
< |
BYTE vb; |
803 |
> |
uby8 vb; |
804 |
|
double d; |
805 |
|
|
806 |
< |
if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1) |
806 |
> |
if (getbinary(&vb, sizeof(uby8), 1, fin) != 1) |
807 |
|
return(-1); |
808 |
|
d = (vb+.5)/256.; |
809 |
|
setcolor(col, d, d, d); |
811 |
|
} |
812 |
|
|
813 |
|
|
814 |
< |
putcascii(col) /* put an ascii color to stdout */ |
815 |
< |
COLOR col; |
814 |
> |
static int |
815 |
> |
getbword( /* get a 16-bit brightness value from fin */ |
816 |
> |
COLOR col |
817 |
> |
) |
818 |
|
{ |
819 |
+ |
uint16 vw; |
820 |
+ |
double d; |
821 |
+ |
|
822 |
+ |
if (getbinary(&vw, sizeof(uint16), 1, fin) != 1) |
823 |
+ |
return(-1); |
824 |
+ |
if (swapbytes) |
825 |
+ |
swap16((char *)&vw, 1); |
826 |
+ |
d = (vw+.5)/65536.; |
827 |
+ |
setcolor(col, d, d, d); |
828 |
+ |
return(0); |
829 |
+ |
} |
830 |
+ |
|
831 |
+ |
|
832 |
+ |
static int |
833 |
+ |
putcascii( /* put an ascii color to stdout */ |
834 |
+ |
COLOR col |
835 |
+ |
) |
836 |
+ |
{ |
837 |
|
fprintf(stdout, "%15.3e %15.3e %15.3e\n", |
838 |
|
colval(col,ord[0]), |
839 |
|
colval(col,ord[1]), |
843 |
|
} |
844 |
|
|
845 |
|
|
846 |
< |
putcfloat(col) /* put a float color to stdout */ |
847 |
< |
COLOR col; |
846 |
> |
static int |
847 |
> |
putcfloat( /* put a float color to stdout */ |
848 |
> |
COLOR col |
849 |
> |
) |
850 |
|
{ |
851 |
|
float vf[3]; |
852 |
|
|
853 |
|
vf[0] = colval(col,ord[0]); |
854 |
|
vf[1] = colval(col,ord[1]); |
855 |
|
vf[2] = colval(col,ord[2]); |
856 |
< |
fwrite((char *)vf, sizeof(float), 3, stdout); |
856 |
> |
if (swapbytes) |
857 |
> |
swap32((char *)vf, 3); |
858 |
> |
putbinary(vf, sizeof(float), 3, stdout); |
859 |
|
|
860 |
|
return(ferror(stdout) ? -1 : 0); |
861 |
|
} |
862 |
|
|
863 |
|
|
864 |
< |
putcdouble(col) /* put a double color to stdout */ |
865 |
< |
COLOR col; |
864 |
> |
static int |
865 |
> |
putcdouble( /* put a double color to stdout */ |
866 |
> |
COLOR col |
867 |
> |
) |
868 |
|
{ |
869 |
|
double vd[3]; |
870 |
|
|
871 |
|
vd[0] = colval(col,ord[0]); |
872 |
|
vd[1] = colval(col,ord[1]); |
873 |
|
vd[2] = colval(col,ord[2]); |
874 |
< |
fwrite((char *)vd, sizeof(double), 3, stdout); |
874 |
> |
if (swapbytes) |
875 |
> |
swap64((char *)vd, 3); |
876 |
> |
putbinary(vd, sizeof(double), 3, stdout); |
877 |
|
|
878 |
|
return(ferror(stdout) ? -1 : 0); |
879 |
|
} |
880 |
|
|
881 |
|
|
882 |
< |
putcint(col) /* put an int color to stdout */ |
883 |
< |
COLOR col; |
882 |
> |
static int |
883 |
> |
putcint( /* put an int color to stdout */ |
884 |
> |
COLOR col |
885 |
> |
) |
886 |
|
{ |
887 |
|
fprintf(stdout, "%d %d %d\n", |
888 |
|
(int)(colval(col,ord[0])*256.), |
893 |
|
} |
894 |
|
|
895 |
|
|
896 |
< |
putcbyte(col) /* put a byte color to stdout */ |
897 |
< |
COLOR col; |
896 |
> |
static int |
897 |
> |
putcbyte( /* put a byte color to stdout */ |
898 |
> |
COLOR col |
899 |
> |
) |
900 |
|
{ |
901 |
< |
register int i; |
902 |
< |
BYTE vb[3]; |
901 |
> |
long i; |
902 |
> |
uby8 vb[3]; |
903 |
|
|
904 |
|
i = colval(col,ord[0])*256.; |
905 |
|
vb[0] = min(i,255); |
907 |
|
vb[1] = min(i,255); |
908 |
|
i = colval(col,ord[2])*256.; |
909 |
|
vb[2] = min(i,255); |
910 |
< |
fwrite((char *)vb, sizeof(BYTE), 3, stdout); |
910 |
> |
putbinary(vb, sizeof(uby8), 3, stdout); |
911 |
|
|
912 |
|
return(ferror(stdout) ? -1 : 0); |
913 |
|
} |
914 |
|
|
915 |
|
|
916 |
< |
putbascii(col) /* put an ascii brightness to stdout */ |
917 |
< |
COLOR col; |
916 |
> |
static int |
917 |
> |
putcword( /* put a 16-bit color to stdout */ |
918 |
> |
COLOR col |
919 |
> |
) |
920 |
|
{ |
921 |
< |
fprintf(stdout, "%15.3e\n", bright(col)); |
921 |
> |
long i; |
922 |
> |
uint16 vw[3]; |
923 |
|
|
924 |
+ |
i = colval(col,ord[0])*65536.; |
925 |
+ |
vw[0] = min(i,65535); |
926 |
+ |
i = colval(col,ord[1])*65536.; |
927 |
+ |
vw[1] = min(i,65535); |
928 |
+ |
i = colval(col,ord[2])*65536.; |
929 |
+ |
vw[2] = min(i,65535); |
930 |
+ |
if (swapbytes) |
931 |
+ |
swap16((char *)vw, 3); |
932 |
+ |
putbinary(vw, sizeof(uint16), 3, stdout); |
933 |
+ |
|
934 |
|
return(ferror(stdout) ? -1 : 0); |
935 |
|
} |
936 |
|
|
937 |
|
|
938 |
< |
putbfloat(col) /* put a float brightness to stdout */ |
939 |
< |
COLOR col; |
938 |
> |
static int |
939 |
> |
putbascii( /* put an ascii brightness to stdout */ |
940 |
> |
COLOR col |
941 |
> |
) |
942 |
|
{ |
943 |
+ |
fprintf(stdout, "%15.3e\n", (*mybright)(col)); |
944 |
+ |
|
945 |
+ |
return(ferror(stdout) ? -1 : 0); |
946 |
+ |
} |
947 |
+ |
|
948 |
+ |
|
949 |
+ |
static int |
950 |
+ |
putbfloat( /* put a float brightness to stdout */ |
951 |
+ |
COLOR col |
952 |
+ |
) |
953 |
+ |
{ |
954 |
|
float vf; |
955 |
|
|
956 |
< |
vf = bright(col); |
957 |
< |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
956 |
> |
vf = (*mybright)(col); |
957 |
> |
if (swapbytes) |
958 |
> |
swap32((char *)&vf, 1); |
959 |
> |
putbinary(&vf, sizeof(float), 1, stdout); |
960 |
|
|
961 |
|
return(ferror(stdout) ? -1 : 0); |
962 |
|
} |
963 |
|
|
964 |
|
|
965 |
< |
putbdouble(col) /* put a double brightness to stdout */ |
966 |
< |
COLOR col; |
965 |
> |
static int |
966 |
> |
putbdouble( /* put a double brightness to stdout */ |
967 |
> |
COLOR col |
968 |
> |
) |
969 |
|
{ |
970 |
|
double vd; |
971 |
|
|
972 |
< |
vd = bright(col); |
973 |
< |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
972 |
> |
vd = (*mybright)(col); |
973 |
> |
if (swapbytes) |
974 |
> |
swap64((char *)&vd, 1); |
975 |
> |
putbinary(&vd, sizeof(double), 1, stdout); |
976 |
|
|
977 |
|
return(ferror(stdout) ? -1 : 0); |
978 |
|
} |
979 |
|
|
980 |
|
|
981 |
< |
putbint(col) /* put an int brightness to stdout */ |
982 |
< |
COLOR col; |
981 |
> |
static int |
982 |
> |
putbint( /* put an int brightness to stdout */ |
983 |
> |
COLOR col |
984 |
> |
) |
985 |
|
{ |
986 |
< |
fprintf(stdout, "%d\n", (int)(bright(col)*256.)); |
986 |
> |
fprintf(stdout, "%d\n", (int)((*mybright)(col)*256.)); |
987 |
|
|
988 |
|
return(ferror(stdout) ? -1 : 0); |
989 |
|
} |
990 |
|
|
991 |
|
|
992 |
< |
putbbyte(col) /* put a byte brightness to stdout */ |
993 |
< |
COLOR col; |
992 |
> |
static int |
993 |
> |
putbbyte( /* put a byte brightness to stdout */ |
994 |
> |
COLOR col |
995 |
> |
) |
996 |
|
{ |
997 |
< |
register int i; |
998 |
< |
BYTE vb; |
997 |
> |
int i; |
998 |
> |
uby8 vb; |
999 |
|
|
1000 |
< |
i = bright(col)*256.; |
1000 |
> |
i = (*mybright)(col)*256.; |
1001 |
|
vb = min(i,255); |
1002 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
1002 |
> |
putbinary(&vb, sizeof(uby8), 1, stdout); |
1003 |
|
|
1004 |
|
return(ferror(stdout) ? -1 : 0); |
1005 |
|
} |
1006 |
|
|
1007 |
|
|
1008 |
< |
putpascii(col) /* put an ascii primary to stdout */ |
1009 |
< |
COLOR col; |
1008 |
> |
static int |
1009 |
> |
putbword( /* put a 16-bit brightness to stdout */ |
1010 |
> |
COLOR col |
1011 |
> |
) |
1012 |
|
{ |
1013 |
+ |
long i; |
1014 |
+ |
uint16 vw; |
1015 |
+ |
|
1016 |
+ |
i = (*mybright)(col)*65536.; |
1017 |
+ |
vw = min(i,65535); |
1018 |
+ |
if (swapbytes) |
1019 |
+ |
swap16((char *)&vw, 1); |
1020 |
+ |
putbinary(&vw, sizeof(uint16), 1, stdout); |
1021 |
+ |
|
1022 |
+ |
return(ferror(stdout) ? -1 : 0); |
1023 |
+ |
} |
1024 |
+ |
|
1025 |
+ |
|
1026 |
+ |
static int |
1027 |
+ |
putpascii( /* put an ascii primary to stdout */ |
1028 |
+ |
COLOR col |
1029 |
+ |
) |
1030 |
+ |
{ |
1031 |
|
fprintf(stdout, "%15.3e\n", colval(col,putprim)); |
1032 |
|
|
1033 |
|
return(ferror(stdout) ? -1 : 0); |
1034 |
|
} |
1035 |
|
|
1036 |
|
|
1037 |
< |
putpfloat(col) /* put a float primary to stdout */ |
1038 |
< |
COLOR col; |
1037 |
> |
static int |
1038 |
> |
putpfloat( /* put a float primary to stdout */ |
1039 |
> |
COLOR col |
1040 |
> |
) |
1041 |
|
{ |
1042 |
|
float vf; |
1043 |
|
|
1044 |
|
vf = colval(col,putprim); |
1045 |
< |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
1045 |
> |
if (swapbytes) |
1046 |
> |
swap32((char *)&vf, 1); |
1047 |
> |
putbinary(&vf, sizeof(float), 1, stdout); |
1048 |
|
|
1049 |
|
return(ferror(stdout) ? -1 : 0); |
1050 |
|
} |
1051 |
|
|
1052 |
|
|
1053 |
< |
putpdouble(col) /* put a double primary to stdout */ |
1054 |
< |
COLOR col; |
1053 |
> |
static int |
1054 |
> |
putpdouble( /* put a double primary to stdout */ |
1055 |
> |
COLOR col |
1056 |
> |
) |
1057 |
|
{ |
1058 |
|
double vd; |
1059 |
|
|
1060 |
|
vd = colval(col,putprim); |
1061 |
< |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
1061 |
> |
if (swapbytes) |
1062 |
> |
swap64((char *)&vd, 1); |
1063 |
> |
putbinary(&vd, sizeof(double), 1, stdout); |
1064 |
|
|
1065 |
|
return(ferror(stdout) ? -1 : 0); |
1066 |
|
} |
1067 |
|
|
1068 |
|
|
1069 |
< |
putpint(col) /* put an int primary to stdout */ |
1070 |
< |
COLOR col; |
1069 |
> |
static int |
1070 |
> |
putpint( /* put an int primary to stdout */ |
1071 |
> |
COLOR col |
1072 |
> |
) |
1073 |
|
{ |
1074 |
|
fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.)); |
1075 |
|
|
1077 |
|
} |
1078 |
|
|
1079 |
|
|
1080 |
< |
putpbyte(col) /* put a byte primary to stdout */ |
1081 |
< |
COLOR col; |
1080 |
> |
static int |
1081 |
> |
putpbyte( /* put a byte primary to stdout */ |
1082 |
> |
COLOR col |
1083 |
> |
) |
1084 |
|
{ |
1085 |
< |
register int i; |
1086 |
< |
BYTE vb; |
1085 |
> |
long i; |
1086 |
> |
uby8 vb; |
1087 |
|
|
1088 |
|
i = colval(col,putprim)*256.; |
1089 |
|
vb = min(i,255); |
1090 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
1090 |
> |
putbinary(&vb, sizeof(uby8), 1, stdout); |
1091 |
|
|
1092 |
|
return(ferror(stdout) ? -1 : 0); |
1093 |
|
} |
1094 |
|
|
1095 |
|
|
1096 |
< |
set_io() /* set put and get functions */ |
1096 |
> |
static int |
1097 |
> |
putpword( /* put a 16-bit primary to stdout */ |
1098 |
> |
COLOR col |
1099 |
> |
) |
1100 |
|
{ |
1101 |
+ |
long i; |
1102 |
+ |
uint16 vw; |
1103 |
+ |
|
1104 |
+ |
i = colval(col,putprim)*65536.; |
1105 |
+ |
vw = min(i,65535); |
1106 |
+ |
if (swapbytes) |
1107 |
+ |
swap16((char *)&vw, 1); |
1108 |
+ |
putbinary(&vw, sizeof(uint16), 1, stdout); |
1109 |
+ |
|
1110 |
+ |
return(ferror(stdout) ? -1 : 0); |
1111 |
+ |
} |
1112 |
+ |
|
1113 |
+ |
|
1114 |
+ |
static void |
1115 |
+ |
set_io(void) /* set put and get functions */ |
1116 |
+ |
{ |
1117 |
|
switch (format) { |
1118 |
|
case 'a': /* ascii */ |
1119 |
|
if (putprim == BRIGHT) { |
1147 |
|
if (fin2 == NULL) |
1148 |
|
goto namerr; |
1149 |
|
if (fseek(fin2, |
1150 |
< |
(long)sizeof(float)*picres.xr*picres.yr, 1)) |
1150 |
> |
(long)sizeof(float)*picres.xr*picres.yr, SEEK_CUR)) |
1151 |
|
goto seekerr; |
1152 |
|
if (fseek(fin3, |
1153 |
< |
(long)sizeof(float)*2*picres.xr*picres.yr, 1)) |
1153 |
> |
(long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR)) |
1154 |
|
goto seekerr; |
1155 |
|
} |
1156 |
|
} |
1169 |
|
if (fin2 == NULL) |
1170 |
|
goto namerr; |
1171 |
|
if (fseek(fin2, |
1172 |
< |
(long)sizeof(double)*picres.xr*picres.yr, 1)) |
1172 |
> |
(long)sizeof(double)*picres.xr*picres.yr, SEEK_CUR)) |
1173 |
|
goto seekerr; |
1174 |
|
if (fseek(fin3, |
1175 |
< |
(long)sizeof(double)*2*picres.xr*picres.yr, 1)) |
1175 |
> |
(long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR)) |
1176 |
|
goto seekerr; |
1177 |
|
} |
1178 |
|
} |
1209 |
|
if (fin2 == NULL) |
1210 |
|
goto namerr; |
1211 |
|
if (fseek(fin2, |
1212 |
< |
(long)sizeof(BYTE)*picres.xr*picres.yr, 1)) |
1212 |
> |
(long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR)) |
1213 |
|
goto seekerr; |
1214 |
|
if (fseek(fin3, |
1215 |
< |
(long)sizeof(BYTE)*2*picres.xr*picres.yr, 1)) |
1215 |
> |
(long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR)) |
1216 |
|
goto seekerr; |
1217 |
|
} |
1218 |
|
} |
1219 |
|
return; |
1220 |
+ |
case 'w': /* 16-bit */ |
1221 |
+ |
if (putprim == BRIGHT) { |
1222 |
+ |
getval = getbword; |
1223 |
+ |
putval = putbword; |
1224 |
+ |
} else if (putprim != ALL) { |
1225 |
+ |
getval = getbword; |
1226 |
+ |
putval = putpword; |
1227 |
+ |
} else { |
1228 |
+ |
getval = getcword; |
1229 |
+ |
putval = putcword; |
1230 |
+ |
if (reverse && !interleave) { |
1231 |
+ |
if (fin2 == NULL) |
1232 |
+ |
goto namerr; |
1233 |
+ |
if (fseek(fin2, |
1234 |
+ |
(long)sizeof(uint16)*picres.xr*picres.yr, SEEK_CUR)) |
1235 |
+ |
goto seekerr; |
1236 |
+ |
if (fseek(fin3, |
1237 |
+ |
(long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR)) |
1238 |
+ |
goto seekerr; |
1239 |
+ |
} |
1240 |
+ |
} |
1241 |
+ |
return; |
1242 |
|
} |
1243 |
< |
badopt: |
1243 |
> |
/* badopt: */ /* label not used */ |
1244 |
|
fprintf(stderr, "%s: botched file type\n", progname); |
1245 |
|
quit(1); |
1246 |
|
namerr: |