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

Go to the source code of this file.

Data Structures

struct  rle_hdr
 

Macros

#define RLE_RED   0 /* Red channel traditionally here. */
 
#define RLE_GREEN   1 /* Green channel traditionally here. */
 
#define RLE_BLUE   2 /* Blue channel traditionally here. */
 
#define RLE_ALPHA   -1 /* Alpha channel here. */
 
#define RLE_SUCCESS   0
 
#define RLE_NOT_RLE   -1
 
#define RLE_NO_SPACE   -2
 
#define RLE_EMPTY   -3
 
#define RLE_EOF   -4
 
#define RLE_INIT_MAGIC   0x6487ED51L
 
#define RLE_CHECK_ALLOC(pgm, ptr, name)   ( !(ptr) ? rle_alloc_error( pgm, name ) : 0 )
 
#define RLE_SET_BIT(glob, bit)   ((glob).bits[((bit)&0xff)/8] |= (1<<((bit)&0x7)))
 
#define RLE_CLR_BIT(glob, bit)   ((glob).bits[((bit)&0xff)/8] &= ~(1<<((bit)&0x7)))
 
#define RLE_BIT(glob, bit)   ((glob).bits[((bit)&0xff)/8] & (1<<((bit)&0x7)))
 

Typedefs

typedef unsigned char rle_pixel
 
typedef unsigned short rle_map
 
typedef struct rle_hdr rle_hdr
 

Enumerations

enum  rle_dispatch { NO_DISPATCH = -1, RUN_DISPATCH = 0 }
 

Functions

int rle_alloc_error (const char *pgm, const char *name)
 
int rle_get_error (int code, const char *pgmname, const char *fname)
 
void rle_debug (int on_off)
 
int rle_get_setup (rle_hdr *the_hdr)
 
void rle_get_setup_ok (rle_hdr *the_hdr, const char *prog_name, const char *file_name)
 
int rle_getrow (rle_hdr *the_hdr, rle_pixel *scanline[])
 
unsigned int rle_getskip (rle_hdr *the_hdr)
 
void rle_names (rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
 
rle_hdrrle_hdr_cp (rle_hdr *from_hdr, rle_hdr *to_hdr)
 
rle_hdrrle_hdr_init (rle_hdr *the_hdr)
 
void rle_hdr_clear (rle_hdr *the_hdr)
 
void rgb_to_bw (rle_pixel *red_row, rle_pixel *green_row, rle_pixel *blue_row, rle_pixel *bw_row, int rowlen)
 
void rle_puteof (rle_hdr *the_hdr)
 
void rle_putrow (rle_pixel *rows[], int rowlen, rle_hdr *the_hdr)
 
void rle_put_init (rle_hdr *the_hdr)
 
void rle_put_setup (rle_hdr *the_hdr)
 
void rle_skiprow (rle_hdr *the_hdr, int nrow)
 
void rle_cp (rle_hdr *in_hdr, rle_hdr *out_hdr)
 
int rle_row_alloc (rle_hdr *the_hdr, rle_pixel ***scanp)
 
void rle_row_free (rle_hdr *the_hdr, rle_pixel **scanp)
 
rle_pixel ** buildmap (rle_hdr *the_hdr, int minmap, double orig_gamma, double new_gamma)
 
char * rle_getcom (const char *name, rle_hdr *the_hdr)
 
const char * rle_delcom (const char *name, rle_hdr *the_hdr)
 
const char * rle_putcom (const char *value, rle_hdr *the_hdr)
 
void bwdithermap (int levels, double gamma, int bwmap[], int divN[256], int modN[256], int magic[16][16])
 
int ditherbw (int x, int y, int val, int divN[256], int modN[256], int magic[16][16])
 
int dithergb (int x, int y, int r, int g, int b, int divN[256], int modN[256], int magic[16][16])
 
void dithermap (int levels, double gamma, int rgbmap[][3], int divN[256], int modN[256], int magic[16][16])
 
void make_square (double N, int divN[256], int modN[256], int magic[16][16])
 
void float_to_exp (int count, float *floats, rle_pixel *pixels)
 
FILE * rle_open_f (const char *prog_name, const char *f_name, const char *mode)
 
FILE * rle_open_f_noexit (const char *prog_name, const char *f_name, const char *mode)
 
void rle_close_f (FILE *fd)
 
int colorquant (rle_pixel *red, rle_pixel *green, rle_pixel *blue, unsigned long pixels, rle_pixel *colormap[3], int colors, int bits, rle_pixel *rgbmap, int fast, int otherimages)
 
void rle_addhist (char *argv[], rle_hdr *in_hdr, rle_hdr *out_hdr)
 
char * cmd_name (char **argv)
 
int scanargs (int argc, char **argv, const char *format,...)
 
void hilbert_c2i (int n, int m, int a[], long int *r)
 
void hilbert_i2c (int n, int m, long int r, int a[])
 
void inv_cmap (int colors, unsigned char *colormap[3], int bits, unsigned long *dist_buf, unsigned char *rgbmap)
 

Variables

rle_hdr rle_dflt_hdr
 

Macro Definition Documentation

#define RLE_ALPHA   -1 /* Alpha channel here. */

Definition at line 65 of file rle.h.

#define RLE_BIT (   glob,
  bit 
)    ((glob).bits[((bit)&0xff)/8] & (1<<((bit)&0x7)))

Definition at line 126 of file rle.h.

#define RLE_BLUE   2 /* Blue channel traditionally here. */

Definition at line 64 of file rle.h.

#define RLE_CHECK_ALLOC (   pgm,
  ptr,
  name 
)    ( !(ptr) ? rle_alloc_error( pgm, name ) : 0 )

