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

Go to the source code of this file.

Macros

#define UPPER   255 /* anything bigger ain't a byte */
 
#define put16(a)    (putc((a)&0xff,rle_fd),putc(((a)>>8)&0xff,rle_fd))
 
#define mk_short_1(oper, a1)
 
#define mk_short_2(oper, a1, a2)
 
#define mk_long_1(oper, a1)
 
#define mk_long_2(oper, a1, a2)
 
#define mk_inst_1(oper, a1)
 
#define mk_inst_2(oper, a1, a2)
 
#define RSkipLines(n)    mk_inst_1(RSkipLinesOp,(n))
 
#define RSetColor(c)    mk_short_1(RSetColorOp,(c))
 
#define RSkipPixels(n)    mk_inst_1(RSkipPixelsOp,(n))
 
#define RNewLine   RSkipLines(1)
 
#define RByteData(n)    mk_inst_1(RByteDataOp,n)
 
#define RRunData(n, c)    mk_inst_2(RRunDataOp,(n),(c))
 
#define REOF   mk_inst_1(REOFOp,0)
 

Functions

char * vax_pshort ()
 
void RunSetup (rle_hdr *the_hdr)
 
void RunSkipBlankLines (int nblank, rle_hdr *the_hdr)
 
void RunSetColor (int c, rle_hdr *the_hdr)
 
void RunSkipPixels (int nskip, int last, int wasrun, rle_hdr *the_hdr)
 
void RunNewScanLine (int flag, rle_hdr *the_hdr)
 
void Runputdata (rle_pixel *buf, int n, rle_hdr *the_hdr)
 
void Runputrun (int color, int n, int last, rle_hdr *the_hdr)
 
void RunputEof (rle_hdr *the_hdr)
 

Macro Definition Documentation

#define mk_inst_1 (   oper,
  a1 
)
Value:
/* one argument inst */ \
if (a1>UPPER) (mk_long_1(oper,a1)); else (mk_short_1(oper,a1))
#define mk_short_1(oper, a1)
Definition: Runput.c:107
#define UPPER
Definition: Runput.c:98
#define mk_long_1(oper, a1)
Definition: Runput.c:114

Definition at line 124 of file Runput.c.

#define mk_inst_2 (   oper,
  a1,
  a2 
)
Value:
/* two argument inst */ \
if (a1>UPPER) (mk_long_2(oper,a1,a2)); else (mk_short_2(oper,a1,a2))
#define UPPER
Definition: Runput.c:98
#define mk_short_2(oper, a1, a2)
Definition: Runput.c:110
#define mk_long_2(oper, a1, a2)
Definition: Runput.c:117

Definition at line 127 of file Runput.c.

#define mk_long_1 (   oper,
  a1 
)
Value:
/* one argument long */ \
putc((char)(LONG|oper),rle_fd), putc('\0', rle_fd), put16(a1)
#define LONG
Definition: rle_code.h:36
#define put16(a)
Definition: Runput.c:104

Definition at line 114 of file Runput.c.

#define mk_long_2 (   oper,
  a1,
  a2 
)
Value:
/* two argument long */ \
putc((char)(LONG|oper),rle_fd), putc('\0', rle_fd), \
put16(a1), put16(a2)
#define LONG
Definition: rle_code.h:36
#define put16(a)
Definition: Runput.c:104

Definition at line 117 of file Runput.c.

#define mk_short_1 (   oper,
  a1 
)
Value:
/* one argument short */ \
putc(oper,rle_fd), putc((char)a1,rle_fd)

Definition at line 107 of file Runput.c.

#define mk_short_2 (   oper,
  a1,
  a2 
)
Value:
/* two argument short */ \
putc(oper,rle_fd), putc((char)a1,rle_fd), put16(a2)
#define put16(a)
Definition: Runput.c:104

Definition at line 110 of file Runput.c.

#define put16 (   a)    (putc((a)&0xff,rle_fd),putc(((a)>>8)&0xff,rle_fd))

Definition at line 104 of file Runput.c.

#define RByteData (   n)    mk_inst_1(RByteDataOp,n)

Definition at line 143 of file Runput.c.

#define REOF   mk_inst_1(REOFOp,0)

Definition at line 155 of file Runput.c.

#define RNewLine   RSkipLines(1)

