51 char *
infname = NULL, * outfname = NULL;
60 int *sortindex, *isort;
65 if (
scanargs( argc, argv,
"% o%-outfile!s infile%s",
66 &oflag, &outfname, &infname ) == 0 )
86 nrow = in_hdr.
xmax - in_hdr.
xmin + 1;
88 if ( in_hdr.
ncmap > 0 )
96 for ( c = 0; c < in_hdr.
ncmap; c++ )
103 for ( c = 0; c < in_hdr.
ncmap; c++ )
104 scmap[c] = &mapp[c * cmaplen];
107 if ( (map_cmt =
rle_getcom(
"color_map_length", &in_hdr )) &&
108 atoi( map_cmt ) > 0 )
109 cmaplen = atoi( map_cmt );
117 sortindex = (
int *)
malloc(
sizeof(
int) * cmaplen );
121 for ( i = 0; i < cmaplen; i++ )
126 qsort( sortindex, cmaplen,
sizeof(
int),
pcompar );
129 isort = (
int *)
malloc(
sizeof(
int) * cmaplen );
131 for ( i = 0; i < cmaplen; i++ )
132 isort[sortindex[i]] = i;
136 for ( i = 1, j = 0; i < cmaplen; i++ )
140 xi1 = sortindex[i-1];
142 for ( c = 0; c <
ncolor; c++ )
149 sortindex[j] = sortindex[
i];
155 for ( i = 0; i < cmaplen; i++ )
157 int xi = sortindex[
i];
159 for ( c = 0; c <
ncolor; c++ )
160 scmap[c][i] =
cmap[c][xi];
165 if ( cmaplen < (1 << out_hdr.
cmaplen ) )
169 sprintf( buf,
"color_map_length=%d", cmaplen );
179 for ( i = 0; i < out_hdr.
ncolors; i++ )
187 while ( (nskip =
rle_getraw( &in_hdr, scan, nraw )) != 32768 )
195 for ( c = 0; c < in_hdr.
ncolors; c++ )
196 if ( c < in_hdr.
ncmap )
197 for ( i = 0; i < nraw[c]; i++ )
198 switch( scan[c][i].opcode )
206 for ( j = 0; j < scan[c][
i].
length;
219 if ( in_hdr.
ncmap > 0 )
void rle_skiprow(rle_hdr *the_hdr, int nrow)
int scanargs(int argc, char **argv, const char *format,...)
void rle_freeraw(rle_hdr *the_hdr, scanraw, nraw)
char * rle_getcom(const char *name, rle_hdr *the_hdr)
const char * rle_putcom(const char *value, rle_hdr *the_hdr)
#define map_pixel(pix, cmaplen, cmap)
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
void rle_puteof(rle_hdr *the_hdr)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
int rle_get_setup(rle_hdr *the_hdr)
int rle_get_error(int code, const char *pgmname, const char *fname)
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
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)
unsigned int rle_getraw(rle_hdr *the_hdr, scanraw, nraw)
#define RLE_CHECK_ALLOC(pgm, ptr, name)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)