39 #include <rasterfile.h>
51 FILE *outfile = stdout;
54 int y, ncol, nscan, nchan, nochan, i;
56 unsigned char *buffer;
57 struct rasterfile header ;
58 unsigned char *image ;
59 Input_Type input_type ;
63 "% o%-outfile!s infile%s",
64 &oflag
, &outfname
, &infname
) == 0 )
77 fprintf( stderr,
"%s is not RGB or b&w image",
78 infname ? infname :
"stdin" );
116 buffer = (
unsigned char *)malloc( ncol );
119 header.ras_magic = RAS_MAGIC ;
120 header.ras_width = ncol ;
121 header.ras_height = nscan ;
124 case GREY: nochan = 1 ;
break ;
125 case COLOR: nochan = 3 ;
break ;
127 default: nochan = 4;
break;
129 header.ras_depth = 8 * nochan ;
130 linebytes = header.ras_width * nochan ;
131 linebytes += linebytes % 2 ;
132 header.ras_length = linebytes * header.ras_height ;
133 header.ras_type = RT_STANDARD ;
136 header.ras_maptype = RMT_EQUAL_RGB ;
137 header.ras_maplength = (1 << hdr.cmaplen) * 3 ;
141 header.ras_maptype = RMT_NONE ;
142 header.ras_maplength = 0 ;
145 fwrite( &header,
sizeof(header), 1, outfile );
147 if( header.ras_maptype == RMT_EQUAL_RGB )
149 register rle_map *iptr ;
154 if( hdr.ncolors == 1 )
157 nco = (1 << hdr.cmaplen) ;
162 nco = header.ras_maplength ;
165 for(chan=0; chan<nch; ++chan)
167 iptr = hdr.cmap + (chan<<8) ;
170 out = (*iptr++ + 0x80) >> 8 ;
171 fwrite(&out, 1,1, outfile) ;
179 while(*comment != NULL)
181 fprintf(stderr,
"%s\n", *comment) ;
186 image = (
unsigned char *) malloc(linebytes * header.ras_height) ;
190 register int row,col,chan ;
191 register unsigned char *ptr ;
193 for(row=0; row<nscan; ++row)
195 ptr = image + row*linebytes ;
196 for(col=ncol; --col >= 0; )
201 for(chan=hdr
.ncolors; --chan >= 0; )
212 register unsigned char *optr, *a,*r,*g,*b ;
215 optr = image + (nscan-y-1+hdr
.ymin)*linebytes ;
220 for(col=ncol; --col >= 0; )
227 for(col=ncol; --col >= 0; )
230 *optr++ = *optr++ = *optr++ = *r++ ;
238 for(col=ncol; --col >= 0; )
251 for(col=ncol; --col >= 0; )
261 fwrite(image, linebytes * header.ras_height, 1, 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_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
int rle_getrow(rle_hdr *the_hdr, scanline)
int scanargs(int argc, char **argv, const char *format,...)
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)