108 int tflag = 0, fflag = 0,
oflag = 0, dflag = 0, pflag = 0,
verbose = 0;
110 char *
fname = NULL, *out_fname = NULL;
113 "% v%- Mm%- f%-from-channels!,d t%-to-channels!,d \n\
114 \td%-delete-channels!,d p%-channel-pairs!,d o%-outfile!s infile%s\n(\
115 \tRearrange or delete channels in an image.\n\
116 \t-v\tVerbose: explain (sort of) what's happening.\n\
117 \t-m\tModify only the colormap, leave the image alone.\n\
118 \t-M\tDon't modify the colormap.\n\
119 \t-f\tComma separated list of channels to copy from. First goes to\n\
120 \t\toutput channel 0, second to output channel 1, etc. An input\n\
121 \t\tchannel can be copied to several output channels this way.\n\
122 \t\tThe alpha channel is always copied \"straight across\".\n\
123 \t-t\tList of channels to copy to. First specifies where input\n\
124 \t\tchannel 0 goes, second where input channel 1 goes, etc. It is\n\
125 \t\tan error to try to copy more than one input channel to the same\n\
126 \t\toutput. The alpha channel is always copied \"straight across\".\n\
127 \t-p\tSpecify input and output channels in pairs. The first number in\n\
128 \t\ta pair is the input channel, the second is the output channel it\n\
129 \t\twill be copied to. A given output channel should appear at most\n\
130 \t\tonce in the list. The alpha channel is copied only if it is\n\
131 \t\texplicitly specified.\n\
132 \t-d\tA list of channels to delete from the input.)";
135 int * outchan = 0, noutput = 0, outalpha = -2;
136 int *mapoutchan = 0, mapnoutput = 0, mapoutalpha = -2;
138 rle_op ** scanraw, ** outraw;
139 int * nraw, * outnraw,
y, nskip;
140 int rle_cnt, rle_err;
146 &fflag, &nspec, &specs,
147 &tflag, &nspec, &specs,
148 &dflag, &nspec, &specs,
149 &pflag, &nspec, &specs,
150 &
oflag, &out_fname, &fname ) == 0 )
154 if ( fflag + tflag + dflag + pflag != 1 )
157 "%s: You must specify exactly one of -d, -f, -t, or -p\n",
166 if ( pflag && (nspec % 2) != 0 )
168 fprintf( stderr,
"%s: You must specify pairs of channels with -p\n",
186 setup_map( fflag, tflag, dflag, pflag, specs, nspec,
188 &outchan, &noutput, &outalpha );
193 &outchan, &noutput, &outalpha );
196 if ( mflag != 2 && in_hdr.
ncmap > 0 )
197 setup_map( fflag, tflag, dflag, pflag, specs, nspec,
198 &in_hdr, in_hdr.
ncmap, 1,
"color map",
199 &mapoutchan, &mapnoutput, &mapoutalpha );
204 int cmap_different = mflag != 2 &&
205 (mflag == 1 || mapnoutput != noutput);
208 cmap_different ?
"image data " :
"" );
209 if ( cmap_different )
210 print_map( -3, mapnoutput, mapoutchan,
"color map " );
223 if ( outalpha != -2 )
233 for ( i = 0; i < noutput; i++ )
234 if ( outchan[i] != -2 )
245 "output background color" );
247 for ( i = 0; i < noutput; i++ )
248 if ( outchan[i] < 0 )
255 if ( mflag != 2 && in_hdr.
ncmap > 0 )
257 int cmaplen = 1 << out_hdr.
cmaplen;
258 int cmapshift = 16 - out_hdr.
cmaplen;
260 if ( mapnoutput > 0 )
265 "output color map" );
269 out_hdr.
ncmap = mapnoutput;
272 for ( i = 0; i < mapnoutput; i++ )
273 if ( mapoutchan[i] >= 0 && mapoutchan[i] < in_hdr.
ncmap )
275 register rle_map * imap, * omap;
277 imap = &in_hdr.
cmap[mapoutchan[
i] * cmaplen];
278 omap = &out_hdr.
cmap[i * cmaplen];
280 for ( j = 0; j < cmaplen; j++ )
287 omap = &out_hdr.
cmap[i * cmaplen];
288 for ( j = 0; j < cmaplen; j++ )
289 *omap++ = j << cmapshift;
307 free( (
char *)outraw[i] );
313 while ( (nskip =
rle_getraw( &in_hdr, scanraw, nraw )) != 32768 )
320 if ( outalpha != -2 )
322 outraw[-1] = scanraw[outalpha];
323 outnraw[-1] = nraw[outalpha];
326 for ( i = 0; i < noutput; i++ )
327 if ( outchan[i] != -2 )
329 outraw[
i] = scanraw[outchan[
i]];
330 outnraw[
i] = nraw[outchan[
i]];
343 if ( outchan != specs )
#define RLE_SET_BIT(glob, bit)
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)
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)
#define RLE_CLR_BIT(glob, bit)
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)