Definition at line 86 of file rle.h.

#define RLE_CLR_BIT (   glob,
  bit 
)    ((glob).bits[((bit)&0xff)/8] &= ~(1<<((bit)&0x7)))

Definition at line 124 of file rle.h.

#define RLE_EMPTY   -3

Definition at line 73 of file rle.h.

#define RLE_EOF   -4

Definition at line 74 of file rle.h.

#define RLE_GREEN   1 /* Green channel traditionally here. */

Definition at line 63 of file rle.h.

#define RLE_INIT_MAGIC   0x6487ED51L

Definition at line 79 of file rle.h.

#define RLE_NO_SPACE   -2

Definition at line 72 of file rle.h.

#define RLE_NOT_RLE   -1

Definition at line 71 of file rle.h.

#define RLE_RED   0 /* Red channel traditionally here. */

Definition at line 62 of file rle.h.

#define RLE_SET_BIT (   glob,
  bit 
)    ((glob).bits[((bit)&0xff)/8] |= (1<<((bit)&0x7)))

Definition at line 122 of file rle.h.

#define RLE_SUCCESS   0

Definition at line 70 of file rle.h.

Typedef Documentation

typedef struct rle_hdr rle_hdr
typedef unsigned short rle_map

Definition at line 57 of file rle.h.

typedef unsigned char rle_pixel

Definition at line 56 of file rle.h.

Enumeration Type Documentation

Enumerator
NO_DISPATCH 
RUN_DISPATCH 

Definition at line 44 of file rle.h.

44  {
45  NO_DISPATCH = -1,
46  RUN_DISPATCH = 0
47 };

Function Documentation

rle_pixel** buildmap ( rle_hdr the_hdr,
int  minmap,
double  orig_gamma,
double  new_gamma 
)

Definition at line 56 of file buildmap.c.

Referenced by find_most_used().

61 {
62  rle_pixel ** cmap, * gammap;
63  double gamma;
64  register int i, j;
65  int maplen, cmaplen, nmap;
66 
67  if ( the_hdr->ncmap == 0 ) /* make identity map */
68  {
69  nmap = (minmap < the_hdr->ncolors) ? the_hdr->ncolors : minmap;
70  cmap = (rle_pixel **)malloc( nmap * sizeof(rle_pixel *) );
71  cmap[0] = (rle_pixel *)malloc( nmap * 256 * sizeof(rle_pixel) );
72  for ( j = 1; j < nmap; j++ )
73  cmap[j] = cmap[j-1] + 256;
74  for ( i = 0; i < 256; i++ )
75  for ( j = 0; j < nmap; j++ )
76  cmap[j][i] = i;
77  maplen = 256;
78  }
79  else /* make map from the_hdr */
80  {
81  /* Map is at least 256 long */
82  cmaplen = (1 << the_hdr->cmaplen);
83  if ( cmaplen < 256 )
84  maplen = 256;
85  else
86  maplen = cmaplen;
87 
88  /* Nmap is max( minmap, the_hdr->ncmap, the_hdr->ncolors ). */
89  nmap = minmap;
90  if ( nmap < the_hdr->ncmap )
91  nmap = the_hdr->ncmap;
92  if ( nmap < the_hdr->ncolors )
93  nmap = the_hdr->ncolors;
94 
95  /* Allocate memory for the map and secondary pointers. */
96  cmap = (rle_pixel **)malloc( nmap * sizeof(rle_pixel *) );
97  cmap[0] = (rle_pixel *)malloc( nmap * maplen * sizeof(rle_pixel) );
98  for ( i = 1; i < nmap; i++ )
99  cmap[i] = cmap[0] + i * maplen;
100 
101  /* Fill it in. */
102  for ( i = 0; i < maplen; i++ )
103  {
104  for ( j = 0; j < the_hdr->ncmap; j++ )
105  if ( i < cmaplen )
106  cmap[j][i] = the_hdr->cmap[j*cmaplen + i] >> 8;
107  else
108  cmap[j][i] = i;
109  for ( ; j < nmap; j++ )
110  cmap[j][i] = cmap[j-1][i];
111  }
112  }
113 
114  /* Gamma compensate if requested */
115  if ( orig_gamma == 0 )
116  {
117  char *v;
118  if ( (v = rle_getcom( "image_gamma", the_hdr )) != NULL )
119  {
120  orig_gamma = atof( v );
121  /* Protect against bogus information */
122  if ( orig_gamma == 0.0 )
123  orig_gamma = 1.0;
124  else
125  orig_gamma = 1.0 / orig_gamma;
126  }
127  else if ( (v = rle_getcom( "display_gamma", the_hdr )) != NULL)
128  {
129  orig_gamma = atof( v );
130  /* Protect */
131  if ( orig_gamma == 0.0 )
132  orig_gamma = 1.0;
133  }
134  else
135  orig_gamma = 1.0;
136  }
137 
138  /* Now, compensate for the gamma of the new display, too. */
139  if ( new_gamma != 0.0 )
140  gamma = orig_gamma / new_gamma;
141  else
142  gamma = orig_gamma;
143 
144  if ( gamma != 1.0 )
145  {
146  gammap = (rle_pixel *)malloc( 256 * sizeof(rle_pixel) );
147  for ( i = 0; i < 256; i++ )
148  gammap[i] = (int)(0.5 + 255.0 * pow( i / 255.0, gamma ));
149  for ( i = 0; i < nmap; i++ )
150  for ( j = 0; j < maplen; j++ )
151  cmap[i][j] = gammap[cmap[i][j]];
152  free( gammap );
153  }
154 
155  return cmap;
156 }
char * rle_getcom(const char *name, rle_hdr *the_hdr)
int maplen
Definition: rletoppm.c:61
rle_map * cmap
Definition: rle.h:112
void gammap()
int gamma(int x, float gamma_value)
Definition: gamma.c:24
int ncmap
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
rle_pixel ** cmap
Definition: get4d.c:47
int ncolors
Definition: rle.h:100

