Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
getren.c
Go to the documentation of this file.
1 /*
2  * getren.c - getren - Display images on the HP Renaissance (98720A)
3  *
4  * Author: John W. Peterson & Glenn McMinn
5  * Computer Science Dept.
6  * University of Utah
7  * Date: Tue Aug 18 1987
8  * Copyright (c) 1987, John W. Peterson
9  *
10  * TODO:
11  * - Should warn you if configuration is not sufficient (< 24 bits)
12  */
13 
14 #define MIN(a,b) ( a<b ? a : b)
15 #include <stdio.h>
16 #include <starbase.c.h>
17 #include "rle.h"
18 
19 int display_flag = FALSE;
20 int driver_flag = FALSE;
21 char *display_name = "/dev/crt";
22 char *driver_name = "hp98721";
23 
24 #define RASTERHEIGHT 1024 /* Calling inquire_sizes is just too tedious */
25 
27 int argc; char *argv[];
28 {
29  int fildes;
30  int x_len, y_len, x_off = 0, y_off = 0;
31  int i, j, map_offset ;
32  rle_hdr hdr;
33  unsigned char **scan;
34  char * filename = NULL;
35  int over_flag = 0;
36  int pos_flag = 0;
37  float tmp;
38  float colors[256][3];
39  gescape_arg arg1, arg2;
40 
41  if (! scanargs( argc, argv,
42  "% pP%-xpos!dypos!d O%- d%-display!s x%-driver!s infile%s",
43  &pos_flag, &x_off, &y_off, &over_flag,
46  &filename ))
47  exit( -1 );
48 
49  hdr = *rle_hdr_init( (rle_hdr *)NULL );
50  rle_names( &hdr, cmd_name( argv ), filename, 0 );
51 
52  if (! over_flag)
53  over_flag = INIT;
54 
55  if (( fildes = gopen(display_name, OUTDEV,
56  driver_name, over_flag )) < 0)
57  fprintf(stderr, "%s: can't open %s\n", hdr.cmd, display_name);
58 
59  hdr.rle_file = rle_open_f(hdr.cmd, filename, "r");
60 
61  rle_get_setup_ok( &hdr, NULL, NULL );
62 
63  /* So we see the whole FB. */
64  clip_indicator( fildes, CLIP_OFF );
65 
66  arg1.i[0] = FALSE;
67  gescape( fildes, SWITCH_SEMAPHORE, &arg1, &arg2 );
68 
69  /* This version assumes a full 24-bit machine */
70  shade_mode( fildes, CMAP_FULL, 0 );
71 
72  if ( hdr.ncmap ) /* Use colormap in file */
73  {
74  map_offset = 1 << hdr.cmaplen;
75  if (hdr.ncmap == 3)
76  {
77  for (i = 0; i < 256; i++)
78  {
79  colors[i][0] = (float) ((hdr.cmap[i] >>8) & 0xFF)
80  / 255.0;
81  colors[i][1] = (float) ((hdr.cmap[i+map_offset] >>8)
82  & 0xFF) / 255.0;
83  colors[i][2] = (float) ((hdr.cmap[i+2*map_offset]>>8)
84  & 0xFF) / 255.0;
85  }
86  }
87  else
88  if (hdr.ncmap == 1)
89  {
90  for (i = 0; i < 256; i++)
91  {
92  tmp = (float) ((hdr.cmap[i] >> 8) * 0xFF);
93  colors[i][0] = tmp;
94  colors[i][1] = tmp;
95  colors[i][2] = tmp;
96  }
97  }
98  else
99  {
100  fprintf(stderr, "%s: Sorry, don't grock %d channel color maps\n",
101  hdr.cmd, hdr.ncmap);
102  exit(-1);
103  }
104  }
105  else
106  {
107  /* Set the color map to default */
108  for (i = 0; i < 256; i++)
109  {
110  tmp = (float) i / 255.0;
111  colors[i][0] = tmp;
112  colors[i][1] = tmp;
113  colors[i][2] = tmp;
114  }
115  }
116  define_color_table( fildes, 0, 256, colors );
117 
118  x_len = hdr.xmax - hdr.xmin + 1;
119  y_len = hdr.ymax - hdr.ymin + 1;
120  if (pos_flag)
121  {
122  if (pos_flag == 1) /* -P, incremental position */
123  {
124  x_off = hdr.xmin + x_off;
125  y_off += hdr.ymin;
126  }
127  }
128  else
129  {
130  x_off = hdr.xmin;
131  y_off = hdr.ymin;
132  }
133 
134  y_off = RASTERHEIGHT - y_off - 1; /* Invert origin */
135 
136  /* This gets rid of the left margin slop in the scanline. */
137  hdr.xmax -= hdr.xmin;
138  hdr.xmin = 0;
139 
140  if (rle_row_alloc( &hdr, &scan ) < 0)
141  RLE_CHECK_ALLOC( hdr.cmd, 0, "image memory" );
142 
143  /* Display each scanline. */
144 
145  y_len = MIN( RASTERHEIGHT-1, y_len );
146  for ( i = 0; i < y_len ; i ++)
147  {
148  rle_getrow(&hdr, scan );
149 
150  for (j = RLE_RED; j < hdr.ncolors; j++)
151  {
152  /* HP numbers channels backwards from URT */
153  bank_switch( fildes, 2-j, 0 );
154  dcblock_write( fildes, x_off, y_off - i,
155  x_len, 1, scan[j], 0 );
156  }
157 
158  /* KLUDGE for black and white. */
159  while (j <= RLE_BLUE)
160  {
161  bank_switch( fildes, 2-j, 1 );
162  dcblock_write( fildes, x_off, y_off - i,
163  x_len, 1, scan[0], 0 );
164  j++;
165  }
166  }
167 }
FILE * rle_open_f(char *prog_name, char *file_name, char *mode)
Definition: rle_open_f.c:216
#define MIN(x, y)
Definition: rletopaint.c:53
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
char * cmd_name(char **argv)
Definition: cmd_name.c:31
#define RASTERHEIGHT
Definition: getren.c:24
void main(int argc, char **argv)
Definition: aliastorle.c:121
rle_map * cmap
Definition: rle.h:112
int rle_row_alloc(rle_hdr *the_hdr, rle_pixel ***scanp)
Definition: rle_row_alc.c:56
int rle_getrow(rle_hdr *the_hdr, scanline)
Definition: rle_getrow.c:333
int ymin
Definition: rle.h:100
#define RLE_BLUE
Definition: rle.h:64
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
const char * cmd
Definition: rle.h:133
#define RLE_RED
Definition: rle.h:62
int xmax
Definition: rle.h:100
char * driver_name
Definition: read98721.c:43
int display_flag
Definition: read98721.c:38
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
Definition: rle_getrow.c:254
char * display_name
Definition: read98721.c:42
int ncmap
Definition: rle.h:100
int ymax
Definition: rle.h:100
int cmaplen
Definition: rle.h:100
int driver_flag
Definition: read98721.c:39
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
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86