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

Go to the source code of this file.

Functions

void rle_box (rle_hdr *the_hdr, int *xminp, int *xmaxp, int *yminp, int *ymaxp)
 

Function Documentation

void rle_box ( rle_hdr the_hdr,
int xminp,
int xmaxp,
int yminp,
int ymaxp 
)

Definition at line 16 of file rle_box.c.

19 {
20  rle_op ** raw;
21  register rle_op ** rawp;
22  register int i;
23  int y, * nrawp;
24  int xmin, xmax, ymin, ymax;
25 
26  if ( rle_raw_alloc( the_hdr, &raw, &nrawp ) < 0 )
27  RLE_CHECK_ALLOC( the_hdr->cmd, 0, 0 );
28  rawp = raw;
29 
30  ymax = -1; /* smaller than it can ever be */
31  ymin = 32768; /* larger than it can ever be */
32  xmax = -1;
33  xmin = 32768;
34 
35  while ( ( y = rle_getraw( the_hdr, rawp, nrawp ) ) != 32768 )
36  {
37  if ( y < ymin ) /* found ymin yet? */
38  {
39  /* Only count it if there is really some data */
40  for ( i = -the_hdr->alpha; i < the_hdr->ncolors; i++ )
41  if ( nrawp[i] > 0 )
42  ymin = y;
43  }
44  if ( y > ymax ) /* update ymax? */
45  {
46  /* Only count it if there is really some data */
47  for ( i = -the_hdr->alpha; i < the_hdr->ncolors; i++ )
48  if ( nrawp[i] > 0 )
49  ymax = y;
50  }
51 
52  /* Now do xmin and xmax */
53  for ( i = -the_hdr->alpha; i < the_hdr->ncolors; i++ )
54  if ( nrawp[i] > 0 )
55  {
56  if ( rawp[i][0].xloc < xmin )
57  xmin = rawp[i][0].xloc;
58  if ( xmax < rawp[i][nrawp[i]-1].xloc +
59  rawp[i][nrawp[i]-1].length - 1 )
60  xmax = rawp[i][nrawp[i]-1].xloc +
61  rawp[i][nrawp[i]-1].length - 1;
62  }
63  }
64 
65  /* If no data, arbitrarily use (0,0)x(0,0) */
66  if ( xmax < xmin )
67  {
68  xmax = xmin = ymax = ymin = 0;
69  }
70 
71  *xminp = xmin;
72  *xmaxp = xmax;
73  *yminp = ymin;
74  *ymaxp = ymax;
75 
76  rle_raw_free( the_hdr, raw, nrawp );
77 }
int length
Definition: rle_raw.h:51
int rle_raw_alloc()
void rle_raw_free()
static int y
Definition: getami.c:691
int xloc
Definition: rle_raw.h:50
const char * cmd
Definition: rle.h:133
int i
Definition: rletorla.c:82
int alpha
Definition: rle.h:100
Definition: rle_raw.h:47
unsigned int rle_getraw(rle_hdr *the_hdr, scanraw, nraw)
Definition: rle_getraw.c:78
#define RLE_CHECK_ALLOC(pgm, ptr, name)
Definition: rle.h:86