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

Go to the source code of this file.

Typedefs

typedef FILE * FILPTR
 

Functions

void main (int argc, argv)
 

Variables

static char default_asciistr [] = "@BR*#$PX0woIcv:+!~\"., "
 

Typedef Documentation

typedef FILE* FILPTR

Definition at line 26 of file rletoascii.c.

Function Documentation

void main ( int  argc,
argv   
)

Definition at line 63 of file rletoascii.c.

66 {
67  char *infnam = NULL; /* Input file name. */
68  rle_hdr hdr;
69  int nrow, nscan, i, row, index, rflag=0;
70  unsigned char ** scan;
71  unsigned char * buffer;
72  char *asciistr = NULL;
73  int numchars;
74 
75  if (! scanargs( argc,argv,
76  "% S%-ascii_string!s r%- infile%s\n(\
77 \t-S\tSpecify set of characters for output (dark to light).\n\
78 \t-r\tReverse black & white -- white on black.)",
79  &i, &asciistr, &rflag, &infnam ))
80  exit( -1 );
81 
82  /* Set up header. */
83  hdr = *rle_hdr_init( (rle_hdr *)NULL );
84  rle_names( &hdr, cmd_name( argv ), infnam, 0 );
85  hdr.rle_file = rle_open_f( hdr.cmd, infnam, "r" );
86 
87  /* Read header information. */
88 
89  rle_get_setup_ok( &hdr, "rletoascii", infnam );
90  if ( hdr.ncolors == 0 )
91  {
92  fprintf( stderr, "%s: Image %s has no data.\n",
93  hdr.cmd, hdr.file_name );
94  exit( 1 );
95  }
96 
97  if ( hdr.ncolors > 3 ) {
98  fprintf( stderr,
99  "%s: Only first 3 channels (out of %d) in %s are shown.\n",
100  hdr.cmd, hdr.ncolors, hdr.file_name );
101  for ( i = 3; i < hdr.ncolors; i++ )
102  RLE_CLR_BIT( hdr, i );
103  }
104  RLE_CLR_BIT( hdr, RLE_ALPHA );
105  hdr.xmax -= hdr.xmin;
106  hdr.xmin = 0;
107  nrow = hdr.xmax + 1;
108  nscan = (hdr.ymax - hdr.ymin + 1);
109  buffer = (unsigned char *)malloc( nrow );
110  scan = (unsigned char **) malloc( hdr.ncolors *
111  sizeof( unsigned char * ) );
112  for ( i = 0; i < hdr.ncolors; i++ )
113  scan[i] = (unsigned char *)malloc( nrow );
114  for ( ; i < 3; i++ )
115  scan[i] = scan[i-1];
116 
117  if ( asciistr == NULL ) {
118  asciistr = (char *) malloc( 1 + strlen( default_asciistr ) );
119  strcpy(asciistr, default_asciistr);
120  }
121  numchars = strlen(asciistr);
122 
123  /* Read .rle file, dumping ascii as we go. */
124 
125  for (row=0; (row<nscan); row++)
126  {
127  if (hdr.ncolors > 1) {
128  rle_getrow( &hdr, scan );
129  rgb_to_bw( scan[0], scan[1], scan[2], buffer, nrow );
130  }
131  else {
132  rle_getrow( &hdr, &buffer );
133  }
134  for (i=0; i < nrow; i++) {
135  index = ((int)(buffer[i]) * numchars) >> 8;
136  if (rflag)
137  putchar(asciistr[numchars - (index + 1)]);
138  else
139  putchar(asciistr[index]);
140  }
141  printf("\n");
142  }
143 }
int xmin
Definition: rle.h:100
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
rle_hdr hdr
Definition: iristorle.c:35
int ymin
Definition: rle.h:100
void rgb_to_bw(rle_pixel *red_row, rle_pixel *green_row, rle_pixel *blue_row, rle_pixel *bw_row, int rowlen)
Definition: rle_putrow.c:680
unsigned char ** scan
Definition: rle.c:26
int nrow
Definition: getsun.c:82
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
const char * cmd
Definition: rle.h:133
Definition: rle.h:96
int xmax
Definition: rle.h:100
#define index
Definition: rle_config.h:96
int nscan
Definition: getsun.c:82
static char default_asciistr[]
Definition: rletoascii.c:60
int
Definition: getami.c:848
#define RLE_CLR_BIT(glob, bit)
Definition: rle.h:124
int ymax
Definition: rle.h:100
void * malloc()
int i
Definition: rletorla.c:82
#define RLE_ALPHA
Definition: rle.h:65
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
char * cmd_name(char **argv)
Definition: cmd_name.c:31
const char * file_name
Definition: rle.h:134
int row
Definition: rle.c:27
unsigned char * buffer
Definition: getsun.c:87
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267

Variable Documentation

char default_asciistr[] = "@BR*#$PX0woIcv:+!~\"., "
static

Definition at line 60 of file rletoascii.c.