Here is the caller graph for this function:

void bwdithermap ( int  levels,
double  gamma,
int  bwmap[],
int  divN[256],
int  modN[256],
int  magic[16][16] 
)
char* cmd_name ( char **  argv)

Definition at line 31 of file cmd_name.c.

33 {
34  register char *cp, *a;
35 
36  /* Be paranoid. */
37  if ( !argv || !(a = *argv) )
38  return no_name;
39 
40  /* Find end of file name. */
41  for ( cp = a; *cp; cp++ )
42  ;
43 
44  /* Find last / or beginning of command name. */
45  for ( cp--; *cp != '/' && cp > a; cp-- )
46  ;
47 
48  /* If it's a /, skip it. */
49  if ( *cp == '/' )
50  cp++;
51 
52  return cp;
53 }
static char no_name[]
Definition: cmd_name.c:28
int colorquant ( rle_pixel red,
rle_pixel green,
rle_pixel blue,
unsigned long  pixels,
rle_pixel colormap[3],
int  colors,
int  bits,
rle_pixel rgbmap,
int  fast,
int  otherimages 
)
int ditherbw ( int  x,
int  y,
int  val,
int  divN[256],
int  modN[256],
int  magic[16][16] 
)
int dithergb ( int  x,
int  y,
int  r,
int  g,
int  b,
int  divN[256],
int  modN[256],
int  magic[16][16] 
)
void dithermap ( int  levels,
double  gamma,
int  rgbmap[][3],
int  divN[256],
int  modN[256],
int  magic[16][16] 
)
void float_to_exp ( int  count,
float *  floats,
rle_pixel pixels 
)

Definition at line 42 of file float_to_exp.c.

46 {
47  register int i;
48  int expon, max_exp = -2000;
49  float * fptr = floats;
50  double f_exp;
51 
52  /* Find largest exponent */
53  /* Use "Block normalization":
54  * ExpScan[x] is largest exponent of the three
55  * color components. Red/Grn/BluScan[1..3] are the
56  * normalized color components.
57  */
58 
59  for (i = 0; i < count; i++)
60  {
61  frexp( *fptr++, &expon );
62  max_exp = (expon > max_exp) ? expon : max_exp;
63  }
64 
65  /* Don't over/underflow */
66  if (max_exp > 128) max_exp = 128;
67  else
68  if (max_exp < -127) max_exp = -127;
69 
70  f_exp = ldexp( 256.0, -max_exp );
71 
72  fptr = floats;
73  for( i = 0; i < count; i++ ) /* Extra casts for broken HP compiler */
74  *pixels++ = (rle_pixel) ((int)(*fptr++ * f_exp));
75 
76  /* Excess 127 exponent */
77  *pixels = (rle_pixel) (max_exp + 127);
78 }
int
Definition: getami.c:848
unsigned char rle_pixel
Definition: rle.h:56
int i
Definition: rletorla.c:82
void hilbert_c2i ( int  n,
int  m,
int  a[],
long int r 
)
void hilbert_i2c ( int  n,
int  m,
long int  r,
int  a[] 
)
void inv_cmap ( int  colors,
unsigned char *  colormap[3],
int  bits,
unsigned long *  dist_buf,
unsigned char *  rgbmap 
)
void make_square ( double  N,
int  divN[256],
int  modN[256],
int  magic[16][16] 
)
void rgb_to_bw ( rle_pixel red_row,
rle_pixel green_row,
rle_pixel blue_row,
rle_pixel bw_row,
int  rowlen 
)

Definition at line 680 of file rle_putrow.c.

686 {
687  register int x, bw;
688 
689  for (x=0; x<rowlen; x++)
690  {
691  /* 68000 won't store float > 127 into byte? */
692  /* HP compiler blows it */
693  bw = 0.5 + .30*red_row[x] + .59*green_row[x] + .11*blue_row[x];
694  bw_row[x] = bw;
695  }
696 }
static int bw
Definition: getami.c:106
static int x
Definition: getami.c:691
void rle_addhist ( char *  argv[],
rle_hdr in_hdr,
rle_hdr out_hdr 
)
int rle_alloc_error ( const char *  pgm,
const char *  name 
)
void rle_close_f ( FILE *  fd)

Definition at line 244 of file rle_open_f.c.

246 {
247  if ( fd == NULL || fd == stdin || fd == stdout )
248  return;
249  else
250  fclose( fd );
251 }
FILE * fd
Definition: getfb.h:18
void rle_cp ( rle_hdr in_hdr,
rle_hdr out_hdr 
)

Definition at line 69 of file rle_cp.c.

