43 |
|
|
44 |
|
long skipbytes = 0; /* skip bytes in input? */ |
45 |
|
|
46 |
+ |
int interleave = 1; /* file is interleaved? */ |
47 |
+ |
|
48 |
|
int resolution = 1; /* put/get resolution string? */ |
49 |
|
|
50 |
|
int original = 0; /* convert to original values? */ |
121 |
|
case 'r': /* reverse conversion */ |
122 |
|
reverse = argv[i][0] == '-'; |
123 |
|
break; |
124 |
+ |
case 'n': /* non-interleaved RGB */ |
125 |
+ |
interleave = argv[i][0] == '+'; |
126 |
+ |
break; |
127 |
|
case 'b': /* brightness values */ |
128 |
|
putprim = argv[i][0] == '-' ? BRIGHT : ALL; |
129 |
|
break; |
210 |
|
progname, argv[i]); |
211 |
|
quit(1); |
212 |
|
} |
208 |
– |
if (skipbytes && fseek(fin, skipbytes, 0)) |
209 |
– |
goto seekerr; |
213 |
|
if (reverse && !brightonly && i == argc-3) { |
214 |
|
if ((fin2 = fopen(argv[i+1], "r")) == NULL) { |
215 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
221 |
|
progname, argv[i+2]); |
222 |
|
quit(1); |
223 |
|
} |
224 |
< |
if (skipbytes && (fseek(fin2, skipbytes, 0) || |
222 |
< |
fseek(fin3, skipbytes, 0))) |
223 |
< |
goto seekerr; |
224 |
> |
interleave = -1; |
225 |
|
} else if (i != argc-1) |
226 |
|
fin = NULL; |
227 |
+ |
if (reverse && !brightonly && !interleave) { |
228 |
+ |
fin2 = fopen(argv[i], "r"); |
229 |
+ |
fin3 = fopen(argv[i], "r"); |
230 |
+ |
} |
231 |
+ |
if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL && |
232 |
+ |
(fseek(fin2, skipbytes, 0) || |
233 |
+ |
fseek(fin3, skipbytes, 0))))) { |
234 |
+ |
fprintf(stderr, "%s: cannot skip %ld bytes on input\n", |
235 |
+ |
progname, skipbytes); |
236 |
+ |
quit(1); |
237 |
+ |
} |
238 |
|
} |
239 |
|
if (fin == NULL) { |
240 |
|
fprintf(stderr, "%s: bad # file arguments\n", progname); |
241 |
|
quit(1); |
242 |
|
} |
243 |
|
|
232 |
– |
set_io(); |
233 |
– |
|
244 |
|
if (reverse) { |
245 |
|
#ifdef MSDOS |
246 |
|
setmode(fileno(stdout), O_BINARY); |
319 |
|
} |
320 |
|
|
321 |
|
quit(0); |
312 |
– |
seekerr: |
313 |
– |
fprintf(stderr, "%s: cannot skip %ld bytes on input\n", |
314 |
– |
progname, skipbytes); |
315 |
– |
quit(1); |
322 |
|
} |
323 |
|
|
324 |
|
|
352 |
|
int dogamma; |
353 |
|
COLOR lastc; |
354 |
|
FLOAT hv[2]; |
355 |
+ |
int startprim, endprim; |
356 |
+ |
long startpos; |
357 |
|
int y; |
358 |
|
register int x; |
359 |
|
|
363 |
|
quit(1); |
364 |
|
} |
365 |
|
dogamma = gamcor < .95 || gamcor > 1.05; |
366 |
< |
setcolor(lastc, 0.0, 0.0, 0.0); |
367 |
< |
for (y = 0; y < numscans(&picres); y++) { |
368 |
< |
if (freadscan(scanln, scanlen(&picres), fin) < 0) { |
369 |
< |
fprintf(stderr, "%s: read error\n", progname); |
366 |
> |
if (putprim == ALL && !interleave) { |
367 |
> |
startprim = RED; endprim = BLU; |
368 |
> |
startpos = ftell(fin); |
369 |
> |
} else { |
370 |
> |
startprim = putprim; endprim = putprim; |
371 |
> |
} |
372 |
> |
for (putprim = startprim; putprim <= endprim; putprim++) { |
373 |
> |
if (putprim != startprim && fseek(fin, startpos, 0)) { |
374 |
> |
fprintf(stderr, "%s: seek error on input file\n", |
375 |
> |
progname); |
376 |
|
quit(1); |
377 |
|
} |
378 |
< |
for (x = 0; x < scanlen(&picres); x++) { |
379 |
< |
if (uniq) |
380 |
< |
if ( colval(scanln[x],RED) == |
381 |
< |
colval(lastc,RED) && |
382 |
< |
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], stdout) < 0) { |
388 |
< |
fprintf(stderr, "%s: write error\n", progname); |
378 |
> |
set_io(); |
379 |
> |
setcolor(lastc, 0.0, 0.0, 0.0); |
380 |
> |
for (y = 0; y < numscans(&picres); y++) { |
381 |
> |
if (freadscan(scanln, scanlen(&picres), fin) < 0) { |
382 |
> |
fprintf(stderr, "%s: read error\n", progname); |
383 |
|
quit(1); |
384 |
|
} |
385 |
+ |
for (x = 0; x < scanlen(&picres); x++) { |
386 |
+ |
if (uniq) |
387 |
+ |
if ( colval(scanln[x],RED) == |
388 |
+ |
colval(lastc,RED) && |
389 |
+ |
colval(scanln[x],GRN) == |
390 |
+ |
colval(lastc,GRN) && |
391 |
+ |
colval(scanln[x],BLU) == |
392 |
+ |
colval(lastc,BLU) ) |
393 |
+ |
continue; |
394 |
+ |
else |
395 |
+ |
copycolor(lastc, scanln[x]); |
396 |
+ |
if (doexposure) |
397 |
+ |
multcolor(scanln[x], exposure); |
398 |
+ |
if (dogamma) |
399 |
+ |
setcolor(scanln[x], |
400 |
+ |
pow(colval(scanln[x],RED), 1.0/gamcor), |
401 |
+ |
pow(colval(scanln[x],GRN), 1.0/gamcor), |
402 |
+ |
pow(colval(scanln[x],BLU), 1.0/gamcor)); |
403 |
+ |
if (!dataonly) { |
404 |
+ |
pix2loc(hv, &picres, x, y); |
405 |
+ |
printf("%7d %7d ", |
406 |
+ |
(int)(hv[0]*picres.xr), |
407 |
+ |
(int)(hv[1]*picres.yr)); |
408 |
+ |
} |
409 |
+ |
if ((*putval)(scanln[x]) < 0) { |
410 |
+ |
fprintf(stderr, "%s: write error\n", |
411 |
+ |
progname); |
412 |
+ |
quit(1); |
413 |
+ |
} |
414 |
+ |
} |
415 |
|
} |
416 |
|
} |
417 |
|
free((char *)scanln); |
431 |
|
quit(1); |
432 |
|
} |
433 |
|
dogamma = gamcor < .95 || gamcor > 1.05; |
434 |
+ |
set_io(); |
435 |
|
for (y = 0; y < numscans(&picres); y++) { |
436 |
|
for (x = 0; x < scanlen(&picres); x++) { |
437 |
|
if (!dataonly) { |
441 |
|
fscanf(fin3, "%*d %*d"); |
442 |
|
} |
443 |
|
} |
444 |
< |
if ((*getval)(scanln[x], fin, fin2, fin3) < 0) { |
444 |
> |
if ((*getval)(scanln[x]) < 0) { |
445 |
|
fprintf(stderr, "%s: read error\n", progname); |
446 |
|
quit(1); |
447 |
|
} |
469 |
|
} |
470 |
|
|
471 |
|
|
472 |
< |
getcascii(col, f1, f2, f3) /* get an ascii color value from stream(s) */ |
472 |
> |
getcascii(col) /* get an ascii color value from stream(s) */ |
473 |
|
COLOR col; |
449 |
– |
FILE *f1, *f2, *f3; |
474 |
|
{ |
475 |
|
double vd[3]; |
476 |
|
|
477 |
< |
if (f2 == NULL) { |
478 |
< |
if (fscanf(f1, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3) |
477 |
> |
if (fin2 == NULL) { |
478 |
> |
if (fscanf(fin, "%lf %lf %lf", &vd[0], &vd[1], &vd[2]) != 3) |
479 |
|
return(-1); |
480 |
|
} else { |
481 |
< |
if (fscanf(f1, "%lf", &vd[0]) != 1 || |
482 |
< |
fscanf(f2, "%lf", &vd[1]) != 1 || |
483 |
< |
fscanf(f3, "%lf", &vd[2]) != 1) |
481 |
> |
if (fscanf(fin, "%lf", &vd[0]) != 1 || |
482 |
> |
fscanf(fin2, "%lf", &vd[1]) != 1 || |
483 |
> |
fscanf(fin3, "%lf", &vd[2]) != 1) |
484 |
|
return(-1); |
485 |
|
} |
486 |
|
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
488 |
|
} |
489 |
|
|
490 |
|
|
491 |
< |
getcdouble(col, f1, f2, f3) /* get a double color value from stream(s) */ |
491 |
> |
getcdouble(col) /* get a double color value from stream(s) */ |
492 |
|
COLOR col; |
469 |
– |
FILE *f1, *f2, *f3; |
493 |
|
{ |
494 |
|
double vd[3]; |
495 |
|
|
496 |
< |
if (f2 == NULL) { |
497 |
< |
if (fread((char *)vd, sizeof(double), 3, f1) != 3) |
496 |
> |
if (fin2 == NULL) { |
497 |
> |
if (fread((char *)vd, sizeof(double), 3, fin) != 3) |
498 |
|
return(-1); |
499 |
|
} else { |
500 |
< |
if (fread((char *)vd, sizeof(double), 1, f1) != 1 || |
501 |
< |
fread((char *)(vd+1), sizeof(double), 1, f2) != 1 || |
502 |
< |
fread((char *)(vd+2), sizeof(double), 1, f3) != 1) |
500 |
> |
if (fread((char *)vd, sizeof(double), 1, fin) != 1 || |
501 |
> |
fread((char *)(vd+1), sizeof(double), 1, fin2) != 1 || |
502 |
> |
fread((char *)(vd+2), sizeof(double), 1, fin3) != 1) |
503 |
|
return(-1); |
504 |
|
} |
505 |
|
setcolor(col, vd[rord[RED]], vd[rord[GRN]], vd[rord[BLU]]); |
507 |
|
} |
508 |
|
|
509 |
|
|
510 |
< |
getcfloat(col, f1, f2, f3) /* get a float color value from stream(s) */ |
510 |
> |
getcfloat(col) /* get a float color value from stream(s) */ |
511 |
|
COLOR col; |
489 |
– |
FILE *f1, *f2, *f3; |
512 |
|
{ |
513 |
|
float vf[3]; |
514 |
|
|
515 |
< |
if (f2 == NULL) { |
516 |
< |
if (fread((char *)vf, sizeof(float), 3, f1) != 3) |
515 |
> |
if (fin2 == NULL) { |
516 |
> |
if (fread((char *)vf, sizeof(float), 3, fin) != 3) |
517 |
|
return(-1); |
518 |
|
} else { |
519 |
< |
if (fread((char *)vf, sizeof(float), 1, f1) != 1 || |
520 |
< |
fread((char *)(vf+1), sizeof(float), 1, f2) != 1 || |
521 |
< |
fread((char *)(vf+2), sizeof(float), 1, f3) != 1) |
519 |
> |
if (fread((char *)vf, sizeof(float), 1, fin) != 1 || |
520 |
> |
fread((char *)(vf+1), sizeof(float), 1, fin2) != 1 || |
521 |
> |
fread((char *)(vf+2), sizeof(float), 1, fin3) != 1) |
522 |
|
return(-1); |
523 |
|
} |
524 |
|
setcolor(col, vf[rord[RED]], vf[rord[GRN]], vf[rord[BLU]]); |
526 |
|
} |
527 |
|
|
528 |
|
|
529 |
< |
getcint(col, f1, f2, f3) /* get an int color value from stream(s) */ |
529 |
> |
getcint(col) /* get an int color value from stream(s) */ |
530 |
|
COLOR col; |
509 |
– |
FILE *f1, *f2, *f3; |
531 |
|
{ |
532 |
|
int vi[3]; |
533 |
|
|
534 |
< |
if (f2 == NULL) { |
535 |
< |
if (fscanf(f1, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3) |
534 |
> |
if (fin2 == NULL) { |
535 |
> |
if (fscanf(fin, "%d %d %d", &vi[0], &vi[1], &vi[2]) != 3) |
536 |
|
return(-1); |
537 |
|
} else { |
538 |
< |
if (fscanf(f1, "%d", &vi[0]) != 1 || |
539 |
< |
fscanf(f2, "%d", &vi[1]) != 1 || |
540 |
< |
fscanf(f3, "%d", &vi[2]) != 1) |
538 |
> |
if (fscanf(fin, "%d", &vi[0]) != 1 || |
539 |
> |
fscanf(fin2, "%d", &vi[1]) != 1 || |
540 |
> |
fscanf(fin3, "%d", &vi[2]) != 1) |
541 |
|
return(-1); |
542 |
|
} |
543 |
|
setcolor(col, (vi[rord[RED]]+.5)/256., |
546 |
|
} |
547 |
|
|
548 |
|
|
549 |
< |
getcbyte(col, f1, f2, f3) /* get a byte color value from stream(s) */ |
549 |
> |
getcbyte(col) /* get a byte color value from stream(s) */ |
550 |
|
COLOR col; |
530 |
– |
FILE *f1, *f2, *f3; |
551 |
|
{ |
552 |
|
BYTE vb[3]; |
553 |
|
|
554 |
< |
if (f2 == NULL) { |
555 |
< |
if (fread((char *)vb, sizeof(BYTE), 3, f1) != 3) |
554 |
> |
if (fin2 == NULL) { |
555 |
> |
if (fread((char *)vb, sizeof(BYTE), 3, fin) != 3) |
556 |
|
return(-1); |
557 |
|
} else { |
558 |
< |
if (fread((char *)vb, sizeof(BYTE), 1, f1) != 1 || |
559 |
< |
fread((char *)(vb+1), sizeof(BYTE), 1, f2) != 1 || |
560 |
< |
fread((char *)(vb+2), sizeof(BYTE), 1, f3) != 1) |
558 |
> |
if (fread((char *)vb, sizeof(BYTE), 1, fin) != 1 || |
559 |
> |
fread((char *)(vb+1), sizeof(BYTE), 1, fin2) != 1 || |
560 |
> |
fread((char *)(vb+2), sizeof(BYTE), 1, fin3) != 1) |
561 |
|
return(-1); |
562 |
|
} |
563 |
|
setcolor(col, (vb[rord[RED]]+.5)/256., |
566 |
|
} |
567 |
|
|
568 |
|
|
569 |
< |
getbascii(col, fp) /* get an ascii brightness value from fp */ |
569 |
> |
getbascii(col) /* get an ascii brightness value from fin */ |
570 |
|
COLOR col; |
551 |
– |
FILE *fp; |
571 |
|
{ |
572 |
|
double vd; |
573 |
|
|
574 |
< |
if (fscanf(fp, "%lf", &vd) != 1) |
574 |
> |
if (fscanf(fin, "%lf", &vd) != 1) |
575 |
|
return(-1); |
576 |
|
setcolor(col, vd, vd, vd); |
577 |
|
return(0); |
578 |
|
} |
579 |
|
|
580 |
|
|
581 |
< |
getbdouble(col, fp) /* get a double brightness value from fp */ |
581 |
> |
getbdouble(col) /* get a double brightness value from fin */ |
582 |
|
COLOR col; |
564 |
– |
FILE *fp; |
583 |
|
{ |
584 |
|
double vd; |
585 |
|
|
586 |
< |
if (fread((char *)&vd, sizeof(double), 1, fp) != 1) |
586 |
> |
if (fread((char *)&vd, sizeof(double), 1, fin) != 1) |
587 |
|
return(-1); |
588 |
|
setcolor(col, vd, vd, vd); |
589 |
|
return(0); |
590 |
|
} |
591 |
|
|
592 |
|
|
593 |
< |
getbfloat(col, fp) /* get a float brightness value from fp */ |
593 |
> |
getbfloat(col) /* get a float brightness value from fin */ |
594 |
|
COLOR col; |
577 |
– |
FILE *fp; |
595 |
|
{ |
596 |
|
float vf; |
597 |
|
|
598 |
< |
if (fread((char *)&vf, sizeof(float), 1, fp) != 1) |
598 |
> |
if (fread((char *)&vf, sizeof(float), 1, fin) != 1) |
599 |
|
return(-1); |
600 |
|
setcolor(col, vf, vf, vf); |
601 |
|
return(0); |
602 |
|
} |
603 |
|
|
604 |
|
|
605 |
< |
getbint(col, fp) /* get an int brightness value from fp */ |
605 |
> |
getbint(col) /* get an int brightness value from fin */ |
606 |
|
COLOR col; |
590 |
– |
FILE *fp; |
607 |
|
{ |
608 |
|
int vi; |
609 |
|
double d; |
610 |
|
|
611 |
< |
if (fscanf(fp, "%d", &vi) != 1) |
611 |
> |
if (fscanf(fin, "%d", &vi) != 1) |
612 |
|
return(-1); |
613 |
|
d = (vi+.5)/256.; |
614 |
|
setcolor(col, d, d, d); |
616 |
|
} |
617 |
|
|
618 |
|
|
619 |
< |
getbbyte(col, fp) /* get a byte brightness value from fp */ |
619 |
> |
getbbyte(col) /* get a byte brightness value from fin */ |
620 |
|
COLOR col; |
605 |
– |
FILE *fp; |
621 |
|
{ |
622 |
|
BYTE vb; |
623 |
|
double d; |
624 |
|
|
625 |
< |
if (fread((char *)&vb, sizeof(BYTE), 1, fp) != 1) |
625 |
> |
if (fread((char *)&vb, sizeof(BYTE), 1, fin) != 1) |
626 |
|
return(-1); |
627 |
|
d = (vb+.5)/256.; |
628 |
|
setcolor(col, d, d, d); |
630 |
|
} |
631 |
|
|
632 |
|
|
633 |
< |
putcascii(col, fp) /* put an ascii color to fp */ |
633 |
> |
putcascii(col) /* put an ascii color to stdout */ |
634 |
|
COLOR col; |
620 |
– |
FILE *fp; |
635 |
|
{ |
636 |
< |
fprintf(fp, "%15.3e %15.3e %15.3e\n", |
636 |
> |
fprintf(stdout, "%15.3e %15.3e %15.3e\n", |
637 |
|
colval(col,ord[0]), |
638 |
|
colval(col,ord[1]), |
639 |
|
colval(col,ord[2])); |
640 |
|
|
641 |
< |
return(ferror(fp) ? -1 : 0); |
641 |
> |
return(ferror(stdout) ? -1 : 0); |
642 |
|
} |
643 |
|
|
644 |
|
|
645 |
< |
putcfloat(col, fp) /* put a float color to fp */ |
645 |
> |
putcfloat(col) /* put a float color to stdout */ |
646 |
|
COLOR col; |
633 |
– |
FILE *fp; |
647 |
|
{ |
648 |
|
float vf[3]; |
649 |
|
|
650 |
|
vf[0] = colval(col,ord[0]); |
651 |
|
vf[1] = colval(col,ord[1]); |
652 |
|
vf[2] = colval(col,ord[2]); |
653 |
< |
fwrite((char *)vf, sizeof(float), 3, fp); |
653 |
> |
fwrite((char *)vf, sizeof(float), 3, stdout); |
654 |
|
|
655 |
< |
return(ferror(fp) ? -1 : 0); |
655 |
> |
return(ferror(stdout) ? -1 : 0); |
656 |
|
} |
657 |
|
|
658 |
|
|
659 |
< |
putcdouble(col, fp) /* put a double color to fp */ |
659 |
> |
putcdouble(col) /* put a double color to stdout */ |
660 |
|
COLOR col; |
648 |
– |
FILE *fp; |
661 |
|
{ |
662 |
|
double vd[3]; |
663 |
|
|
664 |
|
vd[0] = colval(col,ord[0]); |
665 |
|
vd[1] = colval(col,ord[1]); |
666 |
|
vd[2] = colval(col,ord[2]); |
667 |
< |
fwrite((char *)vd, sizeof(double), 3, fp); |
667 |
> |
fwrite((char *)vd, sizeof(double), 3, stdout); |
668 |
|
|
669 |
< |
return(ferror(fp) ? -1 : 0); |
669 |
> |
return(ferror(stdout) ? -1 : 0); |
670 |
|
} |
671 |
|
|
672 |
|
|
673 |
< |
putcint(col, fp) /* put an int color to fp */ |
673 |
> |
putcint(col) /* put an int color to stdout */ |
674 |
|
COLOR col; |
663 |
– |
FILE *fp; |
675 |
|
{ |
676 |
< |
fprintf(fp, "%d %d %d\n", |
676 |
> |
fprintf(stdout, "%d %d %d\n", |
677 |
|
(int)(colval(col,ord[0])*256.), |
678 |
|
(int)(colval(col,ord[1])*256.), |
679 |
|
(int)(colval(col,ord[2])*256.)); |
680 |
|
|
681 |
< |
return(ferror(fp) ? -1 : 0); |
681 |
> |
return(ferror(stdout) ? -1 : 0); |
682 |
|
} |
683 |
|
|
684 |
|
|
685 |
< |
putcbyte(col, fp) /* put a byte color to fp */ |
685 |
> |
putcbyte(col) /* put a byte color to stdout */ |
686 |
|
COLOR col; |
676 |
– |
FILE *fp; |
687 |
|
{ |
688 |
|
register int i; |
689 |
|
BYTE vb[3]; |
694 |
|
vb[1] = min(i,255); |
695 |
|
i = colval(col,ord[2])*256.; |
696 |
|
vb[2] = min(i,255); |
697 |
< |
fwrite((char *)vb, sizeof(BYTE), 3, fp); |
697 |
> |
fwrite((char *)vb, sizeof(BYTE), 3, stdout); |
698 |
|
|
699 |
< |
return(ferror(fp) ? -1 : 0); |
699 |
> |
return(ferror(stdout) ? -1 : 0); |
700 |
|
} |
701 |
|
|
702 |
|
|
703 |
< |
putbascii(col, fp) /* put an ascii brightness to fp */ |
703 |
> |
putbascii(col) /* put an ascii brightness to stdout */ |
704 |
|
COLOR col; |
695 |
– |
FILE *fp; |
705 |
|
{ |
706 |
< |
fprintf(fp, "%15.3e\n", bright(col)); |
706 |
> |
fprintf(stdout, "%15.3e\n", bright(col)); |
707 |
|
|
708 |
< |
return(ferror(fp) ? -1 : 0); |
708 |
> |
return(ferror(stdout) ? -1 : 0); |
709 |
|
} |
710 |
|
|
711 |
|
|
712 |
< |
putbfloat(col, fp) /* put a float brightness to fp */ |
712 |
> |
putbfloat(col) /* put a float brightness to stdout */ |
713 |
|
COLOR col; |
705 |
– |
FILE *fp; |
714 |
|
{ |
715 |
|
float vf; |
716 |
|
|
717 |
|
vf = bright(col); |
718 |
< |
fwrite((char *)&vf, sizeof(float), 1, fp); |
718 |
> |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
719 |
|
|
720 |
< |
return(ferror(fp) ? -1 : 0); |
720 |
> |
return(ferror(stdout) ? -1 : 0); |
721 |
|
} |
722 |
|
|
723 |
|
|
724 |
< |
putbdouble(col, fp) /* put a double brightness to fp */ |
724 |
> |
putbdouble(col) /* put a double brightness to stdout */ |
725 |
|
COLOR col; |
718 |
– |
FILE *fp; |
726 |
|
{ |
727 |
|
double vd; |
728 |
|
|
729 |
|
vd = bright(col); |
730 |
< |
fwrite((char *)&vd, sizeof(double), 1, fp); |
730 |
> |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
731 |
|
|
732 |
< |
return(ferror(fp) ? -1 : 0); |
732 |
> |
return(ferror(stdout) ? -1 : 0); |
733 |
|
} |
734 |
|
|
735 |
|
|
736 |
< |
putbint(col, fp) /* put an int brightness to fp */ |
736 |
> |
putbint(col) /* put an int brightness to stdout */ |
737 |
|
COLOR col; |
731 |
– |
FILE *fp; |
738 |
|
{ |
739 |
< |
fprintf(fp, "%d\n", (int)(bright(col)*256.)); |
739 |
> |
fprintf(stdout, "%d\n", (int)(bright(col)*256.)); |
740 |
|
|
741 |
< |
return(ferror(fp) ? -1 : 0); |
741 |
> |
return(ferror(stdout) ? -1 : 0); |
742 |
|
} |
743 |
|
|
744 |
|
|
745 |
< |
putbbyte(col, fp) /* put a byte brightness to fp */ |
745 |
> |
putbbyte(col) /* put a byte brightness to stdout */ |
746 |
|
COLOR col; |
741 |
– |
FILE *fp; |
747 |
|
{ |
748 |
|
register int i; |
749 |
|
BYTE vb; |
750 |
|
|
751 |
|
i = bright(col)*256.; |
752 |
|
vb = min(i,255); |
753 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, fp); |
753 |
> |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
754 |
|
|
755 |
< |
return(ferror(fp) ? -1 : 0); |
755 |
> |
return(ferror(stdout) ? -1 : 0); |
756 |
|
} |
757 |
|
|
758 |
|
|
759 |
< |
putpascii(col, fp) /* put an ascii primary to fp */ |
759 |
> |
putpascii(col) /* put an ascii primary to stdout */ |
760 |
|
COLOR col; |
756 |
– |
FILE *fp; |
761 |
|
{ |
762 |
< |
fprintf(fp, "%15.3e\n", colval(col,putprim)); |
762 |
> |
fprintf(stdout, "%15.3e\n", colval(col,putprim)); |
763 |
|
|
764 |
< |
return(ferror(fp) ? -1 : 0); |
764 |
> |
return(ferror(stdout) ? -1 : 0); |
765 |
|
} |
766 |
|
|
767 |
|
|
768 |
< |
putpfloat(col, fp) /* put a float primary to fp */ |
768 |
> |
putpfloat(col) /* put a float primary to stdout */ |
769 |
|
COLOR col; |
766 |
– |
FILE *fp; |
770 |
|
{ |
771 |
|
float vf; |
772 |
|
|
773 |
|
vf = colval(col,putprim); |
774 |
< |
fwrite((char *)&vf, sizeof(float), 1, fp); |
774 |
> |
fwrite((char *)&vf, sizeof(float), 1, stdout); |
775 |
|
|
776 |
< |
return(ferror(fp) ? -1 : 0); |
776 |
> |
return(ferror(stdout) ? -1 : 0); |
777 |
|
} |
778 |
|
|
779 |
|
|
780 |
< |
putpdouble(col, fp) /* put a double primary to fp */ |
780 |
> |
putpdouble(col) /* put a double primary to stdout */ |
781 |
|
COLOR col; |
779 |
– |
FILE *fp; |
782 |
|
{ |
783 |
|
double vd; |
784 |
|
|
785 |
|
vd = colval(col,putprim); |
786 |
< |
fwrite((char *)&vd, sizeof(double), 1, fp); |
786 |
> |
fwrite((char *)&vd, sizeof(double), 1, stdout); |
787 |
|
|
788 |
< |
return(ferror(fp) ? -1 : 0); |
788 |
> |
return(ferror(stdout) ? -1 : 0); |
789 |
|
} |
790 |
|
|
791 |
|
|
792 |
< |
putpint(col, fp) /* put an int primary to fp */ |
792 |
> |
putpint(col) /* put an int primary to stdout */ |
793 |
|
COLOR col; |
792 |
– |
FILE *fp; |
794 |
|
{ |
795 |
< |
fprintf(fp, "%d\n", (int)(colval(col,putprim)*256.)); |
795 |
> |
fprintf(stdout, "%d\n", (int)(colval(col,putprim)*256.)); |
796 |
|
|
797 |
< |
return(ferror(fp) ? -1 : 0); |
797 |
> |
return(ferror(stdout) ? -1 : 0); |
798 |
|
} |
799 |
|
|
800 |
|
|
801 |
< |
putpbyte(col, fp) /* put a byte primary to fp */ |
801 |
> |
putpbyte(col) /* put a byte primary to stdout */ |
802 |
|
COLOR col; |
802 |
– |
FILE *fp; |
803 |
|
{ |
804 |
|
register int i; |
805 |
|
BYTE vb; |
806 |
|
|
807 |
|
i = colval(col,putprim)*256.; |
808 |
|
vb = min(i,255); |
809 |
< |
fwrite((char *)&vb, sizeof(BYTE), 1, fp); |
809 |
> |
fwrite((char *)&vb, sizeof(BYTE), 1, stdout); |
810 |
|
|
811 |
< |
return(ferror(fp) ? -1 : 0); |
811 |
> |
return(ferror(stdout) ? -1 : 0); |
812 |
|
} |
813 |
|
|
814 |
|
|
825 |
|
} else { |
826 |
|
getval = getcascii; |
827 |
|
putval = putcascii; |
828 |
+ |
if (reverse && !interleave) { |
829 |
+ |
fprintf(stderr, |
830 |
+ |
"%s: ASCII input files must be interleaved\n", |
831 |
+ |
progname); |
832 |
+ |
quit(1); |
833 |
+ |
} |
834 |
|
} |
835 |
|
return; |
836 |
|
case 'f': /* binary float */ |
843 |
|
} else { |
844 |
|
getval = getcfloat; |
845 |
|
putval = putcfloat; |
846 |
+ |
if (reverse && !interleave) { |
847 |
+ |
if (fin2 == NULL) |
848 |
+ |
goto namerr; |
849 |
+ |
if (fseek(fin2, |
850 |
+ |
(long)sizeof(float)*picres.xr*picres.yr, 1)) |
851 |
+ |
goto seekerr; |
852 |
+ |
if (fseek(fin3, |
853 |
+ |
(long)sizeof(float)*2*picres.xr*picres.yr, 1)) |
854 |
+ |
goto seekerr; |
855 |
+ |
} |
856 |
|
} |
857 |
|
return; |
858 |
|
case 'd': /* binary double */ |
865 |
|
} else { |
866 |
|
getval = getcdouble; |
867 |
|
putval = putcdouble; |
868 |
+ |
if (reverse && !interleave) { |
869 |
+ |
if (fin2 == NULL) |
870 |
+ |
goto namerr; |
871 |
+ |
if (fseek(fin2, |
872 |
+ |
(long)sizeof(double)*picres.xr*picres.yr, 1)) |
873 |
+ |
goto seekerr; |
874 |
+ |
if (fseek(fin3, |
875 |
+ |
(long)sizeof(double)*2*picres.xr*picres.yr, 1)) |
876 |
+ |
goto seekerr; |
877 |
+ |
} |
878 |
|
} |
879 |
|
return; |
880 |
|
case 'i': /* integer */ |
887 |
|
} else { |
888 |
|
getval = getcint; |
889 |
|
putval = putcint; |
890 |
+ |
if (reverse && !interleave) { |
891 |
+ |
fprintf(stderr, |
892 |
+ |
"%s: integer input files must be interleaved\n", |
893 |
+ |
progname); |
894 |
+ |
quit(1); |
895 |
+ |
} |
896 |
|
} |
897 |
|
return; |
898 |
|
case 'b': /* byte */ |
905 |
|
} else { |
906 |
|
getval = getcbyte; |
907 |
|
putval = putcbyte; |
908 |
+ |
if (reverse && !interleave) { |
909 |
+ |
if (fin2 == NULL) |
910 |
+ |
goto namerr; |
911 |
+ |
if (fseek(fin2, |
912 |
+ |
(long)sizeof(BYTE)*picres.xr*picres.yr, 1)) |
913 |
+ |
goto seekerr; |
914 |
+ |
if (fseek(fin3, |
915 |
+ |
(long)sizeof(BYTE)*2*picres.xr*picres.yr, 1)) |
916 |
+ |
goto seekerr; |
917 |
+ |
} |
918 |
|
} |
919 |
|
return; |
920 |
|
} |
921 |
+ |
badopt: |
922 |
+ |
fprintf(stderr, "%s: botched file type\n", progname); |
923 |
+ |
quit(1); |
924 |
+ |
namerr: |
925 |
+ |
fprintf(stderr, "%s: non-interleaved file(s) must be named\n", |
926 |
+ |
progname); |
927 |
+ |
quit(1); |
928 |
+ |
seekerr: |
929 |
+ |
fprintf(stderr, "%s: cannot seek on interleaved input file\n", |
930 |
+ |
progname); |
931 |
+ |
quit(1); |
932 |
|
} |