ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/meta2bmp.c
Revision: 1.1
Committed: Wed May 4 23:43:19 2005 UTC (18 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1
Log Message:
Created meta2bmp file to generate BMP output from metafile graphics

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
3 #endif
4 /*
5 * Program to convert meta-files to BMP 8-bit color-mapped format
6 */
7
8 #include "copyright.h"
9
10 #include "rtprocess.h"
11 #include "meta.h"
12 #include "plot.h"
13 #include "rast.h"
14 #include "bmpfile.h"
15
16 #define MAXALLOC 30000
17 #define DXSIZE 400 /* default x resolution */
18 #define DYSIZE 400 /* default y resolution */
19 #define XCOM "pexpand +vOCImsp -DP %s | psort +y"
20
21
22 char *progname;
23
24 SCANBLOCK outblock;
25
26 int dxsize = DXSIZE, dysize = DYSIZE;
27
28 int maxalloc = MAXALLOC;
29
30 int ydown = 0;
31
32 static char outname[64];
33 static char *outtack = NULL;
34
35 static BMPWriter *bmpw = NULL;
36
37 static int lineno = 0;
38
39 static short condonly = FALSE,
40 conditioned = FALSE;
41
42 static int putthead(struct hdStruct *hp, char *ip, FILE *fp);
43
44
45
46 char *
47 findtack(s) /* find place to tack on suffix */
48 register char *s;
49 {
50 while (*s && *s != '.')
51 s++;
52 return(s);
53 }
54
55
56 int
57 main(
58 int argc,
59 char **argv
60 )
61
62 {
63 FILE *fp;
64 char comargs[200], command[300];
65
66 progname = *argv++;
67 argc--;
68
69 condonly = FALSE;
70 conditioned = FALSE;
71
72 while (argc && **argv == '-') {
73 switch (*(*argv+1)) {
74 case 'c':
75 condonly = TRUE;
76 break;
77 case 'r':
78 conditioned = TRUE;
79 break;
80 case 'm':
81 minwidth = atoi(*++argv);
82 argc--;
83 break;
84 case 'x':
85 dxsize = atoi(*++argv);
86 argc--;
87 break;
88 case 'y':
89 dysize = atoi(*++argv);
90 argc--;
91 break;
92 case 'o':
93 strcpy(outname, *++argv);
94 outtack = findtack(outname);
95 argc--;
96 break;
97 default:
98 error(WARNING, "unknown option");
99 break;
100 }
101 argv++;
102 argc--;
103 }
104
105 if (conditioned) {
106 if (argc)
107 while (argc) {
108 fp = efopen(*argv, "r");
109 plot(fp);
110 fclose(fp);
111 argv++;
112 argc--;
113 }
114 else
115 plot(stdin);
116 if (lineno)
117 nextpage();
118 } else {
119 comargs[0] = '\0';
120 while (argc) {
121 strcat(comargs, " ");
122 strcat(comargs, *argv);
123 argv++;
124 argc--;
125 }
126 sprintf(command, XCOM, comargs);
127 if (condonly)
128 return(system(command));
129 else {
130 if ((fp = popen(command, "r")) == NULL)
131 error(SYSTEM, "cannot execute input filter");
132 plot(fp);
133 pclose(fp);
134 if (lineno)
135 nextpage();
136 }
137 }
138
139 return(0);
140 }
141
142
143
144 void
145 thispage(void) /* rewind current file */
146 {
147 if (lineno)
148 error(USER, "cannot restart page in thispage");
149 }
150
151
152 void
153 initfile(void) /* initialize this file */
154 {
155 /*
156 static unsigned char cmap[24] = {255,255,255, 255,152,0, 0,188,0, 0,0,255,
157 179,179,0, 255,0,255, 0,200,200, 0,0,0};
158 */
159 static const unsigned char cmap[8][3] = {0,0,0, 0,0,255, 0,188,0, 255,152,0,
160 0,200,200, 255,0,255, 179,179,0, 255,255,255};
161 static int filenum = 0;
162 BMPHeader *hp;
163 register int i;
164
165 hp = BMPmappedHeader(dxsize, dysize, 0, 256);
166 hp->compr = BI_RLE8;
167 if (hp == NULL)
168 error(USER, "Illegal image parameter(s)");
169 for (i = 0; i < 8; i++) {
170 hp->palette[i].r = cmap[i][2];
171 hp->palette[i].g = cmap[i][1];
172 hp->palette[i].b = cmap[i][0];
173 }
174 hp->impColors = 8;
175 if (outtack != NULL) {
176 sprintf(outtack, "%d.bmp", ++filenum);
177 bmpw = BMPopenOutputFile(outname, hp);
178 } else {
179 bmpw = BMPopenOutputStream(stdout, hp);
180 }
181 if (bmpw == NULL)
182 error(USER, "Cannot create output");
183 }
184
185
186
187 void
188 nextpage(void) /* advance to next page */
189
190 {
191
192 if (lineno == 0)
193 return;
194 if (bmpw != NULL) {
195 while (lineno < dysize) {
196 nextblock();
197 outputblock();
198 }
199 BMPcloseOutput(bmpw);
200 bmpw = NULL;
201 }
202 lineno = 0;
203
204 }
205
206
207
208 #define MINRUN 4
209
210 extern void
211 printblock(void) /* output scanline block to file */
212
213 {
214 int i, c2;
215 register unsigned char *scanline;
216 register int j, beg, cnt = 0;
217
218 if (lineno == 0)
219 initfile();
220 for (i = outblock.ybot; i <= outblock.ytop && i < dysize; i++) {
221 scanline = outblock.cols[i-outblock.ybot] + outblock.xleft;
222 memcpy((void *)bmpw->scanline, (void *)scanline,
223 sizeof(uint8)*(outblock.xright-outblock.xleft+1));
224 if (BMPwriteScanline(bmpw) != BIR_OK)
225 error(SYSTEM, "Error writing BMP file");
226 lineno++;
227 }
228
229 }