30 int alpha_flag = 0,
oflag = 0;
40 int rle_cnt, rle_err, stdin_used = -1;
42 if (!
scanargs( argc, argv,
"% a%- o%-outfile!s files%*s",
43 &alpha_flag, &
oflag, &out_fname, &nfiles, &filenames ))
47 if (alpha_flag) alpha_flag = 1;
55 in_counts = (
int **)
malloc(
sizeof(
int * ) * nfiles );
57 skips = (
int *)
malloc(
sizeof(
int ) * nfiles );
62 out_count = (
int *)
malloc(
sizeof(
int ) * nfiles );
67 for (i = 0; i < nfiles; i++)
72 if ( in_hdr[i].rle_file == stdin )
75 filenames[
i] =
"Standard Input";
81 "Images %d and %d are both from the standard input\n",
87 rle_names( &out_hdr, in_hdr[0].cmd, out_fname, 0 );
92 for ( rle_cnt = 0; ; rle_cnt++ )
94 for (i = 0; i < nfiles; i++)
101 if ( rle_cnt == 0 || (rle_err !=
RLE_EOF &&
112 if (((in_hdr[i].ncolors-1) < (i-alpha_flag)) ||
113 (!
RLE_BIT( in_hdr[i], i-alpha_flag )))
115 fprintf(stderr,
"mergechan: channel %d not in file %s\n",
116 i-alpha_flag, filenames[i] );
123 if (! ((in_hdr[0].xmin == in_hdr[i].xmin) &&
124 (in_hdr[0].xmax == in_hdr[i].xmax) &&
125 (in_hdr[0].ymin == in_hdr[i].ymin) &&
126 (in_hdr[0].ymax == in_hdr[i].ymax)) )
129 "mergechan: image %s is not the same size as image %s\n",
130 filenames[i], filenames[0] );
135 if (
rle_raw_alloc( &in_hdr[i], &in_rows[i], &in_counts[i] ) < 0 )
145 outfile =
rle_open_f(
"mergechan", out_fname,
"w");
148 out_hdr.
ncolors = nfiles - alpha_flag;
149 out_hdr.
alpha = alpha_flag;
157 "output background color" );
158 for ( i = 0; i < out_hdr.
ncolors; i++ )
168 for (i = -alpha_flag; i < out_hdr.
ncolors; i++)
186 for (i = -alpha_flag; i < out_hdr.
ncolors; i++)
189 out_rows[
i] = in_rows[
i][
i];
191 y = out_hdr.
ymin - 1;
201 for (i = -alpha_flag; i < out_hdr.
ncolors; i++)
206 in_rows[i], in_counts[i] );
212 if (i == -alpha_flag)
215 minskip =
MIN( skips[i], minskip );
226 for (i = -alpha_flag; i < out_hdr.
ncolors; i++)
228 if (skips[i] !=
RLE_END) skips[
i] -= minskip;
232 out_count[
i] = in_counts[
i][
i];
242 for (i = -alpha_flag; i < out_hdr.
ncolors; i++)
246 rle_freeraw( &(in_hdr[i]), in_rows[i], in_counts[i] );
264 for ( i = 0; i < nfiles; i++ )
#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)
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)
#define RLE_BIT(glob, bit)