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) { |
376 |
|
printargs(i, argv, stdout); |
377 |
|
if (expval < .99 || expval > 1.01) |
378 |
|
fputexpos(expval, stdout); |
379 |
+ |
if (swapbytes) { |
380 |
+ |
if (nativebigendian()) |
381 |
+ |
puts("BigEndian=0"); |
382 |
+ |
else |
383 |
+ |
puts("BigEndian=1"); |
384 |
+ |
} else if ((format != 'a') & (format != 'i')) |
385 |
+ |
fputendian(stdout); |
386 |
|
fputformat(fmtid, stdout); |
387 |
|
putchar('\n'); |
388 |
|
} |
405 |
|
char fmt[MAXFMTLEN]; |
406 |
|
double d; |
407 |
|
COLOR ctmp; |
408 |
+ |
int rv; |
409 |
|
|
410 |
|
if (formatval(fmt, line)) { |
411 |
|
if (!strcmp(fmt, CIEFMT)) |
424 |
|
colval(exposure,GRN)/colval(ctmp,GRN), |
425 |
|
colval(exposure,BLU)/colval(ctmp,BLU)); |
426 |
|
doexposure++; |
427 |
+ |
} else if (reverse && (rv = isbigendian(line)) >= 0) { |
428 |
+ |
swapbytes = (nativebigendian() != rv); |
429 |
|
} else if (header) |
430 |
|
fputs(line, stdout); |
431 |
|
return(0); |
449 |
|
quit(1); |
450 |
|
} |
451 |
|
dogamma = gamcor < .95 || gamcor > 1.05; |
452 |
< |
if (putprim == ALL && !interleave) { |
452 |
> |
if ((putprim == ALL) & !interleave) { |
453 |
|
startprim = RED; endprim = BLU; |
454 |
|
startpos = ftell(fin); |
455 |
|
} else { |
456 |
|
startprim = putprim; endprim = putprim; |
457 |
|
} |
458 |
|
for (putprim = startprim; putprim <= endprim; putprim++) { |
459 |
< |
if (putprim != startprim && fseek(fin, startpos, 0)) { |
459 |
> |
if (putprim != startprim && fseek(fin, startpos, SEEK_SET)) { |
460 |
|
fprintf(stderr, "%s: seek error on input file\n", |
461 |
|
progname); |
462 |
|
quit(1); |
1117 |
|
if (fin2 == NULL) |
1118 |
|
goto namerr; |
1119 |
|
if (fseek(fin2, |
1120 |
< |
(long)sizeof(float)*picres.xr*picres.yr, 1)) |
1120 |
> |
(long)sizeof(float)*picres.xr*picres.yr, SEEK_CUR)) |
1121 |
|
goto seekerr; |
1122 |
|
if (fseek(fin3, |
1123 |
< |
(long)sizeof(float)*2*picres.xr*picres.yr, 1)) |
1123 |
> |
(long)sizeof(float)*2*picres.xr*picres.yr, SEEK_CUR)) |
1124 |
|
goto seekerr; |
1125 |
|
} |
1126 |
|
} |
1139 |
|
if (fin2 == NULL) |
1140 |
|
goto namerr; |
1141 |
|
if (fseek(fin2, |
1142 |
< |
(long)sizeof(double)*picres.xr*picres.yr, 1)) |
1142 |
> |
(long)sizeof(double)*picres.xr*picres.yr, SEEK_CUR)) |
1143 |
|
goto seekerr; |
1144 |
|
if (fseek(fin3, |
1145 |
< |
(long)sizeof(double)*2*picres.xr*picres.yr, 1)) |
1145 |
> |
(long)sizeof(double)*2*picres.xr*picres.yr, SEEK_CUR)) |
1146 |
|
goto seekerr; |
1147 |
|
} |
1148 |
|
} |
1179 |
|
if (fin2 == NULL) |
1180 |
|
goto namerr; |
1181 |
|
if (fseek(fin2, |
1182 |
< |
(long)sizeof(uby8)*picres.xr*picres.yr, 1)) |
1182 |
> |
(long)sizeof(uby8)*picres.xr*picres.yr, SEEK_CUR)) |
1183 |
|
goto seekerr; |
1184 |
|
if (fseek(fin3, |
1185 |
< |
(long)sizeof(uby8)*2*picres.xr*picres.yr, 1)) |
1185 |
> |
(long)sizeof(uby8)*2*picres.xr*picres.yr, SEEK_CUR)) |
1186 |
|
goto seekerr; |
1187 |
|
} |
1188 |
|
} |
1201 |
|
if (fin2 == NULL) |
1202 |
|
goto namerr; |
1203 |
|
if (fseek(fin2, |
1204 |
< |
(long)sizeof(uint16)*picres.xr*picres.yr, 1)) |
1204 |
> |
(long)sizeof(uint16)*picres.xr*picres.yr, SEEK_CUR)) |
1205 |
|
goto seekerr; |
1206 |
|
if (fseek(fin3, |
1207 |
< |
(long)sizeof(uint16)*2*picres.xr*picres.yr, 1)) |
1207 |
> |
(long)sizeof(uint16)*2*picres.xr*picres.yr, SEEK_CUR)) |
1208 |
|
goto seekerr; |
1209 |
|
} |
1210 |
|
} |