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

Go to the source code of this file.

Macros

#define VAXSHORT(var, fp)   { var = fgetc(fp)&0xFF; var |= (fgetc(fp)) << 8; }
 
#define OPCODE(inst)   (inst[0] & ~LONG)
 
#define LONGP(inst)   (inst[0] & LONG)
 
#define DATUM(inst)   (inst[1] & 0xff) /* Make sure it's unsigned. */
 

Functions

unsigned int rle_getraw (rle_hdr *the_hdr, scanraw, nraw)
 
void rle_freeraw (rle_hdr *the_hdr, scanraw, nraw)
 

Variables

static char rcs_ident [] = "$Id: rle_getraw.c,v 3.0.1.1 1992/01/28 18:20:36 spencer Exp spencer $"
 

Macro Definition Documentation

#define DATUM (   inst)    (inst[1] & 0xff) /* Make sure it's unsigned. */

Definition at line 46 of file rle_getraw.c.

#define LONGP (   inst)    (inst[0] & LONG)

Definition at line 45 of file rle_getraw.c.

#define OPCODE (   inst)    (inst[0] & ~LONG)

Definition at line 44 of file rle_getraw.c.

#define VAXSHORT (   var,
  fp 
)    { var = fgetc(fp)&0xFF; var |= (fgetc(fp)) << 8; }

Definition at line 39 of file rle_getraw.c.

Function Documentation

void rle_freeraw ( rle_hdr the_hdr,
scanraw  ,
nraw   
)

Definition at line 268 of file rle_getraw.c.

272 {
273  int c, i;
274  register rle_op * raw_p;
275 
276  for ( c = -the_hdr->alpha; c < the_hdr->ncolors; c++ )
277  if ( RLE_BIT( *the_hdr, c ) )
278  for ( i = nraw[c], raw_p = scanraw[c]; i > 0; i--, raw_p++ )
279  if ( raw_p->opcode == RByteDataOp )
280  {
281  if ( raw_p->u.pixels )
282  free( raw_p->u.pixels );
283  else
284  fprintf( stderr,
285  "%s(%s): rle_freeraw given NULL pixel pointer, %d[%d].\n",
286  the_hdr->cmd, the_hdr->file_name,
287  c, nraw[c] - i );
288  raw_p->u.pixels = NULL;
289  }
290 }
int opcode
Definition: rle_raw.h:49
const char * cmd
Definition: rle.h:133
rle_pixel * pixels
Definition: rle_raw.h:53
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
union rle_op::@7 u
const char * file_name
Definition: rle.h:134
Definition: rle_raw.h:47
#define RByteDataOp
Definition: rle_code.h:40
#define RLE_BIT(glob, bit)
Definition: rle.h:126
unsigned int rle_getraw ( rle_hdr the_hdr,
scanraw  ,
nraw   
)

Definition at line 78 of file rle_getraw.c.

