93 |
|
char **argv |
94 |
|
) |
95 |
|
{ |
96 |
< |
double d, expval = 1.0; |
97 |
< |
int i; |
96 |
> |
const char *inpmode = "r"; |
97 |
> |
double d, expval = 1.0; |
98 |
> |
int i; |
99 |
|
|
100 |
|
progname = argv[0]; |
101 |
|
mybright = &rgb_bright; /* default */ |
252 |
|
else |
253 |
|
fmtid = "16-bit_grey"; |
254 |
|
} |
255 |
+ |
if (!reverse || (format != 'a') & (format != 'i')) |
256 |
+ |
inpmode = "rb"; |
257 |
|
/* assign reverse ordering */ |
258 |
|
rord[ord[0]] = 0; |
259 |
|
rord[ord[1]] = 1; |
260 |
|
rord[ord[2]] = 2; |
261 |
|
/* get input */ |
262 |
|
if (i == argc) { |
263 |
+ |
long n = skipbytes; |
264 |
+ |
if (inpmode[1] == 'b') |
265 |
+ |
SET_FILE_BINARY(stdin); |
266 |
+ |
while (n-- > 0) |
267 |
+ |
if (getchar() == EOF) { |
268 |
+ |
fprintf(stderr, |
269 |
+ |
"%s: cannot skip %ld bytes on standard input\n", |
270 |
+ |
progname, skipbytes); |
271 |
+ |
quit(1); |
272 |
+ |
} |
273 |
|
fin = stdin; |
274 |
|
} else if (i < argc) { |
275 |
< |
if ((fin = fopen(argv[i], "r")) == NULL) { |
275 |
> |
if ((fin = fopen(argv[i], inpmode)) == NULL) { |
276 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
277 |
|
progname, argv[i]); |
278 |
|
quit(1); |
279 |
|
} |
280 |
|
if (reverse && putprim != BRIGHT && i == argc-3) { |
281 |
< |
if ((fin2 = fopen(argv[i+1], "r")) == NULL) { |
281 |
> |
if ((fin2 = fopen(argv[i+1], inpmode)) == NULL) { |
282 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
283 |
|
progname, argv[i+1]); |
284 |
|
quit(1); |
285 |
|
} |
286 |
< |
if ((fin3 = fopen(argv[i+2], "r")) == NULL) { |
286 |
> |
if ((fin3 = fopen(argv[i+2], inpmode)) == NULL) { |
287 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
288 |
|
progname, argv[i+2]); |
289 |
|
quit(1); |
292 |
|
} else if (i != argc-1) |
293 |
|
fin = NULL; |
294 |
|
if (reverse && putprim != BRIGHT && !interleave) { |
295 |
< |
fin2 = fopen(argv[i], "r"); |
296 |
< |
fin3 = fopen(argv[i], "r"); |
295 |
> |
fin2 = fopen(argv[i], inpmode); |
296 |
> |
fin3 = fopen(argv[i], inpmode); |
297 |
|
} |
298 |
< |
if (skipbytes && (fseek(fin, skipbytes, 0) || (fin2 != NULL && |
299 |
< |
(fseek(fin2, skipbytes, 0) || |
300 |
< |
fseek(fin3, skipbytes, 0))))) { |
298 |
> |
if (skipbytes && (fseek(fin, skipbytes, SEEK_SET) || (fin2 != NULL && |
299 |
> |
fseek(fin2, skipbytes, SEEK_SET) | |
300 |
> |
fseek(fin3, skipbytes, SEEK_SET)))) { |
301 |
|
fprintf(stderr, "%s: cannot skip %ld bytes on input\n", |
302 |
|
progname, skipbytes); |
303 |
|
quit(1); |
309 |
|
} |
310 |
|
|
311 |
|
if (reverse) { |
299 |
– |
#if defined(_WIN32) || defined(_WIN64) |
312 |
|
SET_FILE_BINARY(stdout); |
301 |
– |
if (format != 'a' && format != 'i') |
302 |
– |
SET_FILE_BINARY(fin); |
303 |
– |
#endif |
313 |
|
/* get header */ |
314 |
|
if (header) { |
315 |
|
if (checkheader(fin, fmtid, stdout) < 0) { |
358 |
|
fputsresolu(&picres, stdout); /* always put resolution */ |
359 |
|
valtopix(); |
360 |
|
} else { |
361 |
< |
#if defined(_WIN32) || defined(_WIN64) |
353 |
< |
SET_FILE_BINARY(fin); |
354 |
< |
if (format != 'a' && format != 'i') |
361 |
> |
if ((format != 'a') & (format != 'i')) |
362 |
|
SET_FILE_BINARY(stdout); |
356 |
– |
#endif |
363 |
|
/* get header */ |
364 |
|
getheader(fin, checkhead, NULL); |
365 |
|
if (wrongformat) { |
395 |
|
void *p |
396 |
|
) |
397 |
|
{ |
398 |
< |
char fmt[32]; |
398 |
> |
char fmt[MAXFMTLEN]; |
399 |
|
double d; |
400 |
|
COLOR ctmp; |
401 |
|
|
425 |
|
static void |
426 |
|
pixtoval(void) /* convert picture to values */ |
427 |
|
{ |
428 |
< |
register COLOR *scanln; |
428 |
> |
COLOR *scanln; |
429 |
|
int dogamma; |
430 |
|
COLOR lastc; |
431 |
|
RREAL hv[2]; |
432 |
|
int startprim, endprim; |
433 |
|
long startpos; |
434 |
< |
int y; |
429 |
< |
register int x; |
434 |
> |
int x, y; |
435 |
|
|
436 |
|
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
437 |
|
if (scanln == NULL) { |
439 |
|
quit(1); |
440 |
|
} |
441 |
|
dogamma = gamcor < .95 || gamcor > 1.05; |
442 |
< |
if (putprim == ALL && !interleave) { |
442 |
> |
if ((putprim == ALL) & !interleave) { |
443 |
|
startprim = RED; endprim = BLU; |
444 |
|
startpos = ftell(fin); |
445 |
|
} else { |
446 |
|
startprim = putprim; endprim = putprim; |
447 |
|
} |
448 |
|
for (putprim = startprim; putprim <= endprim; putprim++) { |
449 |
< |
if (putprim != startprim && fseek(fin, startpos, 0)) { |
449 |
> |
if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) { |
450 |
|
fprintf(stderr, "%s: seek error on input file\n", |
451 |
|
progname); |
452 |
|
quit(1); |
498 |
|
static void |
499 |
|
valtopix(void) /* convert values to a pixel file */ |
500 |
|
{ |
501 |
< |
int dogamma; |
502 |
< |
register COLOR *scanln; |
503 |
< |
int y; |
504 |
< |
register int x; |
501 |
> |
int dogamma; |
502 |
> |
COLOR *scanln; |
503 |
> |
COLR rgbe; |
504 |
> |
int x, y; |
505 |
|
|
506 |
|
scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); |
507 |
|
if (scanln == NULL) { |
530 |
|
pow(colval(scanln[x],BLU), gamcor)); |
531 |
|
if (doexposure) |
532 |
|
multcolor(scanln[x], exposure); |
533 |
+ |
if (uniq) { /* uncompressed? */ |
534 |
+ |
setcolr(rgbe, scanln[x][RED], |
535 |
+ |
scanln[x][GRN], |
536 |
+ |
scanln[x][BLU]); |
537 |
+ |
if (putbinary(rgbe, sizeof(COLR), 1, stdout) != 1) |
538 |
+ |
goto writerr; |
539 |
+ |
} |
540 |
|
} |
541 |
< |
if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { |
542 |
< |
fprintf(stderr, "%s: write error\n", progname); |
543 |
< |
quit(1); |
532 |
< |
} |
541 |
> |
/* write scan if compressed */ |
542 |
> |
if (!uniq && fwritescan(scanln, scanlen(&picres), stdout) < 0) |
543 |
> |
goto writerr; |
544 |
|
} |
545 |
|
free((void *)scanln); |
546 |
+ |
return; |
547 |
+ |
writerr: |
548 |
+ |
fprintf(stderr, "%s: write error\n", progname); |
549 |
+ |
quit(1); |
550 |
|
} |
551 |
|
|
552 |
|
|
954 |
|
COLOR col |
955 |
|
) |
956 |
|
{ |
957 |
< |
register int i; |
957 |
> |
int i; |
958 |
|
uby8 vb; |
959 |
|
|
960 |
|
i = (*mybright)(col)*256.; |
1107 |
|
if (fin2 == NULL) |
1108 |
|
goto namerr; |
1109 |
|
if (fseek(fin2, |
1110 |
< |
(long)sizeof(float)*picres.xr*picres.yr, 1)) |
1110 |
> |
(long)sizeof(float)*picres.xr*picres.yr, SEEK_CUR)) |
1111 |
|
goto seekerr; |
1112 |
|
if (fseek(fin3, |
1113 |
< |
(long)sizeof(float)*2*picres.xr*picres.yr, 1)) |
1113 |
> |
(long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR)) |
1114 |
|
goto seekerr; |
1115 |
|
} |
1116 |
|
} |
1129 |
|
if (fin2 == NULL) |
1130 |
|
goto namerr; |
1131 |
|
if (fseek(fin2, |
1132 |
< |
(long)sizeof(double)*picres.xr*picres.yr, 1)) |
1132 |
> |
(long)sizeof(double)*picres.xr*picres.yr, SEEK_CUR)) |
1133 |
|
goto seekerr; |
1134 |
|
if (fseek(fin3, |
1135 |
< |
(long)sizeof(double)*2*picres.xr*picres.yr, 1)) |
1135 |
> |
(long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR)) |
1136 |
|
goto seekerr; |
1137 |
|
} |
1138 |
|
} |
1169 |
|
if (fin2 == NULL) |
1170 |
|
goto namerr; |
1171 |
|
if (fseek(fin2, |
1172 |
< |
(long)sizeof(uby8)*picres.xr*picres.yr, 1)) |
1172 |
> |
(long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR)) |
1173 |
|
goto seekerr; |
1174 |
|
if (fseek(fin3, |
1175 |
< |
(long)sizeof(uby8)*2*picres.xr*picres.yr, 1)) |
1175 |
> |
(long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR)) |
1176 |
|
goto seekerr; |
1177 |
|
} |
1178 |
|
} |
1191 |
|
if (fin2 == NULL) |
1192 |
|
goto namerr; |
1193 |
|
if (fseek(fin2, |
1194 |
< |
(long)sizeof(uint16)*picres.xr*picres.yr, 1)) |
1194 |
> |
(long)sizeof(uint16)*picres.xr*picres.yr, SEEK_CUR)) |
1195 |
|
goto seekerr; |
1196 |
|
if (fseek(fin3, |
1197 |
< |
(long)sizeof(uint16)*2*picres.xr*picres.yr, 1)) |
1197 |
> |
(long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR)) |
1198 |
|
goto seekerr; |
1199 |
|
} |
1200 |
|
} |