/* * lineacc.c * -- Accumulator holding data for one horizontal line in the image. * * See 'lineacc.h' for comments. * */ #include "lineacc.h" /* lineAcc_t */ #include#include /* malloc(), free() */ /* lineAcc_alloc() -- * * User instantiates a lineAcc_t instance, then calls lineAcc_alloc() to * allocate the internal members of that lineAcc_t instance. * * Parameter: * in_size = the number of different labels that the map must store. * * Returns 0 on failure, 1 on success. */ int lineAcc_alloc( lineAcc_t * pLA, int in_size ) { pLA->pArr = (label_t*)malloc( in_size * sizeof(label_t) ); if ( pLA->pArr == NULL ) { return 0; } pLA->N = in_size; return 1; } /* lineAcc_free() -- * Deallocate the internal members of the lineAcc_t structure. */ void lineAcc_free( lineAcc_t * pLA ) { free( pLA->pArr ); } /* lineAcc_init() -- * Initialize lineAcc_t instance for beginning with a new image: * all elements set to LABEL_EMPTY. */ void lineAcc_init( lineAcc_t * pLA ) { int k; for ( k = 0; k < pLA->N; k++ ) { pLA->pArr[k] = LABEL_EMPTY; } } /* lineAcc_get() -- * Return the label stored in element in_iX. */ label_t lineAcc_get( lineAcc_t * pLA, int in_iX ) { assert( (0 <= in_iX) && (in_iX < pLA->N) ); return pLA->pArr[in_iX]; } /* lineAcc_put() -- * Set element in_iX to the value in_lbl. */ void lineAcc_put( lineAcc_t * pLA, int in_iX, label_t in_lbl ) { assert( (0 <= in_iX) && (in_iX < pLA->N) ); pLA->pArr[in_iX] = in_lbl; }