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

Go to the source code of this file.

Functions

int rle_raw_alloc (rle_hdr *the_hdr, rle_op ***scanp, int **nrawp)
 
void rle_raw_free (rle_hdr *the_hdr, rle_op **scanp, nrawp)
 

Function Documentation

int rle_raw_alloc ( rle_hdr the_hdr,
rle_op ***  scanp,
int **  nrawp 
)

Definition at line 60 of file rle_raw_alc.c.

64 {
65  rle_op ** scanbuf, * opbuf;
66  int rowlen, nchan = 0, i, ncol;
67 
68  rowlen = the_hdr->xmax - the_hdr->xmin + 1;
69  if ( the_hdr->alpha && RLE_BIT( *the_hdr, RLE_ALPHA ) )
70  nchan++;
71  for ( i = 0; i < the_hdr->ncolors; i++ )
72  if ( RLE_BIT( *the_hdr, i ) )
73  nchan++;
74 
75  ncol = the_hdr->ncolors + the_hdr->alpha;
76 
77  if ( (scanbuf = (rle_op **) malloc( ncol * sizeof(rle_op *) )) == 0 )
78  return -1;
79 
80  if ( (opbuf = (rle_op *)malloc( nchan * rowlen * sizeof(rle_op) )) == 0 )
81  {
82  free( scanbuf );
83  return -1;
84  }
85 
86  if ( nrawp && (*nrawp = (int *)malloc( ncol * sizeof(int) )) == 0 )
87  {
88  free( scanbuf );
89  free( opbuf );
90  return -1;
91  }
92 
93  if ( the_hdr->alpha )
94  {
95  scanbuf++;
96  if ( nrawp )
97  (*nrawp)++;
98  }
99 
100  for ( i = -the_hdr->alpha; i < the_hdr->ncolors; i++ )
101  if ( RLE_BIT( *the_hdr, i ) )
102  {
103  scanbuf[i] = opbuf;
104  opbuf += rowlen;
105  }
106  else
107  scanbuf[i] = 0;
108  *scanp = scanbuf;
109 
110  return 0;
111 }
int xmin
Definition: rle.h:100
static gif_pixel ** scanbuf
Definition: rletogif.c:39
int xmax
Definition: rle.h:100
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
Definition: rle_raw.h:47
int ncolors
Definition: rle.h:100
#define RLE_BIT(glob, bit)
Definition: rle.h:126
void rle_raw_free ( rle_hdr the_hdr,
rle_op **  scanp,
nrawp   
)

Definition at line 131 of file rle_raw_alc.c.

135 {
136  int i;
137 
138  if ( the_hdr->alpha )
139  {
140  scanp--;
141  if ( nrawp )
142  nrawp--;
143  }
144  for ( i = 0; i < the_hdr->ncolors + the_hdr->alpha; i++ )
145  if ( scanp[i] != 0 )
146  {
147  free( (char *)scanp[i] );
148  break;
149  }
150  free( (char *)scanp );
151  if ( nrawp )
152  free( (char *)nrawp );
153 }
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
int ncolors
Definition: rle.h:100