ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pcwarp.c
Revision: 3.1
Committed: Wed Feb 5 17:29:25 1997 UTC (27 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

# Content
1 /* Copyright (c) 1997 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * Warp colors in Radiance picture to correct for input/output changes.
9 */
10
11 #include <stdio.h>
12 #include "color.h"
13 #include "warp3d.h"
14
15 char *progname; /* global argv[0] */
16
17 FILE *infp = stdin; /* input stream */
18 int xres, yres; /* input picture resolution */
19
20 WARP3D *cwarp; /* our warp map */
21 int iclip = CGAMUT_UPPER; /* input value gamut clipping */
22 int oclip = CGAMUT_LOWER; /* output value gamut clipping */
23
24
25 main(argc, argv)
26 int argc;
27 char *argv[];
28 {
29 static char picfmt[LPICFMT+1] = PICFMT;
30 int cwflags = 0;
31 int rval;
32 int i;
33
34 progname = argv[0];
35 /* get options */
36 for (i = 1; i < argc && argv[i][0] == '-'; i++)
37 switch (argv[i][1]) {
38 case 'e':
39 cwflags = W3EXACT;
40 break;
41 case 'f':
42 cwflags = W3FAST;
43 break;
44 case 'i':
45 iclip = 0;
46 break;
47 case 'o':
48 oclip = CGAMUT;
49 break;
50 default:
51 goto userr;
52 }
53 /* load warp map */
54 if (i >= argc)
55 goto userr;
56 if ((cwarp = load3dw(argv[i++], NULL)) == NULL)
57 syserror("load3dw");
58 set3dwfl(cwarp, cwflags);
59 /* open input and output pictures */
60 if (i < argc && (infp = fopen(argv[i], "r")) == NULL)
61 syserror(argv[i]);
62 if (i < argc-1 && freopen(argv[i+1], "w", stdout) == NULL)
63 syserror(argv[i+1]);
64 /* transfer header */
65 if ((rval = checkheader(infp, picfmt, stdout)) < 0) {
66 fprintf(stderr, "%s: input not a Radiance picture\n",
67 progname);
68 exit(1);
69 }
70 if (rval)
71 fputformat(picfmt, stdout);
72 /* add new header info. */
73 printargs(i, argv, stdout);
74 putchar('\n');
75 /* get picture size */
76 if ((rval = fgetresolu(&xres, &yres, infp)) < 0) {
77 fprintf(stderr, "%s: bad picture size\n", progname);
78 exit(1);
79 }
80 /* new picture size the same */
81 fputresolu(rval, xres, yres, stdout);
82 /* warp those colors! */
83 picwarp();
84 exit(0);
85 userr:
86 fprintf(stderr,
87 "Usage: %s [-i][-o][-e|-f] map.cwp [input.pic [output.pic]]\n",
88 progname);
89 exit(1);
90 }
91
92
93 syserror(s) /* print system error and exit */
94 char *s;
95 {
96 fprintf(stderr, "%s: ", progname);
97 perror(s);
98 exit(2);
99 }
100
101
102 picwarp() /* warp our picture scanlines */
103 {
104 register COLOR *scan;
105 long ngamut = 0;
106 int rval;
107 int y;
108 register int x;
109
110 scan = (COLOR *)malloc(xres*sizeof(COLOR));
111 if (scan == NULL)
112 syserror("picwarp");
113 for (y = 0; y < yres; y++) {
114 if (freadscan(scan, xres, infp) < 0) {
115 fprintf(stderr, "%s: error reading input picture\n",
116 progname);
117 exit(1);
118 }
119 for (x = 0; x < xres; x++) {
120 if (iclip)
121 clipgamut(scan[x], bright(scan[x]), iclip,
122 cblack, cwhite);
123 rval = warp3d(scan[x], scan[x], cwarp);
124 if (rval & W3ERROR)
125 syserror("warp3d");
126 if (rval & W3BADMAP) {
127 fprintf(stderr, "%s: singular color mapping\n",
128 progname);
129 exit(1);
130 }
131 if (rval & W3GAMUT)
132 ngamut++;
133 if (oclip)
134 clipgamut(scan[x], bright(scan[x]), oclip,
135 cblack, cwhite);
136 }
137 if (fwritescan(scan, xres, stdout) < 0) {
138 fprintf(stderr, "%s: error writing output picture\n",
139 progname);
140 exit(1);
141 }
142 }
143 if (ngamut >= (long)xres*yres/100)
144 fprintf(stderr, "%s: warning - %d%% of pixels out of gamut\n",
145 progname, 100*ngamut/((long)xres*yres));
146 free((char *)scan);
147 }