1 |
– |
/* Copyright (c) 1991 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 |
|
* flip picture file horizontally and/or vertically |
6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdio.h> |
9 |
+ |
#include <time.h> |
10 |
|
|
11 |
+ |
#include "platform.h" |
12 |
|
#include "color.h" |
13 |
+ |
#include "resolu.h" |
14 |
|
|
15 |
< |
int xres, yres; /* input resolution */ |
15 |
> |
int order; /* input orientation */ |
16 |
> |
int xres, yres; /* resolution (scanlen, nscans) */ |
17 |
|
|
18 |
|
long *scanpos; /* scanline positions */ |
19 |
|
|
20 |
< |
int fhoriz, fvert; /* flip flags */ |
20 |
> |
int fhoriz=0, fvert=0; /* flip flags */ |
21 |
|
|
22 |
+ |
int correctorder = 0; /* correcting orientation? */ |
23 |
+ |
|
24 |
|
FILE *fin; /* input file */ |
25 |
|
|
26 |
|
char *progname; |
27 |
|
|
28 |
|
|
29 |
+ |
int |
30 |
+ |
neworder() /* figure out new order from old */ |
31 |
+ |
{ |
32 |
+ |
register int no; |
33 |
+ |
|
34 |
+ |
if (correctorder) |
35 |
+ |
return(order); /* just leave it */ |
36 |
+ |
if ((no = order) & YMAJOR) { |
37 |
+ |
if (fhoriz) no ^= XDECR; |
38 |
+ |
if (fvert) no ^= YDECR; |
39 |
+ |
} else { |
40 |
+ |
if (fhoriz) no ^= YDECR; |
41 |
+ |
if (fvert) no ^= XDECR; |
42 |
+ |
} |
43 |
+ |
return(no); |
44 |
+ |
} |
45 |
+ |
|
46 |
+ |
|
47 |
|
main(argc, argv) |
48 |
|
int argc; |
49 |
|
char *argv[]; |
50 |
|
{ |
51 |
< |
int i; |
52 |
< |
|
51 |
> |
static char picfmt[LPICFMT+1] = PICFMT; |
52 |
> |
int i, rval; |
53 |
> |
SET_DEFAULT_BINARY(); |
54 |
> |
SET_FILE_BINARY(stdout); |
55 |
|
progname = argv[0]; |
56 |
|
|
57 |
|
for (i = 1; i < argc; i++) |
59 |
|
fhoriz++; |
60 |
|
else if (!strcmp(argv[i], "-v")) |
61 |
|
fvert++; |
62 |
+ |
else if (!strcmp(argv[i], "-c")) |
63 |
+ |
correctorder++; |
64 |
|
else |
65 |
|
break; |
66 |
|
if (i >= argc || argv[i][0] == '-') { |
67 |
< |
fprintf(stderr, "Usage: %s [-h][-v] infile [outfile]\n", |
67 |
> |
fprintf(stderr, "Usage: %s [-h][-v][-c] infile [outfile]\n", |
68 |
|
progname); |
69 |
|
exit(1); |
70 |
|
} |
77 |
|
exit(1); |
78 |
|
} |
79 |
|
/* transfer header */ |
80 |
< |
if (checkheader(fin, COLRFMT, stdout) < 0) { |
80 |
> |
if ((rval = checkheader(fin, picfmt, stdout)) < 0) { |
81 |
|
fprintf(stderr, "%s: input not a Radiance picture\n", |
82 |
|
progname); |
83 |
|
exit(1); |
84 |
|
} |
85 |
+ |
if (rval) |
86 |
+ |
fputformat(picfmt, stdout); |
87 |
|
/* add new header info. */ |
88 |
|
printargs(i, argv, stdout); |
62 |
– |
fputformat(COLRFMT, stdout); |
89 |
|
putchar('\n'); |
90 |
|
/* get picture size */ |
91 |
< |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
91 |
> |
if ((order = fgetresolu(&xres, &yres, fin)) < 0) { |
92 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
93 |
|
exit(1); |
94 |
|
} |
95 |
|
/* write new picture size */ |
96 |
< |
fputresolu(YMAJOR|YDECR, xres, yres, stdout); |
96 |
> |
fputresolu(neworder(), xres, yres, stdout); |
97 |
|
/* goto end if vertical flip */ |
98 |
|
if (fvert) |
99 |
|
scanfile(); |
119 |
|
memerr(); |
120 |
|
if ((scanin = (COLR *)malloc(xres*sizeof(COLR))) == NULL) |
121 |
|
memerr(); |
122 |
< |
for (y = yres-1; y >= 0; y--) { |
122 |
> |
for (y = yres-1; y > 0; y--) { |
123 |
|
scanpos[y] = ftell(fin); |
124 |
|
if (freadcolrs(scanin, xres, fin) < 0) { |
125 |
|
fprintf(stderr, "%s: read error\n", progname); |
126 |
|
exit(1); |
127 |
|
} |
128 |
|
} |
129 |
< |
free((char *)scanin); |
129 |
> |
scanpos[0] = ftell(fin); |
130 |
> |
free((void *)scanin); |
131 |
|
} |
132 |
|
|
133 |
|
|
161 |
|
exit(1); |
162 |
|
} |
163 |
|
} |
164 |
< |
free((char *)scanin); |
165 |
< |
free((char *)scanout); |
164 |
> |
free((void *)scanin); |
165 |
> |
if (fhoriz) |
166 |
> |
free((void *)scanout); |
167 |
|
} |