82 {
83  register int channel;
84  register rle_op * rawp = NULL;
85  FILE *infile = the_hdr->rle_file;
86  char inst[2];
87  int scan_x = the_hdr->xmin;
88  register int was_data;
89  short word, long_data, nc, been_some = 0;
90 
91  /* Add in vertical skip from last scanline */
92  if ( the_hdr->priv.get.vert_skip > 0 )
93  the_hdr->priv.get.scan_y += the_hdr->priv.get.vert_skip;
94 
95  /* Set run lengths to 0 */
96  for ( channel = (the_hdr->alpha ? -1 : 0);
97  channel < the_hdr->ncolors;
98  channel++ )
99  if ( RLE_BIT( *the_hdr, channel ) )
100  nraw[channel] = 0;
101  channel = 0;
102 
103  if ( the_hdr->priv.get.is_eof )
104  return 32768; /* too big for 16 bits, signal EOF */
105 
106  /* Otherwise, read and interpret instructions until a skipLines
107  * instruction is encountered.
108  */
109  for (was_data = 0;;)
110  {
111  inst[0] = getc( infile );
112  inst[1] = getc( infile );
113  if ( feof(infile) )
114  {
115  the_hdr->priv.get.is_eof = 1;
116  break; /* <--- one of the exits */
117  }
118 
119  switch( OPCODE(inst) )
120  {
121  case RSkipLinesOp:
122  was_data = 1;
123  if ( LONGP(inst) )
124  {
125  VAXSHORT( the_hdr->priv.get.vert_skip, infile );
126  }
127  else
128  the_hdr->priv.get.vert_skip = DATUM(inst);
129  break; /* need to break for() here, too */
130 
131  case RSetColorOp:
132  was_data = 1;
133  channel = DATUM(inst); /* select color channel */
134  if ( channel == 255 )
135  channel = -1;
136  scan_x = the_hdr->xmin;
137  if ( RLE_BIT( *the_hdr, channel ) )
138  rawp = scanraw[channel];
139  else
140  rawp = NULL;
141  break;
142 
143  case RSkipPixelsOp:
144  was_data = 1;
145  if ( LONGP(inst) )
146  {
147  VAXSHORT( long_data, infile );
148  scan_x += long_data;
149  }
150  else
151  {
152  scan_x += DATUM(inst);
153  }
154  break;
155 
156  case RByteDataOp:
157  was_data = 1;
158  if ( LONGP(inst) )
159  {
160  VAXSHORT( nc, infile );
161  }
162  else
163  nc = DATUM(inst);
164  nc++;
165  if ( rawp != NULL )
166  {
167  rawp->opcode = RByteDataOp;
168  rawp->xloc = scan_x;
169  rawp->length = nc;
170  rawp->u.pixels = (rle_pixel *)malloc( (unsigned)nc );
171  fread( (char *)rawp->u.pixels, 1, nc, infile );
172  if ( nc & 1 )
173  (void)getc( infile ); /* throw away odd byte */
174  rawp++;
175  nraw[channel]++;
176  }
177  else
178  if ( the_hdr->priv.get.is_seek )
179  fseek( infile, ((nc + 1) / 2) * 2, 1 );
180  else
181  {
182  register int ii;
183  for ( ii = ((nc + 1) / 2) * 2; ii > 0; ii-- )
184  (void) getc( infile ); /* discard it */
185  }
186 
187  scan_x += nc;
188  been_some = 1;
189  break;
190 
191  case RRunDataOp:
192  was_data = 1;
193  if ( LONGP(inst) )
194  {
195  VAXSHORT( nc, infile );
196  }
197  else
198  nc = DATUM(inst);
199 
200  nc++;
201  VAXSHORT( word, infile );
202  if ( rawp != NULL )
203  {
204  rawp->opcode = RRunDataOp;
205  rawp->xloc = scan_x;
206  rawp->length = nc;
207  rawp->u.run_val = word;
208  rawp++;
209  nraw[channel]++;
210  }
211  scan_x += nc;
212  been_some = 1;
213  break;
214 
215  case REOFOp:
216  the_hdr->priv.get.is_eof = 1;
217  break;
218 
219  default:
220  fprintf( stderr,
221  "%s: rle_getraw: Unrecognized opcode: %d, reading %s\n",
222  the_hdr->cmd, OPCODE(inst), the_hdr->file_name );
223  exit(1);
224  }
225  if ( OPCODE(inst) == REOFOp )
226  break; /* <--- the other loop exit */
227  if ( OPCODE(inst) == RSkipLinesOp )
228  {
229  if ( been_some )
230  break; /* <--- the other loop exit */
231  else
232  /* No data on that scanline, so move up to this scanline */
233  the_hdr->priv.get.scan_y +=
234  the_hdr->priv.get.vert_skip;
235  }
236  }
237 
238  /* If at top of image, skip any remaining. */
239  if ( the_hdr->priv.get.scan_y >= the_hdr->ymax )
240  {
241  int y = the_hdr->priv.get.scan_y;
242  while ( rle_getskip( the_hdr ) != 32768 )
243  ;
244  return y;
245  }
246 
247  /* Return current Y value */
248  return (was_data == 0) ? 32768 : the_hdr->priv.get.scan_y;
249 }
#define RSetColorOp
Definition: rle_code.h:38
#define RRunDataOp
Definition: rle_code.h:41
int xmin
Definition: rle.h:100
int length
Definition: rle_raw.h:51
int opcode
Definition: rle_raw.h:49
#define RSkipLinesOp
Definition: rle_code.h:37
struct rle_hdr::@0::@1 get
static int y
Definition: getami.c:691
int run_val
Definition: rle_raw.h:54
#define REOFOp
Definition: rle_code.h:42
int xloc
Definition: rle_raw.h:50
union rle_hdr::@0 priv
const char * cmd
Definition: rle.h:133
#define DATUM(inst)
Definition: rle_getraw.c:46
#define OPCODE(inst)
Definition: rle_getraw.c:44
#define RSkipPixelsOp
Definition: rle_code.h:39
unsigned int rle_getskip(rle_hdr *the_hdr)
Definition: rle_getskip.c:57
#define LONGP(inst)
Definition: rle_getraw.c:45
FILE * infile
Definition: targatorle.c:102
int ymax
Definition: rle.h:100
rle_pixel * pixels
Definition: rle_raw.h:53
unsigned char rle_pixel
Definition: rle.h:56
void * malloc()
int alpha
Definition: rle.h:100
union rle_op::@7 u
const char * file_name
Definition: rle.h:134
#define VAXSHORT(var, fp)
Definition: rle_getraw.c:39
Definition: rle_raw.h:47
FILE * rle_file
Definition: rle.h:114
#define RByteDataOp
Definition: rle_code.h:40
#define RLE_BIT(glob, bit)
Definition: rle.h:126

Variable Documentation

char rcs_ident[] = "$Id: rle_getraw.c,v 3.0.1.1 1992/01/28 18:20:36 spencer Exp spencer $"
static

Definition at line 31 of file rle_getraw.c.