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

Go to the source code of this file.

Macros

#define TRUE   1 /* Logical constants. */
 
#define FALSE   0
 
#define MAX(i, j)    ( (i) > (j) ? (i) : (j) )
 
#define RASTERSIZE_LIM   1023
 
#define COLMAP_OFFSET   8
 
#define MONOCHROME_MODE   1
 
#define EIGHT_BIT_COLOR_MODE   2
 
#define DMAP(v, x, y)   (errN[v]>dm16[x][y] ? divN[v] + 1 : divN[v])
 

Typedefs

typedef char * string
 
typedef int boolean
 
typedef float single
 
typedef single starbase_color_type[3]
 
typedef unsigned char starbase_color_index_type
 

Functions

 main (int argc, argv)
 
 init_gamma_map ()
 
 init_8_bit_color_map ()
 
 init_monochrome_color_map (int ncolors)
 
 put_line_8 (int y)
 
 put_line_mono (int y)
 
 direct_setup ()
 
 write_color_map (int star_fd)
 
 write_scanline (int y)
 

Variables

unsigned char scanline [4][1023]
 
unsigned char * rows [4]
 
starbase_color_index_type dest_pixels [1023]
 
int dm16 [16][16]
 
int errN [256]
 
int divN [256]
 
int gammamap [256]
 
float gam = 2.0
 
string infname = ((void *)0)
 
rle_hdr hdr
 
boolean linear_flag = 0
 
boolean gamma_flag = 0
 
boolean dummy
 
string display_name = "/dev/crt"
 
string driver_name = "hp98705"
 
boolean pos_flag
 
int pic_x = 0
 
int pic_y = 0
 
int dev_color_map_size
 
int put_mode
 
int n_colmap_colors
 
static starbase_color_type colmap [216]
 
float r_base_color = 1.0
 
float g_base_color = 1.0
 
float b_base_color = 1.0
 
int picture_fd
 

Macro Definition Documentation

#define COLMAP_OFFSET   8

Definition at line 45 of file getbob.c.

#define DMAP (   v,
  x,
  y 
)    (errN[v]>dm16[x][y] ? divN[v] + 1 : divN[v])

Definition at line 240 of file getbob.c.

#define EIGHT_BIT_COLOR_MODE   2

Definition at line 49 of file getbob.c.

#define FALSE   0

Definition at line 33 of file getbob.c.

#define MAX (   i,
 
)    ( (i) > (j) ? (i) : (j) )

Definition at line 35 of file getbob.c.

#define MONOCHROME_MODE   1

Definition at line 48 of file getbob.c.

#define RASTERSIZE_LIM   1023

Definition at line 42 of file getbob.c.

#define TRUE   1 /* Logical constants. */

Definition at line 32 of file getbob.c.

Typedef Documentation

typedef int boolean

Definition at line 31 of file getbob.c.

typedef float single

Definition at line 34 of file getbob.c.

typedef unsigned char starbase_color_index_type

Definition at line 40 of file getbob.c.

typedef single starbase_color_type[3]

Definition at line 39 of file getbob.c.

typedef char* string

Definition at line 30 of file getbob.c.

Function Documentation

direct_setup ( )

Definition at line 399 of file getbob.c.

References hdr, pic_x, pic_y, picture_fd, put_mode, rle_hdr::xmax, and rle_hdr::ymax.

