31 static char rcs_id[] =
"$Header: /l/spencer/src/urt/cnv/RCS/rletocgm.c,v 3.0.1.1 1992/04/30 13:59:08 spencer Exp $";
44 #if ( unix
&& ( !CRAY && !ardent ) )
50 #include "unix_defs.h"
53 #include "unicos_defs.h"
56 #include "unicos_defs.h"
65 static void open_output(outfname)
69 int ierr= 0, i256= 256;
71 wrcopn(outfname,&ierr);
73 fprintf(stderr,
"rletocgm: Error opening file <%s> for output!\n",outfname);
78 fprintf(stderr,
"rletocgm: Error writing to file!\n");
83 static void close_output()
90 fprintf(stderr,
"rletocgm: Error closing output!\n");
95 static void begin_direct_page(in_hdr)
100 float red, green, blue;
115 fprintf(stderr,
"rletocgm: Error writing begin page!\n");
120 fprintf(stderr,
"rletocgm: Error writing color selection mode!\n");
123 wrbgdc(&red, &green, &blue, &ierr);
125 fprintf(stderr,
"rletocgm: Error writing background color!\n");
130 fprintf(stderr,
"rletocgm: Error writing begin picture body!\n");
135 static void handle_color_table(in_hdr,cmap)
142 int tablesize, i, zero= 0, ierr= 0;
143 float *rarray, *garray, *barray;
153 if (!comstring) comstring=
rle_getcom( "colormap_length", in_hdr
);
154 if (comstring) sscanf( comstring,
"%d", &tablesize );
156 if ( !(rarray= (
float *)malloc( tablesize*
sizeof(
float) )) ) {
158 "rletocgm: unable to allocate %d floats for color table reds!\n",
162 if ( !(garray= (
float *)malloc( tablesize*
sizeof(
float) )) ) {
164 "rletocgm: unable to allocate %d floats for color table greens!\n",
168 if ( !(barray= (
float *)malloc( tablesize*
sizeof(
float) )) ) {
170 "rletocgm: unable to allocate %d floats for color table blues!\n",
176 for (i=0; i<tablesize; i++) {
177 rarray[i]= (
float)cmap[0][i]/255.0;
178 garray[i]= (
float)cmap[1][i]/255.0;
179 barray[i]= (
float)cmap[2][i]/255.0;
183 wrctbl(rarray, garray, barray, &zero, &tablesize, &ierr);
185 fprintf(stderr,
"rletocgm: Error writing color map!\n");
190 free( (
char *)rarray );
191 free( (
char *)garray );
192 free( (
char *)barray );
195 static void begin_indexed_page(in_hdr)
201 float red, green, blue;
206 red= (
float)cmap[0][in_hdr
->bg_color[0]]/255.0;
207 green= (
float)cmap[1][in_hdr
->bg_color[0]]/255.0;
208 blue= (
float)cmap[2][in_hdr
->bg_color[0]]/255.0;
219 fprintf(stderr,
"rletocgm: Error writing begin page!\n");
222 wrbgdc(&red, &green, &blue, &ierr);
224 fprintf(stderr,
"rletocgm: Error writing background color!\n");
229 fprintf(stderr,
"rletocgm: Error writing begin picture body!\n");
234 handle_color_table(in_hdr, cmap);
237 free( (
char *)cmap[0] );
240 static void end_page()
247 fprintf(stderr,
"rletocgm: Error ending output page!\n");
252 static void center_image(in_hdr, px, py, qx, qy, rx, ry)
254 float *px, *py, *qx, *qy, *rx, *ry;
257 float xrange, yrange;
261 if (xrange>=yrange) {
265 *py= 0.5 * (1.0 - yrange/xrange);
273 *px= 0.5 * (1.0 - xrange/yrange);
279 static void process_indexed_page(in_hdr)
285 static int *iarray= (
int *)0;
288 float px, py, qx, qy, rx, ry;
292 if (
verboseflag) fprintf(stderr,
"Found indexed color (1 channel) page\n");
295 begin_indexed_page(in_hdr);
298 center_image(in_hdr, &px, &py, &qx, &qy, &rx, &ry);
304 if (iarray) free( (
char *)iarray );
307 if ( !(iarray= (
int *)malloc( nx*ny*
sizeof(
int) )) ) {
308 fprintf(stderr,
"rletocgm: cannot allocate %d ints!\n",nx*ny);
315 fprintf( stderr,
"rletocgm: Unable to allocate image memory.\n" );
326 for (x=0; x<nx; x++) *iptr++= rows[0][x];
330 wrtcla( iarray, &nx, &ny, &px, &py, &qx, &qy, &rx, &ry, &ierr );
332 fprintf(stderr,
"rletocgm: Error writing indexed cell array!\n");
346 static void process_direct_page(in_hdr)
352 static float *rarray= (
float *)0;
353 static float *garray= (
float *)0;
354 static float *barray= (
float *)0;
355 float *rptr, *gptr, *bptr;
357 float px, py, qx, qy, rx, ry;
361 if (
verboseflag) fprintf(stderr,
"Found direct color (3 channel) page\n");
364 begin_direct_page(in_hdr);
367 center_image(in_hdr, &px, &py, &qx, &qy, &rx, &ry);
373 if (rarray) free( (
char *)rarray );
374 if (garray) free( (
char *)garray );
375 if (barray) free( (
char *)barray );
378 if ( !(rarray= (
float *)malloc( nx*ny*
sizeof(
float) )) ) {
379 fprintf(stderr,
"rletocgm: cannot allocate %d floats for red!\n",nx*ny);
382 if ( !(garray= (
float *)malloc( nx*ny*
sizeof(
float) )) ) {
383 fprintf(stderr,
"rletocgm: cannot allocate %d floats for green!\n",nx*ny);
386 if ( !(barray= (
float *)malloc( nx*ny*
sizeof(
float) )) ) {
387 fprintf(stderr,
"rletocgm: cannot allocate %d floats for blue!\n",nx*ny);
394 fprintf( stderr,
"rletocgm: Unable to allocate image memory.\n" );
407 for (x=0; x<nx; x++) {
408 *rptr++= (
float)rows[0][x]/255.0;
409 *gptr++= (
float)rows[1][x]/255.0;
410 *bptr++= (
float)rows[2][x]/255.0;
415 wcladc( rarray, garray, barray,
416 &nx, &ny, &px, &py, &qx, &qy, &rx, &ry, &ierr );
418 fprintf(stderr,
"rletocgm: Error writing direct color cell array!\n");
456 char *infname = NULL,
458 int rle_cnt, rle_err;
459 int oflag = 0, debugflag= 0;
463 in_hdr = *rle_init_hdr( (rle_hdr *)NULL );
464 if (
scanargs( argc
, argv
, "% o%-outfile!s d%- v%- infile%s",
473 if (ierr) fprintf(stderr,
"rletocgm: couldn't set debugging!\n");
492 if (rle_cnt==0) open_output(oflag ? outfname :
"-");
498 if (
verboseflag) fprintf(stderr,
"image %d: ",rle_cnt);
504 case 1: process_indexed_page(&in_hdr);
break;
505 case 3: process_direct_page(&in_hdr);
break;
506 default: fprintf(stderr,
507 "rletocgm: %d is an invalid number of color planes!\n",
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)
void rle_debug(int on_off)
void rle_row_free(rle_hdr *the_hdr, rle_pixel **scanp)
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,...)
rle_pixel ** buildmap(rle_hdr *the_hdr, int minmap, double orig_gamma, double new_gamma)
unsigned int rle_getskip(rle_hdr *the_hdr)
char * rle_getcom(char *name, rle_hdr *the_hdr) const