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

Go to the source code of this file.

Functions

void main (int argc, char **argv)
 

Variables

static char rcs_ident [] = "$Header: /n/hgp/mendel/u/spencer/src/urt/tools/RCS/tobw.c,v 3.0 1990/08/03 15:24:09 spencer Exp spencer $"
 

Function Documentation

void main ( int  argc,
char **  argv 
)

Definition at line 68 of file tobw.c.

71 {
72  char * infname = NULL, * outfname = NULL;
73  FILE * outfile = stdout;
74  int oflag = 0, tflag = 0, nrow;
76  unsigned char ** scan, *outscan[4];
77  unsigned char * buffer;
78  int rle_cnt, rle_err;
79 
80  if ( scanargs( argc, argv, "% t%- o%-outfile!s infile%s",
81  &tflag, &oflag, &outfname, &infname ) == 0 )
82  exit( 1 );
83 
84  rle_dflt_hdr.rle_file = rle_open_f(cmd_name( argv ), infname, "r");
85 
86  for ( rle_cnt = 0;
87  (rle_err = rle_get_setup( &rle_dflt_hdr )) == RLE_SUCCESS;
88  rle_cnt++ )
89  {
90  if ( rle_dflt_hdr.ncolors == 1 )
91  {
92  fprintf( stderr, "%s: %s is already black & white\n",
93  cmd_name( argv ), infname ? infname : "stdin" );
94  exit( 1 );
95  }
96  if ( rle_dflt_hdr.ncolors < 3 )
97  {
98  fprintf( stderr, "%s: %s is not RGB",
99  cmd_name( argv ), infname ? infname : "stdin" );
100  exit( 1 );
101  }
102  if ( rle_dflt_hdr.alpha )
104 
105  out_hdr = rle_dflt_hdr;
106  if ( rle_cnt == 0 )
107  outfile = rle_open_f(cmd_name( argv ), outfname, "w");
109  rle_dflt_hdr.xmin = 0;
110  nrow = rle_dflt_hdr.xmax + 1;
111  buffer = (unsigned char *)malloc( nrow );
112  rle_row_alloc( &rle_dflt_hdr, &scan );
113  if ( rle_dflt_hdr.alpha )
114  {
115  outscan[0] = scan[-1];
116  }
117  outscan[1] = buffer;
118  /* If 3 channel output, reference the line 3 times */
119  if ( tflag )
120  outscan[2] = outscan[3] = buffer;
121 
122  if ( ! tflag )
123  out_hdr.ncolors = 1;
124  else
125  out_hdr.ncolors = 3;
126 
127  if ( rle_dflt_hdr.background != 0 )
128  {
129  rle_pixel r, g, b, o;
130 
131  out_hdr.bg_color = (int *)malloc( sizeof( int ) );
132  r = rle_dflt_hdr.bg_color[0];
133  g = rle_dflt_hdr.bg_color[1];
134  b = rle_dflt_hdr.bg_color[2];
135  rgb_to_bw( &r, &g, &b, &o, 1 );
136  out_hdr.bg_color[0] = o;
137  }
138 
139  rle_addhist( argv, &rle_dflt_hdr, &out_hdr );
140 
141  out_hdr.rle_file = outfile;
142 
143  rle_put_setup( &out_hdr );
144 
145  while ( rle_getrow( &rle_dflt_hdr, scan ) <= rle_dflt_hdr.ymax )
146  {
147  rgb_to_bw( scan[0], scan[1], scan[2], buffer, nrow );
148  rle_putrow( &outscan[1], nrow, &out_hdr );
149  }
150  rle_puteof( &out_hdr );
151 
152  rle_row_free( &rle_dflt_hdr, scan );
153  }
154 
155  /* Check for an error. EOF or EMPTY is ok if at least one image
156  * has been read. Otherwise, print an error message.
157  */
158  if ( rle_cnt == 0 || (rle_err != RLE_EOF && rle_err != RLE_EMPTY) )
159  rle_get_error( rle_err, cmd_name( argv ), infname );
160 
161  exit( 0 );
162 }
static unsigned char g
Definition: getami.c:692
#define RLE_SET_BIT(glob, bit)
Definition: rle.h:122
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
FILE * outfile
Definition: giftorle.c:61
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
#define RLE_EMPTY
Definition: rle.h:73
static unsigned char r
Definition: getami.c:692
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
int * bg_color
Definition: rle.h:100
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
#define RLE_SUCCESS
Definition: rle.h:70
rle_hdr rle_dflt_hdr
Definition: rle_global.c:66
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
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
unsigned char ** scan
Definition: rle.c:26
static unsigned char b
Definition: getami.c:692
string infname
Definition: getbob.c:68
int nrow
Definition: getsun.c:82
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 background
Definition: rle.h:100
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
void * malloc()
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)
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
char * cmd_name(char **argv)
Definition: cmd_name.c:31
unsigned char * buffer
Definition: getsun.c:87
int oflag
Definition: painttorle.c:45
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
FILE * rle_file
Definition: rle.h:114
rle_hdr out_hdr
Definition: dvirle2.c:89
int ncolors
Definition: rle.h:100

Variable Documentation

char rcs_ident[] = "$Header: /n/hgp/mendel/u/spencer/src/urt/tools/RCS/tobw.c,v 3.0 1990/08/03 15:24:09 spencer Exp spencer $"
static

Definition at line 29 of file tobw.c.