Definition at line 141 of file Runput.c.

#define RRunData (   n,
 
)    mk_inst_2(RRunDataOp,(n),(c))

Definition at line 150 of file Runput.c.

#define RSetColor (   c)    mk_short_1(RSetColorOp,(c))

Definition at line 135 of file Runput.c.

#define RSkipLines (   n)    mk_inst_1(RSkipLinesOp,(n))

Definition at line 133 of file Runput.c.

#define RSkipPixels (   n)    mk_inst_1(RSkipPixelsOp,(n))

Definition at line 139 of file Runput.c.

#define UPPER   255 /* anything bigger ain't a byte */

Definition at line 98 of file Runput.c.

Function Documentation

void RunNewScanLine ( int  flag,
rle_hdr the_hdr 
)

Definition at line 312 of file Runput.c.

315 {
316  register FILE * rle_fd = the_hdr->rle_file;
317  if (flag)
318  {
319  RNewLine;
320  }
321 }
#define RNewLine
Definition: Runput.c:141
FILE * rle_file
Definition: rle.h:114
void Runputdata ( rle_pixel buf,
int  n,
rle_hdr the_hdr 
)

Definition at line 328 of file Runput.c.

332 {
333  register FILE * rle_fd = the_hdr->rle_file;
334  if (n == 0)
335  return;
336 
337  RByteData(n-1);
338  fwrite((char *)buf, n, 1, rle_fd);
339  if ( n & 1 )
340  putc( 0, rle_fd );
341 }
static char buf[4096 +1]
Definition: into.c:46
#define RByteData(n)
Definition: Runput.c:143
FILE * rle_file
Definition: rle.h:114
void RunputEof ( rle_hdr the_hdr)

Definition at line 364 of file Runput.c.

366 {
367  register FILE * rle_fd = the_hdr->rle_file;
368  REOF;
369 }
#define REOF
Definition: Runput.c:155
FILE * rle_file
Definition: rle.h:114
void Runputrun ( int  color,
int  n,
int  last,
rle_hdr the_hdr 
)

Definition at line 350 of file Runput.c.

353 {
354  register FILE * rle_fd = the_hdr->rle_file;
355  RRunData(n-1,color);
356 }
#define RRunData(n, c)
Definition: Runput.c:150
FILE * rle_file
Definition: rle.h:114
void RunSetColor ( int  c,
rle_hdr the_hdr 
)

Definition at line 280 of file Runput.c.

283 {
284  register FILE * rle_fd = the_hdr->rle_file;
285  RSetColor(c);
286 }
FILE * rle_file
Definition: rle.h:114
#define RSetColor(c)
Definition: Runput.c:135
void RunSetup ( rle_hdr the_hdr)

Definition at line 165 of file Runput.c.

