75 char *header_bytes = NULL, *trailer_bytes = NULL;
76 char *
infname = NULL, *outfname = NULL;
79 int oflag = 0, wflag = 0, hflag = 0, nflag = 0;
80 int fflag = 0, tflag = 0, Nsflag = 0, rflag = 0;
81 #define Nflag (Nsflag & 2)
82 #define sflag (Nsflag & 1)
83 int header = 0, trailer = 0, alpha_value = 255;
84 int pflag= 0, right_pad = 0, lflag = 0, left_pad = 0;
85 int aflag = 0, input_alpha = 0;
87 int red_pos, alpha_pos, green_pos = 0, blue_pos = 0;
92 unsigned char *inrows;
96 "% Ns%- r%- w%-width!d h%-height!d f%-header-size!d \n\
97 \t\tt%-trailer-size!d n%-nchannels!d a%-alpha-value%d \n\
98 \t\tp%-scanline-pad!d l%-left-scanline-pad!d o%-outfile!s \n\
100 \t-a\tAdd an alpha channel to the rle file with given value.\n\
101 \t-f,-t\tEach input image is preceded (followed) by so many bytes.\n\
102 \t-l,-p\tScanlines are padded on left (right) end with so many bytes.\n\
103 \t-n\tNumber of channels in the input. If 2 or 4, presence of\n\
104 \t\talpha channel is assumed.\n\
105 \t-N\tinput is in non-interleaved order (e.g.\n\
106 \t\tcat pic.r pic.g pic.b | rawtorle)\n\
107 \t-r\treverse the channel order (e.g. read data as ABGR instead of\n\
108 \t\tthe default RGBA order)\n\
109 \t-s\tInput data is in scanline interleaved order.)",
110 &Nsflag, &rflag, &wflag, &
width, &hflag, &height,
111 &fflag, &header, &tflag, &trailer, &nflag, &nochan,
112 &aflag, &alpha_value,
113 &pflag, &right_pad, &lflag, &left_pad,
114 &oflag, &outfname, &infname ) == 0)
122 if (
width <= 0 || height <= 0 ) {
123 fprintf(stderr,
"%s: Invalid width or height arg (%d,%d)\n",
128 if ( 0 > nochan || nochan > 4 ) {
129 fprintf(stderr,
"%s: Invalid number of channels %d\n",
135 if ( nochan == 2 || nochan == 4 )
139 if (
Nflag && nochan == 1 )
142 if (
Nflag && (lflag || pflag))
144 "%s: -N with -l or -p is not supported, padding ignored.\n",
152 inrows_size =
Nflag ?
width * (height + 1) * (nochan - 1) : width * nochan;
154 if ((inrows = (
unsigned char *)
malloc ( inrows_size )) == NULL) {
155 fprintf(stderr,
"%s: No memory available for inrows malloc\n",
161 inrows_size = width * height * (nochan - 1) + width;
163 img_size = width *
height;
178 if ( aflag || input_alpha )
186 header_bytes = (
char *)
malloc ( header );
188 trailer_bytes = (
char *)
malloc ( trailer );
191 fprintf(stderr,
"%s: No memory available for rle_row_alloc\n",
197 if ( aflag && !input_alpha )
198 for (i = 0; i <
width; i++)
206 red_pos = 2 + input_alpha;
207 green_pos = 1 + input_alpha;
208 blue_pos = 0 + input_alpha;
210 red_pos = 0 + input_alpha;
213 alpha_pos = nochan - input_alpha;
223 green_pos *= img_size;
224 blue_pos *= img_size;
225 alpha_pos *= img_size;
233 while ( !feof( infile ))
238 int fread_len = inrows_size;
239 unsigned char *fread_pos = inrows;
243 fread( header_bytes, 1, header, infile );
247 register int stride = nochan, count;
250 for (count = 0; count < left_pad; count++)
254 if (fread( fread_pos, 1, fread_len, infile ) != fread_len) {
256 perror(
"read error" );
261 for (count = 0; count < right_pad; count++)
274 fread_pos = inrows + (img_size * (nochan - 1));
278 outrows[
RLE_ALPHA] = (rflag ? inrows + ni_y : fread_pos);
283 outrows[
RLE_RED] = inrows + red_pos + ni_y;
286 outrows[
RLE_GREEN] = inrows + green_pos + ni_y;
287 if ( rflag || input_alpha )
288 outrows[
RLE_BLUE] = inrows + blue_pos + ni_y;
293 }
else if (
sflag ) {
300 outrows[
RLE_RED] = inrows + red_pos;
304 outrows[
RLE_BLUE] = inrows + blue_pos;
312 p = inrows + alpha_pos;
314 duff(count, *o++ = *p; p += stride);
318 p = inrows + red_pos;
320 duff( count, *o++ = *p; p += stride);
324 p = inrows + green_pos;
326 duff( count, *o++ = *p; p += stride);
329 p = inrows + blue_pos;
331 duff( count, *o++ = *p; p += stride);
345 fread( trailer_bytes, 1, trailer, infile );
#define RLE_SET_BIT(glob, bit)
int scanargs(int argc, char **argv, const char *format,...)
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
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)
#define duff(counter, block)
#define RLE_CLR_BIT(glob, bit)
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)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)