Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
rleprint.c
Go to the documentation of this file.
1 /*
2  * This software is copyrighted as noted below. It may be freely copied,
3  * modified, and redistributed, provided that the copyright notice is
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is". Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  */
18 /*
19  * rleprint.c - Print all the pixel values in an RLE file.
20  *
21  * Author: Spencer W. Thomas
22  * EECS Dept.
23  * University of Michigan
24  * Date: Tue Jun 5 1990
25  * Copyright (c) 1990, University of Michigan
26  */
27 
28 
29 #include <stdio.h>
30 #include "rle.h"
31 
32 #define MALLOC_ERR RLE_CHECK_ALLOC( cmd_name( argv ), 0, 0 )
33 
34 void
36 int argc;
37 char *argv[];
38 {
39  char *infname = NULL;
40  int i, j;
41  rle_hdr in_hdr;
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 }
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
Definition: rle_open_f.c:216
int xmin
Definition: rle.h:100
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle_hdr.c:48
void rle_row_free(rle_hdr *the_hdr, rle_pixel **scanp)
Definition: rle_row_alc.c:114
#define RLE_EMPTY
Definition: rle.h:73
char * cmd_name(char **argv)
Definition: cmd_name.c:31
void main(int argc, char **argv)
Definition: aliastorle.c:121
int rle_get_setup(rle_hdr *the_hdr)
Definition: rle_getrow.c:74
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
int rle_getrow(rle_hdr *the_hdr, scanline)
Definition: rle_getrow.c:333
#define RLE_SUCCESS
Definition: rle.h:70
int ymin
Definition: rle.h:100
int rle_get_error(int code, const char *pgmname, const char *fname)
Definition: rle_error.c:76
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
const char * cmd
Definition: rle.h:133
int xmax
Definition: rle.h:100
#define MALLOC_ERR
Definition: rlecomp.c:38
#define RLE_EOF
Definition: rle.h:74
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
int alpha
Definition: rle.h:100
#define RLE_ALPHA
Definition: rle.h:65
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86