400 {
401  single p_lim[2][3], res[3], p1[3], p2[3];
402  int map_size;
403  int dev_xmax, dev_ymax;
404 
405  picture_fd = gopen( display_name, OUTDEV, driver_name, 0 );
406  if ( picture_fd < 0 )
407  {
408  fprintf( stderr, "Can't open device.\n" );
409  exit( 1 );
410  }
411 
412  /* Find out info about this device. */
413  inquire_sizes( picture_fd, p_lim, res, p1, p2, &map_size );
414 
415  if ( map_size >= 256 )
416  {
419  }
420  else
421  {
424  }
425 
427 
428  /* Set the screen limits in pixels so we can use starbase in a device
429  * independent way.
430  *
431  * It is assumed that the p_lim values returned by inquire_sizes are the
432  * lower left screen coordinates in (float) pixels and the upper right
433  * screen coordinates in (float) pixels. It is also assumed that the
434  * range of values in x and y coordinates are given from 0 to some
435  * positive maximum value.
436  */
437  dev_xmax = MAX( p_lim[0][0], p_lim[1][0] );
438  dev_ymax = MAX( p_lim[0][1], p_lim[1][1] );
439 
440  if ( hdr.xmax > dev_xmax )
441  hdr.xmax = dev_xmax;
442  if ( hdr.ymax > dev_ymax )
443  hdr.ymax = dev_ymax;
444 
445  /* Make sure that the specified lower left hand corner of the image
446  * will keep the image in bounds.
447  */
448  if ( ( hdr.xmax + pic_x ) > dev_xmax )
449  pic_x = dev_xmax - hdr.xmax;
450  if ( ( hdr.ymax + pic_y ) > dev_ymax )
451  pic_y = dev_ymax - hdr.ymax;
452 
453  /* Set to use the whole display surface. */
454  mapping_mode( picture_fd, DISTORT );
455 
456  /* Set to address the pixels in a device independent way. */
457  vdc_extent( picture_fd, 0.0, 0.0, 0.0,
458  (single)dev_xmax, (single)dev_ymax, 0.0 );
459  clip_rectangle( picture_fd, 0.0, (single)dev_xmax, 0.0, (single)dev_ymax );
460 
461 }
int pic_x
Definition: getbob.c:85
int put_mode
Definition: getbob.c:92
string driver_name
Definition: getbob.c:81
#define MAX(i, j)
Definition: getbob.c:35
int picture_fd
Definition: getbob.c:104
#define MONOCHROME_MODE
Definition: getbob.c:48
init_8_bit_color_map()
Definition: getbob.c:187
float single
Definition: getbob.c:34
int xmax
Definition: rle.h:100
string display_name
Definition: getbob.c:80
#define EIGHT_BIT_COLOR_MODE
Definition: getbob.c:49
int ymax
Definition: rle.h:100
init_monochrome_color_map(int ncolors)
Definition: getbob.c:217
#define COLMAP_OFFSET
Definition: getbob.c:45
rle_hdr hdr
Definition: getbob.c:71
int pic_y
Definition: getbob.c:86
write_color_map(int star_fd)
Definition: getbob.c:472
init_8_bit_color_map ( )

Definition at line 187 of file getbob.c.

References colmap, divN, dm16, errN, make_square(), and n_colmap_colors.

188 {
189  int i;
190 
191  /*
192  * Set up the color map entries. We will use 216 colors.
193  */
194  n_colmap_colors = 216; /* Fill out the global. */
195 
196  for ( i = 0; i < n_colmap_colors; i++ )
197  {
198  colmap[i][0] = ((i%6) * 51) / 255.0;
199  colmap[i][1] = (((i/6)%6) * 51) / 255.0;
200  colmap[i][2] = (((i/36)%6) * 51) / 255.0;
201  }
202 
203  make_square( 6.0, divN, errN, dm16 );
204 }
int errN[256]
Definition: getbob.c:61
static starbase_color_type colmap[216]
Definition: getbob.c:96
int divN[256]
Definition: getbob.c:61
void make_square(double N, int divN[256], int modN[256], int magic[16][16])
int i
Definition: rletorla.c:82
int n_colmap_colors
Definition: getbob.c:95
int dm16[16][16]
Definition: getbob.c:58

Here is the call graph for this function:

init_gamma_map ( )

Definition at line 165 of file getbob.c.

References gam, gammamap, and linear_flag.

166 {
167  int i;
168 
169  /* Compute a gamma correction map. */
170  for ( i = 0; i < 256; i++ )
171  {
172  if ( ! linear_flag )
173  {
174  gammamap[i] = (int)(0.5 + 255 * pow( i / 255.0, 1.0/gam ));
175  }
176  }
177 }
float gam
Definition: getbob.c:65
int gammamap[256]
Definition: getbob.c:64
int
Definition: getami.c:848
boolean linear_flag
Definition: getbob.c:74
int i
Definition: rletorla.c:82
init_monochrome_color_map ( int  ncolors)

Definition at line 217 of file getbob.c.

219 {
220  int k;
221  int color_val;
222 
223  /* Set up the color map entries into a single grayscale ramp. */
224  n_colmap_colors = ncolors; /* Fill out the global. */
225 
226  for ( k = 0; k < ncolors; k++ )
227  {
228  color_val = (k * 255) / (ncolors - 1);
229  colmap[k][0] = (color_val * r_base_color) / 255.;
230  colmap[k][1] = (color_val * g_base_color) / 255.;
231  colmap[k][2] = (color_val * b_base_color) / 255.;
232  }
233 
234  /* Make dithering tables. */
235  make_square( (double)ncolors, divN, errN, dm16 );
236 }
int errN[256]
Definition: getbob.c:61
static starbase_color_type colmap[216]
Definition: getbob.c:96
float r_base_color
Definition: getbob.c:99
int divN[256]
Definition: getbob.c:61
float b_base_color
Definition: getbob.c:101
void make_square(double N, int divN[256], int modN[256], int magic[16][16])
float g_base_color
Definition: getbob.c:100
int n_colmap_colors
Definition: getbob.c:95
int dm16[16][16]
Definition: getbob.c:58
main ( int  argc,
argv   
)

