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

Go to the source code of this file.

Macros

#define LEFTSCALE   0.7 /* Default left scale factor. */
 
#define RIGHTSCALE   1.0 /* Default right scale factor. */
 
#define REDC   0.30
 
#define GREENC   0.59
 
#define BLUEC   0.11
 
#define GREYCONV(r, g, b, m)   (REDC*m[0][r]+GREENC*m[1][g]+BLUEC*m[2][b])
 

Functions

void convert_line ()
 
int get_rle_setup ()
 
void main (int argc, char **argv)
 
int get_rle_setup (rle_hdr *the_hdr, int *xres, int *yres)
 
void convert_line (rle_pixel **out, rle_pixel **left, rle_pixel **right)
 

Variables

char rcsid [] = "$Header: /l/spencer/src/urt/tools/RCS/rlestereo.c,v 3.0.1.3 1992/04/30 14:14:07 spencer Exp $"
 
float LeftScale = 0.7
 
float RightScale = 1.0
 
int GreenFlag = 0
 
int Xres
 
int Yres
 
int lcolors
 
int rcolors
 
int RightIndex
 
int lchan1
 
int lchan2
 
int rchan1
 
int rchan2
 
rle_pixel ** lmap
 
rle_pixel ** rmap
 

Macro Definition Documentation

#define BLUEC   0.11

Definition at line 47 of file rlestereo.c.

#define GREENC   0.59

Definition at line 46 of file rlestereo.c.

#define GREYCONV (   r,
  g,
  b,
 
)    (REDC*m[0][r]+GREENC*m[1][g]+BLUEC*m[2][b])

Definition at line 48 of file rlestereo.c.

#define LEFTSCALE   0.7 /* Default left scale factor. */

Definition at line 38 of file rlestereo.c.

#define REDC   0.30

Definition at line 45 of file rlestereo.c.

#define RIGHTSCALE   1.0 /* Default right scale factor. */

Definition at line 39 of file rlestereo.c.

Function Documentation

void convert_line ( )
void convert_line ( rle_pixel **  out,
rle_pixel **  left,
rle_pixel **  right 
)

Definition at line 261 of file rlestereo.c.

263 {
264  register int i;
265 
266  /*
267  * Convert input scanlines to 'stereo' output scanline.
268  */
269  for (i = 0; i < Xres; i++) {
270  out[0][i] = LeftScale * GREYCONV(left[0][i], left[lchan1][i],
271  left[lchan2][i], lmap);
272  out[RightIndex][i] = RightScale * GREYCONV(right[0][i],
273  right[rchan1][i], right[rchan2][i], rmap);
274  }
275 }
rle_pixel ** rmap
Definition: rlestereo.c:58
int lchan1
Definition: rlestereo.c:56
float RightScale
Definition: rlestereo.c:51
int rchan2
Definition: rlestereo.c:57
int RightIndex
Definition: rlestereo.c:55
int Xres
Definition: rlestereo.c:53
float LeftScale
Definition: rlestereo.c:50
rle_pixel ** lmap
Definition: rlestereo.c:58
int left
Definition: getap.c:93
#define GREYCONV(r, g, b, m)
Definition: rlestereo.c:48
int rchan1
Definition: rlestereo.c:57
int i
Definition: rletorla.c:82
int lchan2
Definition: rlestereo.c:56
int get_rle_setup ( )
int get_rle_setup ( rle_hdr the_hdr,
int xres,
int yres 
)

Definition at line 246 of file rlestereo.c.

249 {
250  int err;
251 
252  err = rle_get_setup(the_hdr);
253  *xres = the_hdr->xmax - the_hdr->xmin + 1;
254  *yres = the_hdr->ymax - the_hdr->ymin + 1;
255  the_hdr->xmax -= the_hdr->xmin;
256  the_hdr->xmin = 0;
257  return err;
258 }
int xmin
Definition: rle.h:100
int ymin
Definition: rle.h:100
int rle_get_setup(rle_hdr *the_hdr)
Definition: rle_getrow.c:74
int xmax
Definition: rle.h:100
int ymax
Definition: rle.h:100
void main ( int  argc,
char **  argv 
)

Definition at line 83 of file rlestereo.c.

