15 #define map_pixel( pix, cmaplen, cmap ) ((pix) > cmaplen ? (pix) :
51 char * infname = NULL, * outfname = NULL;
52 FILE *outfile = stdout;
53 int oflag = 0, y, nskip, nrow;
55 rle_hdr in_hdr, out_hdr;
56 rle_op ** scan, ** outscan;
60 int *sortindex, *isort;
66 &oflag
, &outfname
, &infname
) == 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++ )
143 if ( cmap[c][xi] != cmap[c][xi1] )
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++ )
195 for ( c = 0; c < in_hdr
.ncolors; c++ )
197 for ( i = 0; i < nraw[c]; i++ )
201 scan[c][i].u.run_val =
206 for ( j = 0; j < scan[c][i]
.length;
208 scan[c][i].u.pixels[j] =
259 int a = *ap, b = *bp;
260 unsigned long int ai, bi;
265 case 4: c[3] =
cmap[3][a] >> 8;
266 case 3: c[2] =
cmap[2][a] >> 8;
267 case 2: c[1] =
cmap[1][a] >> 8;
268 case 1: c[0] =
cmap[0][a] >> 8;
274 case 4: c[3] =
cmap[3][b] >> 8;
275 case 3: c[2] =
cmap[2][b] >> 8;
276 case 2: c[1] =
cmap[1][b] >> 8;
277 case 1: c[0] =
cmap[0][b] >> 8;
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
void rle_freeraw(rle_hdr *the_hdr, scanraw, nraw)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
int rle_raw_alloc(rle_hdr *the_hdr, rle_op ***scanp, int **nrawp)
char * cmd_name(char **argv)
void main(int argc, char **argv)
int rle_get_setup(rle_hdr *the_hdr)
void hilbert_c2i(int n, int m, a, long int *r)
void rle_putraw(rle_op **scanraw, int *nraw, rle_hdr *the_hdr)
int rle_get_error(int code, const char *pgmname, const char *fname)
int scanargs(int argc, char **argv, const char *format,...)
void rle_puteof(rle_hdr *the_hdr)
int pcompar(int *ap, int *bp)
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
void rle_skiprow(rle_hdr *the_hdr, int nrow)
char * rle_getcom(char *name, rle_hdr *the_hdr) const
void rle_put_setup(rle_hdr *the_hdr)
#define map_pixel(pix, cmaplen, cmap)
const char * rle_putcom(char *value, rle_hdr *the_hdr) const
void rle_raw_free(rle_hdr *the_hdr, rle_op **scanp, nrawp)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
unsigned int rle_getraw(rle_hdr *the_hdr, scanraw, nraw)
#define RLE_CHECK_ALLOC(pgm, ptr, name)