Definition at line 107 of file getbob.c.

109 {
110  int i;
111  int row;
112  boolean bw_flag = FALSE;
113 
114  /* sbrk( 1000000 ); */
115 
116  /* Get command line arguments. */
117  if ( scanargs( argc, argv,
118  "getbob l%- g%-gamma!f p%-pos!d!d d%-display!s x%-driver!s file%s",
120  &pos_flag, &pic_x, &pic_y,
121  &dummy, &display_name,
122  &dummy, &driver_name,
123  &infname ) == 0 )
124  exit( 1 );
125 
126  /* Open file for reading, if no filename was specified, we'll read
127  * from stdin.
128  */
129  hdr = *rle_hdr_init( (rle_hdr *)NULL );
130  rle_names( &hdr, cmd_name( argv ), infname, 0 );
132  /* Read header information from rle file. */
133  rle_get_setup_ok( &hdr, NULL, NULL );
134 
135  RLE_CLR_BIT( hdr, RLE_ALPHA ); /* No alpha channel */
136 
137  /* Set up gamma correction tables if need be. */
138  init_gamma_map();
139 
140  direct_setup();
141 
142  /* Set up rows to point to our copy of the scanline */
143  for ( i= 0; i < 4; i++ )
144  rows[i] = scanline[i];
145 
146  /* Get the scanlines. */
147  for (i = hdr.ymin; i < hdr.ymax; i++)
148  {
149  rle_getrow( &hdr, rows );
150  if ( put_mode == MONOCHROME_MODE )
151  put_line_mono( i );
152  else
153  put_line_8( i );
154  }
155 }
int pic_x
Definition: getbob.c:85
put_line_mono(int y)
Definition: getbob.c:322
init_gamma_map()
Definition: getbob.c:165
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
int put_mode
Definition: getbob.c:92
string driver_name
Definition: getbob.c:81
float gam
Definition: getbob.c:65
direct_setup()
Definition: getbob.c:399
#define MONOCHROME_MODE
Definition: getbob.c:48
int ymin
Definition: rle.h:100
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
Definition: rle.h:96
string display_name
Definition: getbob.c:80
unsigned char scanline[4][1023]
Definition: getbob.c:52
#define RLE_CLR_BIT(glob, bit)
Definition: rle.h:124
boolean gamma_flag
Definition: getbob.c:75
int ymax
Definition: rle.h:100
#define FALSE
Definition: getbob.c:33
boolean linear_flag
Definition: getbob.c:74
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)
rle_hdr hdr
Definition: getbob.c:71
char * cmd_name(char **argv)
Definition: cmd_name.c:31
int row
Definition: rle.c:27
boolean dummy
Definition: getbob.c:77
boolean pos_flag
Definition: getbob.c:84
put_line_8(int y)
Definition: getbob.c:248
int bw_flag
Definition: getap.c:89
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[])
unsigned char * rows[4]
Definition: getbob.c:52
FILE * rle_file
Definition: rle.h:114
int pic_y
Definition: getbob.c:86
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
put_line_8 ( int  y)

Definition at line 248 of file getbob.c.

