9 |
|
* 2/26/88 |
10 |
|
*/ |
11 |
|
|
12 |
< |
#include <stdio.h> |
12 |
> |
#include "standard.h" |
13 |
|
|
14 |
|
#include "color.h" |
15 |
|
|
16 |
|
int xres, yres; /* input resolution */ |
17 |
+ |
double inpaspect = 1.0; /* input aspect ratio */ |
18 |
|
|
19 |
|
char buf[1<<20]; /* output buffer */ |
20 |
|
|
21 |
|
int nrows; /* number of rows output at once */ |
22 |
|
|
23 |
+ |
int wrongformat = 0; |
24 |
+ |
|
25 |
|
#define scanbar ((COLR *)buf) |
26 |
|
|
27 |
|
char *progname; |
28 |
|
|
29 |
|
|
30 |
+ |
headline(s) /* process line from header */ |
31 |
+ |
char *s; |
32 |
+ |
{ |
33 |
+ |
char fmt[32]; |
34 |
+ |
|
35 |
+ |
fputs(s, stdout); |
36 |
+ |
if (isaspect(s)) |
37 |
+ |
inpaspect *= aspectval(s); |
38 |
+ |
else if (isformat(s)) { |
39 |
+ |
formatval(fmt, s); |
40 |
+ |
wrongformat = strcmp(fmt, COLRFMT); |
41 |
+ |
} |
42 |
+ |
} |
43 |
+ |
|
44 |
+ |
|
45 |
|
main(argc, argv) |
46 |
|
int argc; |
47 |
|
char *argv[]; |
62 |
|
fprintf(stderr, "%s: cannot open\n", argv[2]); |
63 |
|
exit(1); |
64 |
|
} |
65 |
< |
/* copy header */ |
66 |
< |
while (fgets(buf, sizeof(buf), fin) != NULL && buf[0] != '\n') |
67 |
< |
fputs(buf, stdout); |
65 |
> |
/* transfer header */ |
66 |
> |
getheader(fin, headline, NULL); |
67 |
> |
if (wrongformat) { |
68 |
> |
fprintf(stderr, "%s: wrong picture format\n", progname); |
69 |
> |
exit(1); |
70 |
> |
} |
71 |
|
/* add new header info. */ |
72 |
+ |
if (inpaspect < .99 || inpaspect > 1.01) |
73 |
+ |
fputaspect(1./inpaspect/inpaspect, stdout); |
74 |
|
printf("%s\n\n", progname); |
75 |
|
/* get picture size */ |
76 |
< |
if (fgets(buf, sizeof(buf), fin) == NULL || |
54 |
< |
sscanf(buf, "-Y %d +X %d\n", &yres, &xres) != 2) { |
76 |
> |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
77 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
78 |
|
exit(1); |
79 |
|
} |
80 |
|
/* write new picture size */ |
81 |
< |
printf("-Y %d +X %d\n", xres, yres); |
81 |
> |
fputresolu(YMAJOR|YDECR, yres, xres, stdout); |
82 |
|
/* compute buffer capacity */ |
83 |
|
nrows = sizeof(buf)/sizeof(COLR)/yres; |
84 |
|
rotate(fin); /* rotate the image */ |
89 |
|
rotate(fp) /* rotate picture */ |
90 |
|
FILE *fp; |
91 |
|
{ |
92 |
< |
register COLR *inline; |
92 |
> |
register COLR *inln; |
93 |
|
register int xoff, inx, iny; |
94 |
|
long start, ftell(); |
95 |
|
|
96 |
< |
if ((inline = (COLR *)malloc(xres*sizeof(COLR))) == NULL) { |
96 |
> |
if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) { |
97 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
98 |
|
exit(1); |
99 |
|
} |
104 |
|
exit(1); |
105 |
|
} |
106 |
|
for (iny = yres-1; iny >= 0; iny--) { |
107 |
< |
if (freadcolrs(inline, xres, fp) < 0) { |
107 |
> |
if (freadcolrs(inln, xres, fp) < 0) { |
108 |
|
fprintf(stderr, "%s: read error\n", progname); |
109 |
|
exit(1); |
110 |
|
} |
111 |
|
for (inx = 0; inx < nrows && xoff+inx < xres; inx++) |
112 |
< |
bcopy(inline[xoff+inx], scanbar[inx*yres+iny], |
112 |
> |
bcopy((char *)inln[xoff+inx], |
113 |
> |
(char *)scanbar[inx*yres+iny], |
114 |
|
sizeof(COLR)); |
115 |
|
} |
116 |
|
for (inx = 0; inx < nrows && xoff+inx < xres; inx++) |
119 |
|
exit(1); |
120 |
|
} |
121 |
|
} |
122 |
< |
free((char *)inline); |
122 |
> |
free((char *)inln); |
123 |
|
} |