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