29 static char rcs_id[] =
"$Header: /l/spencer/src/urt/cnv/RCS/rletoalias.c,v 3.0.1.1 1992/04/30 13:58:47 spencer Exp $";
39 #define byte unsigned char
40 #define Fread(p, s, n, f) if ( fread(p, s, n, f) != n ) error(3
)
41 #define Fwrite(p, s, n, f) if ( fwrite(p, s, n, f) != n ) error(4
)
42 #define VPRINTF if (verbose) fprintf
81 static void read_rle( FILE *, bitmap_hdr *);
82 static void write_alias( FILE *, bitmap_hdr *);
83 static void error(
int );
84 static void rlecmap_to_bitmapcmap( rle_hdr *, bitmap_hdr * );
85 static void code_alias24(
byte *,
byte *,
byte *,
int, FILE * );
86 static char *Malloc(
long int );
88 static void read_rle(), write_alias(), error(), rlecmap_to_bitmapcmap();
89 static void code_alias24();
90 static char *Malloc();
117 char *outname = NULL;
119 FILE *outfile = stdout;
127 if ( !
scanargs( argc
, argv
, "% v%- o%-outfile!s infile%s",
140 read_rle(infile, &bitmap);
149 write_alias(outfile, &bitmap);
156 read_rle(handle, image)
162 byte *r, *g = 0, *b = 0;
183 offset_last = totalsize - image
->xsize;
187 VPRINTF(stderr,
"%s colormap\n",
193 VPRINTF(stderr,
"Image type ");
197 VPRINTF(stderr,
"GRAYSCALE\n");
200 VPRINTF(stderr,
"PSEUDOCOLOR\n");
202 default:
VPRINTF(stderr,
"unkown\n");
209 VPRINTF(stderr,
"DIRECTCOLOR\n");
212 VPRINTF(stderr,
"TRUECOLOR\n");
214 default:
VPRINTF(stderr,
"unkown\n");
235 r= image
->r = (
byte *) Malloc(totalsize);
236 g= image
->g = (
byte *) Malloc(totalsize);
237 b= image
->b = (
byte *) Malloc(totalsize);
240 rlecmap_to_bitmapcmap(&
the_hdr, image);
245 r= image
->r = (
byte *) Malloc(totalsize);
247 rlecmap_to_bitmapcmap(&
the_hdr, image);
256 VPRINTF(stderr,
"Uncompressing RLE file\n");
260 for (j= 0; j< image
->ysize; j++) {
275 *r++ = map[row[0][i]][0];
276 *g++ = map[row[1][i]][1];
277 *b++ = map[row[2][i]][i];
300 rlecmap_to_bitmapcmap(rle, bitmap)
317 for (i= 0; i< bitmap
->colors; i++) {
318 *ptr++ = (
byte) (*rch++ >> 8);
319 *ptr++ = (
byte) (*gch++ >> 8);
320 *ptr++ = (
byte) (*bch++ >> 8);
325 write_alias(handle, image)
331 byte *rbuf, *gbuf, *bbuf;
338 fprintf(stderr,
"Bitmap with 8 planes\n");
342 VPRINTF(stderr,
"Writing Alias file\n");
349 Fwrite(&alias,
sizeof(alias_hdr), 1, handle);
357 for (i= 0; i< image
->ysize; i++) {
362 code_alias24(rbuf, gbuf, bbuf, image
->xsize, handle);
371 code_alias24(rbuf, gbuf, bbuf, xmax, handle)
372 byte *rbuf, *gbuf, *bbuf;
377 unsigned int number= 0;
379 static byte buf[5120];
384 r= *rbuf++; g= *gbuf++; b= *bbuf++;
391 if (r== *rbuf && g== *gbuf && b== *bbuf && repeat < 255) {
393 rbuf++; gbuf++; bbuf++;
405 r= *rbuf++; g= *gbuf++; b= *bbuf++;
419 Fwrite(buf, number, 1, handle);
428 case 0: fprintf(stderr,
"Usage: %s [-v] [-o outfile] [infile] \n",
431 case 1: fprintf(stderr,
"Cannot open file.\n");
433 case 2: fprintf(stderr,
"Out of memory.\n");
435 case 3: fprintf(stderr,
"Error while reading input file\n");
437 case 4: fprintf(stderr,
"Error while writing output file\n");
439 case 5: fprintf(stderr,
"Input file is not an Alias pix\n");
441 case 6: fprintf(stderr,
"Incorrect # of planes or # of colors\n");
443 case 99: fprintf(stderr,
"Not ready\n");
445 default: fprintf(stderr,
"Unknow erro code (%d)\n", code);
455 static char *Malloc(size)
460 if ((ptr = (
char *) malloc(size)) == NULL)
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)
unsigned char color_map[3]
int rle_getrow(rle_hdr *the_hdr, scanline)
int scanargs(int argc, char **argv, const char *format,...)
#define Fwrite(p, s, n, f)
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)