1 |
< |
/* Copyright (c) 1988 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
#endif |
6 |
+ |
|
7 |
|
/* |
8 |
|
* prot.c - program to rotate picture file 90 degrees clockwise. |
9 |
|
* |
10 |
|
* 2/26/88 |
11 |
|
*/ |
12 |
|
|
13 |
< |
#include <stdio.h> |
13 |
> |
#include "standard.h" |
14 |
|
|
15 |
|
#include "color.h" |
16 |
|
|
17 |
+ |
#include "resolu.h" |
18 |
+ |
|
19 |
+ |
int order; /* input scanline order */ |
20 |
|
int xres, yres; /* input resolution */ |
21 |
|
|
22 |
+ |
int correctorder = 0; /* order correction? */ |
23 |
+ |
|
24 |
+ |
#ifdef BIGMEM |
25 |
+ |
char buf[1<<22]; /* output buffer */ |
26 |
+ |
#else |
27 |
|
char buf[1<<20]; /* output buffer */ |
28 |
+ |
#endif |
29 |
|
|
30 |
|
int nrows; /* number of rows output at once */ |
31 |
|
|
33 |
|
|
34 |
|
char *progname; |
35 |
|
|
36 |
+ |
#define neworder() (correctorder ? order : \ |
37 |
+ |
(order^(order&YMAJOR?YDECR:XDECR)^YMAJOR)) |
38 |
|
|
39 |
+ |
|
40 |
|
main(argc, argv) |
41 |
|
int argc; |
42 |
|
char *argv[]; |
43 |
|
{ |
44 |
+ |
static char picfmt[LPICFMT+1] = PICFMT; |
45 |
+ |
int rval; |
46 |
|
FILE *fin; |
47 |
|
|
48 |
|
progname = argv[0]; |
49 |
|
|
50 |
+ |
if (argc > 2 && !strcmp(argv[1], "-c")) { |
51 |
+ |
correctorder++; |
52 |
+ |
argc--; argv++; |
53 |
+ |
} |
54 |
|
if (argc != 2 && argc != 3) { |
55 |
< |
fprintf(stderr, "Usage: %s infile [outfile]\n", progname); |
55 |
> |
fprintf(stderr, "Usage: %s [-c] infile [outfile]\n", progname); |
56 |
|
exit(1); |
57 |
|
} |
58 |
|
if ((fin = fopen(argv[1], "r")) == NULL) { |
63 |
|
fprintf(stderr, "%s: cannot open\n", argv[2]); |
64 |
|
exit(1); |
65 |
|
} |
66 |
< |
/* copy header */ |
67 |
< |
while (fgets(buf, sizeof(buf), fin) != NULL && buf[0] != '\n') |
68 |
< |
fputs(buf, stdout); |
66 |
> |
/* transfer header */ |
67 |
> |
if ((rval = checkheader(fin, picfmt, stdout)) < 0) { |
68 |
> |
fprintf(stderr, "%s: not a Radiance picture\n", progname); |
69 |
> |
exit(1); |
70 |
> |
} |
71 |
> |
if (rval) |
72 |
> |
fputformat(picfmt, stdout); |
73 |
|
/* add new header info. */ |
74 |
< |
printf("%s\n\n", progname); |
74 |
> |
printf("%s%s\n\n", progname, correctorder?" -c":""); |
75 |
|
/* get picture size */ |
76 |
< |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
76 |
> |
if ((order = fgetresolu(&xres, &yres, fin)) < 0) { |
77 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
78 |
|
exit(1); |
79 |
|
} |
80 |
|
/* write new picture size */ |
81 |
< |
fputresolu(YMAJOR|YDECR, yres, xres, stdout); |
81 |
> |
fputresolu(neworder(), 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 |
|
} |