Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
rle_putraw.c
Go to the documentation of this file.
1 /*
2  * This software is copyrighted as noted below. It may be freely copied,
3  * modified, and redistributed, provided that the copyright notice is
4  * preserved on all copies.
5  *
6  * There is no warranty or other guarantee of fitness for this software,
7  * it is provided solely "as is". Bug reports or fixes may be sent
8  * to the author, who may or may not act on them as he desires.
9  *
10  * You may not include this software in a program or other software product
11  * without supplying the source, or without informing the end-user that the
12  * source is available for no extra charge.
13  *
14  * If you modify this software, you should include a notice giving the
15  * name of the person performing the modification, the date of modification,
16  * and the reason for such modification.
17  *
18  * Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
19  * to have all "void" functions so declared.
20  */
21 /*
22  * rle_putraw.c - Generate RLE from "raw" form.
23  *
24  * Author: Spencer W. Thomas
25  * Computer Science Dept.
26  * University of Utah
27  * Date: Tue Jul 8 1986
28  * Copyright (c) 1986, Spencer W. Thomas
29  */
30 #ifndef lint
31 static char rcs_ident[] = "$Id: rle_putraw.c,v 3.0.1.1 1992/01/28 18:25:24 spencer Exp $";
32 #endif
33 
34 #include <stdio.h>
35 #include "rle_put.h"
36 #include "rle.h"
37 #include "rle_raw.h"
38 
39 /*****************************************************************
40  * TAG( rle_putraw )
41  *
42  * Put "raw" RLE data to an output file.
43  * Inputs:
44  * nraw: Array of lengths of the rows. One per color channel.
45  * rows: array of pointers to individual channels of rle data.
46  * Rows is assumed to have have the_hdr->ncolors (plus
47  * a [-1] element if alpha is being saved) pointers to
48  * arrays of rle_op. The length of each array is given
49  * by the corresponding nraw element.
50  * the_hdr: Header struct describing this image.
51  *
52  * Outputs:
53  * Writes RLE data to output file.
54  * Assumptions:
55  * [None]
56  * Algorithm:
57  * [None]
58  */
59 void
61 rle_op **scanraw;
62 int *nraw;
63 rle_hdr *the_hdr;
64 {
65  register int channel;
66  int scan_x,
67  i,
68  n_op;
69  register rle_op * scan_r;
70 
71  for ( channel = (the_hdr->alpha ? -1 : 0);
72  channel < the_hdr->ncolors;
73  channel++ )
74  {
75  if ( ! RLE_BIT( *the_hdr, channel ) || nraw[channel] == 0 )
76  {
77  continue;
78  }
79 
80  /* If really data on this scanline, skip to here */
81  if ( the_hdr->priv.put.nblank > 0 )
82  {
83  SkipBlankLines( the_hdr->priv.put.nblank );
84  the_hdr->priv.put.nblank = 0;
85  }
86 
87  SetColor( channel );
88  n_op = nraw[channel] - 1;
89  scan_x = the_hdr->xmin;
90  for ( i = 0, scan_r = scanraw[channel]; i <= n_op; i++, scan_r++ )
91  {
92  if ( scan_r->xloc > scan_x )
93  SkipPixels( scan_r->xloc - scan_x, 0,
94  i > 0 && (scan_r - 1)->opcode == RRunDataOp );
95  scan_x = scan_r->xloc + scan_r->length;
96  switch( scan_r->opcode )
97  {
98  case RRunDataOp:
99  putrun( scan_r->u.run_val, scan_r->length,
100  i < n_op && scan_x == (scan_r + 1)->xloc );
101  break;
102 
103  case RByteDataOp:
104  putdata( scan_r->u.pixels, scan_r->length );
105  break;
106  }
107  }
108  if ( scan_x <= the_hdr->xmax )
109  SkipPixels( the_hdr->xmax - scan_x,
110  1,
111  i > 0 && (scan_r - 1)->opcode == RRunDataOp );
112  if ( channel != the_hdr->ncolors - 1 )
113  NewScanLine( 0 );
114  }
115 
116  the_hdr->priv.put.nblank++; /* increment to next scanline */
117  /* Flush each scanline */
118 /* fflush( the_hdr->rle_file );*/
119 }
#define RRunDataOp
Definition: rle_code.h:41
int xmin
Definition: rle.h:100
#define SkipPixels(n, l, r)
Definition: rle_put.h:78
int length
Definition: rle_raw.h:51
int opcode
Definition: rle_raw.h:49
void rle_putraw(rle_op **scanraw, int *nraw, rle_hdr *the_hdr)
Definition: rle_putraw.c:60
#define putrun(val, len, f)
Definition: rle_put.h:81
#define SetColor(c)
Definition: rle_put.h:77
int xloc
Definition: rle_raw.h:50
int xmax
Definition: rle.h:100
#define SkipBlankLines(n)
Definition: rle_put.h:76
static char rcs_ident[]
Definition: rle_putraw.c:31
#define NewScanLine(flag)
Definition: rle_put.h:79
#define putdata(buf, len)
Definition: rle_put.h:80
int alpha
Definition: rle.h:100
int ncolors
Definition: rle.h:100
#define RByteDataOp
Definition: rle_code.h:40
#define RLE_BIT(glob, bit)
Definition: rle.h:126