72 {
73  register FILE *infile = in_hdr->rle_file;
74  register FILE *outfile = the_hdr->rle_file;
75  char inst[2];
76  short nc, buflen;
77  char *buffer;
78 
79  /* Add in vertical skip from last scanline */
80  if ( in_hdr->priv.get.vert_skip > 0 )
81  {
82  in_hdr->priv.get.scan_y += in_hdr->priv.get.vert_skip;
83  if ( in_hdr->priv.get.vert_skip > 1 )
84  rle_skiprow( the_hdr, in_hdr->priv.get.vert_skip - 1 );
85  }
86 
87  if ( in_hdr->priv.get.is_eof )
88  {
90  return;
91  }
92 
93  if ( the_hdr->priv.put.nblank > 0 )
94  {
95  SkipBlankLines( the_hdr->priv.put.nblank );
96  the_hdr->priv.put.nblank = 0;
97  }
98 
99  /* Allocate memory for reading byte data. */
100  buflen = in_hdr->xmax - in_hdr->xmin + 2;
101  buffer = (char *)malloc( buflen );
102 
103  /* Otherwise, read and write instructions until an EOF
104  * instruction is encountered.
105  */
106  for (;;)
107  {
108  inst[0] = getc( infile );
109  inst[1] = getc( infile );
110 
111  /* Don't 'put' the instruction until we know what it is. */
112  if ( feof(infile) )
113  {
114  in_hdr->priv.get.is_eof = 1;
115  rle_puteof( the_hdr );
116  break; /* <--- one of the exits */
117  }
118 
119  switch( OPCODE(inst) )
120  {
121  case RSkipLinesOp:
122  putc( inst[0], outfile );
123  putc( inst[1], outfile );
124  if ( LONGP(inst) )
125  {
126  putc( getc( infile ), outfile );
127  putc( getc( infile ), outfile );
128  }
129  break; /* need to break for() here, too */
130 
131  case RSetColorOp:
132  putc( inst[0], outfile );
133  putc( inst[1], outfile );
134  break;
135 
136  case RSkipPixelsOp:
137  putc( inst[0], outfile );
138  putc( inst[1], outfile );
139  if ( LONGP(inst) )
140  {
141  putc( getc( infile ), outfile );
142  putc( getc( infile ), outfile );
143  }
144  break;
145 
146  case RByteDataOp:
147  putc( inst[0], outfile );
148  putc( inst[1], outfile );
149  if ( LONGP(inst) )
150  {
151  VAXSHORT( nc, infile );
152  put16( nc );
153  }
154  else
155  nc = DATUM(inst);
156  nc++;
157  nc = 2 * ((nc + 1) / 2);
158  /* Total paranoia. nc should never be > buflen. */
159  while ( nc > buflen )
160  {
161  fread( buffer, nc, 1, infile );
162  fwrite( buffer, nc, 1, outfile );
163  nc -= buflen;
164  }
165 
166  fread( buffer, nc, 1, infile );
167  fwrite( buffer, nc, 1, outfile );
168  break;
169 
170  case RRunDataOp:
171  putc( inst[0], outfile );
172  putc( inst[1], outfile );
173  if ( LONGP(inst) )
174  {
175  putc( getc( infile ), outfile );
176  putc( getc( infile ), outfile );
177  }
178 
179  putc( getc( infile ), outfile );
180  putc( getc( infile ), outfile );
181  break;
182 
183  case REOFOp:
184  in_hdr->priv.get.is_eof = 1;
185  rle_puteof( the_hdr );
186  break;
187 
188  default:
189  fprintf( stderr,
190  "%s: rle_cp: Unrecognized opcode: %d, reading %s\n",
191  the_hdr->cmd, OPCODE(inst), the_hdr->file_name );
192  fflush( the_hdr->rle_file );
193  exit(1);
194  }
195  if ( OPCODE(inst) == REOFOp )
196  break; /* <--- the other loop exit */
197  }
198 
199  /* Just in case the caller does something silly like calling rle_getrow. */
200  in_hdr->priv.get.scan_y = in_hdr->ymax;
201  in_hdr->priv.get.vert_skip = 0;
202 
203  return;
204 }
rle_hdr the_hdr
Definition: aliastorle.c:100
#define RSetColorOp
Definition: rle_code.h:38
void rle_skiprow(rle_hdr *the_hdr, int nrow)
Definition: rle_putrow.c:393
#define RRunDataOp
Definition: rle_code.h:41
int xmin
Definition: rle.h:100
FILE * outfile
Definition: giftorle.c:61
#define RSkipLinesOp
Definition: rle_code.h:37
struct rle_hdr::@0::@2 put
struct rle_hdr::@0::@1 get
void rle_puteof(rle_hdr *the_hdr)
Definition: rle_putrow.c:474
#define REOFOp
Definition: rle_code.h:42
union rle_hdr::@0 priv
const char * cmd
Definition: rle.h:133
#define put16(a)
Definition: rle_cp.c:43
#define DATUM(inst)
Definition: rle_cp.c:40
int xmax
Definition: rle.h:100
#define RSkipPixelsOp
Definition: rle_code.h:39
#define SkipBlankLines(n)
Definition: rle_put.h:76
#define OPCODE(inst)
Definition: rle_cp.c:38
#define VAXSHORT(var, fp)
Definition: rle_cp.c:33
FILE * infile
Definition: targatorle.c:102
int ymax
Definition: rle.h:100
void * malloc()
const char * file_name
Definition: rle.h:134
#define LONGP(inst)
Definition: rle_cp.c:39
unsigned char * buffer
Definition: getsun.c:87
FILE * rle_file
Definition: rle.h:114
#define RByteDataOp
Definition: rle_code.h:40
void rle_debug ( int  on_off)

Definition at line 293 of file rle_getrow.c.

295 {
296  debug_f = on_off;
297 
298  /* Set line buffering on stderr. Character buffering is the default, and
299  * it is SLOOWWW for large amounts of output.
300  */
301  setlinebuf( stderr );
302 }
static int debug_f
Definition: rle_getrow.c:50
const char* rle_delcom ( const char *  name,
rle_hdr the_hdr 
)
int rle_get_error ( int  code,
const char *  pgmname,
const char *  fname 
)
int rle_get_setup ( rle_hdr the_hdr)

Definition at line 74 of file rle_getrow.c.

