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 |
|
|
10 |
+ |
#ifdef MSDOS |
11 |
+ |
#include <fcntl.h> |
12 |
+ |
#endif |
13 |
+ |
|
14 |
+ |
#include <time.h> |
15 |
+ |
|
16 |
|
#include "color.h" |
17 |
|
|
18 |
< |
int xres, yres; /* input resolution */ |
18 |
> |
#include "resolu.h" |
19 |
|
|
20 |
+ |
int order; /* input orientation */ |
21 |
+ |
int xres, yres; /* resolution (scanlen, nscans) */ |
22 |
+ |
|
23 |
|
long *scanpos; /* scanline positions */ |
24 |
|
|
25 |
< |
int fhoriz, fvert; /* flip flags */ |
25 |
> |
int fhoriz=0, fvert=0; /* flip flags */ |
26 |
|
|
27 |
+ |
int correctorder = 0; /* correcting orientation? */ |
28 |
+ |
|
29 |
|
FILE *fin; /* input file */ |
30 |
|
|
31 |
|
char *progname; |
32 |
|
|
33 |
|
|
34 |
+ |
int |
35 |
+ |
neworder() /* figure out new order from old */ |
36 |
+ |
{ |
37 |
+ |
register int no; |
38 |
+ |
|
39 |
+ |
if (correctorder) |
40 |
+ |
return(order); /* just leave it */ |
41 |
+ |
if ((no = order) & YMAJOR) { |
42 |
+ |
if (fhoriz) no ^= XDECR; |
43 |
+ |
if (fvert) no ^= YDECR; |
44 |
+ |
} else { |
45 |
+ |
if (fhoriz) no ^= YDECR; |
46 |
+ |
if (fvert) no ^= XDECR; |
47 |
+ |
} |
48 |
+ |
return(no); |
49 |
+ |
} |
50 |
+ |
|
51 |
+ |
|
52 |
|
main(argc, argv) |
53 |
|
int argc; |
54 |
|
char *argv[]; |
55 |
|
{ |
56 |
< |
int i; |
57 |
< |
|
56 |
> |
static char picfmt[LPICFMT+1] = PICFMT; |
57 |
> |
int i, rval; |
58 |
> |
#ifdef MSDOS |
59 |
> |
extern int _fmode; |
60 |
> |
_fmode = O_BINARY; |
61 |
> |
setmode(fileno(stdout), O_BINARY); |
62 |
> |
#endif |
63 |
|
progname = argv[0]; |
64 |
|
|
65 |
|
for (i = 1; i < argc; i++) |
67 |
|
fhoriz++; |
68 |
|
else if (!strcmp(argv[i], "-v")) |
69 |
|
fvert++; |
70 |
+ |
else if (!strcmp(argv[i], "-c")) |
71 |
+ |
correctorder++; |
72 |
|
else |
73 |
|
break; |
74 |
|
if (i >= argc || argv[i][0] == '-') { |
75 |
< |
fprintf(stderr, "Usage: %s [-h][-v] infile [outfile]\n", |
75 |
> |
fprintf(stderr, "Usage: %s [-h][-v][-c] infile [outfile]\n", |
76 |
|
progname); |
77 |
|
exit(1); |
78 |
|
} |
85 |
|
exit(1); |
86 |
|
} |
87 |
|
/* transfer header */ |
88 |
< |
copyheader(fin, stdout); |
88 |
> |
if ((rval = checkheader(fin, picfmt, stdout)) < 0) { |
89 |
> |
fprintf(stderr, "%s: input not a Radiance picture\n", |
90 |
> |
progname); |
91 |
> |
exit(1); |
92 |
> |
} |
93 |
> |
if (rval) |
94 |
> |
fputformat(picfmt, stdout); |
95 |
|
/* add new header info. */ |
96 |
|
printargs(i, argv, stdout); |
97 |
|
putchar('\n'); |
98 |
|
/* get picture size */ |
99 |
< |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
99 |
> |
if ((order = fgetresolu(&xres, &yres, fin)) < 0) { |
100 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
101 |
|
exit(1); |
102 |
|
} |
103 |
|
/* write new picture size */ |
104 |
< |
fputresolu(YMAJOR|YDECR, xres, yres, stdout); |
104 |
> |
fputresolu(neworder(), xres, yres, stdout); |
105 |
|
/* goto end if vertical flip */ |
106 |
|
if (fvert) |
107 |
|
scanfile(); |
127 |
|
memerr(); |
128 |
|
if ((scanin = (COLR *)malloc(xres*sizeof(COLR))) == NULL) |
129 |
|
memerr(); |
130 |
< |
for (y = yres-1; y >= 0; y--) { |
130 |
> |
for (y = yres-1; y > 0; y--) { |
131 |
|
scanpos[y] = ftell(fin); |
132 |
|
if (freadcolrs(scanin, xres, fin) < 0) { |
133 |
|
fprintf(stderr, "%s: read error\n", progname); |
134 |
|
exit(1); |
135 |
|
} |
136 |
|
} |
137 |
< |
free((char *)scanin); |
137 |
> |
scanpos[0] = ftell(fin); |
138 |
> |
free((void *)scanin); |
139 |
|
} |
140 |
|
|
141 |
|
|
169 |
|
exit(1); |
170 |
|
} |
171 |
|
} |
172 |
< |
free((char *)scanin); |
173 |
< |
free((char *)scanout); |
172 |
> |
free((void *)scanin); |
173 |
> |
if (fhoriz) |
174 |
> |
free((void *)scanout); |
175 |
|
} |