Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Macros | Functions
rleprint.c File Reference
#include <stdio.h>
#include "rle.h"
Include dependency graph for rleprint.c:

Go to the source code of this file.

Macros

#define MALLOC_ERR   RLE_CHECK_ALLOC( cmd_name( argv ), 0, 0 )
 

Functions

void main (int argc, argv)
 

Macro Definition Documentation

#define MALLOC_ERR   RLE_CHECK_ALLOC( cmd_name( argv ), 0, 0 )

Definition at line 32 of file rleprint.c.

Function Documentation

void main ( int  argc,
argv   
)

Definition at line 35 of file rleprint.c.

38 {
39  char *infname = NULL;
40  int i, j;
42  rle_pixel **rows0;
43  rle_pixel *prev;
44  int chan;
45  int rle_cnt, rle_err;
46  int out_alpha = 0, cur_out_alpha, uniq = 0, first;
47 
48  in_hdr = *rle_hdr_init( NULL );
49 
50  if ( scanargs( argc, argv, "% a%- u%- infile%s",
51  &out_alpha, &uniq, &infname ) == 0 )
52  exit( 1 );
53  in_hdr.rle_file = rle_open_f( cmd_name( argv ), infname, "r" );
54  rle_names( &in_hdr, cmd_name( argv ), infname, 0 );
55 
56  for ( rle_cnt = 0;
57  (rle_err = rle_get_setup( &in_hdr )) == RLE_SUCCESS;
58  rle_cnt++ )
59  {
60  if ( rle_row_alloc( &in_hdr, &rows0 ) < 0 )
61  MALLOC_ERR;
62  prev = (rle_pixel *)malloc( (in_hdr.alpha + in_hdr.ncolors) *
63  sizeof(rle_pixel) );
64  prev += in_hdr.alpha;
65  RLE_CHECK_ALLOC( in_hdr.cmd, prev, NULL );
66  first = 1;
67 
68  /* output alpha if it exists and is wanted */
69  cur_out_alpha = in_hdr.alpha && out_alpha ;
70 
71  for ( j = in_hdr.ymin; j <= in_hdr.ymax ; j++ )
72  {
73  rle_getrow(&in_hdr, rows0 );
74 
75  for ( i = in_hdr.xmin; i <= in_hdr.xmax; i++ )
76  {
77  if ( uniq && !first )
78  {
79  for ( chan = -cur_out_alpha;
80  chan < in_hdr.ncolors;
81  chan++ )
82  if ( rows0[chan][i] != prev[chan] )
83  break;
84  if ( chan >= in_hdr.ncolors )
85  continue;
86  }
87  first = 0;
88  for ( chan = 0; chan < in_hdr.ncolors; chan++ )
89  {
90  printf( "%d ", rows0[chan][i] );
91  prev[chan] = rows0[chan][i];
92  }
93  if ( cur_out_alpha )
94  {
95  printf( "%d", rows0[RLE_ALPHA][i] );
96  prev[-1] = rows0[RLE_ALPHA][i];
97  }
98  printf( "\n" );
99  }
100  }
101  rle_row_free( &in_hdr, rows0 );
102  prev -= in_hdr.alpha;
103  free( prev );
104  }
105 
106  /* Check for an error. EOF or EMPTY is ok if at least one image
107  * has been read. Otherwise, print an error message.
108  */
109  if ( rle_cnt == 0 || (rle_err != RLE_EOF && rle_err != RLE_EMPTY) )
110  rle_get_error( rle_err, cmd_name( argv ), infname );
111 
112  exit( 0 );
113 }
void rle_row_free(rle_hdr *the_hdr, rle_pixel **scanp)
Definition: rle_row_alc.c:114
int xmin
Definition: rle.h:100
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
static rle_hdr in_hdr
Definition: rletogif.c:37
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
#define RLE_EMPTY
Definition: rle.h:73
#define RLE_SUCCESS
Definition: rle.h:70
int ymin
Definition: rle.h:100
string infname
Definition: getbob.c:68
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
const char * cmd
Definition: rle.h:133
int rle_get_setup(rle_hdr *the_hdr)
Definition: rle_getrow.c:74
Definition: rle.h:96
int xmax
Definition: rle.h:100
int rle_get_error(int code, const char *pgmname, const char *fname)
#define RLE_EOF
Definition: rle.h:74
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
void * malloc()
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
#define RLE_ALPHA
Definition: rle.h:65
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
#define MALLOC_ERR
Definition: rleprint.c:32
char * cmd_name(char **argv)
Definition: cmd_name.c:31
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267