Referenced by display_rle(), find_most_used(), RLE::open:, and read_rle_header().

76 {
77  struct XtndRsetup setup;
78  short magic;
79  register FILE *infile = the_hdr->rle_file;
81  register int i;
82  char * comment_buf;
83 
84  /* Clear old stuff out of the header. */
85  rle_hdr_clear( the_hdr );
86  if ( the_hdr->is_init != RLE_INIT_MAGIC )
87  rle_names( the_hdr, "Urt", "some file", 0 );
88  the_hdr->img_num++; /* Count images. */
89 
90  VAXSHORT( magic, infile );
91  if ( feof( infile ) )
92  return RLE_EMPTY;
93  if ( magic != RLE_MAGIC )
94  return RLE_NOT_RLE;
95  fread( &setup, 1, SETUPSIZE, infile ); /* assume VAX packing */
96  if ( feof( infile ) )
97  return RLE_EOF;
98 
99  /* Extract information from setup */
100  the_hdr->ncolors = setup.h_ncolors;
101  for ( i = 0; i < the_hdr->ncolors; i++ )
102  RLE_SET_BIT( *the_hdr, i );
103 
104  if ( !(setup.h_flags & H_NO_BACKGROUND) && setup.h_ncolors > 0 )
105  {
106  the_hdr->bg_color = (int *)malloc(
107  (unsigned)(sizeof(int) * setup.h_ncolors) );
108  bg_color = (rle_pixel *)malloc(
109  (unsigned)(1 + (setup.h_ncolors / 2) * 2) );
110  RLE_CHECK_ALLOC( the_hdr->cmd, the_hdr->bg_color && bg_color,
111  "background color" );
112  fread( (char *)bg_color, 1, 1 + (setup.h_ncolors / 2) * 2, infile );
113  for ( i = 0; i < setup.h_ncolors; i++ )
114  the_hdr->bg_color[i] = bg_color[i];
115  free( bg_color );
116  }
117  else
118  {
119  (void)getc( infile ); /* skip filler byte */
120  the_hdr->bg_color = NULL;
121  }
122 
123  if ( setup.h_flags & H_NO_BACKGROUND )
124  the_hdr->background = 0;
125  else if ( setup.h_flags & H_CLEARFIRST )
126  the_hdr->background = 2;
127  else
128  the_hdr->background = 1;
129  if ( setup.h_flags & H_ALPHA )
130  {
131  the_hdr->alpha = 1;
132  RLE_SET_BIT( *the_hdr, RLE_ALPHA );
133  }
134  else
135  the_hdr->alpha = 0;
136 
137  the_hdr->xmin = vax_gshort( setup.hc_xpos );
138  the_hdr->ymin = vax_gshort( setup.hc_ypos );
139  the_hdr->xmax = the_hdr->xmin + vax_gshort( setup.hc_xlen ) - 1;
140  the_hdr->ymax = the_hdr->ymin + vax_gshort( setup.hc_ylen ) - 1;
141 
142  the_hdr->ncmap = setup.h_ncmap;
143  the_hdr->cmaplen = setup.h_cmaplen;
144  if ( the_hdr->ncmap > 0 )
145  {
146  register int maplen =
147  the_hdr->ncmap * (1 << the_hdr->cmaplen);
148  register int i;
149  register char *maptemp;
150 
151  the_hdr->cmap = (rle_map *)malloc(
152  (unsigned)(sizeof(rle_map) * maplen) );
153  maptemp = (char *)malloc( 2 * maplen );
154  if ( the_hdr->cmap == NULL || maptemp == NULL )
155  {
156  fprintf( stderr,
157 "%s: Malloc failed for color map of size %d*%d in rle_get_setup, reading %s\n",
158  the_hdr->cmd,
159  the_hdr->ncmap, (1 << the_hdr->cmaplen),
160  the_hdr->file_name );
161  return RLE_NO_SPACE;
162  }
163  fread( maptemp, 2, maplen, infile );
164  for ( i = 0; i < maplen; i++ )
165  the_hdr->cmap[i] = vax_gshort( &maptemp[i * 2] );
166  free( maptemp );
167  }
168 
169  /* Check for comments */
170  if ( setup.h_flags & H_COMMENT )
171  {
172  short comlen, evenlen;
173  register char * cp;
174 
175  VAXSHORT( comlen, infile ); /* get comment length */
176  evenlen = (comlen + 1) & ~1; /* make it even */
177  if ( evenlen )
178  {
179  comment_buf = (char *)malloc( (unsigned) evenlen );
180 
181  if ( comment_buf == NULL )
182  {
183  fprintf( stderr,
184 "%s: Malloc failed for comment buffer of size %d in rle_get_setup, reading %s\n",
185  the_hdr->cmd, comlen, the_hdr->file_name );
186  return RLE_NO_SPACE;
187  }
188  fread( comment_buf, 1, evenlen, infile );
189  /* Count the comments */
190  for ( i = 0, cp = comment_buf; cp < comment_buf + comlen; cp++ )
191  if ( *cp == 0 )
192  i++;
193  i++; /* extra for NULL pointer at end */
194  /* Get space to put pointers to comments */
195  the_hdr->comments =
196  (CONST_DECL char **)malloc( (unsigned)(i * sizeof(char *)) );
197  if ( the_hdr->comments == NULL )
198  {
199  fprintf( stderr,
200  "%s: Malloc failed for %d comment pointers in rle_get_setup, reading %s\n",
201  the_hdr->cmd, i, the_hdr->file_name );
202  return RLE_NO_SPACE;
203  }
204  /* Get pointers to the comments */
205  *the_hdr->comments = comment_buf;
206  for ( i = 1, cp = comment_buf + 1;
207  cp < comment_buf + comlen;
208  cp++ )
209  if ( *(cp - 1) == 0 )
210  the_hdr->comments[i++] = cp;
211  the_hdr->comments[i] = NULL;
212  }
213  else
214  the_hdr->comments = NULL;
215  }
216  else
217  the_hdr->comments = NULL;
218 
219  /* Initialize state for rle_getrow */
220  the_hdr->priv.get.scan_y = the_hdr->ymin;
221  the_hdr->priv.get.vert_skip = 0;
222  the_hdr->priv.get.is_eof = 0;
223  the_hdr->priv.get.is_seek = ftell( infile ) > 0;
224  debug_f = 0;
225 
226  if ( !feof( infile ) )
227  return RLE_SUCCESS; /* success! */
228  else
229  {
230  the_hdr->priv.get.is_eof = 1;
231  return RLE_EOF;
232  }
233 }
#define RLE_SET_BIT(glob, bit)
Definition: rle.h:122
int xmin
Definition: rle.h:100
const char ** comments
Definition: rle.h:113
#define H_COMMENT
Definition: rle_code.h:47
int maplen
Definition: rletoppm.c:61
#define RLE_EMPTY
Definition: rle.h:73
#define RLE_MAGIC
Definition: rle_code.h:67
rle_map * cmap
Definition: rle.h:112
int * bg_color
Definition: rle.h:100
#define RLE_SUCCESS
Definition: rle.h:70
struct rle_hdr::@0::@1 get
#define H_ALPHA
Definition: rle_code.h:46
#define RLE_NOT_RLE
Definition: rle.h:71
int ymin
Definition: rle.h:100
long int is_init
Definition: rle.h:131
#define H_CLEARFIRST
Definition: rle_code.h:44
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
static int bg_color[3]
Definition: rle_global.c:64
union rle_hdr::@0 priv
const char * cmd
Definition: rle.h:133
int xmax
Definition: rle.h:100
int img_num
Definition: rle.h:135
#define RLE_INIT_MAGIC
Definition: rle.h:79
#define RLE_NO_SPACE
Definition: rle.h:72
#define RLE_EOF
Definition: rle.h:74
#define CONST_DECL
Definition: rle_config.h:42
int
Definition: getami.c:848
int background
Definition: rle.h:100
FILE * infile
Definition: targatorle.c:102
int ncmap
Definition: rle.h:100
int ymax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
static int debug_f
Definition: rle_getrow.c:50
void * malloc()
int cmaplen
Definition: rle.h:100
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
#define RLE_ALPHA
Definition: rle.h:65
#define SETUPSIZE
Definition: rle_code.h:61
unsigned short rle_map
Definition: rle.h:57
const char * file_name
Definition: rle.h:134
void rle_hdr_clear(rle_hdr *the_hdr)
Definition: rle_hdr.c:222
int vax_gshort()
#define H_NO_BACKGROUND
Definition: rle_code.h:45
#define VAXSHORT(var, fp)
Definition: rle_getrow.c:41
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86

