18 #define MIN(i,j) ( (i) < (j) ? (i) : (j) )
30 int alpha_flag = 0, oflag = 0;
36 CONST_DECL char **filenames, *out_fname = NULL, *cmd_nm;
37 FILE *outfile = stdout;
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;
49 in_hdr = (rle_hdr *) malloc(
sizeof( rle_hdr )
53 in_rows = (rle_op ***) malloc(
sizeof( rle_op ** ) * nfiles );
55 in_counts = (
int **) malloc(
sizeof(
int * ) * nfiles );
57 skips = (
int *) malloc(
sizeof(
int ) * nfiles );
60 out_rows = (rle_op **) malloc(
sizeof( rle_op * ) * nfiles );
62 out_count = (
int *) malloc(
sizeof(
int ) * nfiles );
67 for (i = 0; i < nfiles; i++)
75 filenames[i] =
"Standard Input";
81 "Images %d and %d are both from the standard input\n",
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] );
129 "mergechan: image %s is not the same size as image %s\n",
130 filenames[i], filenames[0] );
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++)
264 for ( i = 0; i < nfiles; i++ )
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
#define RLE_SET_BIT(glob, bit)
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 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)
void rle_addhist(argv, rle_hdr *in_hdr, rle_hdr *out_hdr)
void rle_skiprow(rle_hdr *the_hdr, int nrow)
void rle_put_setup(rle_hdr *the_hdr)
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)
#define RLE_BIT(glob, bit)