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

Go to the source code of this file.

Functions

void main (int argc, argv)
 

Variables

static char rcs_ident [] = "$Header: /l/spencer/src/urt/tools/RCS/avg4.c,v 3.0.1.4 1992/04/30 14:08:43 spencer Exp $"
 
static bit_count [16]
 

Function Documentation

void main ( int  argc,
argv   
)

Definition at line 41 of file avg4.c.

44 {
45  char *infname = NULL, *outfname = NULL;
46  char *cmd = cmd_name( argv );
47  int oflag = 0;
48  int rle_cnt;
49  FILE *outfile = stdout;
50  int i, j;
51  int new_xlen,
52  new_ylen;
53  int rle_err;
55  rle_pixel **rows0, **rows1, **rowsout;
56  rle_pixel *ptr0, *ptr1, *ptrout, *alphptr;
57  int A, chan;
58 
59  in_hdr = *rle_hdr_init( NULL );
60  out_hdr = *rle_hdr_init( NULL );
61 
62  if ( scanargs( argc, argv, "% o%-outfile!s infile%s",
63  &oflag, &outfname, &infname ) == 0 )
64  exit( 1 );
65 
66  in_hdr.rle_file = rle_open_f( cmd, infname, "r" );
67  rle_names( &in_hdr, cmd, infname, 0 );
68  rle_names( &out_hdr, in_hdr.cmd, outfname, 0 );
69 
70  for ( rle_cnt = 0;
71  (rle_err = rle_get_setup( &in_hdr )) == RLE_SUCCESS;
72  rle_cnt++ )
73  {
74  if ( rle_cnt == 0 )
75  outfile = rle_open_f( cmd, outfname, "w" );
76 
77  (void)rle_hdr_cp( &in_hdr, &out_hdr );
78  rle_addhist( argv, &in_hdr, &out_hdr );
79 
80  /* Force input to an even length line. */
81  if ( (in_hdr.xmax - in_hdr.xmin) % 2 == 0 )
82  in_hdr.xmax++;
83 
84  new_xlen = (in_hdr.xmax - in_hdr.xmin + 1 ) / 2;
85  new_ylen = (in_hdr.ymax - in_hdr.ymin + 2 ) / 2;
86  out_hdr.xmin = in_hdr.xmin / 2;
87  out_hdr.ymin = in_hdr.ymin / 2;
88  out_hdr.xmax = out_hdr.xmin + new_xlen - 1;
89  out_hdr.ymax = out_hdr.ymin + new_ylen - 1;
90 
91  out_hdr.alpha = 1; /* Force alpha in output. */
92  RLE_SET_BIT( out_hdr, RLE_ALPHA );
93 
94  out_hdr.rle_file = outfile;
95  rle_put_setup( &out_hdr );
96 
97  /* Oink. */
98  if ( rle_row_alloc( &in_hdr, &rows0 ) < 0 ||
99  rle_row_alloc( &in_hdr, &rows1 ) < 0 ||
100  rle_row_alloc( &out_hdr, &rowsout ) < 0 )
101  RLE_CHECK_ALLOC( cmd, 0, "image" );
102 
103  for ( j = 0; j < new_ylen*2; j+=2 )
104  {
105  rle_getrow(&in_hdr, rows0 );
106  rle_getrow(&in_hdr, rows1 );
107 
108  for (chan = RLE_ALPHA; chan < in_hdr.ncolors; chan++)
109  {
110  ptr0 = &(rows0[chan][in_hdr.xmin]);
111  ptr1 = &(rows1[chan][in_hdr.xmin]);
112  ptrout = rowsout[chan];
113  alphptr = rowsout[RLE_ALPHA];
114  /*
115  * If we don't start out with an alpha channel in the
116  * original image, then we want to fake one up. This
117  * works by counting the number of non-zero pixels in the
118  * R, G and B channels. We set bits in the alpha channel
119  * for the non-zero pixels found, then use bit_count to
120  * convert this to reasonable coverage values.
121  */
122  if ((chan == RLE_ALPHA) && (!in_hdr.alpha))
123  {
124  bzero(alphptr, new_xlen);
125  }
126  else for( i = 0; i < new_xlen; i++)
127  {
128  if (!in_hdr.alpha)
129  {
130  *alphptr |= (*ptr0 ? 1 : 0) | (ptr0[1] ? 2 : 0) |
131  (*ptr1 ? 4 : 0) | (ptr1[1] ? 8 : 0);
132 
133  /* calc fake alpha from bit count */
134  if (chan == (in_hdr.ncolors - 1))
135  *alphptr = bit_count[*alphptr];
136 
137  alphptr++;
138  }
139  A = (int) *ptr0++ + (int) *ptr1++;
140  A += (int) *ptr0++ + (int) *ptr1++;
141  *ptrout++ = (rle_pixel) (A / 4);
142  }
143  }
144  rle_putrow( rowsout, new_xlen, &out_hdr );
145  }
146  rle_puteof( &out_hdr );
147 
148  /* Skip last row if odd number of rows. */
149  while ( rle_getskip( &in_hdr ) != 32768 )
150  ;
151 
152  rle_row_free( &in_hdr, rows0 );
153  rle_row_free( &in_hdr, rows1 );
154  rle_row_free( &out_hdr, rowsout );
155  }
156 
157  if ( rle_cnt == 0 || (rle_err != RLE_EOF && rle_err != RLE_EMPTY) )
158  rle_get_error( rle_err, cmd, infname );
159 
160  exit( 0 );
161 }
#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
static rle_hdr in_hdr
Definition: rletogif.c:37
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
void rle_putrow(rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
#define RLE_SUCCESS
Definition: rle.h:70
int ymin
Definition: rle.h:100
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
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)
unsigned int rle_getskip(rle_hdr *the_hdr)
Definition: rle_getskip.c:57
static bit_count[16]
Definition: avg4.c:37
#define RLE_EOF
Definition: rle.h:74
int
Definition: getami.c:848
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
Definition: rle_hdr.c:119
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)
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
char * cmd_name(char **argv)
Definition: cmd_name.c:31
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
#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

Variable Documentation

bit_count[16]
static
Initial value:
= {0, 63, 63, 127, 63, 127, 127,
192, 63, 127, 127, 192, 127, 192, 192, 255}

Definition at line 37 of file avg4.c.

char rcs_ident[] = "$Header: /l/spencer/src/urt/tools/RCS/avg4.c,v 3.0.1.4 1992/04/30 14:08:43 spencer Exp $"
static

Definition at line 30 of file avg4.c.