Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
getfb.c
Go to the documentation of this file.
1 /*
2  * getfb.c - Display Extended Run Length Encoding with Alpha1 channel
3  * on BRL libfb frame buffer.
4  *
5  * Author: Paul R. Stay
6  * Ballistic Research Labratory
7  * Aberdeen Proving Ground, Md.
8  * Date: Mon Jun 23 1986
9  */
10 
11 #include <stdio.h>
12 #include <brlcad/fb.h>
13 #include "rle.h"
14 
15 #define MAX_PIXELS 1024
16 
18 int argc;
19 char ** argv;
20 {
21  rle_hdr hdr;
22  FILE *rle_fd;
23  FBIO *fbp;
24  int r_debug;
25  char * rle_file;
26  register int i,j;
27 
28  unsigned char scanline[4][MAX_PIXELS]; /* Run length scan line */
29  unsigned char *rows[4]; /* Character pointers for rle_getrow */
30 
31  RGBpixel pix[MAX_PIXELS]; /* pixel structure */
32  int x_len, y_len;
33 
34  hdr = *rle_hdr_init( (rle_hdr *)NULL );
35  rle_names( &hdr, cmd_name( argv ), NULL, 0 );
36  argc--; argv++;
37  while( argv[0][0] == '-') {
38 
39  switch( argv[0][1] ) {
40  case 'D':
41  r_debug = 1;
42  break;
43  default:
44  break;
45  }
46  argc--; argv++;
47  }
48 
49  rle_file = argv[0];
50  rle_names( &hdr, hdr.cmd, rle_file );
51  hdr.rle_file = rle_open_f(hdr.cmd, rle_file, "r");
52  if( rle_get_setup( &hdr ) < 0 ) {
53  fprintf(stderr, "getfb: Error reading setup information\n");
54  exit(1);
55  }
56 
57  if (r_debug)
58  {
59  fprintf( stderr,"Image bounds\n\tmin %d %d\n\tmax %d %d\n",
60  hdr.xmin, hdr.ymin,
61  hdr.xmax, hdr.ymax );
62  if ( hdr.alpha )
63  fprintf( stderr, "Alpha Channel present\n");
64  rle_debug(1);
65  }
66 
67  /* We`re only interested in R, G, & B */
68  RLE_CLR_BIT(hdr, RLE_ALPHA);
69  for (i = 3; i < hdr.ncolors; i++)
70  RLE_CLR_BIT(hdr, i);
71 
72  x_len = hdr.xmax - hdr.xmin + 1;
73  y_len = hdr.ymax - hdr.ymin + 1;
74 
75  if( (fbp = fb_open( "", hdr.xmax+1, hdr.ymax+1 )) == NULL )
76  exit(12);
77 
78  for ( i = hdr.ymin; i <= hdr.ymax; i++) {
79  rows[0] = (unsigned char *)-1;
80  rows[1] = scanline[1];
81  rows[2] = scanline[2];
82  rows[3] = scanline[3];
83  rle_getrow(&hdr, &rows[1] );
84 
85  for ( j = 0; j < x_len; j++)
86  {
87  pix[j][RED] = scanline[1][j];
88  pix[j][GRN] = scanline[2][j];
89  pix[j][BLU] = scanline[3][j];
90  }
91  fb_write( fbp, hdr.xmin, i, pix, x_len );
92  }
93  exit(0);
94 }
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_debug(int on_off)
Definition: rle_getrow.c:293
#define MAX_PIXELS
Definition: getfb.c:15
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_getrow(rle_hdr *the_hdr, scanline)
Definition: rle_getrow.c:333
int ymin
Definition: rle.h:100
const char * cmd
Definition: rle.h:133
int xmax
Definition: rle.h:100
#define RLE_CLR_BIT(glob, bit)
Definition: rle.h:124
int ymax
Definition: rle.h:100
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