Here is the caller graph for this function:

void rle_get_setup_ok ( rle_hdr the_hdr,
const char *  prog_name,
const char *  file_name 
)
char* rle_getcom ( const char *  name,
rle_hdr the_hdr 
)
int rle_getrow ( rle_hdr the_hdr,
rle_pixel scanline[] 
)
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
void rle_hdr_clear ( rle_hdr the_hdr)

Definition at line 222 of file rle_hdr.c.

224 {
225  /* Try to free memory. Assume if is_init is properly set that this
226  * header has been previously initialized, therefore it is safe to
227  * free memory.
228  */
229  if ( the_hdr && the_hdr->is_init == RLE_INIT_MAGIC )
230  {
231  if ( the_hdr->bg_color )
232  free( the_hdr->bg_color );
233  the_hdr->bg_color = 0;
234  if ( the_hdr->cmap )
235  free( the_hdr->cmap );
236  the_hdr->cmap = 0;
237  /* Unfortunately, we don't know how to free the comment memory. */
238  if ( the_hdr->comments )
239  free( the_hdr->comments );
240  the_hdr->comments = 0;
241  }
242 }
const char ** comments
Definition: rle.h:113
rle_map * cmap
Definition: rle.h:112
int * bg_color
Definition: rle.h:100
long int is_init
Definition: rle.h:131
#define RLE_INIT_MAGIC
Definition: rle.h:79
rle_hdr* rle_hdr_cp ( rle_hdr from_hdr,
rle_hdr to_hdr 
)

Definition at line 119 of file rle_hdr.c.

