27 static char rcsid[] =
"$Header: /l/spencer/src/urt/cnv/RCS/xbmtorle.c,v 3.0.1.1 1992/04/30 14:01:53 spencer Exp $";
39 static int ReadBitmapFile( FILE *,
int *,
int *,
int *,
char ** );
41 static int ReadBitmapFile();
83 int width, height, bytes;
92 "% b%-bg_color_comps%*d f%-fg_color_comps%*d o%-outfile!s infile.xbm%s\n(\
93 \tConvert an X bitmap file (NOT X window dump) to URT format.\n\
94 \t-b/-f\tSpecify color to use for background/foreground bits.\n\
95 \t\tFollowed by one or more color components. Number of\n\
96 \t\tcomponents must be the same for both -b and -f.\n\
97 \t\tDefaults are 0 and 255 respectively.)",
98 &bflag
, &nbg
, &bg
, &fflag
, &nfg
, &fg
,
99 &oflag
, &ofname
, &infname
) == 0 )
105 if ( bflag && fflag && nbg != nfg )
108 "%s: Warning: Number of background color components (%d) not the same as\n\
109 the foreground (%d), using %d\n",
110 MY_NAME, nbg, nfg, nbg < nfg ? nbg : nfg );
118 if ( bflag & !fflag && nbg > 1 )
120 fg = (
int *)malloc( nbg *
sizeof(
int) );
121 for ( nfg = 0; nfg < nbg; nfg++ )
124 if ( fflag & !bflag && nfg > 1 )
126 bg = (
int *)malloc( nfg *
sizeof(
int) );
127 for ( nbg = 0; nbg < nfg; nbg++ )
133 if ( ReadBitmapFile( xbm_file, &width, &height, &bytes, &data ) == 0 )
142 out_hdr
.xmax = width - 1;
143 out_hdr
.ymax = height - 1;
153 for ( y = 0; y < height; y++ )
157 register char *datap;
159 datap = data + (height - y - 1) * bytes;
160 for ( x = 0; x < width; x++ )
162 if ( charcount >= 8 )
168 for ( c = 0; c < nbg; c++ )
169 scans[c][x] = ( *datap & mask ) ? fg[c] : bg[c];
180 ReadBitmapFile( stream, widthP, heightP, bytesP, dataP )
182 int *widthP, *heightP, *bytesP;
187 int version10, raster_length, v;
188 register int bytes, bytes_per_line, padding;
189 register int c1, c2, value1, value2;
190 static int hex_table[256];
192 *widthP = *heightP = -1;
196 if ( fgets( line,
MAX_LINE, stream ) == NULL )
198 fprintf( stderr,
"%s: bitmap premature EOF\n",
MY_NAME);
201 if ( strlen( line ) ==
MAX_LINE - 1 )
203 fprintf( stderr,
"%s: bitmap line too long\n",
MY_NAME );
207 if ( sscanf( line,
"#define %s %d", name_and_type, &v ) == 2 )
209 if ( ! (t =
rindex( name_and_type,
'_' )) )
213 if ( ! strcmp(
"width", t ) )
215 if ( ! strcmp(
"height", t ) )
220 if ( sscanf( line,
"static short %s = {", name_and_type ) == 1 )
225 else if ( sscanf( line,
"static char %s = {", name_and_type ) == 1 )
236 fprintf( stderr,
"%s: bitmap width invalid\n",
MY_NAME );
239 if ( *heightP == -1 )
241 fprintf( stderr,
"%s: bitmap height invalid\n",
MY_NAME );
246 if ( ((*widthP % 16) >= 1) && ((*widthP % 16) <= 8) && version10 )
249 bytes_per_line = (*widthP+7)/8 + padding;
250 *bytesP = bytes_per_line;
252 raster_length = bytes_per_line * *heightP;
253 *dataP = (
char *) malloc( raster_length );
254 if ( *dataP == (
char *) 0 )
256 fprintf( stderr,
"%s: out of memory\n",
MY_NAME );
261 for ( c1 = 0; c1 < 256; c1++ )
287 for ( bytes = 0, ptr = *dataP; bytes < raster_length; bytes += 2 )
289 while ( ( c1 = getc( stream ) ) !=
'x' )
295 if ( c1 == EOF || c2 == EOF )
297 value1 = ( hex_table[c1] << 4 ) + hex_table[c2];
299 fprintf( stderr,
"%s: bitmap syntax error\n",
MY_NAME );
302 if ( c1 == EOF || c2 == EOF )
304 value2 = ( hex_table[c1] << 4 ) + hex_table[c2];
306 fprintf( stderr,
"%s: bitmap syntax error\n",
MY_NAME );
308 if ( ( ! padding ) || ( ( bytes + 2 ) % bytes_per_line ) )
312 for ( bytes = 0, ptr = *dataP; bytes < raster_length; bytes++ )
314 while ( ( c1 = getc( stream ) ) !=
'x' )
319 if ( c1 == EOF || c2 == EOF )
321 value1 = ( hex_table[c1] << 4 ) + hex_table[c2];
323 fprintf( stderr,
"%s: bitmap syntax error\n",
MY_NAME );
330 fprintf( stderr,
"%s: bitmap premature EOF\n",
MY_NAME );
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
char * cmd_name(char **argv)
void main(int argc, char **argv)
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
int scanargs(int argc, char **argv, const char *format,...)
void rle_puteof(rle_hdr *the_hdr)
void rle_putrow(rows, int rowlen, rle_hdr *the_hdr)
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
void rle_put_setup(rle_hdr *the_hdr)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)