44 #define duff(counter, block) {
45 while (counter >= 4
) {
52 switch (counter & 3
) {
62 if (fwrite( outrows, 1
, fwrite_len, outfile ) != fwrite_len) {
63 perror( "write error" );
74 char *nullbytes = NULL;
75 char *infname = NULL, *outfname = NULL, *progname;
76 FILE *infile, *outfile;
79 int fflag = 0, tflag = 0, Nflag = 0, rflag = 0;
80 int header = 0, trailer = 0;
81 int pflag= 0, right_pad = 0, lflag = 0, left_pad = 0;
82 int aflag = 0, output_alpha = 0, sflag = 0;
84 int height, width, nochan;
85 int red_pos, alpha_pos, green_pos = 0, blue_pos = 0;
89 unsigned char *outrows;
95 unsigned char *fwrite_pos;
100 "% Ns%- r%- a%- f%-header-size!d t%-trailer-size!d \n\
101 \t\tp%-scanline-pad!d l%-left-scanline-pad!d o%-outfile!s \n\
103 \t-a\tDon't strip the alpha channel from the rle file.\n\
104 \t-f,-t\tEach output image is preceded (followed) by so many bytes.\n\
105 \t-l,-p\tScanlines are padded on left (right) end with so many bytes.\n\
106 \t\tAll padding is with null (0) bytes.\n\
107 \t-s\tOutput data in scanline interleaved order\n\
108 \t-N\tOutput data in non-interleaved order (eg. | split -Wid*Height -)\n\
109 \t-r\treverse the channel order (e.g. write data as ABGR instead of\n\
110 \t\tthe default RGBA order).)",
111 &Nflag
, &rflag
, &aflag
, &fflag
, &header
,
112 &tflag
, &trailer
, &pflag
, &right_pad
, &lflag
, &left_pad
,
113 &oflag
, &outfname
, &infname
) == 0)
152 fprintf(stderr,
"width %d, height %d, channels %d\n", width, height, nochan);
160 outrows_size = width * (nochan + output_alpha);
162 outrows_size *= height;
163 if ((outrows = (
unsigned char *) malloc ( outrows_size )) == NULL ) {
164 fprintf(stderr,
"%s: No memory available for rows malloc\n", progname);
168 img_size = width * height;
175 fprintf(stderr,
"%s: No memory available for rle_row_alloc\n", progname);
180 if (fflag || tflag) {
181 nullbytes = (
char *) malloc ( (header > trailer) ? header : trailer );
183 fprintf(stderr,
"%s: No memory for nullbytes\n", progname);
185 for( i = (header > trailer) ? header : trailer; i > 0; )
194 red_pos = 2 + output_alpha;
195 green_pos = 1 + output_alpha;
196 blue_pos = 0 + output_alpha;
198 red_pos = 0 + output_alpha;
211 green_pos *= img_size;
212 blue_pos *= img_size;
213 alpha_pos *= img_size;
214 }
else if ( sflag ) {
223 fwrite_len = outrows_size;
224 fwrite_pos = outrows;
228 fwrite( nullbytes, 1, header, outfile );
232 register int stride = nochan + output_alpha, count;
245 bcopy(inrows[
RLE_ALPHA], outrows + alpha_pos + line_pos,width);
247 bcopy(inrows[
RLE_RED], outrows + red_pos + line_pos, width);
250 bcopy(inrows[
RLE_GREEN], outrows + green_pos + line_pos,width);
251 bcopy(inrows[
RLE_BLUE], outrows + blue_pos + line_pos,width);
257 bcopy (inrows[
RLE_ALPHA], outrows + alpha_pos, width);
259 bcopy (inrows[
RLE_RED], outrows + red_pos, width);
262 bcopy(inrows[
RLE_GREEN], outrows + green_pos, width);
263 bcopy(inrows[
RLE_BLUE], outrows + blue_pos, width);
268 #define COPY_LINE() duff(count, *o = *p++; o += stride);
271 if ( output_alpha ) {
272 o = outrows + alpha_pos;
278 o = outrows + red_pos;
284 o = outrows + green_pos;
289 o = outrows + blue_pos;
297 for (count = 0; count < left_pad; count++)
305 for (count = 0; count < right_pad; count++)
314 fwrite( nullbytes, 1, trailer, outfile );
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
char * cmd_name(char **argv)
void main(int argc, char **argv)
int rle_get_setup(rle_hdr *the_hdr)
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
int rle_getrow(rle_hdr *the_hdr, scanline)
int rle_get_error(int code, const char *pgmname, const char *fname)
int scanargs(int argc, char **argv, const char *format,...)
#define duff(counter, block)
#define RLE_CLR_BIT(glob, bit)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
#define RLE_BIT(glob, bit)