1 |
greg |
1.9 |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
greg |
1.1 |
|
3 |
|
|
#ifndef lint |
4 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
|
#endif |
6 |
greg |
1.9 |
|
7 |
greg |
1.1 |
/* |
8 |
|
|
* prot.c - program to rotate picture file 90 degrees clockwise. |
9 |
|
|
* |
10 |
|
|
* 2/26/88 |
11 |
|
|
*/ |
12 |
|
|
|
13 |
greg |
1.7 |
#include "standard.h" |
14 |
greg |
1.1 |
|
15 |
|
|
#include "color.h" |
16 |
|
|
|
17 |
greg |
1.9 |
#include "resolu.h" |
18 |
|
|
|
19 |
|
|
int order; /* input scanline order */ |
20 |
greg |
1.1 |
int xres, yres; /* input resolution */ |
21 |
|
|
|
22 |
greg |
1.9 |
int correctorder = 0; /* order correction? */ |
23 |
|
|
|
24 |
greg |
2.2 |
#ifdef BIGMEM |
25 |
|
|
char buf[1<<22]; /* output buffer */ |
26 |
|
|
#else |
27 |
greg |
1.1 |
char buf[1<<20]; /* output buffer */ |
28 |
greg |
2.2 |
#endif |
29 |
greg |
1.1 |
|
30 |
|
|
int nrows; /* number of rows output at once */ |
31 |
|
|
|
32 |
|
|
#define scanbar ((COLR *)buf) |
33 |
|
|
|
34 |
|
|
char *progname; |
35 |
|
|
|
36 |
greg |
1.9 |
#define neworder() (correctorder ? order : \ |
37 |
|
|
(order^(order&YMAJOR?YDECR:XDECR)^YMAJOR)) |
38 |
greg |
1.1 |
|
39 |
greg |
1.8 |
|
40 |
greg |
1.1 |
main(argc, argv) |
41 |
|
|
int argc; |
42 |
|
|
char *argv[]; |
43 |
|
|
{ |
44 |
|
|
FILE *fin; |
45 |
|
|
|
46 |
|
|
progname = argv[0]; |
47 |
|
|
|
48 |
greg |
1.9 |
if (argc > 2 && !strcmp(argv[1], "-c")) { |
49 |
|
|
correctorder++; |
50 |
|
|
argc--; argv++; |
51 |
|
|
} |
52 |
greg |
1.1 |
if (argc != 2 && argc != 3) { |
53 |
greg |
1.9 |
fprintf(stderr, "Usage: %s [-c] infile [outfile]\n", progname); |
54 |
greg |
1.1 |
exit(1); |
55 |
|
|
} |
56 |
|
|
if ((fin = fopen(argv[1], "r")) == NULL) { |
57 |
|
|
fprintf(stderr, "%s: cannot open\n", argv[1]); |
58 |
|
|
exit(1); |
59 |
|
|
} |
60 |
|
|
if (argc == 3 && freopen(argv[2], "w", stdout) == NULL) { |
61 |
|
|
fprintf(stderr, "%s: cannot open\n", argv[2]); |
62 |
|
|
exit(1); |
63 |
|
|
} |
64 |
greg |
1.6 |
/* transfer header */ |
65 |
greg |
1.9 |
if (checkheader(fin, COLRFMT, stdout) < 0) { |
66 |
|
|
fprintf(stderr, "%s: not a Radiance picture\n", progname); |
67 |
greg |
1.8 |
exit(1); |
68 |
|
|
} |
69 |
greg |
1.1 |
/* add new header info. */ |
70 |
|
|
printf("%s\n\n", progname); |
71 |
|
|
/* get picture size */ |
72 |
greg |
1.9 |
if ((order = fgetresolu(&xres, &yres, fin)) < 0) { |
73 |
greg |
1.1 |
fprintf(stderr, "%s: bad picture size\n", progname); |
74 |
|
|
exit(1); |
75 |
|
|
} |
76 |
|
|
/* write new picture size */ |
77 |
greg |
1.9 |
fputresolu(neworder(), yres, xres, stdout); |
78 |
greg |
1.1 |
/* compute buffer capacity */ |
79 |
|
|
nrows = sizeof(buf)/sizeof(COLR)/yres; |
80 |
|
|
rotate(fin); /* rotate the image */ |
81 |
|
|
exit(0); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
|
85 |
|
|
rotate(fp) /* rotate picture */ |
86 |
|
|
FILE *fp; |
87 |
|
|
{ |
88 |
greg |
1.5 |
register COLR *inln; |
89 |
greg |
1.1 |
register int xoff, inx, iny; |
90 |
|
|
long start, ftell(); |
91 |
|
|
|
92 |
greg |
1.5 |
if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) { |
93 |
greg |
1.1 |
fprintf(stderr, "%s: out of memory\n", progname); |
94 |
|
|
exit(1); |
95 |
|
|
} |
96 |
|
|
start = ftell(fp); |
97 |
|
|
for (xoff = 0; xoff < xres; xoff += nrows) { |
98 |
|
|
if (fseek(fp, start, 0) < 0) { |
99 |
|
|
fprintf(stderr, "%s: seek error\n", progname); |
100 |
|
|
exit(1); |
101 |
|
|
} |
102 |
|
|
for (iny = yres-1; iny >= 0; iny--) { |
103 |
greg |
1.5 |
if (freadcolrs(inln, xres, fp) < 0) { |
104 |
greg |
1.1 |
fprintf(stderr, "%s: read error\n", progname); |
105 |
|
|
exit(1); |
106 |
|
|
} |
107 |
|
|
for (inx = 0; inx < nrows && xoff+inx < xres; inx++) |
108 |
greg |
1.5 |
bcopy((char *)inln[xoff+inx], |
109 |
greg |
1.3 |
(char *)scanbar[inx*yres+iny], |
110 |
greg |
1.1 |
sizeof(COLR)); |
111 |
|
|
} |
112 |
|
|
for (inx = 0; inx < nrows && xoff+inx < xres; inx++) |
113 |
|
|
if (fwritecolrs(scanbar+inx*yres, yres, stdout) < 0) { |
114 |
|
|
fprintf(stderr, "%s: write error\n", progname); |
115 |
|
|
exit(1); |
116 |
|
|
} |
117 |
|
|
} |
118 |
greg |
1.5 |
free((char *)inln); |
119 |
greg |
1.1 |
} |