42 static char rcsid[] = 
"$Header: /l/spencer/src/urt/cnv/RCS/rastorle.c,v 3.0.1.6 1992/04/30 13:58:02 spencer Exp $";
 
   49 #include <rasterfile.h> 
   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 )
 
  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 )
 
  140     alfline = image + depth * npix - rashdr.ras_width;
 
  141     redline = image + npix - rashdr.ras_width;
 
  145     grnline = image + 2 * npix - rashdr.ras_width;
 
  146     bluline = image + 3 * npix - rashdr.ras_width;
 
  150     switch(rashdr.ras_maptype)
 
  154     fprintf (stderr, 
"No color map\n");
 
  156     for (i = 0; i < 256; i++)
 
  157       red[i] = green[i] = blue[i] = i ;
 
  161     fprintf (stderr, 
"Raw color map\n");
 
  163     for (i = 0; i < 256; i++)
 
  164       red[i] = green[i] = blue[i] = 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++)
 
  210         p = getbit(rasfile, 0);
 
  215         redline -= rashdr.ras_width;
 
  217         alfline -= rashdr.ras_width;
 
  234     if (rashdr.ras_depth == 8)
 
  239         rlehdr.cmap = out_map;
 
  240         for (i=0;i<(1<<8);i++)
 
  242             out_map[i+(0<<8)] = red[i] << 8;
 
  243             out_map[i+(1<<8)] = green[i] << 8;
 
  244             out_map[i+(2<<8)] = blue[i] << 8;
 
  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++)
 
  302             grnline[h] = green[g];
 
  303             bluline[h] = blue[b];
 
  307                     if (redline[h] || grnline[h] || bluline[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 ;
 
  326             grnline[h] = green[g];
 
  327             bluline[h] = blue[b];
 
  333         alfline -= rashdr.ras_width;
 
  334         redline -= rashdr.ras_width;
 
  337         grnline -= rashdr.ras_width;
 
  338         bluline -= rashdr.ras_width;
 
  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;
 
  365     rle_putrow( &outrows[1], rashdr.ras_width, &rlehdr );
 
  384     static unsigned int mask
 
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
#define RLE_SET_BIT(glob, bit)
static unsigned char * outrows[4]
static unsigned char blue[256]
void rle_names(rle_hdr *the_hdr, const  char *pgmname, const  char *fname, int img_num)
static unsigned char * grnline
static unsigned char * bluline
char * cmd_name(char **argv)
void main(int argc, char **argv)
static unsigned char * alfline
int scanargs(int argc, char **argv, const char *format,...)
void rle_puteof(rle_hdr *the_hdr)
static rle_map out_map[3 *(1<< 8)]
static unsigned char green[256]
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
#define RLE_CLR_BIT(glob, bit)
static unsigned char * redline
void rle_put_setup(rle_hdr *the_hdr)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
static unsigned char red[256]
#define RLE_CHECK_ALLOC(pgm, ptr, name)
static unsigned char * image