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 |
|
|
25 |
|
char *progname; |
26 |
|
|
27 |
|
|
28 |
+ |
headline(s) /* process line from header */ |
29 |
+ |
char *s; |
30 |
+ |
{ |
31 |
+ |
fputs(s, stdout); |
32 |
+ |
if (isaspect(s)) |
33 |
+ |
inpaspect *= aspectval(s); |
34 |
+ |
} |
35 |
+ |
|
36 |
+ |
|
37 |
|
main(argc, argv) |
38 |
|
int argc; |
39 |
|
char *argv[]; |
54 |
|
fprintf(stderr, "%s: cannot open\n", argv[2]); |
55 |
|
exit(1); |
56 |
|
} |
57 |
< |
/* copy header */ |
58 |
< |
while (fgets(buf, sizeof(buf), fin) != NULL && buf[0] != '\n') |
49 |
< |
fputs(buf, stdout); |
57 |
> |
/* transfer header */ |
58 |
> |
getheader(fin, headline); |
59 |
|
/* add new header info. */ |
60 |
+ |
if (inpaspect < .99 || inpaspect > 1.01) |
61 |
+ |
fputaspect(1./inpaspect/inpaspect, stdout); |
62 |
|
printf("%s\n\n", progname); |
63 |
|
/* get picture size */ |
64 |
< |
if (fgets(buf, sizeof(buf), fin) == NULL || |
54 |
< |
sscanf(buf, "-Y %d +X %d\n", &yres, &xres) != 2) { |
64 |
> |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
65 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
66 |
|
exit(1); |
67 |
|
} |
68 |
|
/* write new picture size */ |
69 |
< |
printf("-Y %d +X %d\n", xres, yres); |
69 |
> |
fputresolu(YMAJOR|YDECR, yres, xres, stdout); |
70 |
|
/* compute buffer capacity */ |
71 |
|
nrows = sizeof(buf)/sizeof(COLR)/yres; |
72 |
|
rotate(fin); /* rotate the image */ |
77 |
|
rotate(fp) /* rotate picture */ |
78 |
|
FILE *fp; |
79 |
|
{ |
80 |
< |
register COLR *inline; |
80 |
> |
register COLR *inln; |
81 |
|
register int xoff, inx, iny; |
82 |
|
long start, ftell(); |
83 |
|
|
84 |
< |
if ((inline = (COLR *)malloc(xres*sizeof(COLR))) == NULL) { |
84 |
> |
if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) { |
85 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
86 |
|
exit(1); |
87 |
|
} |
92 |
|
exit(1); |
93 |
|
} |
94 |
|
for (iny = yres-1; iny >= 0; iny--) { |
95 |
< |
if (freadcolrs(inline, xres, fp) < 0) { |
95 |
> |
if (freadcolrs(inln, xres, fp) < 0) { |
96 |
|
fprintf(stderr, "%s: read error\n", progname); |
97 |
|
exit(1); |
98 |
|
} |
99 |
|
for (inx = 0; inx < nrows && xoff+inx < xres; inx++) |
100 |
< |
bcopy(inline[xoff+inx], scanbar[inx*yres+iny], |
100 |
> |
bcopy((char *)inln[xoff+inx], |
101 |
> |
(char *)scanbar[inx*yres+iny], |
102 |
|
sizeof(COLR)); |
103 |
|
} |
104 |
|
for (inx = 0; inx < nrows && xoff+inx < xres; inx++) |
107 |
|
exit(1); |
108 |
|
} |
109 |
|
} |
110 |
< |
free((char *)inline); |
110 |
> |
free((char *)inln); |
111 |
|
} |