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 |
|
* |
14 |
|
|
15 |
|
#include "color.h" |
16 |
|
|
17 |
+ |
#include "resolu.h" |
18 |
+ |
|
19 |
+ |
int order; /* input scanline order */ |
20 |
|
int xres, yres; /* input resolution */ |
17 |
– |
double inpaspect = 1.0; /* input aspect ratio */ |
21 |
|
|
22 |
+ |
int correctorder = 0; /* order correction? */ |
23 |
+ |
|
24 |
|
char buf[1<<20]; /* output buffer */ |
25 |
|
|
26 |
|
int nrows; /* number of rows output at once */ |
29 |
|
|
30 |
|
char *progname; |
31 |
|
|
32 |
+ |
#define neworder() (correctorder ? order : \ |
33 |
+ |
(order^(order&YMAJOR?YDECR:XDECR)^YMAJOR)) |
34 |
|
|
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 |
– |
|
36 |
|
main(argc, argv) |
37 |
|
int argc; |
38 |
|
char *argv[]; |
41 |
|
|
42 |
|
progname = argv[0]; |
43 |
|
|
44 |
+ |
if (argc > 2 && !strcmp(argv[1], "-c")) { |
45 |
+ |
correctorder++; |
46 |
+ |
argc--; argv++; |
47 |
+ |
} |
48 |
|
if (argc != 2 && argc != 3) { |
49 |
< |
fprintf(stderr, "Usage: %s infile [outfile]\n", progname); |
49 |
> |
fprintf(stderr, "Usage: %s [-c] infile [outfile]\n", progname); |
50 |
|
exit(1); |
51 |
|
} |
52 |
|
if ((fin = fopen(argv[1], "r")) == NULL) { |
58 |
|
exit(1); |
59 |
|
} |
60 |
|
/* transfer header */ |
61 |
< |
getheader(fin, headline); |
61 |
> |
if (checkheader(fin, COLRFMT, stdout) < 0) { |
62 |
> |
fprintf(stderr, "%s: not a Radiance picture\n", progname); |
63 |
> |
exit(1); |
64 |
> |
} |
65 |
|
/* add new header info. */ |
60 |
– |
if (inpaspect < .99 || inpaspect > 1.01) |
61 |
– |
fputaspect(1./inpaspect/inpaspect, stdout); |
66 |
|
printf("%s\n\n", progname); |
67 |
|
/* get picture size */ |
68 |
< |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
68 |
> |
if ((order = fgetresolu(&xres, &yres, fin)) < 0) { |
69 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
70 |
|
exit(1); |
71 |
|
} |
72 |
|
/* write new picture size */ |
73 |
< |
fputresolu(YMAJOR|YDECR, yres, xres, stdout); |
73 |
> |
fputresolu(neworder(), yres, xres, stdout); |
74 |
|
/* compute buffer capacity */ |
75 |
|
nrows = sizeof(buf)/sizeof(COLR)/yres; |
76 |
|
rotate(fin); /* rotate the image */ |