121 {
122  static rle_hdr dflt_hdr;
123  CONST_DECL char *cmd, *file;
124  int num;
125 
126  /* Save command, file name, and image number if already initialized. */
127  if ( to_hdr && to_hdr->is_init == RLE_INIT_MAGIC )
128  {
129  cmd = to_hdr->cmd;
130  file = to_hdr->file_name;
131  num = to_hdr->img_num;
132  }
133  else
134  {
135  cmd = file = NULL;
136  num = 0;
137  }
138 
139  if ( !no_recurse )
140  {
141  no_recurse++;
142  rle_hdr_init( to_hdr );
143  no_recurse--;
144  }
145 
146  if ( to_hdr == NULL )
147  to_hdr = &dflt_hdr;
148 
149  *to_hdr = *from_hdr;
150 
151  if ( to_hdr->bg_color )
152  {
153  int size = to_hdr->ncolors * sizeof(int);
154  to_hdr->bg_color = (int *)malloc( size );
155  RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->bg_color, "background color" );
156  bcopy( from_hdr->bg_color, to_hdr->bg_color, size );
157  }
158 
159  if ( to_hdr->cmap )
160  {
161  int size = to_hdr->ncmap * (1 << to_hdr->cmaplen) * sizeof(rle_map);
162  to_hdr->cmap = (rle_map *)malloc( size );
163  RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->cmap, "color map" );
164  bcopy( from_hdr->cmap, to_hdr->cmap, size );
165  }
166 
167  /* Only copy array of pointers, as the original comment memory
168  * never gets overwritten.
169  */
170  if ( to_hdr->comments )
171  {
172  int size = 0;
173  CONST_DECL char **cp;
174  for ( cp=to_hdr->comments; *cp; cp++ )
175  size++; /* Count the comments. */
176  /* Check if there are really any comments. */
177  if ( size )
178  {
179  size++; /* Copy the NULL pointer, too. */
180  size *= sizeof(char *);
181  to_hdr->comments = (CONST_DECL char **)malloc( size );
182  RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->comments, "comments" );
183  bcopy( from_hdr->comments, to_hdr->comments, size );
184  }
185  else
186  to_hdr->comments = NULL; /* Blow off empty comment list. */
187  }
188 
189  /* Restore the names to their original values. */
190  to_hdr->cmd = cmd;
191  to_hdr->file_name = file;
192 
193  /* Lines above mean nothing much happens if cmd and file are != NULL. */
194  rle_names( to_hdr, to_hdr->cmd, to_hdr->file_name, num );
195 
196  return to_hdr;
197 }
const char ** comments
Definition: rle.h:113
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle_hdr.c:48
rle_map * cmap
Definition: rle.h:112
int * bg_color
Definition: rle.h:100
long int is_init
Definition: rle.h:131
const char * cmd
Definition: rle.h:133
Definition: rle.h:96
static int no_recurse
Definition: rle_hdr.c:100
int img_num
Definition: rle.h:135
#define RLE_INIT_MAGIC
Definition: rle.h:79
#define CONST_DECL
Definition: rle_config.h:42
int
Definition: getami.c:848
int ncmap
Definition: rle.h:100
void * malloc()
int cmaplen
Definition: rle.h:100
gpr_ $offset_t size
Definition: getap.c:96
unsigned short rle_map
Definition: rle.h:57
const char * file_name
Definition: rle.h:134
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
int ncolors
Definition: rle.h:100
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86
rle_hdr* rle_hdr_init ( rle_hdr the_hdr)

Definition at line 267 of file rle_hdr.c.

Referenced by read_file().

269 {
270  rle_hdr *ret_hdr;
271 
272  rle_dflt_hdr.rle_file = stdout;
273  /* The rest of rle_dflt_hdr is set by the loader's data initialization */
274 
275  if ( the_hdr == &rle_dflt_hdr )
276  return the_hdr;
277 
278  rle_hdr_clear( the_hdr );
279 
280  /* Only call rle_hdr_cp if not called from there. */
281  if ( !no_recurse )
282  {
283  no_recurse++;
284  ret_hdr = rle_hdr_cp( &rle_dflt_hdr, the_hdr );
285  no_recurse--;
286  }
287  else
288  ret_hdr = the_hdr;
289 
290  return ret_hdr;
291 }
rle_hdr the_hdr
Definition: aliastorle.c:100
rle_hdr * rle_hdr_cp(rle_hdr *from_hdr, rle_hdr *to_hdr)
Definition: rle_hdr.c:119
rle_hdr rle_dflt_hdr
Definition: rle_global.c:66
Definition: rle.h:96
static int no_recurse
Definition: rle_hdr.c:100
void rle_hdr_clear(rle_hdr *the_hdr)
Definition: rle_hdr.c:222
FILE * rle_file
Definition: rle.h:114

Here is the caller graph for this function:

void rle_names ( rle_hdr the_hdr,
const char *  pgmname,
const char *  fname,
int  img_num 
)
FILE* rle_open_f ( const char *  prog_name,
const char *  f_name,
const char *  mode 
)
FILE* rle_open_f_noexit ( const char *  prog_name,
const char *  f_name,
const char *  mode 
)
void rle_put_init ( rle_hdr the_hdr)

Definition at line 415 of file rle_putrow.c.

417 {
418  the_hdr->dispatch = RUN_DISPATCH;
419 
420  if ( the_hdr->is_init != RLE_INIT_MAGIC )
421  {
422  the_hdr->cmd = "Urt";
423  the_hdr->file_name = "some file";
424  }
425  the_hdr->priv.put.nblank = 0; /* Reinit static vars */
426  /* Would like to be able to free previously allocated storage,
427  * but can't count on a non-NULL value being a valid pointer.
428  */
429  PBRUN = NULL;
430  the_hdr->priv.put.fileptr = 0;
431 
432  /* Only save alpha if alpha AND alpha channel bit are set. */
433  if ( the_hdr->alpha )
434  the_hdr->alpha = (RLE_BIT( *the_hdr, -1 ) != 0);
435  else
436  RLE_CLR_BIT( *the_hdr, -1 );
437 }
struct rle_hdr::@0::@2 put
long int is_init
Definition: rle.h:131
union rle_hdr::@0 priv
const char * cmd
Definition: rle.h:133
enum rle_dispatch dispatch
Definition: rle.h:99
#define RLE_INIT_MAGIC
Definition: rle.h:79
#define RLE_CLR_BIT(glob, bit)
Definition: rle.h:124
int alpha
Definition: rle.h:100
const char * file_name
Definition: rle.h:134
#define PBRUN
Definition: rle_putrow.c:48
#define RLE_BIT(glob, bit)
Definition: rle.h:126
void rle_put_setup ( rle_hdr the_hdr)

