Skip to content

Commit

Permalink
IMAGE: Indeo: Replace memory-related functions with standard ones
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Sep 11, 2016
1 parent fe65d37 commit a035334
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 81 deletions.
18 changes: 9 additions & 9 deletions image/codecs/indeo/indeo.cpp
Expand Up @@ -225,7 +225,7 @@ int IVIBandDesc::initTiles(IVITile *refTile, int p, int b, int tHeight, int tWid
_mbSize);

avFreeP(&tile->_mbs);
tile->_mbs = (IVIMbInfo *)avMallocZArray(tile->_numMBs, sizeof(IVIMbInfo));
tile->_mbs = (IVIMbInfo *)calloc(tile->_numMBs, sizeof(IVIMbInfo));
if (!tile->_mbs)
return -2;

Expand Down Expand Up @@ -284,7 +284,7 @@ int IVIPlaneDesc::initPlanes(IVIPlaneDesc *planes, const IVIPicConfig *cfg, bool
planes[1]._numBands = planes[2]._numBands = cfg->_chromaBands;

for (int p = 0; p < 3; p++) {
planes[p]._bands = (IVIBandDesc *)avMallocZArray(planes[p]._numBands, sizeof(IVIBandDesc));
planes[p]._bands = (IVIBandDesc *)calloc(planes[p]._numBands, sizeof(IVIBandDesc));
if (!planes[p]._bands)
return -2;

Expand All @@ -311,20 +311,20 @@ int IVIPlaneDesc::initPlanes(IVIPlaneDesc *planes, const IVIPicConfig *cfg, bool
band->_height = b_height;
band->_pitch = width_aligned;
band->_aHeight = height_aligned;
band->_bufs[0] = (int16 *)avMallocZ(bufSize);
band->_bufs[1] = (int16 *)avMallocZ(bufSize);
band->_bufs[0] = (int16 *)calloc(bufSize, 1);
band->_bufs[1] = (int16 *)calloc(bufSize, 1);
band->_bufSize = bufSize / 2;
if (!band->_bufs[0] || !band->_bufs[1])
return -2;

// allocate the 3rd band buffer for scalability mode
if (cfg->_lumaBands > 1) {
band->_bufs[2] = (int16 *)avMallocZ(bufSize);
band->_bufs[2] = (int16 *)calloc(bufSize, 1);
if (!band->_bufs[2])
return -2;
}
if (isIndeo4) {
band->_bufs[3] = (int16 *)avMallocZ(bufSize);
band->_bufs[3] = (int16 *)calloc(bufSize, 1);
if (!band->_bufs[3])
return -2;
}
Expand Down Expand Up @@ -358,7 +358,7 @@ int IVIPlaneDesc::initTiles(IVIPlaneDesc *planes, int tileWidth, int tileHeight)
band->_numTiles = xTiles * yTiles;

avFreeP(&band->_tiles);
band->_tiles = (IVITile *)avMallocZArray(band->_numTiles, sizeof(IVITile));
band->_tiles = (IVITile *)calloc(band->_numTiles, sizeof(IVITile));
if (!band->_tiles)
return -2;

Expand Down Expand Up @@ -420,7 +420,7 @@ int AVFrame::getBuffer(int flags) {
freeFrame();

// Luminance channel
_data[0] = (uint8 *)avMallocZ(_width * _height);
_data[0] = (uint8 *)calloc(_width * _height, 1);

// UV Chroma Channels
_data[1] = (uint8 *)malloc(_width * _height);
Expand Down Expand Up @@ -1072,7 +1072,7 @@ int IndeoDecoderBase::decodeBlocks(GetBits *_gb, IVIBandDesc *band, IVITile *til
if (_ctx._isIndeo4)
quant = avClipUintp2(quant, 5);
else
quant = av_clip((int)quant, 0, 23);
quant = CLIP((int)quant, 0, 23);

const uint8 *scaleTab = isIntra ? band->_intraScale : band->_interScale;
if (scaleTab)
Expand Down
24 changes: 1 addition & 23 deletions image/codecs/indeo/mem.cpp
Expand Up @@ -83,34 +83,12 @@ static inline int avSizeMult(size_t a, size_t b, size_t *r) {

/*------------------------------------------------------------------------*/

void *avMallocZ(size_t size) {
void *ptr = malloc(size);
if (ptr)
memset(ptr, 0, size);

return ptr;
}

void *avMallocArray(size_t nmemb, size_t size) {
assert(size && nmemb < MAX_INTEGER / size);
return malloc(nmemb * size);
}

void *avMallocZArray(size_t nmemb, size_t size) {
assert(size && nmemb < MAX_INTEGER / size);
return avMallocZ(nmemb * size);
}

void avFreeP(void *arg) {
void **ptr = (void **)arg;
free(*ptr);
*ptr = nullptr;
}

static void *avRealloc(void *ptr, size_t size) {
return realloc(ptr, size + !size);
}

void *avReallocF(void *ptr, size_t nelem, size_t elsize) {
size_t size;
void *r;
Expand All @@ -119,7 +97,7 @@ void *avReallocF(void *ptr, size_t nelem, size_t elsize) {
free(ptr);
return nullptr;
}
r = avRealloc(ptr, size);
r = realloc(ptr, size);
if (!r)
free(ptr);

Expand Down
48 changes: 0 additions & 48 deletions image/codecs/indeo/mem.h
Expand Up @@ -39,45 +39,6 @@ namespace Indeo {
#define FFSIGN(a) ((a) > 0 ? 1 : -1)
#define MAX_INTEGER 0x7ffffff

/**
* Allocate a memory block with alignment suitable for all memory accesses
* (including vectors if available on the CPU) and zero all the bytes of the
* block.
*
* @param size Size in bytes for the memory block to be allocated
* @return Pointer to the allocated block, or `NULL` if it cannot be allocated
* @see av_malloc()
*/
extern void *avMallocZ(size_t size);

/**
* Allocate a memory block for an array with av_malloc().
*
* The allocated memory will have size `size * nmemb` bytes.
*
* @param nmemb Number of element
* @param size Size of a single element
* @return Pointer to the allocated block, or `NULL` if the block cannot
* be allocated
* @see av_malloc()
*/
extern void *avMallocArray(size_t nmemb, size_t size);

/**
* Allocate a memory block for an array with av_mallocz().
*
* The allocated memory will have size `size * nmemb` bytes.
*
* @param nmemb Number of elements
* @param size Size of the single element
* @return Pointer to the allocated block, or `NULL` if the block cannot
* be allocated
*
* @see av_mallocz()
* @see av_malloc_array()
*/
extern void *avMallocZArray(size_t nmemb, size_t size);

/**
* Free a memory block which has been allocated with a function of av_malloc()
* or av_realloc() family, and set the pointer pointing to it to `NULL`.
Expand Down Expand Up @@ -131,15 +92,6 @@ extern uint8 avClipUint8(int a);
*/
extern unsigned avClipUintp2(int a, int p);

/**
* Clip a signed integer value into the amin-amax range.
* @param a value to clip
* @param amin minimum value of the clip range
* @param amax maximum value of the clip range
* @return clipped value
*/
#define av_clip CLIP

extern const uint8 ffZigZagDirect[64];

} // End of namespace Indeo
Expand Down
2 changes: 1 addition & 1 deletion image/codecs/indeo/vlc.cpp
Expand Up @@ -165,7 +165,7 @@ int VLC::init_vlc(int nbBits, int nbCodes, const void *p_bits, int bitsWrap,
vlc->_tableAllocated = 0;
vlc->_tableSize = 0;

buf = (VLCcode *)avMallocArray((nbCodes + 1), sizeof(VLCcode));
buf = (VLCcode *)malloc((nbCodes + 1) * sizeof(VLCcode));
assert(buf);
}

Expand Down

0 comments on commit a035334

Please sign in to comment.