IMAGE: Further formatting of Indeo decoders

This commit is contained in:
Paul Gilbert 2016-09-11 09:42:12 -04:00
parent a5f4366387
commit 08143af482
5 changed files with 106 additions and 144 deletions

View File

@ -86,9 +86,9 @@ static const IVIHuffDesc ivi_blk_huff_desc[8] = {
/*------------------------------------------------------------------------*/
int IVIHuffDesc::createHuffFromDesc(VLC *vlc, bool flag) const {
int pos, i, j, codesPerRow, prefix, notLastRow;
uint16 codewords[256];
uint8 bits[256];
int pos, i, j, codesPerRow, prefix, notLastRow;
uint16 codewords[256];
uint8 bits[256];
pos = 0; // current position = 0
@ -268,8 +268,7 @@ IVIPlaneDesc::IVIPlaneDesc() : _width(0), _height(0), _numBands(0), _bands(nullp
int IVIPlaneDesc::initPlanes(IVIPlaneDesc *planes, const IVIPicConfig *cfg, bool isIndeo4) {
int p, b;
uint32 b_width, b_height, align_fac, width_aligned,
height_aligned, bufSize;
uint32 b_width, b_height, align_fac, width_aligned, height_aligned, bufSize;
IVIBandDesc *band;
freeBuffers(planes);
@ -430,8 +429,8 @@ int AVFrame::getBuffer(int flags) {
_data[0] = (uint8 *)avMallocZ(_width * _height);
// UV Chroma Channels
_data[1] = (uint8 *)avMalloc(_width * _height);
_data[2] = (uint8 *)avMalloc(_width * _height);
_data[1] = (uint8 *)malloc(_width * _height);
_data[2] = (uint8 *)malloc(_width * _height);
Common::fill(_data[1], _data[1] + _width * _height, 0x80);
Common::fill(_data[2], _data[2] + _width * _height, 0x80);
@ -603,8 +602,8 @@ int IndeoDecoderBase::decodeIndeoFrame() {
}
int IndeoDecoderBase::decode_band(IVIBandDesc *band) {
int result, i, t, idx1, idx2, pos;
IVITile * tile;
int result, i, t, idx1, idx2, pos;
IVITile *tile;
band->_buf = band->_bufs[_ctx._dstBuf];
if (!band->_buf) {
@ -711,12 +710,12 @@ int IndeoDecoderBase::decode_band(IVIBandDesc *band) {
void IndeoDecoderBase::recomposeHaar(const IVIPlaneDesc *_plane,
uint8 *dst, const int dstPitch) {
int x, y, indx, b0, b1, b2, b3, p0, p1, p2, p3;
const short * b0Ptr, *b1Ptr, *b2Ptr, *b3Ptr;
int32 _pitch;
int x, y, indx, b0, b1, b2, b3, p0, p1, p2, p3;
const short *b0Ptr, *b1Ptr, *b2Ptr, *b3Ptr;
int32 pitch;
// all bands should have the same _pitch
_pitch = _plane->_bands[0]._pitch;
pitch = _plane->_bands[0]._pitch;
// get pointers to the wavelet bands
b0Ptr = _plane->_bands[0]._buf;
@ -747,22 +746,22 @@ void IndeoDecoderBase::recomposeHaar(const IVIPlaneDesc *_plane,
dst += dstPitch << 1;
b0Ptr += _pitch;
b1Ptr += _pitch;
b2Ptr += _pitch;
b3Ptr += _pitch;
b0Ptr += pitch;
b1Ptr += pitch;
b2Ptr += pitch;
b3Ptr += pitch;
}// for y
}
void IndeoDecoderBase::recompose53(const IVIPlaneDesc *_plane,
uint8 *dst, const int dstPitch) {
int x, y, indx;
int32 p0, p1, p2, p3, tmp0, tmp1, tmp2;
int32 b0_1, b0_2, b1_1, b1_2, b1_3, b2_1, b2_2, b2_3, b2_4, b2_5, b2_6;
int32 b3_1, b3_2, b3_3, b3_4, b3_5, b3_6, b3_7, b3_8, b3_9;
int32 _pitch, back_pitch;
const short * b0Ptr, *b1Ptr, *b2Ptr, *b3Ptr;
const int _numBands = 4;
int x, y, indx;
int32 p0, p1, p2, p3, tmp0, tmp1, tmp2;
int32 b0_1, b0_2, b1_1, b1_2, b1_3, b2_1, b2_2, b2_3, b2_4, b2_5, b2_6;
int32 b3_1, b3_2, b3_3, b3_4, b3_5, b3_6, b3_7, b3_8, b3_9;
int32 _pitch, back_pitch;
const short *b0Ptr, *b1Ptr, *b2Ptr, *b3Ptr;
const int numBands = 4;
// all bands should have the same _pitch
_pitch = _plane->_bands[0]._pitch;
@ -781,25 +780,25 @@ void IndeoDecoderBase::recompose53(const IVIPlaneDesc *_plane,
if (y + 2 >= _plane->_height)
_pitch = 0;
// load storage variables with values
if (_numBands > 0) {
if (numBands > 0) {
b0_1 = b0Ptr[0];
b0_2 = b0Ptr[_pitch];
}
if (_numBands > 1) {
if (numBands > 1) {
b1_1 = b1Ptr[back_pitch];
b1_2 = b1Ptr[0];
b1_3 = b1_1 - b1_2 * 6 + b1Ptr[_pitch];
}
if (_numBands > 2) {
if (numBands > 2) {
b2_2 = b2Ptr[0]; // b2[x, y ]
b2_3 = b2_2; // b2[x+1,y ] = b2[x,y]
b2_5 = b2Ptr[_pitch]; // b2[x ,y+1]
b2_6 = b2_5; // b2[x+1,y+1] = b2[x,y+1]
}
if (_numBands > 3) {
if (numBands > 3) {
b3_2 = b3Ptr[back_pitch]; // b3[x ,y-1]
b3_3 = b3_2; // b3[x+1,y-1] = b3[x ,y-1]
b3_5 = b3Ptr[0]; // b3[x ,y ]
@ -832,7 +831,7 @@ void IndeoDecoderBase::recompose53(const IVIPlaneDesc *_plane,
p0 = p1 = p2 = p3 = 0;
// process the LL-band by applying LPF both vertically and horizontally
if (_numBands > 0) {
if (numBands > 0) {
tmp0 = b0_1;
tmp2 = b0_2;
b0_1 = b0Ptr[indx + 1];
@ -846,7 +845,7 @@ void IndeoDecoderBase::recompose53(const IVIPlaneDesc *_plane,
}
// process the HL-band by applying HPF vertically and LPF horizontally
if (_numBands > 1) {
if (numBands > 1) {
tmp0 = b1_2;
tmp1 = b1_1;
b1_2 = b1Ptr[indx + 1];
@ -862,7 +861,7 @@ void IndeoDecoderBase::recompose53(const IVIPlaneDesc *_plane,
}
// process the LH-band by applying LPF vertically and HPF horizontally
if (_numBands > 2) {
if (numBands > 2) {
b2_3 = b2Ptr[indx + 1];
b2_6 = b2Ptr[_pitch + indx + 1];
@ -876,7 +875,7 @@ void IndeoDecoderBase::recompose53(const IVIPlaneDesc *_plane,
}
// process the HH-band by applying HPF both vertically and horizontally
if (_numBands > 3) {
if (numBands > 3) {
b3_6 = b3Ptr[indx + 1]; // b3[x+1,y ]
b3_3 = b3Ptr[back_pitch + indx + 1]; // b3[x+1,y-1]
@ -911,9 +910,9 @@ void IndeoDecoderBase::recompose53(const IVIPlaneDesc *_plane,
}
void IndeoDecoderBase::outputPlane(IVIPlaneDesc *_plane, uint8 *dst, int dstPitch) {
int x, y;
const int16 * src = _plane->_bands[0]._buf;
uint32 pitch = _plane->_bands[0]._pitch;
int x, y;
const int16 *src = _plane->_bands[0]._buf;
uint32 pitch = _plane->_bands[0]._pitch;
if (!src)
return;
@ -928,12 +927,12 @@ void IndeoDecoderBase::outputPlane(IVIPlaneDesc *_plane, uint8 *dst, int dstPitc
int IndeoDecoderBase::processEmptyTile(IVIBandDesc *band,
IVITile *tile, int32 mvScale) {
int x, y, needMc, mbn, blk, numBlocks, mvX, mvY, mcType;
int offs, mbOffset, rowOffset, ret;
IVIMbInfo *mb, *refMb;
const int16 * src;
int16 * dst;
IviMCFunc mcNoDeltaFunc;
int x, y, needMc, mbn, blk, numBlocks, mvX, mvY, mcType;
int offs, mbOffset, rowOffset, ret;
IVIMbInfo *mb, *refMb;
const int16 *src;
int16 *dst;
IviMCFunc mcNoDeltaFunc;
if (tile->_numMBs != IVI_MBs_PER_TILE(tile->_width, tile->_height, band->_mbSize)) {
warning("Allocated tile size %d mismatches "
@ -1237,7 +1236,7 @@ int IndeoDecoderBase::ivi_decode_coded_blocks(GetBits *gb, IVIBandDesc *band,
IviMCFunc mc, IviMCAvgFunc mcAvg, int mvX, int mvY,
int mvX2, int mvY2, int *prevDc, int isIntra,
int mcType, int mcType2, uint32 quant, int offs) {
const uint16 *base_tab = isIntra ? band->_intraBase : band->_interBase;
const uint16 *baseTab = isIntra ? band->_intraBase : band->_interBase;
RVMapDesc *rvmap = band->_rvMap;
uint8 colFlags[8];
int32 trvec[64];
@ -1295,7 +1294,7 @@ int IndeoDecoderBase::ivi_decode_coded_blocks(GetBits *gb, IVIBandDesc *band,
if (!val)
warning("Val = 0 encountered!");
q = (base_tab[pos] * quant) >> 9;
q = (baseTab[pos] * quant) >> 9;
if (q > 1)
val = val * q + FFSIGN(val) * (((q ^ 1) - 1) >> 1);
trvec[pos] = val;

View File

@ -83,12 +83,8 @@ static inline int avSizeMult(size_t a, size_t b, size_t *r) {
/*------------------------------------------------------------------------*/
void *avMalloc(size_t size) {
return malloc(size);
}
void *avMallocZ(size_t size) {
void *ptr = avMalloc(size);
void *ptr = malloc(size);
if (ptr)
memset(ptr, 0, size);
@ -96,22 +92,15 @@ void *avMallocZ(size_t size) {
}
void *avMallocArray(size_t nmemb, size_t size) {
if (!size || nmemb >= MAX_INTEGER / size)
return nullptr;
assert(size && nmemb < MAX_INTEGER / size);
return malloc(nmemb * size);
}
void *avMallocZArray(size_t nmemb, size_t size) {
if (!size || nmemb >= MAX_INTEGER / size)
return NULL;
assert(size && nmemb < MAX_INTEGER / size);
return avMallocZ(nmemb * size);
}
void avFree(void *ptr) {
free(ptr);
}
void avFreeP(void *arg) {
void **ptr = (void **)arg;
free(*ptr);
@ -127,12 +116,12 @@ void *avReallocF(void *ptr, size_t nelem, size_t elsize) {
void *r;
if (avSizeMult(elsize, nelem, &size)) {
avFree(ptr);
free(ptr);
return nullptr;
}
r = avRealloc(ptr, size);
if (!r)
avFree(ptr);
free(ptr);
return r;
}

View File

@ -39,17 +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).
*
* @param size Size in bytes for the memory block to be allocated
* @return Pointer to the allocated block, or `NULL` if the block cannot
* be allocated
* @see av_mallocz()
*/
extern void *avMalloc(size_t size);
/**
* 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
@ -89,19 +78,6 @@ extern void *avMallocArray(size_t nmemb, size_t size);
*/
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.
*
* @param ptr Pointer to the memory block which should be freed.
*
* @note `ptr = NULL` is explicitly allowed.
* @note It is recommended that you use av_freep() instead, to prevent leaving
* behind dangling pointers.
* @see av_freep()
*/
extern void avFree(void *ptr);
/**
* 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`.

View File

@ -89,8 +89,8 @@ const Graphics::Surface *Indeo4Decoder::decodeFrame(Common::SeekableReadStream &
}
int Indeo4Decoder::decodePictureHeader() {
int pic_size_indx, i, p;
IVIPicConfig _picConf;
int pic_size_indx, i, p;
IVIPicConfig picConf;
if (_ctx._gb->getBits(18) != 0x3FFF8) {
warning("Invalid picture start code!");
@ -133,21 +133,21 @@ int Indeo4Decoder::decodePictureHeader() {
pic_size_indx = _ctx._gb->getBits(3);
if (pic_size_indx == IVI4_PIC_SIZE_ESC) {
_picConf._picHeight = _ctx._gb->getBits(16);
_picConf._picWidth = _ctx._gb->getBits(16);
picConf._picHeight = _ctx._gb->getBits(16);
picConf._picWidth = _ctx._gb->getBits(16);
} else {
_picConf._picHeight = _ivi4_common_pic_sizes[pic_size_indx * 2 + 1];
_picConf._picWidth = _ivi4_common_pic_sizes[pic_size_indx * 2];
picConf._picHeight = _ivi4_common_pic_sizes[pic_size_indx * 2 + 1];
picConf._picWidth = _ivi4_common_pic_sizes[pic_size_indx * 2];
}
// Decode tile dimensions.
_ctx._usesTiling = _ctx._gb->getBit();
if (_ctx._usesTiling) {
_picConf._tileHeight = scaleTileSize(_picConf._picHeight, _ctx._gb->getBits(4));
_picConf._tileWidth = scaleTileSize(_picConf._picWidth, _ctx._gb->getBits(4));
picConf._tileHeight = scaleTileSize(picConf._picHeight, _ctx._gb->getBits(4));
picConf._tileWidth = scaleTileSize(picConf._picWidth, _ctx._gb->getBits(4));
} else {
_picConf._tileHeight = _picConf._picHeight;
_picConf._tileWidth = _picConf._picWidth;
picConf._tileHeight = picConf._picHeight;
picConf._tileWidth = picConf._picWidth;
}
// Decode chroma subsampling. We support only 4:4 aka YVU9.
@ -155,34 +155,34 @@ int Indeo4Decoder::decodePictureHeader() {
warning("Only YVU9 picture format is supported!");
return -1;
}
_picConf._chromaHeight = (_picConf._picHeight + 3) >> 2;
_picConf._chromaWidth = (_picConf._picWidth + 3) >> 2;
picConf._chromaHeight = (picConf._picHeight + 3) >> 2;
picConf._chromaWidth = (picConf._picWidth + 3) >> 2;
// decode subdivision of the planes
_picConf._lumaBands = decodePlaneSubdivision();
_picConf._chromaBands = 0;
if (_picConf._lumaBands)
_picConf._chromaBands = decodePlaneSubdivision();
_ctx._isScalable = _picConf._lumaBands != 1 || _picConf._chromaBands != 1;
if (_ctx._isScalable && (_picConf._lumaBands != 4 || _picConf._chromaBands != 1)) {
picConf._lumaBands = decodePlaneSubdivision();
picConf._chromaBands = 0;
if (picConf._lumaBands)
picConf._chromaBands = decodePlaneSubdivision();
_ctx._isScalable = picConf._lumaBands != 1 || picConf._chromaBands != 1;
if (_ctx._isScalable && (picConf._lumaBands != 4 || picConf._chromaBands != 1)) {
warning("Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d",
_picConf._lumaBands, _picConf._chromaBands);
picConf._lumaBands, picConf._chromaBands);
return -1;
}
// check if picture layout was changed and reallocate buffers
if (_picConf.ivi_pic_config_cmp(_ctx._picConf)) {
if (IVIPlaneDesc::initPlanes(_ctx._planes, &_picConf, 1)) {
if (picConf.ivi_pic_config_cmp(_ctx._picConf)) {
if (IVIPlaneDesc::initPlanes(_ctx._planes, &picConf, 1)) {
warning("Couldn't reallocate color planes!");
_ctx._picConf._lumaBands = 0;
return -2;
}
_ctx._picConf = _picConf;
_ctx._picConf = picConf;
// set default macroblock/block dimensions
for (p = 0; p <= 2; p++) {
for (i = 0; i < (!p ? _picConf._lumaBands : _picConf._chromaBands); i++) {
for (i = 0; i < (!p ? picConf._lumaBands : picConf._chromaBands); i++) {
_ctx._planes[p]._bands[i]._mbSize = !p ? (!_ctx._isScalable ? 16 : 8) : 4;
_ctx._planes[p]._bands[i]._blkSize = !p ? 8 : 4;
}
@ -233,13 +233,13 @@ int Indeo4Decoder::decodePictureHeader() {
}
void Indeo4Decoder::switchBuffers() {
int is_prev_ref = 0, is_ref = 0;
int isPrevRef = 0, isRef = 0;
switch (_ctx._prevFrameType) {
case IVI4_FRAMETYPE_INTRA:
case IVI4_FRAMETYPE_INTRA1:
case IVI4_FRAMETYPE_INTER:
is_prev_ref = 1;
isPrevRef = 1;
break;
}
@ -247,16 +247,16 @@ void Indeo4Decoder::switchBuffers() {
case IVI4_FRAMETYPE_INTRA:
case IVI4_FRAMETYPE_INTRA1:
case IVI4_FRAMETYPE_INTER:
is_ref = 1;
isRef = 1;
break;
default:
break;
}
if (is_prev_ref && is_ref) {
if (isPrevRef && isRef) {
SWAP(_ctx._dstBuf, _ctx._refBuf);
} else if (is_prev_ref) {
} else if (isPrevRef) {
SWAP(_ctx._refBuf, _ctx._bRefBuf);
SWAP(_ctx._dstBuf, _ctx._refBuf);
}
@ -443,13 +443,13 @@ int Indeo4Decoder::decodeBandHeader(IVIBandDesc *band) {
}
int Indeo4Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
int x, y, mvX, mvY, mvDelta, offs, mbOffset, blksPerMb,
int x, y, mvX, mvY, mvDelta, offs, mbOffset, blksPerMb,
mvScale, mbTypeBits, s;
IVIMbInfo *mb, *ref_mb;
int row_offset = band->_mbSize * band->_pitch;
IVIMbInfo *mb, *refMb;
int row_offset = band->_mbSize * band->_pitch;
mb = tile->_mbs;
ref_mb = tile->_refMbs;
refMb = tile->_refMbs;
offs = tile->_yPos * band->_pitch + tile->_xPos;
blksPerMb = band->_mbSize != band->_blkSize ? 4 : 1;
@ -489,24 +489,24 @@ int Indeo4Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
}
mb->_mvX = mb->_mvY = 0; // no motion vector coded
if (band->_inheritMv && ref_mb) {
if (band->_inheritMv && refMb) {
// motion vector inheritance
if (mvScale) {
mb->_mvX = scaleMV(ref_mb->_mvX, mvScale);
mb->_mvY = scaleMV(ref_mb->_mvY, mvScale);
mb->_mvX = scaleMV(refMb->_mvX, mvScale);
mb->_mvY = scaleMV(refMb->_mvY, mvScale);
} else {
mb->_mvX = ref_mb->_mvX;
mb->_mvY = ref_mb->_mvY;
mb->_mvX = refMb->_mvX;
mb->_mvY = refMb->_mvY;
}
}
} else {
if (band->_inheritMv) {
// copy mb_type from corresponding reference mb
if (!ref_mb) {
warning("ref_mb unavailable");
if (!refMb) {
warning("refMb unavailable");
return -1;
}
mb->_type = ref_mb->_type;
mb->_type = refMb->_type;
} else if (_ctx._frameType == IVI4_FRAMETYPE_INTRA ||
_ctx._frameType == IVI4_FRAMETYPE_INTRA1) {
mb->_type = 0; // mb_type is always INTRA for intra-frames
@ -518,7 +518,7 @@ int Indeo4Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
mb->_qDelta = 0;
if (band->_inheritQDelta) {
if (ref_mb) mb->_qDelta = ref_mb->_qDelta;
if (refMb) mb->_qDelta = refMb->_qDelta;
} else if (mb->_cbp || (!band->_plane && !band->_bandNum &&
_ctx._inQ)) {
mb->_qDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table,
@ -530,14 +530,14 @@ int Indeo4Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
mb->_mvX = mb->_mvY = 0; // there is no motion vector in intra-macroblocks
} else {
if (band->_inheritMv) {
if (ref_mb) {
if (refMb) {
// motion vector inheritance
if (mvScale) {
mb->_mvX = scaleMV(ref_mb->_mvX, mvScale);
mb->_mvY = scaleMV(ref_mb->_mvY, mvScale);
mb->_mvX = scaleMV(refMb->_mvX, mvScale);
mb->_mvY = scaleMV(refMb->_mvY, mvScale);
} else {
mb->_mvX = ref_mb->_mvX;
mb->_mvY = ref_mb->_mvY;
mb->_mvX = refMb->_mvX;
mb->_mvY = refMb->_mvY;
}
}
} else {
@ -582,8 +582,8 @@ int Indeo4Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
}
mb++;
if (ref_mb)
ref_mb++;
if (refMb)
refMb++;
mbOffset += band->_mbSize;
}

View File

@ -100,8 +100,7 @@ const Graphics::Surface *Indeo5Decoder::decodeFrame(Common::SeekableReadStream &
}
int Indeo5Decoder::decodePictureHeader() {
IVIPicConfig picConf;
IVIPicConfig picConf;
int ret;
if (_ctx._gb->getBits(5) != 0x1F) {
@ -201,8 +200,8 @@ bool Indeo5Decoder::isNonNullFrame() const {
}
int Indeo5Decoder::decodeBandHeader(IVIBandDesc *band) {
int i, ret;
uint8 bandFlags;
int i, ret;
uint8 bandFlags;
bandFlags = _ctx._gb->getBits(8);
@ -259,10 +258,9 @@ int Indeo5Decoder::decodeBandHeader(IVIBandDesc *band) {
}
int Indeo5Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
int x, y, mvX, mvY, mvDelta, offs, mbOffset,
mvScale, blksPerMb, s;
IVIMbInfo *mb, *refMb;
int rowOffset = band->_mbSize * band->_pitch;
int x, y, mvX, mvY, mvDelta, offs, mbOffset, mvScale, blksPerMb, s;
IVIMbInfo *mb, *refMb;
int rowOffset = band->_mbSize * band->_pitch;
mb = tile->_mbs;
refMb = tile->_refMbs;
@ -386,11 +384,11 @@ int Indeo5Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
}
int Indeo5Decoder::decode_gop_header() {
int result, i, p, tileSize, picSizeIndx, mbSize, blkSize, isScalable;
int quantMat;
bool blkSizeChanged = false;
IVIBandDesc *band, *band1, *band2;
IVIPicConfig picConf;
int result, i, p, tileSize, picSizeIndx, mbSize, blkSize, isScalable;
int quantMat;
bool blkSizeChanged = false;
IVIBandDesc *band, *band1, *band2;
IVIPicConfig picConf;
_ctx._gopFlags = _ctx._gb->getBits(8);