aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2016-09-11 18:04:49 +0200
committerEugene Sandulenko2016-09-11 18:04:49 +0200
commita035334cbdec8b618506156f13f274f81004fd8d (patch)
treed67ee66fbcbcf738630ed384b00713478ba00e7c
parentfe65d374d18ec7c5abea7df7fed499f3b9e049e4 (diff)
downloadscummvm-rg350-a035334cbdec8b618506156f13f274f81004fd8d.tar.gz
scummvm-rg350-a035334cbdec8b618506156f13f274f81004fd8d.tar.bz2
scummvm-rg350-a035334cbdec8b618506156f13f274f81004fd8d.zip
IMAGE: Indeo: Replace memory-related functions with standard ones
-rw-r--r--image/codecs/indeo/indeo.cpp18
-rw-r--r--image/codecs/indeo/mem.cpp24
-rw-r--r--image/codecs/indeo/mem.h48
-rw-r--r--image/codecs/indeo/vlc.cpp2
4 files changed, 11 insertions, 81 deletions
diff --git a/image/codecs/indeo/indeo.cpp b/image/codecs/indeo/indeo.cpp
index e54d6d4c54..44cfdf90ef 100644
--- a/image/codecs/indeo/indeo.cpp
+++ b/image/codecs/indeo/indeo.cpp
@@ -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;
@@ -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;
@@ -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;
}
@@ -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;
@@ -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);
@@ -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)
diff --git a/image/codecs/indeo/mem.cpp b/image/codecs/indeo/mem.cpp
index ab28c34cb6..736b3b4de9 100644
--- a/image/codecs/indeo/mem.cpp
+++ b/image/codecs/indeo/mem.cpp
@@ -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;
@@ -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);
diff --git a/image/codecs/indeo/mem.h b/image/codecs/indeo/mem.h
index 8e889e5cbf..c4001bdfa2 100644
--- a/image/codecs/indeo/mem.h
+++ b/image/codecs/indeo/mem.h
@@ -40,45 +40,6 @@ namespace Indeo {
#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`.
*
@@ -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
diff --git a/image/codecs/indeo/vlc.cpp b/image/codecs/indeo/vlc.cpp
index baf3984869..1793952bcf 100644
--- a/image/codecs/indeo/vlc.cpp
+++ b/image/codecs/indeo/vlc.cpp
@@ -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);
}