80 char *outfname = NULL;
82 int aflag = 0,
oflag = 0;
91 struct rasterfile rashdr;
94 if (
scanargs( argc, argv,
"% a%- o%-outfile!s infile%s\n(\
95 \tConvert a Sun Raster file to URT RLE format.\n\
96 \t-a\tFake an alpha channel: opaque when pixel non-zero.)",
97 &aflag, &
oflag, &outfname, &infname ) == 0 )
103 rasfile =
rle_open_f( rlehdr.cmd, infname,
"r" );
104 outfile =
rle_open_f( rlehdr.cmd, outfname,
"w" );
109 if(fread(&rashdr,
sizeof(rashdr), 1, rasfile) != 1)
111 fprintf(stderr,
"Can't read rasterfile header.\n");
115 if (rashdr.ras_magic != RAS_MAGIC)
117 fprintf(stderr,
"Error: \"%s\" is not a rasterfile.\n",
118 rasfile==stdin?
"stdin":argv[1]);
122 fprintf (stderr,
"rasterfile width = %d\n", rashdr.ras_width);
123 fprintf (stderr,
"rasterfile height = %d\n", rashdr.ras_height);
124 fprintf (stderr,
"rasterfile depth = %d\n", rashdr.ras_depth);
125 fprintf (stderr,
"rasterfile length = %d\n", rashdr.ras_length);
126 fprintf (stderr,
"rasterfile type = %d\n", rashdr.ras_type);
127 fprintf (stderr,
"rasterfile maplength = %d\n", rashdr.ras_maplength);
131 if ( rashdr.ras_depth == 32 )
133 depth = (rashdr.ras_depth + 7) / 8 + aflag;
134 npix = rashdr.ras_width * rashdr.ras_height;
137 if ( rashdr.ras_depth == 32 )
150 switch(rashdr.ras_maptype)
154 fprintf (stderr,
"No color map\n");
156 for (i = 0; i < 256; i++)
161 fprintf (stderr,
"Raw color map\n");
163 for (i = 0; i < 256; i++)
165 for (i = 0; i < rashdr.ras_maplength; i++)
170 fprintf (stderr,
"RGB color map\n");
173 for (i = 0; i < rashdr.ras_maplength/3; i++)
174 red[i] = getc(rasfile);
176 for (i = 0; i < rashdr.ras_maplength/3; i++)
177 green[i] = getc(rasfile);
179 for (i = 0; i < rashdr.ras_maplength/3; i++)
180 blue[i] = getc(rasfile);
183 fprintf (stderr,
"Unknown color map type (%d)\n", rashdr.ras_maptype);
188 switch(rashdr.ras_depth)
192 "Sorry, I can't deal with a rasterfile depth %d\n",rashdr.ras_depth);
206 for (i=0; i<rashdr.ras_height; i++)
208 for(h = 0; h < rashdr.ras_width; h++)
234 if (rashdr.ras_depth == 8)
240 for (i=0;i<(1<<8);i++)
248 if (rashdr.ras_type == RT_BYTE_ENCODED)
250 for (i=0; i<rashdr.ras_height; i++)
253 switch(rashdr.ras_depth)
256 for (h=0; h < rashdr.ras_width; h++)
258 if (rashdr.ras_type != RT_BYTE_ENCODED)
267 count = getc(rasfile);
291 if (rashdr.ras_width & 1) p = getc(rasfile);
295 for (h=0; h < rashdr.ras_width; h++)
314 if (rashdr.ras_width & 1) p = getc(rasfile);
318 for (h=0; h < rashdr.ras_width; h++)
320 register int r,
g,
b,a ;
346 rlehdr.xmax = rashdr.ras_width-1;
347 rlehdr.ymax = rashdr.ras_height-1;
361 for ( i = 0; i <= rlehdr.xmax; i++ )
363 for ( h = 1 - aflag; h <
depth + 1 - aflag; h++ )
364 outrows[h] += rashdr.ras_width;
#define RLE_SET_BIT(glob, bit)
int scanargs(int argc, char **argv, const char *format,...)
static unsigned char * outrows[4]
static unsigned char blue[256]
static unsigned char * grnline
static unsigned char * bluline
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
void rle_puteof(rle_hdr *the_hdr)
static unsigned char * alfline
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
static rle_map out_map[3 *(1<< 8)]
static unsigned char green[256]
#define RLE_CLR_BIT(glob, bit)
static unsigned char * redline
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
void rle_put_setup(rle_hdr *the_hdr)
char * cmd_name(char **argv)
static unsigned char red[256]
#define RLE_CHECK_ALLOC(pgm, ptr, name)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
static unsigned char * image