Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Macros | Functions
rle_getskip.c File Reference
#include "rle.h"
#include "rle_code.h"
Include dependency graph for rle_getskip.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_getskip (rle_hdr *the_hdr)
 

Macro Definition Documentation

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

Definition at line 39 of file rle_getskip.c.

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

Definition at line 38 of file rle_getskip.c.

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

Definition at line 37 of file rle_getskip.c.

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

Definition at line 32 of file rle_getskip.c.

Function Documentation

unsigned int rle_getskip ( rle_hdr the_hdr)

Definition at line 57 of file rle_getskip.c.

59 {
60  unsigned char inst[2];
61  register FILE *infile = the_hdr->rle_file;
62  int nc;
63 
64  /* Add in vertical skip from last scanline */
65  if ( the_hdr->priv.get.vert_skip > 0)
66  the_hdr->priv.get.scan_y += the_hdr->priv.get.vert_skip;
67  the_hdr->priv.get.vert_skip = 0;
68 
69  if ( the_hdr->priv.get.is_eof )
70  return 32768; /* too big for 16 bits, signal EOF */
71 
72  /* Otherwise, read and interpret instructions until a skipLines
73  * instruction is encountered.
74  */
75  for (;;)
76  {
77  inst[0] = getc( infile );
78  inst[1] = getc( infile );
79  if ( feof(infile) )
80  {
81  the_hdr->priv.get.is_eof = 1;
82  break; /* <--- one of the exits */
83  }
84 
85  switch( OPCODE(inst) )
86  {
87  case RSkipLinesOp:
88  if ( LONGP(inst) )
89  {
90  VAXSHORT( the_hdr->priv.get.vert_skip, infile );
91  }
92  else
93  the_hdr->priv.get.vert_skip = DATUM(inst);
94  break; /* need to break for() here, too */
95 
96  case RSetColorOp:
97  /* No-op here. */
98  break;
99 
100  case RSkipPixelsOp:
101  if ( LONGP(inst) )
102  {
103  (void)getc( infile );
104  (void)getc( infile );
105  }
106  break;
107 
108  case RByteDataOp:
109  if ( LONGP(inst) )
110  {
111  VAXSHORT( nc, infile );
112  }
113  else
114  nc = DATUM(inst);
115  nc++;
116  if ( the_hdr->priv.get.is_seek )
117  fseek( infile, ((nc + 1) / 2) * 2, 1 );
118  else
119  {
120  register int ii;
121  for ( ii = ((nc + 1) / 2) * 2; ii > 0; ii-- )
122  (void) getc( infile ); /* discard it */
123  }
124 
125  break;
126 
127  case RRunDataOp:
128  if ( LONGP(inst) )
129  {
130  (void)getc( infile );
131  (void)getc( infile );
132  }
133  (void)getc( infile );
134  (void)getc( infile );
135  break;
136 
137  case REOFOp:
138  the_hdr->priv.get.is_eof = 1;
139  break;
140 
141  default:
142  fprintf( stderr,
143  "%s: rle_getskip: Unrecognized opcode: %d, reading %s\n",
144  the_hdr->cmd, OPCODE(inst), the_hdr->file_name );
145  exit(1);
146  }
147  if ( OPCODE(inst) == REOFOp )
148  break; /* <--- the other loop exit */
149  if ( OPCODE(inst) == RSkipLinesOp )
150  break;
151  }
152 
153  /* Return the number of the NEXT scanline. */
154  the_hdr->priv.get.scan_y +=
155  the_hdr->priv.get.vert_skip;
156  the_hdr->priv.get.vert_skip = 0;
157 
158  if ( the_hdr->priv.get.is_eof )
159  return 32768; /* too big for 16 bits, signal EOF */
160  else
161  return the_hdr->priv.get.scan_y;
162 }
#define RSetColorOp
Definition: rle_code.h:38
#define RRunDataOp
Definition: rle_code.h:41
#define DATUM(inst)
Definition: rle_getskip.c:39
#define LONGP(inst)
Definition: rle_getskip.c:38
#define VAXSHORT(var, fp)
Definition: rle_getskip.c:32
#define RSkipLinesOp
Definition: rle_code.h:37
struct rle_hdr::@0::@1 get
#define REOFOp
Definition: rle_code.h:42
union rle_hdr::@0 priv
const char * cmd
Definition: rle.h:133
#define RSkipPixelsOp
Definition: rle_code.h:39
#define OPCODE(inst)
Definition: rle_getskip.c:37
FILE * infile
Definition: targatorle.c:102
const char * file_name
Definition: rle.h:134
FILE * rle_file
Definition: rle.h:114
#define RByteDataOp
Definition: rle_code.h:40