167 {
168  struct XtndRsetup setup;
169  register FILE * rle_fd = the_hdr->rle_file;
170 
171  put16( RLE_MAGIC );
172 
173  if ( the_hdr->background == 2 )
174  setup.h_flags = H_CLEARFIRST;
175  else if ( the_hdr->background == 0 )
176  setup.h_flags = H_NO_BACKGROUND;
177  else
178  setup.h_flags = 0;
179  if ( the_hdr->alpha )
180  setup.h_flags |= H_ALPHA;
181  if ( the_hdr->comments != NULL && *the_hdr->comments != NULL )
182  setup.h_flags |= H_COMMENT;
183 
184  setup.h_ncolors = the_hdr->ncolors;
185  setup.h_pixelbits = 8; /* Grinnell dependent */
186  if ( the_hdr->ncmap > 0 && the_hdr->cmap == NULL )
187  {
188  fprintf( stderr,
189  "%s: Color map of size %d*%d specified, but not supplied, writing %s\n",
190  the_hdr->cmd, the_hdr->ncmap, (1 << the_hdr->cmaplen),
191  the_hdr->file_name );
192  the_hdr->ncmap = 0;
193  }
194  setup.h_cmaplen = the_hdr->cmaplen; /* log2 of color map size */
195  setup.h_ncmap = the_hdr->ncmap; /* no of color channels */
196  vax_pshort(setup.hc_xpos,the_hdr->xmin);
197  vax_pshort(setup.hc_ypos,the_hdr->ymin);
198  vax_pshort(setup.hc_xlen,the_hdr->xmax - the_hdr->xmin + 1);
199  vax_pshort(setup.hc_ylen,the_hdr->ymax - the_hdr->ymin + 1);
200  fwrite((char *)&setup, SETUPSIZE, 1, rle_fd);
201  if ( the_hdr->background != 0 )
202  {
203  register int i;
204  register rle_pixel *background =
205  (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) );
206  register int *bg_color;
207  /*
208  * If even number of bg color bytes, put out one more to get to
209  * 16 bit boundary.
210  */
211  bg_color = the_hdr->bg_color;
212  for ( i = 0; i < the_hdr->ncolors; i++ )
213  background[i] = *bg_color++;
214  /* Extra byte, if written, should be 0. */
215  background[i] = 0;
216  fwrite((char *)background, (the_hdr->ncolors / 2) * 2 + 1, 1, rle_fd);
217  free( background );
218  }
219  else
220  putc( '\0', rle_fd );
221  if (the_hdr->ncmap > 0)
222  {
223  /* Big-endian machines are harder */
224  register int i, nmap = (1 << the_hdr->cmaplen) *
225  the_hdr->ncmap;
226  register char *h_cmap = (char *)malloc( nmap * 2 );
227  if ( h_cmap == NULL )
228  {
229  fprintf( stderr,
230  "%s: Malloc failed for color map of size %d, writing %s\n",
231  the_hdr->cmd, nmap, the_hdr->file_name );
232  exit( 1 );
233  }
234  for ( i = 0; i < nmap; i++ )
235  vax_pshort( &h_cmap[i*2], the_hdr->cmap[i] );
236 
237  fwrite( h_cmap, nmap, 2, rle_fd );
238  free( h_cmap );
239  }
240 
241  /* Now write out comments if given */
242  if ( setup.h_flags & H_COMMENT )
243  {
244  int comlen;
245  register CONST_DECL char ** com_p;
246 
247  /* Get the total length of comments */
248  comlen = 0;
249  for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ )
250  comlen += 1 + strlen( *com_p );
251 
252  put16( comlen );
253  for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ )
254  fwrite( *com_p, 1, strlen( *com_p ) + 1, rle_fd );
255 
256  if ( comlen & 1 ) /* if odd length, round up */
257  putc( '\0', rle_fd );
258  }
259 }
int xmin
Definition: rle.h:100
const char ** comments
Definition: rle.h:113
#define H_COMMENT
Definition: rle_code.h:47
#define RLE_MAGIC
Definition: rle_code.h:67
rle_map * cmap
Definition: rle.h:112
int * bg_color
Definition: rle.h:100
#define H_ALPHA
Definition: rle_code.h:46
int ymin
Definition: rle.h:100
#define H_CLEARFIRST
Definition: rle_code.h:44
static int bg_color[3]
Definition: rle_global.c:64
const char * cmd
Definition: rle.h:133
int xmax
Definition: rle.h:100
#define CONST_DECL
Definition: rle_config.h:42
int background
Definition: rle.h:100
int ncmap
Definition: rle.h:100
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
void * malloc()
int cmaplen
Definition: rle.h:100
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
int background
Definition: getgmr.c:18
#define SETUPSIZE
Definition: rle_code.h:61
#define put16(a)
Definition: Runput.c:104
const char * file_name
Definition: rle.h:134
#define H_NO_BACKGROUND
Definition: rle_code.h:45
char * vax_pshort()
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
void RunSkipBlankLines ( int  nblank,
rle_hdr the_hdr 
)

Definition at line 266 of file Runput.c.

269 {
270  register FILE * rle_fd = the_hdr->rle_file;
271  RSkipLines(nblank);
272 }
#define RSkipLines(n)
Definition: Runput.c:133
FILE * rle_file
Definition: rle.h:114
void RunSkipPixels ( int  nskip,
int  last,
int  wasrun,
rle_hdr the_hdr 
)

Definition at line 295 of file Runput.c.

298 {
299  register FILE * rle_fd = the_hdr->rle_file;
300  if (! last && nskip > 0)
301  {
302  RSkipPixels(nskip);
303  }
304 }
#define RSkipPixels(n)
Definition: Runput.c:139
FILE * rle_file
Definition: rle.h:114
char* vax_pshort ( )