250 {
251  register unsigned char *r, *g, *b;
252  register int i, dither_col, dither_row;
253  register starbase_color_index_type *dest_pixel_ptr;
254  int xmax = hdr.xmax;
255  int g_offset, b_offset;
256 
257 
258  /* In case we have less than 3 color channels. */
259  for (i = 2; i >= hdr.ncolors; i--)
260  bcopy(rows[0], rows[i], hdr.xmax - hdr.xmin);
261 
262  dither_row = y % 16;
263  dither_col = 0;
264  r = rows[0];
265  g = rows[1];
266  b = rows[2];
267  dest_pixel_ptr = &dest_pixels[0];
268 
269  /* Linear map. */
270  if ( linear_flag )
271  for ( i = 0; i < xmax; i++, r++, g++, b++,
272  dither_col = ((dither_col + 1) & 15),
273  dest_pixel_ptr++ )
274  *dest_pixel_ptr =
275  DMAP( *r, dither_col, dither_row ) +
276  DMAP( *g, dither_col, dither_row ) * 6 +
277  DMAP( *b, dither_col, dither_row ) * 36 +
279 
280  /* RLE file with color map. */
281  else if ( hdr.ncmap )
282  {
283  /* Compute offsets to the green and blue sections of the color map. */
284  g_offset = 1 << hdr.cmaplen;
285  b_offset = 2 * g_offset;
286 
287  for ( i = 0; i < xmax; i++, r++, g++, b++,
288  dither_col = ((dither_col + 1) & 15),
289  dest_pixel_ptr++ )
290  *dest_pixel_ptr =
291  DMAP( hdr.cmap[*r], dither_col, dither_row ) +
292  DMAP( hdr.cmap[*g + g_offset],
293  dither_col, dither_row ) * 6 +
294  DMAP( hdr.cmap[*b + b_offset],
295  dither_col, dither_row ) * 36 +
297  }
298 
299  /* Gamma correction is the default. */
300  else
301  for ( i = 0; i < xmax; i++, r++, g++, b++,
302  dither_col = ((dither_col + 1) & 15),
303  dest_pixel_ptr++ )
304  *dest_pixel_ptr =
305  DMAP( gammamap[*r], dither_col, dither_row ) +
306  DMAP( gammamap[*g], dither_col, dither_row ) * 6 +
307  DMAP( gammamap[*b], dither_col, dither_row ) * 36 +
309 
310  /* Write this scanline to the device. */
311  write_scanline( y );
312 }
static unsigned char g
Definition: getami.c:692
int xmin
Definition: rle.h:100
static unsigned char r
Definition: getami.c:692
starbase_color_index_type dest_pixels[1023]
Definition: getbob.c:55
rle_map * cmap
Definition: rle.h:112
static int y
Definition: getami.c:691
unsigned char starbase_color_index_type
Definition: getbob.c:40
static unsigned char b
Definition: getami.c:692
int xmax
Definition: rle.h:100
int gammamap[256]
Definition: getbob.c:64
int ncmap
Definition: rle.h:100
boolean linear_flag
Definition: getbob.c:74
int cmaplen
Definition: rle.h:100
int i
Definition: rletorla.c:82
#define COLMAP_OFFSET
Definition: getbob.c:45
rle_hdr hdr
Definition: getbob.c:71
write_scanline(int y)
Definition: getbob.c:488
#define DMAP(v, x, y)
Definition: getbob.c:240
unsigned char * rows[4]
Definition: getbob.c:52
int ncolors
Definition: rle.h:100
put_line_mono ( int  y)

Definition at line 322 of file getbob.c.

324 {
325  register unsigned char *r, *g, *b;
326  register int i, dither_col, dither_row;
327  register starbase_color_index_type *dest_pixel_ptr;
328  int xmax = hdr.xmax;
329  int bw_val;
330  int g_offset, b_offset;
331 
332  /* In case we have less than 3 color channels. */
333  for (i = 2; i >= hdr.ncolors; i--)
334  bcopy(rows[0], rows[i], hdr.xmax - hdr.xmin);
335 
336  dither_row = y % 16;
337  dither_col = 0;
338  r = rows[0];
339  g = rows[1];
340  b = rows[2];
341  dest_pixel_ptr = &dest_pixels[0];
342 
343  /* Linear map. */
344  if ( linear_flag )
345  for ( i = 0; i < xmax; i++, r++, g++, b++,
346  dither_col = ((dither_col + 1) & 15),
347  dest_pixel_ptr++ )
348  {
349  bw_val =
350  (35*(*r) + 55*(*g) + 10*(*b)) / 100;
351  *dest_pixel_ptr =
352  DMAP( bw_val, dither_col, dither_row ) + COLMAP_OFFSET;
353  }
354 
355  /* RLE file with color map. */
356  else if ( hdr.ncmap )
357  {
358  /* Compute offsets to the green and blue sections of the color map. */
359  g_offset = 1 << hdr.cmaplen;
360  b_offset = 2 * g_offset;
361 
362  for ( i = 0; i < xmax; i++, r++, g++, b++,
363  dither_col = ((dither_col + 1) & 15),
364  dest_pixel_ptr++ )
365  {
366  bw_val =
367  ( 35 * hdr.cmap[*r] +
368  55 * hdr.cmap[*g + g_offset] +
369  10 * hdr.cmap[*b + b_offset] ) / 100;
370  *dest_pixel_ptr =
371  DMAP( bw_val, dither_col, dither_row ) + COLMAP_OFFSET;
372  }
373  }
374 
375  /* Gamma correction is the default. */
376  else
377  for ( i = 0; i < xmax; i++, r++, g++, b++,
378  dither_col = ((dither_col + 1) & 15),
379  dest_pixel_ptr++ )
380  {
381  bw_val =
382  (35*gammamap[*r] + 55*gammamap[*g] + 10*gammamap[*b]) / 100;
383  *dest_pixel_ptr =
384  DMAP( bw_val, dither_col, dither_row ) + COLMAP_OFFSET;
385  }
386 
387  /* Write this scanline to the device. */
388  write_scanline( y );
389 }
static unsigned char g
Definition: getami.c:692
int xmin
Definition: rle.h:100
static unsigned char r
Definition: getami.c:692
starbase_color_index_type dest_pixels[1023]
Definition: getbob.c:55
rle_map * cmap
Definition: rle.h:112
static int y
Definition: getami.c:691
unsigned char starbase_color_index_type
Definition: getbob.c:40
static unsigned char b
Definition: getami.c:692
int xmax
Definition: rle.h:100
int gammamap[256]
Definition: getbob.c:64
int ncmap
Definition: rle.h:100
boolean linear_flag
Definition: getbob.c:74
int cmaplen
Definition: rle.h:100
int i
Definition: rletorla.c:82
#define COLMAP_OFFSET
Definition: getbob.c:45
rle_hdr hdr
Definition: getbob.c:71
write_scanline(int y)
Definition: getbob.c:488
#define DMAP(v, x, y)
Definition: getbob.c:240
unsigned char * rows[4]
Definition: getbob.c:52
int ncolors
Definition: rle.h:100
write_color_map ( int  star_fd)

