ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pcwarp.c
Revision: 3.3
Committed: Sat Feb 22 02:07:27 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 3.2: +2 -5 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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