172 rle_pixel *img_red, *img_green, *img_blue;
184 "% b%-bits!d c%- d%- f%- i%-cubeside!d m%- n%-colors!d r%-rlemap!s o%-outfile!s infile%s",
185 &bflag, &bits, &cflag, &dflag, &fflag,
187 &mflag, &nflag, &colors_in,
189 &oflag, &outfname, &infname ) == 0 )
193 if ( cubeside <= 1 || cubeside > 6 )
196 "%s: Cubeside (%d given) must be be >= 2 and <= 6.\n",
198 fprintf( stderr,
"%s: Cubeside set to 0.",
MY_NAME );
202 cubesize = cubeside * cubeside * cubeside;
213 if ( (map_comment =
rle_getcom(
"color_map_length", &map_hdr )) )
214 mapsize = atoi( map_comment );
217 mapsize = 1 << map_hdr.
cmaplen;
220 inputmap =
buildmap( &map_hdr, 3, 1.0, 1.0 );
224 if ( bits <= 0 || bits > 8 )
226 fprintf( stderr,
"%s: The bits argument must be >0 and <= 8.\n",
234 colors_in = 256 - mapsize - cubesize;
240 if ( colors_in + mapsize + cubesize <= 0 ||
241 colors_in + mapsize + cubesize > 256 )
244 "%s: colors + cubeside^3 + rlemap size (%d + %d + %d = %d ) \n\
245 \tmust be >0 and <= 256.\n",
246 MY_NAME, colors_in, cubesize, mapsize,
247 colors_in + cubesize + mapsize );
252 if ( mapsize > 0 || cubesize > 0 )
265 if ( mflag && (!cflag) && ftell( in_hdr.
rle_file ) < 0 )
268 "%s: Piped input with -m, colors will be chosen from first image only.\n",
291 if ( colors_in == 0 )
293 else if ( mflag > 0 )
325 "%s: Input image %d has only %d color%s, faking the other %d.\n",
327 in_hdr.
ncolors == 1 ?
"" :
"s",
340 copy_hdr( argv, &in_hdr, &out_hdr, outfile, cflag );
342 width = in_hdr.
xmax + 1;
343 height = in_hdr.
ymax - in_hdr.
ymin + 1;
349 mem_alloc( &in_hdr, entries, dflag, &rows,
350 &red, &green, &blue, &alpha,
351 &img_red, &img_green, &img_blue );
354 if ( !(cflag && state ==
OUTPUT) )
356 red, green, blue, alpha,
357 img_red, img_green, img_blue, rows );
361 colors =
colorquant( red, green, blue, entries,
362 colormap, colors_in, bits,
363 rgbmap, fflag, state );
374 for ( i = 0; i < mapsize; i++, colors++ )
376 colormap[0][colors] = inputmap[0][
i];
377 colormap[1][colors] = inputmap[1][
i];
378 colormap[2][colors] = inputmap[2][
i];
382 add_cube( colormap, colors, cubeside );
386 if ( mapsize + cubesize > 0 )
388 unsigned long *dist_buf;
392 (1L << (3*bits)) *
sizeof(
long),
394 inv_cmap( colors, colormap, bits, dist_buf, rgbmap );
412 red, green, blue, alpha,
413 img_red, img_green, img_blue, rgbmap, colormap,
418 if (mflag < 0 && state ==
NORMAL)
423 free_mem( &in_hdr, dflag, red, green, blue, alpha,
424 img_red, img_green, img_blue, rows, outrows );
440 colormap, colors_in, bits,
449 for ( i = 0; i < mapsize; i++, colors++ )
451 colormap[colors][0] = inputmap[
i][0];
452 colormap[colors][1] = inputmap[
i][1];
453 colormap[colors][2] = inputmap[
i][2];
458 add_cube( colormap, colors, cubeside );
int scanargs(int argc, char **argv, const char *format,...)
static unsigned char blue[256]
char * rle_getcom(const char *name, rle_hdr *the_hdr)
static const char * MY_NAME
static void setup_output()
static void write_output()
void rle_puteof(rle_hdr *the_hdr)
void inv_cmap(int colors, unsigned char *colormap[3], int bits, unsigned long *dist_buf, unsigned char *rgbmap)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
int rle_get_setup(rle_hdr *the_hdr)
static unsigned char green[256]
int rle_get_error(int code, const char *pgmname, const char *fname)
#define CHECK_MALLOC(type, ptr, size, desc)
rle_pixel ** buildmap(rle_hdr *the_hdr, int minmap, double orig_gamma, double new_gamma)
int colorquant(rle_pixel *red, rle_pixel *green, rle_pixel *blue, unsigned long pixels, rle_pixel *colormap[3], int colors, int bits, rle_pixel *rgbmap, int fast, int otherimages)
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
char * cmd_name(char **argv)
static unsigned char red[256]
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)