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 |
|
* prot.c - program to rotate picture file 90 degrees clockwise. |
6 |
|
* |
7 |
|
* 2/26/88 |
8 |
|
*/ |
9 |
|
|
10 |
+ |
#include "platform.h" |
11 |
|
#include "standard.h" |
12 |
|
|
13 |
|
#include "color.h" |
14 |
|
|
15 |
+ |
#include <time.h> |
16 |
+ |
|
17 |
|
#include "resolu.h" |
18 |
|
|
19 |
|
int order; /* input scanline order */ |
22 |
|
int correctorder = 0; /* order correction? */ |
23 |
|
int ccw = 0; /* rotate CCW? */ |
24 |
|
|
25 |
< |
#ifdef BIGMEM |
26 |
< |
char buf[1<<22]; /* output buffer */ |
27 |
< |
#else |
25 |
> |
#ifdef SMLMEM |
26 |
|
char buf[1<<20]; /* output buffer */ |
27 |
+ |
#else |
28 |
+ |
char buf[1<<22]; /* output buffer */ |
29 |
|
#endif |
30 |
|
|
31 |
|
int nrows; /* number of rows output at once */ |
35 |
|
char *progname; |
36 |
|
|
37 |
|
short ordertab[4][2] = { |
38 |
< |
{0,XDECR}, {XDECR,XDECR|YDECR}, {XDECR|YDECR,YDECR}, {YDECR,0} |
38 |
> |
{0,0}, {XDECR,XDECR|YDECR}, {XDECR|YDECR,YDECR}, {YDECR,XDECR} |
39 |
|
}; |
40 |
|
|
41 |
|
|
42 |
< |
int |
43 |
< |
neworder() /* return corrected order */ |
42 |
> |
static int neworder(void); |
43 |
> |
static void rotatecw(FILE *fp); |
44 |
> |
static void rotateccw(FILE *fp); |
45 |
> |
|
46 |
> |
|
47 |
> |
|
48 |
> |
static int |
49 |
> |
neworder(void) /* return corrected order */ |
50 |
|
{ |
51 |
+ |
static short ordercw[8]; |
52 |
|
register int i; |
53 |
|
|
54 |
|
if (correctorder) |
55 |
|
return(order); |
56 |
< |
for (i = 4; i--; ) |
57 |
< |
if ((order&~YMAJOR) == ordertab[i][ccw]) |
58 |
< |
return(ordertab[i][1-ccw] | ((order&YMAJOR)^YMAJOR)); |
56 |
> |
if (!ordercw[0]) { |
57 |
> |
ordercw[YMAJOR|YDECR] = 0; |
58 |
> |
ordercw[0] = YMAJOR|XDECR; |
59 |
> |
ordercw[YMAJOR|XDECR] = XDECR|YDECR; |
60 |
> |
ordercw[XDECR|YDECR] = YMAJOR|YDECR; |
61 |
> |
ordercw[YMAJOR|XDECR|YDECR] = XDECR; |
62 |
> |
ordercw[XDECR] = YMAJOR; |
63 |
> |
ordercw[YMAJOR] = YDECR; |
64 |
> |
ordercw[YDECR] = YMAJOR|XDECR|YDECR; |
65 |
> |
} |
66 |
> |
if (!ccw) |
67 |
> |
return(ordercw[order]); |
68 |
> |
for (i = 8; i--; ) |
69 |
> |
if (ordercw[i] == order) |
70 |
> |
return(i); |
71 |
|
fputs("Order botch!\n", stderr); |
72 |
|
exit(2); |
73 |
|
} |
74 |
|
|
75 |
< |
|
76 |
< |
main(argc, argv) |
77 |
< |
int argc; |
78 |
< |
char *argv[]; |
75 |
> |
int |
76 |
> |
main( |
77 |
> |
int argc, |
78 |
> |
char *argv[] |
79 |
> |
) |
80 |
|
{ |
81 |
< |
static char picfmt[LPICFMT+1] = PICFMT; |
81 |
> |
static char picfmt[MAXFMTLEN] = PICFMT; |
82 |
|
int rval; |
83 |
|
FILE *fin; |
84 |
|
|
85 |
+ |
SET_DEFAULT_BINARY(); |
86 |
+ |
SET_FILE_BINARY(stdout); |
87 |
+ |
|
88 |
|
progname = argv[0]; |
89 |
|
|
90 |
|
while (argc > 2 && argv[1][0] == '-') { |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
< |
rotatecw(fp) /* rotate picture clockwise */ |
146 |
< |
FILE *fp; |
145 |
> |
static void |
146 |
> |
rotatecw( /* rotate picture clockwise */ |
147 |
> |
FILE *fp |
148 |
> |
) |
149 |
|
{ |
150 |
|
register COLR *inln; |
151 |
|
register int xoff, inx, iny; |
167 |
|
exit(1); |
168 |
|
} |
169 |
|
for (inx = 0; inx < nrows && xoff+inx < xres; inx++) |
170 |
< |
bcopy((char *)inln[xoff+inx], |
171 |
< |
(char *)scanbar[inx*yres+iny], |
147 |
< |
sizeof(COLR)); |
170 |
> |
copycolr(scanbar[inx*yres+iny], |
171 |
> |
inln[xoff+inx]); |
172 |
|
} |
173 |
|
for (inx = 0; inx < nrows && xoff+inx < xres; inx++) |
174 |
|
if (fwritecolrs(scanbar+inx*yres, yres, stdout) < 0) { |
176 |
|
exit(1); |
177 |
|
} |
178 |
|
} |
179 |
< |
free((char *)inln); |
179 |
> |
free((void *)inln); |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
< |
rotateccw(fp) /* rotate picture counter-clockwise */ |
184 |
< |
FILE *fp; |
183 |
> |
static void |
184 |
> |
rotateccw( /* rotate picture counter-clockwise */ |
185 |
> |
FILE *fp |
186 |
> |
) |
187 |
|
{ |
188 |
|
register COLR *inln; |
189 |
|
register int xoff, inx, iny; |
205 |
|
exit(1); |
206 |
|
} |
207 |
|
for (inx = 0; inx < nrows && xoff-inx >= 0; inx++) |
208 |
< |
bcopy((char *)inln[xoff-inx], |
209 |
< |
(char *)scanbar[inx*yres+iny], |
184 |
< |
sizeof(COLR)); |
208 |
> |
copycolr(scanbar[inx*yres+iny], |
209 |
> |
inln[xoff-inx]); |
210 |
|
} |
211 |
|
for (inx = 0; inx < nrows && xoff-inx >= 0; inx++) |
212 |
|
if (fwritecolrs(scanbar+inx*yres, yres, stdout) < 0) { |
214 |
|
exit(1); |
215 |
|
} |
216 |
|
} |
217 |
< |
free((char *)inln); |
217 |
> |
free((void *)inln); |
218 |
|
} |