86 {
87  int y, i, Xtmp, Ytmp, scaleflag = 0;
88  char *leftname = NULL, *rightname = NULL;
89  char *outname = NULL;
90  FILE *outfile = stdout;
91  int oflag;
92  rle_pixel **lline, **rline, **outline;
93  rle_hdr left_hdr, right_hdr, out_hdr;
94  int rle_cnt = 0, rle_err;
95  char *err_name = NULL;
96 
97  left_hdr = *rle_hdr_init( NULL );
98  right_hdr = *rle_hdr_init( NULL );
99  out_hdr = *rle_hdr_init( NULL );
100 
101  if (scanargs(argc, argv,
102  "% g%- l%-leftscale!f r%-rightscale!f o%-outfile!s \n\
103  leftimage!s rightimage!s",
104  &GreenFlag, &scaleflag, &LeftScale, &scaleflag, &RightScale,
105  &oflag, &outname,
106  &leftname, &rightname) == 0) {
107  exit(-1);
108  }
109 
110  /*
111  * Open left and right images.
112  */
113  (void)rle_hdr_init( &left_hdr );
114  (void)rle_hdr_init( &right_hdr );
115  left_hdr.rle_file = rle_open_f(cmd_name(argv), leftname, "r");
116  right_hdr.rle_file = rle_open_f(cmd_name(argv), rightname, "r");
117  rle_names( &left_hdr, cmd_name(argv), leftname, 0 );
118  rle_names( &right_hdr, cmd_name(argv), rightname, 0 );
119  rle_names( &out_hdr, left_hdr.cmd, outname, 0 );
120 
121  for ( rle_cnt = 0;; rle_cnt++ )
122  {
123  /*
124  * Read headers of both images.
125  */
126  if ( (rle_err =
127  get_rle_setup(&left_hdr, &Xres, &Yres)) != RLE_SUCCESS )
128  {
129  err_name = leftname;
130  break;
131  }
132  if ( (rle_err =
133  get_rle_setup(&right_hdr, &Xtmp, &Ytmp)) != RLE_SUCCESS )
134  {
135  err_name = rightname;
136  break;
137  }
138 
139  /* Open the output file when first header is successfully read. */
140  if ( rle_cnt == 0 )
141  outfile = rle_open_f( cmd_name( argv ), outname, "w" );
142 
143  if (Xres != Xtmp || Yres != Ytmp) {
144  fprintf(stderr,"Images are of different sizes.\n");
145  exit(-1);
146  }
147 
148  (void)rle_hdr_cp( &left_hdr, &out_hdr );
149  out_hdr.ncolors = 3;
150  out_hdr.ncmap = 0;
151  out_hdr.rle_file = outfile;
152  rle_addhist(argv, &left_hdr, &out_hdr);
153  rle_put_setup(&out_hdr);
154 
155  /*
156  * Ignore alpha and any channels > #2.
157  */
158  RLE_CLR_BIT(left_hdr, RLE_ALPHA);
159  RLE_CLR_BIT(right_hdr, RLE_ALPHA);
160  for (i = 3; i < left_hdr.ncolors; i++)
161  RLE_CLR_BIT(left_hdr, i);
162  for (i = 3; i < right_hdr.ncolors; i++)
163  RLE_CLR_BIT(right_hdr, i);
164 
165  lcolors = left_hdr.ncolors > 3 ? 3 : left_hdr.ncolors;
166  rcolors = right_hdr.ncolors > 3 ? 3 : right_hdr.ncolors;
167 
168  if (lcolors == 1)
169  lchan1 = lchan2 = 0;
170  else if (lcolors == 2) {
171  lchan1 = 1;
172  lchan2 = 0;
173  } else {
174  lchan1 = 1;
175  lchan2 = 2;
176  }
177 
178  if (rcolors == 1)
179  rchan1 = rchan2 = 0;
180  else if (rcolors == 2) {
181  rchan1 = 1;
182  rchan2 = 0;
183  } else {
184  rchan1 = 1;
185  rchan2 = 2;
186  }
187 
188  if ( rle_row_alloc(&left_hdr, &lline) < 0 ||
189  rle_row_alloc(&right_hdr, &rline) < 0 ||
190  rle_row_alloc(&out_hdr, &outline) < 0 )
191  RLE_CHECK_ALLOC( left_hdr.cmd, 0, "images" );
192  /*
193  * Zero unused channel of output scanline.
194  */
195  if (GreenFlag) {
196  RightIndex = 1;
197  bzero(outline[2], Xres * sizeof(rle_pixel));
198  } else {
199  RightIndex = 2;
200  bzero(outline[1], Xres * sizeof(rle_pixel));
201  }
202 
203  /*
204  * In case there's a colormap, DTRT. We use a gamma of 1.
205  * here because we want the output image to have the same
206  * gamma as the left image.
207  */
208  lmap = buildmap(&left_hdr, 3, 1., 1.0);
209  rmap = buildmap(&right_hdr, 3, 1., 1.0);
210  /*
211  * For each output scanline...
212  */
213  for (y = 0; y < Yres; y++) {
214  /*
215  * Read left and right scanline, converting each
216  * to greyscale data.
217  */
218  rle_getrow(&left_hdr, lline);
219  rle_getrow(&right_hdr, rline);
220  convert_line(outline, lline, rline);
221  rle_putrow(outline, Xres, &out_hdr);
222  }
223  while ( rle_getskip(&left_hdr) != 32768 )
224  ;
225  while ( rle_getskip(&right_hdr) != 32768 )
226  ;
227 
228  rle_row_free(&left_hdr, lline);
229  rle_row_free(&right_hdr, rline);
230  rle_row_free(&out_hdr, outline);
231 
232  rle_puteof( &out_hdr );
233  }
234  fclose(left_hdr.rle_file);
235  fclose(right_hdr.rle_file);
236 
237  /* Check for an error. EOF or EMPTY is ok if at least one image
238  * has been read. Otherwise, print an error message.
239  */
240  if ( rle_cnt == 0 || (rle_err != RLE_EOF && rle_err != RLE_EMPTY) )
241  rle_get_error( rle_err, cmd_name( argv ), err_name );
242  exit(0);
243 }
void rle_row_free(rle_hdr *the_hdr, rle_pixel **scanp)
Definition: rle_row_alc.c:114
rle_pixel ** rmap
Definition: rlestereo.c:58
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
int lchan1
Definition: rlestereo.c:56
FILE * outfile
Definition: giftorle.c:61
float RightScale
Definition: rlestereo.c:51
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)
int rchan2
Definition: rlestereo.c:57
void rle_addhist(char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
#define RLE_SUCCESS
Definition: rle.h:70
int RightIndex
Definition: rlestereo.c:55
int lcolors
Definition: rlestereo.c:54
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
static int y
Definition: getami.c:691
int Xres
Definition: rlestereo.c:53
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
float LeftScale
Definition: rlestereo.c:50
int rle_get_error(int code, const char *pgmname, const char *fname)
rle_pixel ** lmap
Definition: rlestereo.c:58
unsigned int rle_getskip(rle_hdr *the_hdr)
Definition: rle_getskip.c:57
#define RLE_EOF
Definition: rle.h:74
int rcolors
Definition: rlestereo.c:54
int get_rle_setup()
#define RLE_CLR_BIT(glob, bit)
Definition: rle.h:124
int ncmap
Definition: rle.h:100
rle_pixel ** buildmap(rle_hdr *the_hdr, int minmap, double orig_gamma, double new_gamma)
Definition: buildmap.c:56
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 rchan1
Definition: rlestereo.c:57
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)
int Yres
Definition: rlestereo.c:53
void rle_put_setup(rle_hdr *the_hdr)
Definition: rle_putrow.c:453
char * cmd_name(char **argv)
Definition: cmd_name.c:31
int GreenFlag
Definition: rlestereo.c:52
int lchan2
Definition: rlestereo.c:56
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
void convert_line()

Variable Documentation

int GreenFlag = 0

Definition at line 52 of file rlestereo.c.

int lchan1

Definition at line 56 of file rlestereo.c.

int lchan2

Definition at line 56 of file rlestereo.c.

int lcolors

Definition at line 54 of file rlestereo.c.

float LeftScale = 0.7

Definition at line 50 of file rlestereo.c.

rle_pixel** lmap

Definition at line 58 of file rlestereo.c.

int rchan1

Definition at line 57 of file rlestereo.c.

int rchan2

Definition at line 57 of file rlestereo.c.

int rcolors

Definition at line 54 of file rlestereo.c.

char rcsid[] = "$Header: /l/spencer/src/urt/tools/RCS/rlestereo.c,v 3.0.1.3 1992/04/30 14:14:07 spencer Exp $"

Definition at line 29 of file rlestereo.c.

int RightIndex

Definition at line 55 of file rlestereo.c.

float RightScale = 1.0

Definition at line 51 of file rlestereo.c.

rle_pixel ** rmap

Definition at line 58 of file rlestereo.c.

int Xres

Definition at line 53 of file rlestereo.c.

int Yres

Definition at line 53 of file rlestereo.c.