Definition at line 472 of file getbob.c.

474 {
475  define_color_table( star_fd, COLMAP_OFFSET, n_colmap_colors, colmap );
476 
477 }
static starbase_color_type colmap[216]
Definition: getbob.c:96
#define COLMAP_OFFSET
Definition: getbob.c:45
int n_colmap_colors
Definition: getbob.c:95
write_scanline ( int  y)

Definition at line 488 of file getbob.c.

490 {
491  block_write( picture_fd,
492  (single)(hdr.xmin + pic_x), (single)(y + pic_y),
493  hdr.xmax - hdr.xmin, 1,
494  dest_pixels, FALSE );
495 }
int pic_x
Definition: getbob.c:85
int xmin
Definition: rle.h:100
int picture_fd
Definition: getbob.c:104
starbase_color_index_type dest_pixels[1023]
Definition: getbob.c:55
float single
Definition: getbob.c:34
static int y
Definition: getami.c:691
int xmax
Definition: rle.h:100
#define FALSE
Definition: getbob.c:33
rle_hdr hdr
Definition: getbob.c:71
int pic_y
Definition: getbob.c:86

Variable Documentation

float b_base_color = 1.0

Definition at line 101 of file getbob.c.

starbase_color_type colmap[216]
static

Definition at line 96 of file getbob.c.

Referenced by init_8_bit_color_map().

starbase_color_index_type dest_pixels[1023]

Definition at line 55 of file getbob.c.

int dev_color_map_size

Definition at line 89 of file getbob.c.

string display_name = "/dev/crt"

Definition at line 80 of file getbob.c.

int divN[256]

Definition at line 61 of file getbob.c.

int dm16[16][16]

Definition at line 58 of file getbob.c.

string driver_name = "hp98705"

Definition at line 81 of file getbob.c.

boolean dummy

Definition at line 77 of file getbob.c.

int errN[256]
float g_base_color = 1.0

Definition at line 100 of file getbob.c.

float gam = 2.0

Definition at line 65 of file getbob.c.

Referenced by borrow_color_map(), init_gamma_map(), and window_color_map().

boolean gamma_flag = 0

Definition at line 75 of file getbob.c.

int gammamap[256]

Definition at line 64 of file getbob.c.

rle_hdr hdr

Definition at line 71 of file getbob.c.

string infname = ((void *)0)

Definition at line 68 of file getbob.c.

boolean linear_flag = 0

Definition at line 74 of file getbob.c.

Referenced by init_gamma_map().

int n_colmap_colors

Definition at line 95 of file getbob.c.

Referenced by init_8_bit_color_map().

int pic_x = 0

Definition at line 85 of file getbob.c.

Referenced by direct_setup().

int pic_y = 0

Definition at line 86 of file getbob.c.

Referenced by direct_setup().

int picture_fd

Definition at line 104 of file getbob.c.

boolean pos_flag

Definition at line 84 of file getbob.c.

int put_mode

Definition at line 92 of file getbob.c.

Referenced by direct_setup().

float r_base_color = 1.0

Definition at line 99 of file getbob.c.

unsigned char * rows[4]

Definition at line 52 of file getbob.c.

unsigned char scanline[4][1023]

Definition at line 52 of file getbob.c.