Definition at line 453 of file rle_putrow.c.

Referenced by find_most_used(), and write_rle_header().

455 {
456  rle_put_init( the_hdr );
457  the_hdr->img_num++; /* Count output images. */
458  Setup();
459 }
int img_num
Definition: rle.h:135
void rle_put_init(rle_hdr *the_hdr)
Definition: rle_putrow.c:415
#define Setup()
Definition: rle_put.h:75

Here is the caller graph for this function:

const char* rle_putcom ( const char *  value,
rle_hdr the_hdr 
)
void rle_puteof ( rle_hdr the_hdr)

Definition at line 474 of file rle_putrow.c.

Referenced by FormFeed(), rasterDone(), and write_rle_data().

476 {
477  /* Don't puteof twice. */
478  if ( the_hdr->dispatch == NO_DISPATCH )
479  return;
480  PutEof();
481  fflush( the_hdr->rle_file );
482  /* Free storage allocated by rle_put_init. */
483  if ( PBRUN != NULL )
484  {
485  free( PBRUN );
486  PBRUN = NULL;
487  }
488  /* Signal that puteof has been called. */
489  the_hdr->dispatch = NO_DISPATCH;
490 }
#define PutEof()
Definition: rle_put.h:83
enum rle_dispatch dispatch
Definition: rle.h:99
#define PBRUN
Definition: rle_putrow.c:48
FILE * rle_file
Definition: rle.h:114

Here is the caller graph for this function:

void rle_putrow ( rle_pixel rows[],
int  rowlen,
rle_hdr the_hdr 
)
int rle_row_alloc ( rle_hdr the_hdr,
rle_pixel ***  scanp 
)

Definition at line 56 of file rle_row_alc.c.

Referenced by get_scanlines(), RLE::open:, write_ppm_data(), write_rlb_data(), and write_rle_data().

59 {
60  rle_pixel ** scanbuf, * pixbuf;
61  int rowlen, nchan = 0, i, ncol;
62 
63  rowlen = the_hdr->xmax + 1;
64  if ( the_hdr->alpha && RLE_BIT( *the_hdr, RLE_ALPHA ) )
65  nchan++;
66  for ( i = 0; i < the_hdr->ncolors; i++ )
67  if ( RLE_BIT( *the_hdr, i ) )
68  nchan++;
69 
70  ncol = the_hdr->ncolors + the_hdr->alpha;
71 
72  if ( (scanbuf = (rle_pixel **)malloc( ncol * sizeof(rle_pixel *) )) == 0 )
73  return -1;
74  if ( (pixbuf = (rle_pixel *)malloc( nchan * rowlen *
75  sizeof(rle_pixel) )) == 0 )
76  {
77  free( scanbuf );
78  return -1;
79  }
80 
81  if ( the_hdr->alpha )
82  scanbuf++;
83 
84  for ( i = -the_hdr->alpha; i < the_hdr->ncolors; i++ )
85  if ( RLE_BIT( *the_hdr, i ) )
86  {
87  scanbuf[i] = pixbuf;
88  pixbuf += rowlen;
89  }
90  else
91  scanbuf[i] = 0;
92  *scanp = scanbuf;
93 
94  return 0;
95 }
static gif_pixel ** scanbuf
Definition: rletogif.c:39
int xmax
Definition: rle.h:100
unsigned char rle_pixel
Definition: rle.h:56
void * malloc()
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
#define RLE_ALPHA
Definition: rle.h:65
int nchan
Definition: fant.c:104
int ncolors
Definition: rle.h:100
#define RLE_BIT(glob, bit)
Definition: rle.h:126

Here is the caller graph for this function:

void rle_row_free ( rle_hdr the_hdr,
rle_pixel **  scanp 
)

Definition at line 114 of file rle_row_alc.c.

Referenced by RLE::open:, write_ppm_data(), and write_rle_data().

117 {
118  int i;
119 
120  if ( the_hdr->alpha )
121  scanp--;
122  for ( i = 0; i < the_hdr->ncolors + the_hdr->alpha; i++ )
123  if ( scanp[i] != 0 )
124  {
125  free( (char *)scanp[i] );
126  break;
127  }
128  free( (char *)scanp );
129 }
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
int ncolors
Definition: rle.h:100

Here is the caller graph for this function:

void rle_skiprow ( rle_hdr the_hdr,
int  nrow 
)

Definition at line 393 of file rle_putrow.c.

Referenced by write_rle_data().

396 {
397  the_hdr->priv.put.nblank += nrow;
398 }
struct rle_hdr::@0::@2 put
int nrow
Definition: getsun.c:82
union rle_hdr::@0 priv

Here is the caller graph for this function:

int scanargs ( int  argc,
char **  argv,
const char *  format,
  ... 
)

Definition at line 94 of file scanargs.c.

References _do_scanargs().

96 {
97  va_list argl;
98  int retval;
99 #ifndef USE_STDARG
100  int argc;
101  char ** argv;
102  CONST_DECL char *format;
103 
104  va_start( argl );
105  argc = va_arg( argl, int );
106  argv = va_arg( argl, char ** );
107  format = va_arg( argl, CONST_DECL char * );
108 #else
109  va_start( argl, format );
110 #endif
111  retval = _do_scanargs( argc, argv, format, argl );
112  va_end( argl );
113  return retval;
114 }
#define CONST_DECL
Definition: rle_config.h:42
int format
Definition: pgmtorle.c:50
static int _do_scanargs()

Here is the call graph for this function:

Variable Documentation

rle_hdr rle_dflt_hdr

Definition at line 66 of file rle_global.c.

Referenced by find_most_used(), and write_rlb_data().