| 9 |
|
*/ |
| 10 |
|
|
| 11 |
|
#include <stdio.h> |
| 12 |
< |
|
| 12 |
> |
#include <math.h> |
| 13 |
|
#include "color.h" |
| 14 |
|
#include "resolu.h" |
| 15 |
|
|
| 16 |
+ |
#ifdef MSDOS |
| 17 |
+ |
#include <fcntl.h> |
| 18 |
+ |
#endif |
| 19 |
+ |
|
| 20 |
+ |
extern char *malloc(); |
| 21 |
+ |
|
| 22 |
|
int bradj = 0; /* brightness adjustment */ |
| 23 |
|
|
| 24 |
|
int doflat = 1; /* produce flat file */ |
| 31 |
|
char *argv[]; |
| 32 |
|
{ |
| 33 |
|
int i; |
| 34 |
< |
|
| 34 |
> |
|
| 35 |
|
progname = argv[0]; |
| 36 |
|
|
| 37 |
|
for (i = 1; i < argc; i++) |
| 59 |
|
exit(1); |
| 60 |
|
} |
| 61 |
|
if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { |
| 62 |
< |
fprintf(stderr, "can't open output \"%s\"\n", |
| 62 |
> |
fprintf(stderr, "%s: can't open output \"%s\"\n", |
| 63 |
|
progname, argv[i+1]); |
| 64 |
|
exit(1); |
| 65 |
|
} |
| 66 |
+ |
#ifdef MSDOS |
| 67 |
+ |
setmode(fileno(stdin), O_BINARY); |
| 68 |
+ |
setmode(fileno(stdout), O_BINARY); |
| 69 |
+ |
#endif |
| 70 |
|
transfer(); |
| 71 |
|
exit(0); |
| 72 |
|
userr: |
| 89 |
|
|
| 90 |
|
transfer() /* transfer Radiance picture */ |
| 91 |
|
{ |
| 92 |
< |
extern double pow(); |
| 92 |
> |
static char ourfmt[LPICFMT+1] = PICFMT; |
| 93 |
|
int order; |
| 94 |
< |
int xmax, ymax; |
| 94 |
> |
int xmax, ymax; |
| 95 |
|
COLR *scanin; |
| 86 |
– |
register int x; |
| 96 |
|
int y; |
| 97 |
|
/* get header info. */ |
| 98 |
< |
if (checkheader(stdin, COLRFMT, stdout) < 0 || |
| 98 |
> |
if ((y = checkheader(stdin, ourfmt, stdout)) < 0 || |
| 99 |
|
(order = fgetresolu(&xmax, &ymax, stdin)) < 0) |
| 100 |
|
quiterr("bad picture format"); |
| 101 |
+ |
if (!y) |
| 102 |
+ |
strcpy(ourfmt, COLRFMT); |
| 103 |
|
fputs(progname, stdout); |
| 104 |
|
if (bradj) |
| 105 |
< |
printf(" -e %+d", bradj); |
| 106 |
< |
if (doflat) |
| 107 |
< |
fputs("\n", stdout); |
| 108 |
< |
else { |
| 98 |
< |
fputs(" -r\n", stdout); |
| 99 |
< |
fputformat(COLRFMT, stdout); |
| 100 |
< |
} |
| 105 |
> |
fprintf(stdout, " -e %+d", bradj); |
| 106 |
> |
if (!doflat) |
| 107 |
> |
fputs(" -r", stdout); |
| 108 |
> |
fputc('\n', stdout); |
| 109 |
|
if (bradj) |
| 110 |
|
fputexpos(pow(2.0, (double)bradj), stdout); |
| 111 |
< |
fputs("\n", stdout); |
| 111 |
> |
fputformat(ourfmt, stdout); |
| 112 |
> |
fputc('\n', stdout); |
| 113 |
|
fputresolu(order, xmax, ymax, stdout); |
| 114 |
|
/* allocate scanline */ |
| 115 |
|
scanin = (COLR *)malloc(xmax*sizeof(COLR)); |
| 116 |
|
if (scanin == NULL) |
| 117 |
|
quiterr("out of memory in transfer"); |
| 118 |
|
/* convert image */ |
| 119 |
< |
for (y = ymax-1; y >= 0; y--) { |
| 119 |
> |
for (y = ymax; y--; ) { |
| 120 |
|
if (freadcolrs(scanin, xmax, stdin) < 0) |
| 121 |
|
quiterr("error reading input picture"); |
| 122 |
|
if (bradj) |
| 126 |
|
else |
| 127 |
|
fwritecolrs(scanin, xmax, stdout); |
| 128 |
|
if (ferror(stdout)) |
| 129 |
< |
quiterr("error writing rasterfile"); |
| 129 |
> |
quiterr("error writing output picture"); |
| 130 |
|
} |
| 131 |
|
/* free scanline */ |
| 132 |
|
free((char *)scanin); |