IMAGE: Renaming structure fields for Indeo decoders

This commit is contained in:
Paul Gilbert 2016-09-10 16:04:22 -04:00
parent fe6d624277
commit 58ad70f351
5 changed files with 1086 additions and 1084 deletions

File diff suppressed because it is too large Load Diff

View File

@ -64,15 +64,14 @@ enum {
* Declare inverse transform function types
*/
typedef void (InvTransformPtr)(const int32 *in, int16 *out, uint32 pitch, const uint8 *flags);
typedef void (DCTransformPtr) (const int32 *in, int16 *out, uint32 pitch, int blk_size);
typedef void (DCTransformPtr) (const int32 *in, int16 *out, uint32 pitch, int blkSize);
typedef void(*ivi_mc_func) (int16 *buf, const int16 *ref_buf,
uint32 pitch, int mc_type);
typedef void(*ivi_mc_avg_func) (int16 *buf, const int16 *ref_buf1,
const int16 *ref_buf2,
uint32 pitch, int mc_type, int mc_type2);
typedef void(*IviMCFunc) (int16 *buf, const int16 *refBuf, uint32 pitch, int mc_type);
typedef void(*IviMCAvgFunc) (int16 *buf, const int16 *refBuf1, const int16 *refBuf2,
uint32 pitch, int mcType, int mcType2);
#define IVI_VLC_BITS 13 ///< max number of bits of the ivi's huffman codes
///< max number of bits of the ivi's huffman codes
#define IVI_VLC_BITS 13
#define IVI5_IS_PROTECTED 0x20
/**
@ -83,15 +82,15 @@ typedef void(*ivi_mc_avg_func) (int16 *buf, const int16 *ref_buf1,
/**
* calculate number of macroblocks in a tile
*/
#define IVI_MBs_PER_TILE(tile_width, tile_height, mb_size) \
((((tile_width) + (mb_size) - 1) / (mb_size)) * (((tile_height) + (mb_size) - 1) / (mb_size)))
#define IVI_MBs_PER_TILE(_tileWidth, _tileHeight, _mbSize) \
((((_tileWidth) + (_mbSize) - 1) / (_mbSize)) * (((_tileHeight) + (_mbSize) - 1) / (_mbSize)))
/**
* huffman codebook descriptor
*/
struct IVIHuffDesc {
int32 num_rows;
uint8 xbits[16];
int32 _numRows;
uint8 _xBits[16];
/*
* Generate a huffman codebook from the given descriptor
@ -126,13 +125,13 @@ struct IVI45DecContext;
*/
struct IVIHuffTab {
public:
int32 tab_sel; /// index of one of the predefined tables
int32 _tabSel; /// index of one of the predefined tables
/// or "7" for custom one
VLC *tab; /// pointer to the table associated with tab_sel
VLC * _tab; /// pointer to the table associated with tab_sel
/// the following are used only when tab_sel == 7
IVIHuffDesc cust_desc; /// custom Huffman codebook descriptor
VLC cust_tab; /// vlc table for custom codebook
IVIHuffDesc _custDesc; /// custom Huffman codebook descriptor
VLC _custTab; /// vlc table for custom codebook
/**
* Constructor
@ -146,26 +145,26 @@ public:
* run-value (RLE) table descriptor
*/
struct RVMapDesc {
uint8 eob_sym; ///< end of block symbol
uint8 esc_sym; ///< escape symbol
uint8 runtab[256];
int8 valtab[256];
uint8 _eobSym; ///< end of block symbol
uint8 _escSym; ///< escape symbol
uint8 _runtab[256];
int8 _valtab[256];
};
/**
* information for Indeo macroblock (16x16, 8x8 or 4x4)
*/
struct IVIMbInfo {
int16 xpos;
int16 ypos;
uint32 buf_offs; ///< address in the output buffer for this mb
uint8 type; ///< macroblock type: 0 - INTRA, 1 - INTER
uint8 cbp; ///< coded block pattern
int8 q_delta; ///< quant delta
int8 mv_x; ///< motion vector (x component)
int8 mv_y; ///< motion vector (y component)
int8 b_mv_x; ///< second motion vector (x component)
int8 b_mv_y; ///< second motion vector (y component)
int16 _xPos;
int16 _yPos;
uint32 _bufOffs; ///< address in the output buffer for this mb
uint8 _type; ///< macroblock type: 0 - INTRA, 1 - INTER
uint8 _cbp; ///< coded block pattern
int8 _qDelta; ///< quant delta
int8 _mvX; ///< motion vector (x component)
int8 _mvY; ///< motion vector (y component)
int8 _bMvX; ///< second motion vector (x component)
int8 _bMvY; ///< second motion vector (y component)
IVIMbInfo();
};
@ -174,16 +173,16 @@ struct IVIMbInfo {
* information for Indeo tile
*/
struct IVITile {
int xpos;
int ypos;
int width;
int height;
int mb_size;
int is_empty; ///< = 1 if this tile doesn't contain any data
int data_size; ///< size of the data in bytes
int num_MBs; ///< number of macroblocks in this tile
IVIMbInfo * mbs; ///< array of macroblock descriptors
IVIMbInfo * ref_mbs; ///< ptr to the macroblock descriptors of the reference tile
int _xPos;
int _yPos;
int _width;
int _height;
int _mbSize;
bool _isEmpty;
int _dataSize; ///< size of the data in bytes
int _numMBs; ///< number of macroblocks in this tile
IVIMbInfo * _mbs; ///< array of macroblock descriptors
IVIMbInfo * _refMbs; ///< ptr to the macroblock descriptors of the reference tile
IVITile();
};
@ -192,49 +191,49 @@ struct IVITile {
* information for Indeo wavelet band
*/
struct IVIBandDesc {
int plane; ///< plane number this band belongs to
int band_num; ///< band number
int width;
int height;
int aheight; ///< aligned band height
const uint8 * data_ptr; ///< ptr to the first byte of the band data
int data_size; ///< size of the band data
int16 * buf; ///< pointer to the output buffer for this band
int16 * ref_buf; ///< pointer to the reference frame buffer (for motion compensation)
int16 * b_ref_buf; ///< pointer to the second reference frame buffer (for motion compensation)
int16 * bufs[4]; ///< array of pointers to the band buffers
int pitch; ///< pitch associated with the buffers above
int is_empty; ///< = 1 if this band doesn't contain any data
int mb_size; ///< macroblock size
int blk_size; ///< block size
int is_halfpel; ///< precision of the motion compensation: 0 - fullpel, 1 - halfpel
int inherit_mv; ///< tells if motion vector is inherited from reference macroblock
int inherit_qdelta; ///< tells if quantiser delta is inherited from reference macroblock
int qdelta_present; ///< tells if Qdelta signal is present in the bitstream (Indeo5 only)
int quant_mat; ///< dequant matrix index
int glob_quant; ///< quant base for this band
const uint8 * scan; ///< ptr to the scan pattern
int scan_size; ///< size of the scantable
int _plane; ///< plane number this band belongs to
int _bandNum; ///< band number
int _width;
int _height;
int _aHeight; ///< aligned band height
const uint8 * _dataPtr; ///< ptr to the first byte of the band data
int _dataSize; ///< size of the band data
int16 * _buf; ///< pointer to the output buffer for this band
int16 * _refBuf; ///< pointer to the reference frame buffer (for motion compensation)
int16 * _bRefBuf; ///< pointer to the second reference frame buffer (for motion compensation)
int16 * _bufs[4]; ///< array of pointers to the band buffers
int _pitch; ///< _pitch associated with the buffers above
bool _isEmpty;
int _mbSize; ///< macroblock size
int _blkSize; ///< block size
uint8 _isHalfpel; ///< precision of the motion compensation: 0 - fullpel, 1 - halfpel
bool _inheritMv; ///< tells if motion vector is inherited from reference macroblock
bool _inheritQDelta; ///< tells if quantiser delta is inherited from reference macroblock
bool _qdeltaPresent; ///< tells if Qdelta signal is present in the bitstream (Indeo5 only)
int _quantMat; ///< dequant matrix index
int _globQuant; ///< quant base for this band
const uint8 * _scan; ///< ptr to the scan pattern
int _scanSize; ///< size of the scantable
IVIHuffTab blk_vlc; ///< vlc table for decoding block data
IVIHuffTab _blkVlc; ///< vlc table for decoding block data
int num_corr; ///< number of correction entries
uint8 corr[61 * 2]; ///< rvmap correction pairs
int rvmap_sel; ///< rvmap table selector
RVMapDesc * rv_map; ///< ptr to the RLE table for this band
int num_tiles; ///< number of tiles in this band
IVITile * tiles; ///< array of tile descriptors
InvTransformPtr *inv_transform;
int transform_size;
DCTransformPtr *dc_transform;
int is_2d_trans; ///< 1 indicates that the two-dimensional inverse transform is used
int32 checksum; ///< for debug purposes
int checksum_present;
int bufsize; ///< band buffer size in bytes
const uint16 * intra_base; ///< quantization matrix for intra blocks
const uint16 * inter_base; ///< quantization matrix for inter blocks
const uint8 * intra_scale; ///< quantization coefficient for intra blocks
const uint8 * inter_scale; ///< quantization coefficient for inter blocks
int _numCorr; ///< number of correction entries
uint8 _corr[61 * 2]; ///< rvmap correction pairs
int _rvmapSel; ///< rvmap table selector
RVMapDesc * _rvMap; ///< ptr to the RLE table for this band
int _numTiles; ///< number of tiles in this band
IVITile * _tiles; ///< array of tile descriptors
InvTransformPtr *_invTransform;
int _transformSize;
DCTransformPtr *_dcTransform;
bool _is2dTrans;
int32 _checksum; ///< for debug purposes
int _checksumPresent;
int _bufSize; ///< band buffer size in bytes
const uint16 * _intraBase; ///< quantization matrix for intra blocks
const uint16 * _interBase; ///< quantization matrix for inter blocks
const uint8 * _intraScale; ///< quantization coefficient for intra blocks
const uint8 * _interScale; ///< quantization coefficient for inter blocks
IVIBandDesc();
@ -242,14 +241,14 @@ struct IVIBandDesc {
};
struct IVIPicConfig {
uint16 pic_width;
uint16 pic_height;
uint16 chroma_width;
uint16 chroma_height;
uint16 tile_width;
uint16 tile_height;
uint8 luma_bands;
uint8 chroma_bands;
uint16 _picWidth;
uint16 _picHeight;
uint16 _chromaWidth;
uint16 _chromaHeight;
uint16 _tileWidth;
uint16 _tileHeight;
uint8 _lumaBands;
uint8 _chromaBands;
IVIPicConfig();
@ -263,16 +262,16 @@ struct IVIPicConfig {
* color plane (luma or chroma) information
*/
struct IVIPlaneDesc {
uint16 width;
uint16 height;
uint8 num_bands; ///< number of bands this plane subdivided into
IVIBandDesc *bands; ///< array of band descriptors
uint16 _width;
uint16 _height;
uint8 _numBands; ///< number of bands this plane subdivided into
IVIBandDesc * _bands; ///< array of band descriptors
IVIPlaneDesc();
static int ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg, bool is_indeo4);
static int ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg, bool _isIndeo4);
static int ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height);
static int ff_ivi_init_tiles(IVIPlaneDesc *planes, int _tileWidth, int _tileHeight);
/*
* Free planes, bands and macroblocks buffers.
@ -349,60 +348,60 @@ struct AVFrame {
struct IVI45DecContext {
friend struct IVIHuffTab;
private:
VLC_TYPE table_data[8192 * 16][2];
VLC ivi_mb_vlc_tabs[8]; ///< static macroblock Huffman tables
VLC ivi_blk_vlc_tabs[8]; ///< static block Huffman tables
VLC_TYPE _tableData[8192 * 16][2];
VLC _iviMbVlcTabs[8]; ///< static macroblock Huffman tables
VLC _iviBlkVlcTabs[8]; ///< static block Huffman tables
public:
GetBits * gb;
RVMapDesc rvmap_tabs[9]; ///< local corrected copy of the static rvmap tables
GetBits * _gb;
RVMapDesc _rvmapTabs[9]; ///< local corrected copy of the static rvmap tables
uint32 frame_num;
int frame_type;
int prev_frame_type; ///< frame type of the previous frame
uint32 data_size; ///< size of the frame data in bytes from picture header
int is_scalable;
const uint8 * frame_data; ///< input frame data pointer
int inter_scal; ///< signals a sequence of scalable inter frames
uint32 frame_size; ///< frame size in bytes
uint32 pic_hdr_size; ///< picture header size in bytes
uint8 frame_flags;
uint16 checksum; ///< frame checksum
uint32 _frameNum;
int _frameType;
int _prevFrameType; ///< frame type of the previous frame
uint32 _dataSize; ///< size of the frame data in bytes from picture header
int _isScalable;
const uint8 * _frameData; ///< input frame data pointer
int _interScal; ///< signals a sequence of scalable inter frames
uint32 _frameSize; ///< frame size in bytes
uint32 _picHdrSize; ///< picture header size in bytes
uint8 _frameFlags;
uint16 _checksum; ///< frame _checksum
IVIPicConfig pic_conf;
IVIPlaneDesc planes[3]; ///< color planes
IVIPicConfig _picConf;
IVIPlaneDesc _planes[3]; ///< color planes
int buf_switch; ///< used to switch between three buffers
int dst_buf; ///< buffer index for the currently decoded frame
int ref_buf; ///< inter frame reference buffer index
int ref2_buf; ///< temporal storage for switching buffers
int b_ref_buf; ///< second reference frame buffer index
int _bufSwitch; ///< used to switch between three buffers
int _dstBuf; ///< buffer index for the currently decoded frame
int _refBuf; ///< inter frame reference buffer index
int _ref2Buf; ///< temporal storage for switching buffers
int _bRefBuf; ///< second reference frame buffer index
IVIHuffTab mb_vlc; ///< current macroblock table descriptor
IVIHuffTab blk_vlc; ///< current block table descriptor
IVIHuffTab _mbVlc; ///< current macroblock table descriptor
IVIHuffTab _blkVlc; ///< current block table descriptor
uint8 rvmap_sel;
uint8 in_imf;
uint8 in_q; ///< flag for explicitly stored quantiser delta
uint8 pic_glob_quant;
uint8 unknown1;
uint8 _rvmapSel;
bool _inImf;
bool _inQ; ///< flag for explicitly stored quantiser delta
uint8 _picGlobQuant;
uint8 _unknown1;
uint16 gop_hdr_size;
uint8 gop_flags;
uint32 lock_word;
uint16 _gopHdrSize;
uint8 _gopFlags;
uint32 _lockWord;
uint8 has_b_frames;
uint8 has_transp; ///< transparency mode status: 1 - enabled
uint8 uses_tiling;
uint8 uses_haar;
uint8 uses_fullpel;
bool _hasBFrames;
bool _hasTransp; ///< transparency mode enabled
bool _usesTiling;
bool _usesHaar;
bool _usesFullpel;
int gop_invalid;
int buf_invalid[4];
bool _gopInvalid;
int _bufInvalid[4];
int is_indeo4;
bool _isIndeo4;
AVFrame * p_frame;
int got_p_frame;
AVFrame * _pFrame;
bool _gotPFrame;
IVI45DecContext();
private:
@ -427,7 +426,7 @@ private:
*
* @param[in] plane pointer to the descriptor of the plane being processed
* @param[out] dst pointer to the destination buffer
* @param[in] dst_pitch pitch of the destination buffer
* @param[in] dst_pitch _pitch of the destination buffer
*/
void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8 *dst,
const int dst_pitch);
@ -437,7 +436,7 @@ private:
*
* @param[in] plane pointer to the descriptor of the plane being processed
* @param[out] dst pointer to the destination buffer
* @param[in] dst_pitch pitch of the destination buffer
* @param[in] dst_pitch _pitch of the destination buffer
*/
void ff_ivi_recompose53(const IVIPlaneDesc *plane,
uint8 *dst, const int dst_pitch);
@ -449,7 +448,7 @@ private:
*
* @param[in] plane pointer to the descriptor of the plane being processed
* @param[out] dst pointer to the buffer receiving converted pixels
* @param[in] dst_pitch pitch for moving to the next y line
* @param[in] dst_pitch _pitch for moving to the next y line
*/
void ivi_output_plane(IVIPlaneDesc *plane, uint8 *dst, int dst_pitch);
@ -488,17 +487,17 @@ private:
*/
int ivi_decode_blocks(GetBits *gb, IVIBandDesc *band, IVITile *tile);
int ivi_mc(IVIBandDesc *band, ivi_mc_func mc, ivi_mc_avg_func mc_avg,
int offs, int mv_x, int mv_y, int mv_x2, int mv_y2,
int ivi_mc(IVIBandDesc *band, IviMCFunc mc, IviMCAvgFunc mc_avg,
int offs, int _mvX, int _mvY, int mv_x2, int mv_y2,
int mc_type, int mc_type2);
int ivi_decode_coded_blocks(GetBits *gb, IVIBandDesc *band,
ivi_mc_func mc, ivi_mc_avg_func mc_avg, int mv_x, int mv_y,
IviMCFunc mc, IviMCAvgFunc mc_avg, int _mvX, int _mvY,
int mv_x2, int mv_y2, int *prev_dc, int is_intra,
int mc_type, int mc_type2, uint32 quant, int offs);
int ivi_dc_transform(IVIBandDesc *band, int *prev_dc, int buf_offs,
int blk_size);
int ivi_dc_transform(IVIBandDesc *band, int *prevDc, int bufOffs,
int blkSize);
protected:
IVI45DecContext _ctx;
Graphics::PixelFormat _pixelFormat;
@ -538,7 +537,7 @@ protected:
virtual int decode_band_hdr(IVIBandDesc *band) = 0;
/**
* Decode information (block type, cbp, quant delta, motion vector)
* Decode information (block type, _cbp, quant delta, motion vector)
* for all macroblocks in the current tile.
*
* @param[in,out] band pointer to the band descriptor

View File

@ -41,10 +41,10 @@ namespace Image {
#define IVI4_PIC_SIZE_ESC 7
Indeo4Decoder::Indeo4Decoder(uint16 width, uint16 height) : IndeoDecoderBase(width, height) {
_ctx.is_indeo4 = true;
_ctx.ref_buf = 1;
_ctx.b_ref_buf = 3;
_ctx.p_frame = new AVFrame();
_ctx._isIndeo4 = true;
_ctx._refBuf = 1;
_ctx._bRefBuf = 3;
_ctx._pFrame = new AVFrame();
}
bool Indeo4Decoder::isIndeo4(Common::SeekableReadStream &stream) {
@ -72,56 +72,56 @@ const Graphics::Surface *Indeo4Decoder::decodeFrame(Common::SeekableReadStream &
// Set up the frame data buffer
byte *frameData = new byte[stream.size()];
stream.read(frameData, stream.size());
_ctx.frame_data = frameData;
_ctx.frame_size = stream.size();
_ctx._frameData = frameData;
_ctx._frameSize = stream.size();
// Set up the GetBits instance for reading the data
_ctx.gb = new GetBits(_ctx.frame_data, _ctx.frame_size * 8);
_ctx._gb = new GetBits(_ctx._frameData, _ctx._frameSize * 8);
// Decode the frame
int err = decodeIndeoFrame();
// Free the bit reader and frame buffer
delete _ctx.gb;
_ctx.gb = nullptr;
delete _ctx._gb;
_ctx._gb = nullptr;
delete[] frameData;
_ctx.frame_data = nullptr;
_ctx.frame_size = 0;
_ctx._frameData = nullptr;
_ctx._frameSize = 0;
return (err < 0) ? nullptr : &_surface->rawSurface();
}
int Indeo4Decoder::decodePictureHeader() {
int pic_size_indx, i, p;
IVIPicConfig pic_conf;
IVIPicConfig _picConf;
if (_ctx.gb->getBits(18) != 0x3FFF8) {
if (_ctx._gb->getBits(18) != 0x3FFF8) {
warning("Invalid picture start code!");
return -1;
}
_ctx.prev_frame_type = _ctx.frame_type;
_ctx.frame_type = _ctx.gb->getBits(3);
if (_ctx.frame_type == 7) {
warning("Invalid frame type: %d", _ctx.frame_type);
_ctx._prevFrameType = _ctx._frameType;
_ctx._frameType = _ctx._gb->getBits(3);
if (_ctx._frameType == 7) {
warning("Invalid frame type: %d", _ctx._frameType);
return -1;
}
if (_ctx.frame_type == IVI4_FRAMETYPE_BIDIR)
_ctx.has_b_frames = 1;
if (_ctx._frameType == IVI4_FRAMETYPE_BIDIR)
_ctx._hasBFrames = true;
_ctx.has_transp = _ctx.gb->getBits1();
_ctx._hasTransp = _ctx._gb->getBits1();
// unknown bit: Mac decoder ignores this bit, XANIM returns error
if (_ctx.gb->getBits1()) {
if (_ctx._gb->getBits1()) {
warning("Sync bit is set!");
return -1;
}
_ctx.data_size = _ctx.gb->getBits1() ? _ctx.gb->getBits(24) : 0;
_ctx._dataSize = _ctx._gb->getBits1() ? _ctx._gb->getBits(24) : 0;
// null frames don't contain anything else so we just return
if (_ctx.frame_type >= IVI4_FRAMETYPE_NULL_FIRST) {
if (_ctx._frameType >= IVI4_FRAMETYPE_NULL_FIRST) {
warning("Null frame encountered!");
return 0;
}
@ -129,108 +129,108 @@ int Indeo4Decoder::decodePictureHeader() {
// Check key lock status. If enabled - ignore lock word.
// Usually we have to prompt the user for the password, but
// we don't do that because Indeo 4 videos can be decoded anyway
if (_ctx.gb->getBits1()) {
_ctx.gb->skipBitsLong(32);
if (_ctx._gb->getBits1()) {
_ctx._gb->skipBitsLong(32);
warning("Password-protected clip!");
}
pic_size_indx = _ctx.gb->getBits(3);
pic_size_indx = _ctx._gb->getBits(3);
if (pic_size_indx == IVI4_PIC_SIZE_ESC) {
pic_conf.pic_height = _ctx.gb->getBits(16);
pic_conf.pic_width = _ctx.gb->getBits(16);
_picConf._picHeight = _ctx._gb->getBits(16);
_picConf._picWidth = _ctx._gb->getBits(16);
} else {
pic_conf.pic_height = _ivi4_common_pic_sizes[pic_size_indx * 2 + 1];
pic_conf.pic_width = _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.uses_tiling = _ctx.gb->getBits1();
if (_ctx.uses_tiling) {
pic_conf.tile_height = scaleTileSize(pic_conf.pic_height, _ctx.gb->getBits(4));
pic_conf.tile_width = scaleTileSize(pic_conf.pic_width, _ctx.gb->getBits(4));
_ctx._usesTiling = _ctx._gb->getBits1();
if (_ctx._usesTiling) {
_picConf._tileHeight = scaleTileSize(_picConf._picHeight, _ctx._gb->getBits(4));
_picConf._tileWidth = scaleTileSize(_picConf._picWidth, _ctx._gb->getBits(4));
} else {
pic_conf.tile_height = pic_conf.pic_height;
pic_conf.tile_width = pic_conf.pic_width;
_picConf._tileHeight = _picConf._picHeight;
_picConf._tileWidth = _picConf._picWidth;
}
// Decode chroma subsampling. We support only 4:4 aka YVU9.
if (_ctx.gb->getBits(2)) {
if (_ctx._gb->getBits(2)) {
warning("Only YVU9 picture format is supported!");
return -1;
}
pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2;
pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2;
_picConf._chromaHeight = (_picConf._picHeight + 3) >> 2;
_picConf._chromaWidth = (_picConf._picWidth + 3) >> 2;
// decode subdivision of the planes
pic_conf.luma_bands = decodePlaneSubdivision();
pic_conf.chroma_bands = 0;
if (pic_conf.luma_bands)
pic_conf.chroma_bands = decodePlaneSubdivision();
_ctx.is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1;
if (_ctx.is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 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",
pic_conf.luma_bands, pic_conf.chroma_bands);
_picConf._lumaBands, _picConf._chromaBands);
return -1;
}
// check if picture layout was changed and reallocate buffers
if (pic_conf.ivi_pic_config_cmp(_ctx.pic_conf)) {
if (IVIPlaneDesc::ff_ivi_init_planes(_ctx.planes, &pic_conf, 1)) {
if (_picConf.ivi_pic_config_cmp(_ctx._picConf)) {
if (IVIPlaneDesc::ff_ivi_init_planes(_ctx._planes, &_picConf, 1)) {
warning("Couldn't reallocate color planes!");
_ctx.pic_conf.luma_bands = 0;
_ctx._picConf._lumaBands = 0;
return -2;
}
_ctx.pic_conf = pic_conf;
_ctx._picConf = _picConf;
// set default macroblock/block dimensions
for (p = 0; p <= 2; p++) {
for (i = 0; i < (!p ? pic_conf.luma_bands : pic_conf.chroma_bands); i++) {
_ctx.planes[p].bands[i].mb_size = !p ? (!_ctx.is_scalable ? 16 : 8) : 4;
_ctx.planes[p].bands[i].blk_size = !p ? 8 : 4;
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;
}
}
if (IVIPlaneDesc::ff_ivi_init_tiles(_ctx.planes, _ctx.pic_conf.tile_width,
_ctx.pic_conf.tile_height)) {
if (IVIPlaneDesc::ff_ivi_init_tiles(_ctx._planes, _ctx._picConf._tileWidth,
_ctx._picConf._tileHeight)) {
warning("Couldn't reallocate internal structures!");
return -2;
}
}
_ctx.frame_num = _ctx.gb->getBits1() ? _ctx.gb->getBits(20) : 0;
_ctx._frameNum = _ctx._gb->getBits1() ? _ctx._gb->getBits(20) : 0;
// skip decTimeEst field if present
if (_ctx.gb->getBits1())
_ctx.gb->skipBits(8);
if (_ctx._gb->getBits1())
_ctx._gb->skipBits(8);
// decode macroblock and block huffman codebooks
if (_ctx.mb_vlc.ff_ivi_dec_huff_desc(&_ctx, _ctx.gb->getBits1(), IVI_MB_HUFF) ||
_ctx.blk_vlc.ff_ivi_dec_huff_desc(&_ctx, _ctx.gb->getBits1(), IVI_BLK_HUFF))
if (_ctx._mbVlc.ff_ivi_dec_huff_desc(&_ctx, _ctx._gb->getBits1(), IVI_MB_HUFF) ||
_ctx._blkVlc.ff_ivi_dec_huff_desc(&_ctx, _ctx._gb->getBits1(), IVI_BLK_HUFF))
return -1;
_ctx.rvmap_sel = _ctx.gb->getBits1() ? _ctx.gb->getBits(3) : 8;
_ctx._rvmapSel = _ctx._gb->getBits1() ? _ctx._gb->getBits(3) : 8;
_ctx.in_imf = _ctx.gb->getBits1();
_ctx.in_q = _ctx.gb->getBits1();
_ctx._inImf = _ctx._gb->getBits1();
_ctx._inQ = _ctx._gb->getBits1();
_ctx.pic_glob_quant = _ctx.gb->getBits(5);
_ctx._picGlobQuant = _ctx._gb->getBits(5);
// TODO: ignore this parameter if unused
_ctx.unknown1 = _ctx.gb->getBits1() ? _ctx.gb->getBits(3) : 0;
_ctx._unknown1 = _ctx._gb->getBits1() ? _ctx._gb->getBits(3) : 0;
_ctx.checksum = _ctx.gb->getBits1() ? _ctx.gb->getBits(16) : 0;
_ctx._checksum = _ctx._gb->getBits1() ? _ctx._gb->getBits(16) : 0;
// skip picture header extension if any
while (_ctx.gb->getBits1()) {
_ctx.gb->skipBits(8);
while (_ctx._gb->getBits1()) {
_ctx._gb->skipBits(8);
}
if (_ctx.gb->getBits1()) {
if (_ctx._gb->getBits1()) {
warning("Bad blocks bits encountered!");
}
_ctx.gb->alignGetBits();
_ctx._gb->alignGetBits();
return 0;
}
@ -238,7 +238,7 @@ int Indeo4Decoder::decodePictureHeader() {
void Indeo4Decoder::switch_buffers() {
int is_prev_ref = 0, is_ref = 0;
switch (_ctx.prev_frame_type) {
switch (_ctx._prevFrameType) {
case IVI4_FRAMETYPE_INTRA:
case IVI4_FRAMETYPE_INTRA1:
case IVI4_FRAMETYPE_INTER:
@ -246,7 +246,7 @@ void Indeo4Decoder::switch_buffers() {
break;
}
switch (_ctx.frame_type) {
switch (_ctx._frameType) {
case IVI4_FRAMETYPE_INTRA:
case IVI4_FRAMETYPE_INTRA1:
case IVI4_FRAMETYPE_INTER:
@ -258,67 +258,67 @@ void Indeo4Decoder::switch_buffers() {
}
if (is_prev_ref && is_ref) {
FFSWAP(int, _ctx.dst_buf, _ctx.ref_buf);
FFSWAP(int, _ctx._dstBuf, _ctx._refBuf);
} else if (is_prev_ref) {
FFSWAP(int, _ctx.ref_buf, _ctx.b_ref_buf);
FFSWAP(int, _ctx.dst_buf, _ctx.ref_buf);
FFSWAP(int, _ctx._refBuf, _ctx._bRefBuf);
FFSWAP(int, _ctx._dstBuf, _ctx._refBuf);
}
}
bool Indeo4Decoder::is_nonnull_frame() const {
return _ctx.frame_type < IVI4_FRAMETYPE_NULL_FIRST;
return _ctx._frameType < IVI4_FRAMETYPE_NULL_FIRST;
}
int Indeo4Decoder::decode_band_hdr(IVIBandDesc *band) {
int plane, band_num, indx, transform_id, scan_indx;
int plane, _bandNum, indx, transform_id, scan_indx;
int i;
int quant_mat;
int _quantMat;
plane = _ctx.gb->getBits(2);
band_num = _ctx.gb->getBits(4);
if (band->plane != plane || band->band_num != band_num) {
plane = _ctx._gb->getBits(2);
_bandNum = _ctx._gb->getBits(4);
if (band->_plane != plane || band->_bandNum != _bandNum) {
warning("Invalid band header sequence!");
return -1;
}
band->is_empty = _ctx.gb->getBits1();
if (!band->is_empty) {
int old_blk_size = band->blk_size;
band->_isEmpty = _ctx._gb->getBits1();
if (!band->_isEmpty) {
int old_blk_size = band->_blkSize;
// skip header size
// If header size is not given, header size is 4 bytes.
if (_ctx.gb->getBits1())
_ctx.gb->skipBits(16);
if (_ctx._gb->getBits1())
_ctx._gb->skipBits(16);
band->is_halfpel = _ctx.gb->getBits(2);
if (band->is_halfpel >= 2) {
band->_isHalfpel = _ctx._gb->getBits(2);
if (band->_isHalfpel >= 2) {
warning("Invalid/unsupported mv resolution: %d!",
band->is_halfpel);
band->_isHalfpel);
return -1;
}
if (!band->is_halfpel)
_ctx.uses_fullpel = 1;
if (!band->_isHalfpel)
_ctx._usesFullpel = true;
band->checksum_present = _ctx.gb->getBits1();
if (band->checksum_present)
band->checksum = _ctx.gb->getBits(16);
band->_checksumPresent = _ctx._gb->getBits1();
if (band->_checksumPresent)
band->_checksum = _ctx._gb->getBits(16);
indx = _ctx.gb->getBits(2);
indx = _ctx._gb->getBits(2);
if (indx == 3) {
warning("Invalid block size!");
return -1;
}
band->mb_size = 16 >> indx;
band->blk_size = 8 >> (indx >> 1);
band->_mbSize = 16 >> indx;
band->_blkSize = 8 >> (indx >> 1);
band->inherit_mv = _ctx.gb->getBits1();
band->inherit_qdelta = _ctx.gb->getBits1();
band->_inheritMv = _ctx._gb->getBits1();
band->_inheritQDelta = _ctx._gb->getBits1();
band->glob_quant = _ctx.gb->getBits(5);
band->_globQuant = _ctx._gb->getBits(5);
if (!_ctx.gb->getBits1() || _ctx.frame_type == IVI4_FRAMETYPE_INTRA) {
transform_id = _ctx.gb->getBits(5);
if (!_ctx._gb->getBits1() || _ctx._frameType == IVI4_FRAMETYPE_INTRA) {
transform_id = _ctx._gb->getBits(5);
if ((uint)transform_id >= FF_ARRAY_ELEMS(_transforms) ||
!_transforms[transform_id].inv_trans) {
!_transforms[transform_id]._invTrans) {
warning("Transform %d", transform_id);
return -3;
}
@ -328,117 +328,117 @@ int Indeo4Decoder::decode_band_hdr(IVIBandDesc *band) {
return -3;
}
if (transform_id < 10 && band->blk_size < 8) {
if (transform_id < 10 && band->_blkSize < 8) {
warning("wrong transform size!");
return -1;
}
if ((transform_id >= 0 && transform_id <= 2) || transform_id == 10)
_ctx.uses_haar = 1;
_ctx._usesHaar = true;
band->inv_transform = _transforms[transform_id].inv_trans;
band->dc_transform = _transforms[transform_id].dc_trans;
band->is_2d_trans = _transforms[transform_id].is_2d_trans;
band->_invTransform = _transforms[transform_id]._invTrans;
band->_dcTransform = _transforms[transform_id]._dcTrans;
band->_is2dTrans = _transforms[transform_id]._is2dTrans;
if (transform_id < 10)
band->transform_size = 8;
band->_transformSize = 8;
else
band->transform_size = 4;
band->_transformSize = 4;
if (band->blk_size != band->transform_size) {
warning("transform and block size mismatch (%d != %d)", band->transform_size, band->blk_size);
if (band->_blkSize != band->_transformSize) {
warning("transform and block size mismatch (%d != %d)", band->_transformSize, band->_blkSize);
return -1;
}
scan_indx = _ctx.gb->getBits(4);
scan_indx = _ctx._gb->getBits(4);
if (scan_indx == 15) {
warning("Custom scan pattern encountered!");
return -1;
}
if (scan_indx > 4 && scan_indx < 10) {
if (band->blk_size != 4) {
if (band->_blkSize != 4) {
warning("mismatching scan table!");
return -1;
}
} else if (band->blk_size != 8) {
} else if (band->_blkSize != 8) {
warning("mismatching scan table!");
return -1;
}
band->scan = _scan_index_to_tab[scan_indx];
band->scan_size = band->blk_size;
band->_scan = _scan_index_to_tab[scan_indx];
band->_scanSize = band->_blkSize;
quant_mat = _ctx.gb->getBits(5);
if (quant_mat == 31) {
_quantMat = _ctx._gb->getBits(5);
if (_quantMat == 31) {
warning("Custom quant matrix encountered!");
return -1;
}
if ((uint)quant_mat >= FF_ARRAY_ELEMS(_quant_index_to_tab)) {
warning("Quantization matrix %d", quant_mat);
if ((uint)_quantMat >= FF_ARRAY_ELEMS(_quant_index_to_tab)) {
warning("Quantization matrix %d", _quantMat);
return -1;
}
band->quant_mat = quant_mat;
band->_quantMat = _quantMat;
} else {
if (old_blk_size != band->blk_size) {
if (old_blk_size != band->_blkSize) {
warning("The band block size does not match the configuration inherited");
return -1;
}
}
if (_quant_index_to_tab[band->quant_mat] > 4 && band->blk_size == 4) {
if (_quant_index_to_tab[band->_quantMat] > 4 && band->_blkSize == 4) {
warning("Invalid quant matrix for 4x4 block encountered!");
band->quant_mat = 0;
band->_quantMat = 0;
return -1;
}
if (band->scan_size != band->blk_size) {
if (band->_scanSize != band->_blkSize) {
warning("mismatching scan table!");
return -1;
}
if (band->transform_size == 8 && band->blk_size < 8) {
warning("mismatching transform_size!");
if (band->_transformSize == 8 && band->_blkSize < 8) {
warning("mismatching _transformSize!");
return -1;
}
// decode block huffman codebook
if (!_ctx.gb->getBits1())
band->blk_vlc.tab = _ctx.blk_vlc.tab;
if (!_ctx._gb->getBits1())
band->_blkVlc._tab = _ctx._blkVlc._tab;
else
if (band->blk_vlc.ff_ivi_dec_huff_desc(&_ctx, 1, IVI_BLK_HUFF))
if (band->_blkVlc.ff_ivi_dec_huff_desc(&_ctx, 1, IVI_BLK_HUFF))
return -1;
// select appropriate rvmap table for this band
band->rvmap_sel = _ctx.gb->getBits1() ? _ctx.gb->getBits(3) : 8;
band->_rvmapSel = _ctx._gb->getBits1() ? _ctx._gb->getBits(3) : 8;
// decode rvmap probability corrections if any
band->num_corr = 0; // there is no corrections
if (_ctx.gb->getBits1()) {
band->num_corr = _ctx.gb->getBits(8); // get number of correction pairs
if (band->num_corr > 61) {
band->_numCorr = 0; // there is no corrections
if (_ctx._gb->getBits1()) {
band->_numCorr = _ctx._gb->getBits(8); // get number of correction pairs
if (band->_numCorr > 61) {
warning("Too many corrections: %d",
band->num_corr);
band->_numCorr);
return -1;
}
// read correction pairs
for (i = 0; i < band->num_corr * 2; i++)
band->corr[i] = _ctx.gb->getBits(8);
for (i = 0; i < band->_numCorr * 2; i++)
band->_corr[i] = _ctx._gb->getBits(8);
}
}
if (band->blk_size == 8) {
band->intra_base = &_ivi4_quant_8x8_intra[_quant_index_to_tab[band->quant_mat]][0];
band->inter_base = &_ivi4_quant_8x8_inter[_quant_index_to_tab[band->quant_mat]][0];
if (band->_blkSize == 8) {
band->_intraBase = &_ivi4_quant_8x8_intra[_quant_index_to_tab[band->_quantMat]][0];
band->_interBase = &_ivi4_quant_8x8_inter[_quant_index_to_tab[band->_quantMat]][0];
} else {
band->intra_base = &_ivi4_quant_4x4_intra[_quant_index_to_tab[band->quant_mat]][0];
band->inter_base = &_ivi4_quant_4x4_inter[_quant_index_to_tab[band->quant_mat]][0];
band->_intraBase = &_ivi4_quant_4x4_intra[_quant_index_to_tab[band->_quantMat]][0];
band->_interBase = &_ivi4_quant_4x4_inter[_quant_index_to_tab[band->_quantMat]][0];
}
// Indeo 4 doesn't use scale tables
band->intra_scale = NULL;
band->inter_scale = NULL;
band->_intraScale = NULL;
band->_interScale = NULL;
_ctx.gb->alignGetBits();
_ctx._gb->alignGetBits();
if (!band->scan) {
warning("band->scan not set");
if (!band->_scan) {
warning("band->_scan not set");
return -1;
}
@ -446,155 +446,154 @@ int Indeo4Decoder::decode_band_hdr(IVIBandDesc *band) {
}
int Indeo4Decoder::decode_mb_info(IVIBandDesc *band, IVITile *tile) {
int x, y, mv_x, mv_y, mv_delta, offs, mb_offset, blks_per_mb,
int x, y, _mvX, _mvY, mv_delta, offs, mb_offset, blks_per_mb,
mv_scale, mb_type_bits, s;
IVIMbInfo *mb, *ref_mb;
int row_offset = band->mb_size * band->pitch;
int row_offset = band->_mbSize * band->_pitch;
mb = tile->mbs;
ref_mb = tile->ref_mbs;
offs = tile->ypos * band->pitch + tile->xpos;
mb = tile->_mbs;
ref_mb = tile->_refMbs;
offs = tile->_yPos * band->_pitch + tile->_xPos;
blks_per_mb = band->mb_size != band->blk_size ? 4 : 1;
mb_type_bits = _ctx.frame_type == IVI4_FRAMETYPE_BIDIR ? 2 : 1;
blks_per_mb = band->_mbSize != band->_blkSize ? 4 : 1;
mb_type_bits = _ctx._frameType == IVI4_FRAMETYPE_BIDIR ? 2 : 1;
/* scale factor for motion vectors */
mv_scale = (_ctx.planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3);
mv_x = mv_y = 0;
mv_scale = (_ctx._planes[0]._bands[0]._mbSize >> 3) - (band->_mbSize >> 3);
_mvX = _mvY = 0;
if (((tile->width + band->mb_size - 1) / band->mb_size) * ((tile->height + band->mb_size - 1) / band->mb_size) != tile->num_MBs) {
warning("num_MBs mismatch %d %d %d %d", tile->width, tile->height, band->mb_size, tile->num_MBs);
if (((tile->_width + band->_mbSize - 1) / band->_mbSize) * ((tile->_height + band->_mbSize - 1) / band->_mbSize) != tile->_numMBs) {
warning("_numMBs mismatch %d %d %d %d", tile->_width, tile->_height, band->_mbSize, tile->_numMBs);
return -1;
}
for (y = tile->ypos; y < tile->ypos + tile->height; y += band->mb_size) {
for (y = tile->_yPos; y < tile->_yPos + tile->_height; y += band->_mbSize) {
mb_offset = offs;
for (x = tile->xpos; x < tile->xpos + tile->width; x += band->mb_size) {
mb->xpos = x;
mb->ypos = y;
mb->buf_offs = mb_offset;
mb->b_mv_x =
mb->b_mv_y = 0;
for (x = tile->_xPos; x < tile->_xPos + tile->_width; x += band->_mbSize) {
mb->_xPos = x;
mb->_yPos = y;
mb->_bufOffs = mb_offset;
mb->_bMvX = mb->_bMvY = 0;
if (_ctx.gb->getBits1()) {
if (_ctx.frame_type == IVI4_FRAMETYPE_INTRA) {
if (_ctx._gb->getBits1()) {
if (_ctx._frameType == IVI4_FRAMETYPE_INTRA) {
warning("Empty macroblock in an INTRA picture!");
return -1;
}
mb->type = 1; // empty macroblocks are always INTER
mb->cbp = 0; // all blocks are empty
mb->_type = 1; // empty macroblocks are always INTER
mb->_cbp = 0; // all blocks are empty
mb->q_delta = 0;
if (!band->plane && !band->band_num && _ctx.in_q) {
mb->q_delta = _ctx.gb->getVLC2(_ctx.mb_vlc.tab->_table,
mb->_qDelta = 0;
if (!band->_plane && !band->_bandNum && _ctx._inQ) {
mb->_qDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table,
IVI_VLC_BITS, 1);
mb->q_delta = IVI_TOSIGNED(mb->q_delta);
mb->_qDelta = IVI_TOSIGNED(mb->_qDelta);
}
mb->mv_x = mb->mv_y = 0; /* no motion vector coded */
if (band->inherit_mv && ref_mb) {
/* motion vector inheritance */
mb->_mvX = mb->_mvY = 0; // no motion vector coded
if (band->_inheritMv && ref_mb) {
// motion vector inheritance
if (mv_scale) {
mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale);
mb->_mvX = ivi_scale_mv(ref_mb->_mvX, mv_scale);
mb->_mvY = ivi_scale_mv(ref_mb->_mvY, mv_scale);
} else {
mb->mv_x = ref_mb->mv_x;
mb->mv_y = ref_mb->mv_y;
mb->_mvX = ref_mb->_mvX;
mb->_mvY = ref_mb->_mvY;
}
}
} else {
if (band->inherit_mv) {
if (band->_inheritMv) {
// copy mb_type from corresponding reference mb
if (!ref_mb) {
warning("ref_mb unavailable");
return -1;
}
mb->type = ref_mb->type;
} else if (_ctx.frame_type == IVI4_FRAMETYPE_INTRA ||
_ctx.frame_type == IVI4_FRAMETYPE_INTRA1) {
mb->type = 0; // mb_type is always INTRA for intra-frames
mb->_type = ref_mb->_type;
} else if (_ctx._frameType == IVI4_FRAMETYPE_INTRA ||
_ctx._frameType == IVI4_FRAMETYPE_INTRA1) {
mb->_type = 0; // mb_type is always INTRA for intra-frames
} else {
mb->type = _ctx.gb->getBits(mb_type_bits);
mb->_type = _ctx._gb->getBits(mb_type_bits);
}
mb->cbp = _ctx.gb->getBits(blks_per_mb);
mb->_cbp = _ctx._gb->getBits(blks_per_mb);
mb->q_delta = 0;
if (band->inherit_qdelta) {
if (ref_mb) mb->q_delta = ref_mb->q_delta;
} else if (mb->cbp || (!band->plane && !band->band_num &&
_ctx.in_q)) {
mb->q_delta = _ctx.gb->getVLC2(_ctx.mb_vlc.tab->_table,
mb->_qDelta = 0;
if (band->_inheritQDelta) {
if (ref_mb) mb->_qDelta = ref_mb->_qDelta;
} else if (mb->_cbp || (!band->_plane && !band->_bandNum &&
_ctx._inQ)) {
mb->_qDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table,
IVI_VLC_BITS, 1);
mb->q_delta = IVI_TOSIGNED(mb->q_delta);
mb->_qDelta = IVI_TOSIGNED(mb->_qDelta);
}
if (!mb->type) {
mb->mv_x = mb->mv_y = 0; // there is no motion vector in intra-macroblocks
if (!mb->_type) {
mb->_mvX = mb->_mvY = 0; // there is no motion vector in intra-macroblocks
} else {
if (band->inherit_mv) {
if (band->_inheritMv) {
if (ref_mb) {
// motion vector inheritance
if (mv_scale) {
mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale);
mb->_mvX = ivi_scale_mv(ref_mb->_mvX, mv_scale);
mb->_mvY = ivi_scale_mv(ref_mb->_mvY, mv_scale);
} else {
mb->mv_x = ref_mb->mv_x;
mb->mv_y = ref_mb->mv_y;
mb->_mvX = ref_mb->_mvX;
mb->_mvY = ref_mb->_mvY;
}
}
} else {
// decode motion vector deltas
mv_delta = _ctx.gb->getVLC2(_ctx.mb_vlc.tab->_table,
mv_delta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table,
IVI_VLC_BITS, 1);
mv_y += IVI_TOSIGNED(mv_delta);
mv_delta = _ctx.gb->getVLC2(_ctx.mb_vlc.tab->_table,
_mvY += IVI_TOSIGNED(mv_delta);
mv_delta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table,
IVI_VLC_BITS, 1);
mv_x += IVI_TOSIGNED(mv_delta);
mb->mv_x = mv_x;
mb->mv_y = mv_y;
if (mb->type == 3) {
mv_delta = _ctx.gb->getVLC2(
_ctx.mb_vlc.tab->_table,
_mvX += IVI_TOSIGNED(mv_delta);
mb->_mvX = _mvX;
mb->_mvY = _mvY;
if (mb->_type == 3) {
mv_delta = _ctx._gb->getVLC2(
_ctx._mbVlc._tab->_table,
IVI_VLC_BITS, 1);
mv_y += IVI_TOSIGNED(mv_delta);
mv_delta = _ctx.gb->getVLC2(
_ctx.mb_vlc.tab->_table,
_mvY += IVI_TOSIGNED(mv_delta);
mv_delta = _ctx._gb->getVLC2(
_ctx._mbVlc._tab->_table,
IVI_VLC_BITS, 1);
mv_x += IVI_TOSIGNED(mv_delta);
mb->b_mv_x = -mv_x;
mb->b_mv_y = -mv_y;
_mvX += IVI_TOSIGNED(mv_delta);
mb->_bMvX = -_mvX;
mb->_bMvY = -_mvY;
}
}
if (mb->type == 2) {
mb->b_mv_x = -mb->mv_x;
mb->b_mv_y = -mb->mv_y;
mb->mv_x = 0;
mb->mv_y = 0;
if (mb->_type == 2) {
mb->_bMvX = -mb->_mvX;
mb->_bMvY = -mb->_mvY;
mb->_mvX = 0;
mb->_mvY = 0;
}
}
}
s = band->is_halfpel;
if (mb->type)
if (x + (mb->mv_x >> s) + (y + (mb->mv_y >> s))*band->pitch < 0 ||
x + ((mb->mv_x + s) >> s) + band->mb_size - 1
+ (y + band->mb_size - 1 + ((mb->mv_y + s) >> s))*band->pitch > band->bufsize - 1) {
warning("motion vector %d %d outside reference", x*s + mb->mv_x, y*s + mb->mv_y);
s = band->_isHalfpel;
if (mb->_type)
if (x + (mb->_mvX >> s) + (y + (mb->_mvY >> s))*band->_pitch < 0 ||
x + ((mb->_mvX + s) >> s) + band->_mbSize - 1
+ (y + band->_mbSize - 1 + ((mb->_mvY + s) >> s))*band->_pitch > band->_bufSize - 1) {
warning("motion vector %d %d outside reference", x*s + mb->_mvX, y*s + mb->_mvY);
return -1;
}
mb++;
if (ref_mb)
ref_mb++;
mb_offset += band->mb_size;
mb_offset += band->_mbSize;
}
offs += row_offset;
}
_ctx.gb->alignGetBits();
_ctx._gb->alignGetBits();
return 0;
}
@ -605,12 +604,12 @@ int Indeo4Decoder::scaleTileSize(int def_size, int size_factor) {
int Indeo4Decoder::decodePlaneSubdivision() {
int i;
switch (_ctx.gb->getBits(2)) {
switch (_ctx._gb->getBits(2)) {
case 3:
return 1;
case 2:
for (i = 0; i < 4; i++)
if (_ctx.gb->getBits(2) != 3)
if (_ctx._gb->getBits(2) != 3)
return 0;
return 4;
default:

View File

@ -52,9 +52,9 @@ using namespace Indeo;
*/
class Indeo4Decoder : public IndeoDecoderBase {
struct Transform {
InvTransformPtr *inv_trans;
DCTransformPtr *dc_trans;
int is_2d_trans;
InvTransformPtr *_invTrans;
DCTransformPtr *_dcTrans;
bool _is2dTrans;
};
public:
Indeo4Decoder(uint16 width, uint16 height);

View File

@ -52,10 +52,10 @@ enum {
#define IVI5_PIC_SIZE_ESC 15
Indeo5Decoder::Indeo5Decoder(uint16 width, uint16 height) : IndeoDecoderBase(width, height) {
_ctx.is_indeo4 = true;
_ctx.ref_buf = 1;
_ctx.b_ref_buf = 3;
_ctx.p_frame = new AVFrame();
_ctx._isIndeo4 = false;
_ctx._refBuf = 1;
_ctx._bRefBuf = 3;
_ctx._pFrame = new AVFrame();
}
bool Indeo5Decoder::isIndeo5(Common::SeekableReadStream &stream) {
@ -83,21 +83,21 @@ const Graphics::Surface *Indeo5Decoder::decodeFrame(Common::SeekableReadStream &
// Set up the frame data buffer
byte *frameData = new byte[stream.size()];
stream.read(frameData, stream.size());
_ctx.frame_data = frameData;
_ctx.frame_size = stream.size();
_ctx._frameData = frameData;
_ctx._frameSize = stream.size();
// Set up the GetBits instance for reading the data
_ctx.gb = new GetBits(_ctx.frame_data, _ctx.frame_size * 8);
_ctx._gb = new GetBits(_ctx._frameData, _ctx._frameSize * 8);
// Decode the frame
int err = decodeIndeoFrame();
// Free the bit reader and frame buffer
delete _ctx.gb;
_ctx.gb = nullptr;
delete _ctx._gb;
_ctx._gb = nullptr;
delete[] frameData;
_ctx.frame_data = nullptr;
_ctx.frame_size = 0;
_ctx._frameData = nullptr;
_ctx._frameSize = 0;
return (err < 0) ? nullptr : &_surface->rawSurface();
}
@ -108,87 +108,87 @@ int Indeo5Decoder::decodePictureHeader() {
int ret;
if (_ctx.gb->getBits(5) != 0x1F) {
if (_ctx._gb->getBits(5) != 0x1F) {
warning("Invalid picture start code!");
return -1;
}
_ctx.prev_frame_type = _ctx.frame_type;
_ctx.frame_type = _ctx.gb->getBits(3);
if (_ctx.frame_type >= 5) {
warning("Invalid frame type: %d", _ctx.frame_type);
_ctx._prevFrameType = _ctx._frameType;
_ctx._frameType = _ctx._gb->getBits(3);
if (_ctx._frameType >= 5) {
warning("Invalid frame type: %d", _ctx._frameType);
return -1;
}
_ctx.frame_num = _ctx.gb->getBits(8);
_ctx._frameNum = _ctx._gb->getBits(8);
if (_ctx.frame_type == FRAMETYPE_INTRA) {
if (_ctx._frameType == FRAMETYPE_INTRA) {
if ((ret = decode_gop_header()) < 0) {
warning("Invalid GOP header, skipping frames.");
_ctx.gop_invalid = 1;
_ctx._gopInvalid = true;
return ret;
}
_ctx.gop_invalid = 0;
_ctx._gopInvalid = false;
}
if (_ctx.frame_type == FRAMETYPE_INTER_SCAL && !_ctx.is_scalable) {
if (_ctx._frameType == FRAMETYPE_INTER_SCAL && !_ctx._isScalable) {
warning("Scalable inter frame in non scalable stream");
_ctx.frame_type = FRAMETYPE_INTER;
_ctx._frameType = FRAMETYPE_INTER;
return -1;
}
if (_ctx.frame_type != FRAMETYPE_NULL) {
_ctx.frame_flags = _ctx.gb->getBits(8);
if (_ctx._frameType != FRAMETYPE_NULL) {
_ctx._frameFlags = _ctx._gb->getBits(8);
_ctx.pic_hdr_size = (_ctx.frame_flags & 1) ? _ctx.gb->getBitsLong(24) : 0;
_ctx._picHdrSize = (_ctx._frameFlags & 1) ? _ctx._gb->getBitsLong(24) : 0;
_ctx.checksum = (_ctx.frame_flags & 0x10) ? _ctx.gb->getBits(16) : 0;
_ctx._checksum = (_ctx._frameFlags & 0x10) ? _ctx._gb->getBits(16) : 0;
// skip unknown extension if any
if (_ctx.frame_flags & 0x20)
if (_ctx._frameFlags & 0x20)
skip_hdr_extension(); // XXX: untested
// decode macroblock huffman codebook
ret = _ctx.mb_vlc.ff_ivi_dec_huff_desc(&_ctx, _ctx.frame_flags & 0x40,
ret = _ctx._mbVlc.ff_ivi_dec_huff_desc(&_ctx, _ctx._frameFlags & 0x40,
IVI_MB_HUFF);
if (ret < 0)
return ret;
_ctx.gb->skipBits(3); // FIXME: unknown meaning!
_ctx._gb->skipBits(3); // FIXME: unknown meaning!
}
_ctx.gb->alignGetBits();
_ctx._gb->alignGetBits();
return 0;
}
void Indeo5Decoder::switch_buffers() {
switch (_ctx.prev_frame_type) {
switch (_ctx._prevFrameType) {
case FRAMETYPE_INTRA:
case FRAMETYPE_INTER:
_ctx.buf_switch ^= 1;
_ctx.dst_buf = _ctx.buf_switch;
_ctx.ref_buf = _ctx.buf_switch ^ 1;
_ctx._bufSwitch ^= 1;
_ctx._dstBuf = _ctx._bufSwitch;
_ctx._refBuf = _ctx._bufSwitch ^ 1;
break;
case FRAMETYPE_INTER_SCAL:
if (!_ctx.inter_scal) {
_ctx.ref2_buf = 2;
_ctx.inter_scal = 1;
if (!_ctx._interScal) {
_ctx._ref2Buf = 2;
_ctx._interScal = 1;
}
FFSWAP(int, _ctx.dst_buf, _ctx.ref2_buf);
_ctx.ref_buf = _ctx.ref2_buf;
FFSWAP(int, _ctx._dstBuf, _ctx._ref2Buf);
_ctx._refBuf = _ctx._ref2Buf;
break;
case FRAMETYPE_INTER_NOREF:
break;
}
switch (_ctx.frame_type) {
switch (_ctx._frameType) {
case FRAMETYPE_INTRA:
_ctx.buf_switch = 0;
_ctx._bufSwitch = 0;
// FALLTHROUGH
case FRAMETYPE_INTER:
_ctx.inter_scal = 0;
_ctx.dst_buf = _ctx.buf_switch;
_ctx.ref_buf = _ctx.buf_switch ^ 1;
_ctx._interScal = 0;
_ctx._dstBuf = _ctx._bufSwitch;
_ctx._refBuf = _ctx._bufSwitch ^ 1;
break;
case FRAMETYPE_INTER_SCAL:
case FRAMETYPE_INTER_NOREF:
@ -198,207 +198,209 @@ void Indeo5Decoder::switch_buffers() {
}
bool Indeo5Decoder::is_nonnull_frame() const {
return _ctx.frame_type != FRAMETYPE_NULL;
return _ctx._frameType != FRAMETYPE_NULL;
}
int Indeo5Decoder::decode_band_hdr(IVIBandDesc *band) {
int i, ret;
uint8 band_flags;
band_flags = _ctx.gb->getBits(8);
band_flags = _ctx._gb->getBits(8);
if (band_flags & 1) {
band->is_empty = 1;
band->_isEmpty = true;
return 0;
}
band->data_size = (_ctx.frame_flags & 0x80) ? _ctx.gb->getBitsLong(24) : 0;
band->_dataSize = (_ctx._frameFlags & 0x80) ? _ctx._gb->getBitsLong(24) : 0;
band->inherit_mv = band_flags & 2;
band->inherit_qdelta = band_flags & 8;
band->qdelta_present = band_flags & 4;
if (!band->qdelta_present) band->inherit_qdelta = 1;
band->_inheritMv = (band_flags & 2) != 0;
band->_inheritQDelta = (band_flags & 8) != 0;
band->_qdeltaPresent = (band_flags & 4) != 0;
if (!band->_qdeltaPresent)
band->_inheritQDelta = 1;
// decode rvmap probability corrections if any
band->num_corr = 0; // there are no corrections
band->_numCorr = 0; // there are no corrections
if (band_flags & 0x10) {
band->num_corr = _ctx.gb->getBits(8); // get number of correction pairs
if (band->num_corr > 61) {
warning("Too many corrections: %d", band->num_corr);
band->_numCorr = _ctx._gb->getBits(8); // get number of correction pairs
if (band->_numCorr > 61) {
warning("Too many corrections: %d", band->_numCorr);
return -1;
}
// read correction pairs
for (i = 0; i < band->num_corr * 2; i++)
band->corr[i] = _ctx.gb->getBits(8);
for (i = 0; i < band->_numCorr * 2; i++)
band->_corr[i] = _ctx._gb->getBits(8);
}
// select appropriate rvmap table for this band
band->rvmap_sel = (band_flags & 0x40) ? _ctx.gb->getBits(3) : 8;
band->_rvmapSel = (band_flags & 0x40) ? _ctx._gb->getBits(3) : 8;
// decode block huffman codebook
ret = band->blk_vlc.ff_ivi_dec_huff_desc(&_ctx, band_flags & 0x80, IVI_BLK_HUFF);
ret = band->_blkVlc.ff_ivi_dec_huff_desc(&_ctx, band_flags & 0x80, IVI_BLK_HUFF);
if (ret < 0)
return ret;
band->checksum_present = _ctx.gb->getBits1();
if (band->checksum_present)
band->checksum = _ctx.gb->getBits(16);
band->_checksumPresent = _ctx._gb->getBits1();
if (band->_checksumPresent)
band->_checksum = _ctx._gb->getBits(16);
band->glob_quant = _ctx.gb->getBits(5);
band->_globQuant = _ctx._gb->getBits(5);
// skip unknown extension if any
if (band_flags & 0x20) { // XXX: untested
_ctx.gb->alignGetBits();
_ctx._gb->alignGetBits();
skip_hdr_extension();
}
_ctx.gb->alignGetBits();
_ctx._gb->alignGetBits();
return 0;
}
int Indeo5Decoder::decode_mb_info(IVIBandDesc *band, IVITile *tile) {
int x, y, mv_x, mv_y, mv_delta, offs, mb_offset,
int x, y, _mvX, _mvY, mv_delta, offs, mb_offset,
mv_scale, blks_per_mb, s;
IVIMbInfo *mb, *ref_mb;
int row_offset = band->mb_size * band->pitch;
int row_offset = band->_mbSize * band->_pitch;
mb = tile->mbs;
ref_mb = tile->ref_mbs;
offs = tile->ypos * band->pitch + tile->xpos;
mb = tile->_mbs;
ref_mb = tile->_refMbs;
offs = tile->_yPos * band->_pitch + tile->_xPos;
if (!ref_mb &&
((band->qdelta_present && band->inherit_qdelta) || band->inherit_mv))
((band->_qdeltaPresent && band->_inheritQDelta) || band->_inheritMv))
return -1;
if (tile->num_MBs != IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size)) {
if (tile->_numMBs != IVI_MBs_PER_TILE(tile->_width, tile->_height, band->_mbSize)) {
warning("Allocated tile size %d mismatches parameters %d",
tile->num_MBs, IVI_MBs_PER_TILE(tile->width, tile->height, band->mb_size));
tile->_numMBs, IVI_MBs_PER_TILE(tile->_width, tile->_height, band->_mbSize));
return -1;
}
// scale factor for motion vectors
mv_scale = (_ctx.planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3);
mv_x = mv_y = 0;
mv_scale = (_ctx._planes[0]._bands[0]._mbSize >> 3) - (band->_mbSize >> 3);
_mvX = _mvY = 0;
for (y = tile->ypos; y < (tile->ypos + tile->height); y += band->mb_size) {
for (y = tile->_yPos; y < (tile->_yPos + tile->_height); y += band->_mbSize) {
mb_offset = offs;
for (x = tile->xpos; x < (tile->xpos + tile->width); x += band->mb_size) {
mb->xpos = x;
mb->ypos = y;
mb->buf_offs = mb_offset;
for (x = tile->_xPos; x < (tile->_xPos + tile->_width); x += band->_mbSize) {
mb->_xPos = x;
mb->_yPos = y;
mb->_bufOffs = mb_offset;
if (_ctx.gb->getBits1()) {
if (_ctx.frame_type == FRAMETYPE_INTRA) {
if (_ctx._gb->getBits1()) {
if (_ctx._frameType == FRAMETYPE_INTRA) {
warning("Empty macroblock in an INTRA picture!");
return -1;
}
mb->type = 1; // empty macroblocks are always INTER
mb->cbp = 0; // all blocks are empty
mb->_type = 1; // empty macroblocks are always INTER
mb->_cbp = 0; // all blocks are empty
mb->q_delta = 0;
if (!band->plane && !band->band_num && (_ctx.frame_flags & 8)) {
mb->q_delta = _ctx.gb->getVLC2(_ctx.mb_vlc.tab->_table, IVI_VLC_BITS, 1);
mb->q_delta = IVI_TOSIGNED(mb->q_delta);
mb->_qDelta = 0;
if (!band->_plane && !band->_bandNum && (_ctx._frameFlags & 8)) {
mb->_qDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table, IVI_VLC_BITS, 1);
mb->_qDelta = IVI_TOSIGNED(mb->_qDelta);
}
mb->mv_x = mb->mv_y = 0; // no motion vector coded
if (band->inherit_mv && ref_mb) {
mb->_mvX = mb->_mvY = 0; // no motion vector coded
if (band->_inheritMv && ref_mb) {
// motion vector inheritance
if (mv_scale) {
mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale);
mb->_mvX = ivi_scale_mv(ref_mb->_mvX, mv_scale);
mb->_mvY = ivi_scale_mv(ref_mb->_mvY, mv_scale);
} else {
mb->mv_x = ref_mb->mv_x;
mb->mv_y = ref_mb->mv_y;
mb->_mvX = ref_mb->_mvX;
mb->_mvY = ref_mb->_mvY;
}
}
} else {
if (band->inherit_mv && ref_mb) {
mb->type = ref_mb->type; // copy mb_type from corresponding reference mb
} else if (_ctx.frame_type == FRAMETYPE_INTRA) {
mb->type = 0; // mb_type is always INTRA for intra-frames
if (band->_inheritMv && ref_mb) {
mb->_type = ref_mb->_type; // copy mb_type from corresponding reference mb
} else if (_ctx._frameType == FRAMETYPE_INTRA) {
mb->_type = 0; // mb_type is always INTRA for intra-frames
} else {
mb->type = _ctx.gb->getBits1();
mb->_type = _ctx._gb->getBits1();
}
blks_per_mb = band->mb_size != band->blk_size ? 4 : 1;
mb->cbp = _ctx.gb->getBits(blks_per_mb);
blks_per_mb = band->_mbSize != band->_blkSize ? 4 : 1;
mb->_cbp = _ctx._gb->getBits(blks_per_mb);
mb->q_delta = 0;
if (band->qdelta_present) {
if (band->inherit_qdelta) {
if (ref_mb) mb->q_delta = ref_mb->q_delta;
} else if (mb->cbp || (!band->plane && !band->band_num &&
(_ctx.frame_flags & 8))) {
mb->q_delta = _ctx.gb->getVLC2(_ctx.mb_vlc.tab->_table, IVI_VLC_BITS, 1);
mb->q_delta = IVI_TOSIGNED(mb->q_delta);
mb->_qDelta = 0;
if (band->_qdeltaPresent) {
if (band->_inheritQDelta) {
if (ref_mb) mb->_qDelta = ref_mb->_qDelta;
} else if (mb->_cbp || (!band->_plane && !band->_bandNum &&
(_ctx._frameFlags & 8))) {
mb->_qDelta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table, IVI_VLC_BITS, 1);
mb->_qDelta = IVI_TOSIGNED(mb->_qDelta);
}
}
if (!mb->type) {
mb->mv_x = mb->mv_y = 0; // there is no motion vector in intra-macroblocks
if (!mb->_type) {
mb->_mvX = mb->_mvY = 0; // there is no motion vector in intra-macroblocks
} else {
if (band->inherit_mv && ref_mb) {
if (band->_inheritMv && ref_mb) {
// motion vector inheritance
if (mv_scale) {
mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale);
mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale);
mb->_mvX = ivi_scale_mv(ref_mb->_mvX, mv_scale);
mb->_mvY = ivi_scale_mv(ref_mb->_mvY, mv_scale);
} else {
mb->mv_x = ref_mb->mv_x;
mb->mv_y = ref_mb->mv_y;
mb->_mvX = ref_mb->_mvX;
mb->_mvY = ref_mb->_mvY;
}
} else {
// decode motion vector deltas
mv_delta = _ctx.gb->getVLC2(_ctx.mb_vlc.tab->_table, IVI_VLC_BITS, 1);
mv_y += IVI_TOSIGNED(mv_delta);
mv_delta = _ctx.gb->getVLC2(_ctx.mb_vlc.tab->_table, IVI_VLC_BITS, 1);
mv_x += IVI_TOSIGNED(mv_delta);
mb->mv_x = mv_x;
mb->mv_y = mv_y;
mv_delta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table, IVI_VLC_BITS, 1);
_mvY += IVI_TOSIGNED(mv_delta);
mv_delta = _ctx._gb->getVLC2(_ctx._mbVlc._tab->_table, IVI_VLC_BITS, 1);
_mvX += IVI_TOSIGNED(mv_delta);
mb->_mvX = _mvX;
mb->_mvY = _mvY;
}
}
}
s = band->is_halfpel;
if (mb->type)
if (x + (mb->mv_x >> s) + (y + (mb->mv_y >> s))*band->pitch < 0 ||
x + ((mb->mv_x + s) >> s) + band->mb_size - 1
+ (y + band->mb_size - 1 + ((mb->mv_y + s) >> s))*band->pitch > band->bufsize - 1) {
warning("motion vector %d %d outside reference", x*s + mb->mv_x, y*s + mb->mv_y);
s = band->_isHalfpel;
if (mb->_type)
if (x + (mb->_mvX >> s) + (y + (mb->_mvY >> s))*band->_pitch < 0 ||
x + ((mb->_mvX + s) >> s) + band->_mbSize - 1
+ (y + band->_mbSize - 1 + ((mb->_mvY + s) >> s))*band->_pitch > band->_bufSize - 1) {
warning("motion vector %d %d outside reference", x*s + mb->_mvX, y*s + mb->_mvY);
return -1;
}
mb++;
if (ref_mb)
ref_mb++;
mb_offset += band->mb_size;
mb_offset += band->_mbSize;
}
offs += row_offset;
}
_ctx.gb->alignGetBits();
_ctx._gb->alignGetBits();
return 0;
}
int Indeo5Decoder::decode_gop_header() {
int result, i, p, tile_size, pic_size_indx, mb_size, blk_size, is_scalable;
int quant_mat, blk_size_changed = 0;
int result, i, p, tile_size, pic_size_indx, mbSize, blkSize, isScalable;
int quantMat;
bool blk_size_changed = false;
IVIBandDesc *band, *band1, *band2;
IVIPicConfig pic_conf;
_ctx.gop_flags = _ctx.gb->getBits(8);
_ctx._gopFlags = _ctx._gb->getBits(8);
_ctx.gop_hdr_size = (_ctx.gop_flags & 1) ? _ctx.gb->getBits(16) : 0;
_ctx._gopHdrSize = (_ctx._gopFlags & 1) ? _ctx._gb->getBits(16) : 0;
if (_ctx.gop_flags & IVI5_IS_PROTECTED)
_ctx.lock_word = _ctx.gb->getBitsLong(32);
if (_ctx._gopFlags & IVI5_IS_PROTECTED)
_ctx._lockWord = _ctx._gb->getBitsLong(32);
tile_size = (_ctx.gop_flags & 0x40) ? 64 << _ctx.gb->getBits(2) : 0;
tile_size = (_ctx._gopFlags & 0x40) ? 64 << _ctx._gb->getBits(2) : 0;
if (tile_size > 256) {
warning("Invalid tile size: %d", tile_size);
return -1;
@ -406,73 +408,73 @@ int Indeo5Decoder::decode_gop_header() {
// decode number of wavelet bands
// num_levels * 3 + 1
pic_conf.luma_bands = _ctx.gb->getBits(2) * 3 + 1;
pic_conf.chroma_bands = _ctx.gb->getBits1() * 3 + 1;
is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1;
if (is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) {
pic_conf._lumaBands = _ctx._gb->getBits(2) * 3 + 1;
pic_conf._chromaBands = _ctx._gb->getBits1() * 3 + 1;
isScalable = pic_conf._lumaBands != 1 || pic_conf._chromaBands != 1;
if (isScalable && (pic_conf._lumaBands != 4 || pic_conf._chromaBands != 1)) {
warning("Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d",
pic_conf.luma_bands, pic_conf.chroma_bands);
pic_conf._lumaBands, pic_conf._chromaBands);
return -1;
}
pic_size_indx = _ctx.gb->getBits(4);
pic_size_indx = _ctx._gb->getBits(4);
if (pic_size_indx == IVI5_PIC_SIZE_ESC) {
pic_conf.pic_height = _ctx.gb->getBits(13);
pic_conf.pic_width = _ctx.gb->getBits(13);
pic_conf._picHeight = _ctx._gb->getBits(13);
pic_conf._picWidth = _ctx._gb->getBits(13);
} else {
pic_conf.pic_height = _ivi5_common_pic_sizes[pic_size_indx * 2 + 1] << 2;
pic_conf.pic_width = _ivi5_common_pic_sizes[pic_size_indx * 2] << 2;
pic_conf._picHeight = _ivi5_common_pic_sizes[pic_size_indx * 2 + 1] << 2;
pic_conf._picWidth = _ivi5_common_pic_sizes[pic_size_indx * 2] << 2;
}
if (_ctx.gop_flags & 2) {
if (_ctx._gopFlags & 2) {
warning("YV12 picture format");
return -2;
}
pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2;
pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2;
pic_conf._chromaHeight = (pic_conf._picHeight + 3) >> 2;
pic_conf._chromaWidth = (pic_conf._picWidth + 3) >> 2;
if (!tile_size) {
pic_conf.tile_height = pic_conf.pic_height;
pic_conf.tile_width = pic_conf.pic_width;
pic_conf._tileHeight = pic_conf._picHeight;
pic_conf._tileWidth = pic_conf._picWidth;
} else {
pic_conf.tile_height = pic_conf.tile_width = tile_size;
pic_conf._tileHeight = pic_conf._tileWidth = tile_size;
}
// check if picture layout was changed and reallocate buffers
if (pic_conf.ivi_pic_config_cmp(_ctx.pic_conf) || _ctx.gop_invalid) {
result = IVIPlaneDesc::ff_ivi_init_planes(_ctx.planes, &pic_conf, 0);
if (pic_conf.ivi_pic_config_cmp(_ctx._picConf) || _ctx._gopInvalid) {
result = IVIPlaneDesc::ff_ivi_init_planes(_ctx._planes, &pic_conf, 0);
if (result < 0) {
warning("Couldn't reallocate color planes!");
return result;
}
_ctx.pic_conf = pic_conf;
_ctx.is_scalable = is_scalable;
_ctx._picConf = pic_conf;
_ctx._isScalable = isScalable;
blk_size_changed = 1; // force reallocation of the internal structures
}
for (p = 0; p <= 1; p++) {
for (i = 0; i < (!p ? pic_conf.luma_bands : pic_conf.chroma_bands); i++) {
band = &_ctx.planes[p].bands[i];
for (i = 0; i < (!p ? pic_conf._lumaBands : pic_conf._chromaBands); i++) {
band = &_ctx._planes[p]._bands[i];
band->is_halfpel = _ctx.gb->getBits1();
band->_isHalfpel = _ctx._gb->getBits1();
mb_size = _ctx.gb->getBits1();
blk_size = 8 >> _ctx.gb->getBits1();
mb_size = blk_size << !mb_size;
mbSize = _ctx._gb->getBits1();
blkSize = 8 >> _ctx._gb->getBits1();
mbSize = blkSize << !mbSize;
if (p == 0 && blk_size == 4) {
if (p == 0 && blkSize == 4) {
warning("4x4 luma blocks are unsupported!");
return -2;
}
blk_size_changed = mb_size != band->mb_size || blk_size != band->blk_size;
blk_size_changed = mbSize != band->_mbSize || blkSize != band->_blkSize;
if (blk_size_changed) {
band->mb_size = mb_size;
band->blk_size = blk_size;
band->_mbSize = mbSize;
band->_blkSize = blkSize;
}
if (_ctx.gb->getBits1()) {
if (_ctx._gb->getBits1()) {
warning("Extended transform info");
return -2;
}
@ -480,73 +482,73 @@ int Indeo5Decoder::decode_gop_header() {
// select transform function and scan pattern according to plane and band number
switch ((p << 2) + i) {
case 0:
band->inv_transform = IndeoDSP::ff_ivi_inverse_slant_8x8;
band->dc_transform = IndeoDSP::ff_ivi_dc_slant_2d;
band->scan = ff_zigzag_direct;
band->transform_size = 8;
band->_invTransform = IndeoDSP::ff_ivi_inverse_slant_8x8;
band->_dcTransform = IndeoDSP::ff_ivi_dc_slant_2d;
band->_scan = ff_zigzag_direct;
band->_transformSize = 8;
break;
case 1:
band->inv_transform = IndeoDSP::ff_ivi_row_slant8;
band->dc_transform = IndeoDSP::ff_ivi_dc_row_slant;
band->scan = _ff_ivi_vertical_scan_8x8;
band->transform_size = 8;
band->_invTransform = IndeoDSP::ff_ivi_row_slant8;
band->_dcTransform = IndeoDSP::ff_ivi_dc_row_slant;
band->_scan = _ff_ivi_vertical_scan_8x8;
band->_transformSize = 8;
break;
case 2:
band->inv_transform = IndeoDSP::ff_ivi_col_slant8;
band->dc_transform = IndeoDSP::ff_ivi_dc_col_slant;
band->scan = _ff_ivi_horizontal_scan_8x8;
band->transform_size = 8;
band->_invTransform = IndeoDSP::ff_ivi_col_slant8;
band->_dcTransform = IndeoDSP::ff_ivi_dc_col_slant;
band->_scan = _ff_ivi_horizontal_scan_8x8;
band->_transformSize = 8;
break;
case 3:
band->inv_transform = IndeoDSP::ff_ivi_put_pixels_8x8;
band->dc_transform = IndeoDSP::ff_ivi_put_dc_pixel_8x8;
band->scan = _ff_ivi_horizontal_scan_8x8;
band->transform_size = 8;
band->_invTransform = IndeoDSP::ff_ivi_put_pixels_8x8;
band->_dcTransform = IndeoDSP::ff_ivi_put_dc_pixel_8x8;
band->_scan = _ff_ivi_horizontal_scan_8x8;
band->_transformSize = 8;
break;
case 4:
band->inv_transform = IndeoDSP::ff_ivi_inverse_slant_4x4;
band->dc_transform = IndeoDSP::ff_ivi_dc_slant_2d;
band->scan = _ff_ivi_direct_scan_4x4;
band->transform_size = 4;
band->_invTransform = IndeoDSP::ff_ivi_inverse_slant_4x4;
band->_dcTransform = IndeoDSP::ff_ivi_dc_slant_2d;
band->_scan = _ff_ivi_direct_scan_4x4;
band->_transformSize = 4;
break;
}
band->is_2d_trans = band->inv_transform == IndeoDSP::ff_ivi_inverse_slant_8x8 ||
band->inv_transform == IndeoDSP::ff_ivi_inverse_slant_4x4;
band->_is2dTrans = band->_invTransform == IndeoDSP::ff_ivi_inverse_slant_8x8 ||
band->_invTransform == IndeoDSP::ff_ivi_inverse_slant_4x4;
if (band->transform_size != band->blk_size) {
warning("transform and block size mismatch (%d != %d)", band->transform_size, band->blk_size);
if (band->_transformSize != band->_blkSize) {
warning("transform and block size mismatch (%d != %d)", band->_transformSize, band->_blkSize);
return -1;
}
// select dequant matrix according to plane and band number
if (!p) {
quant_mat = (pic_conf.luma_bands > 1) ? i + 1 : 0;
quantMat = (pic_conf._lumaBands > 1) ? i + 1 : 0;
} else {
quant_mat = 5;
quantMat = 5;
}
if (band->blk_size == 8) {
if (quant_mat >= 5) {
warning("quant_mat %d too large!", quant_mat);
if (band->_blkSize == 8) {
if (quantMat >= 5) {
warning("_quantMat %d too large!", quantMat);
return -1;
}
band->intra_base = &_ivi5_base_quant_8x8_intra[quant_mat][0];
band->inter_base = &_ivi5_base_quant_8x8_inter[quant_mat][0];
band->intra_scale = &_ivi5_scale_quant_8x8_intra[quant_mat][0];
band->inter_scale = &_ivi5_scale_quant_8x8_inter[quant_mat][0];
band->_intraBase = &_ivi5_base_quant_8x8_intra[quantMat][0];
band->_interBase = &_ivi5_base_quant_8x8_inter[quantMat][0];
band->_intraScale = &_ivi5_scale_quant_8x8_intra[quantMat][0];
band->_interScale = &_ivi5_scale_quant_8x8_inter[quantMat][0];
} else {
band->intra_base = _ivi5_base_quant_4x4_intra;
band->inter_base = _ivi5_base_quant_4x4_inter;
band->intra_scale = _ivi5_scale_quant_4x4_intra;
band->inter_scale = _ivi5_scale_quant_4x4_inter;
band->_intraBase = _ivi5_base_quant_4x4_intra;
band->_interBase = _ivi5_base_quant_4x4_inter;
band->_intraScale = _ivi5_scale_quant_4x4_intra;
band->_interScale = _ivi5_scale_quant_4x4_inter;
}
if (_ctx.gb->getBits(2)) {
if (_ctx._gb->getBits(2)) {
warning("End marker missing!");
return -1;
}
@ -554,58 +556,58 @@ int Indeo5Decoder::decode_gop_header() {
}
// copy chroma parameters into the 2nd chroma plane
for (i = 0; i < pic_conf.chroma_bands; i++) {
band1 = &_ctx.planes[1].bands[i];
band2 = &_ctx.planes[2].bands[i];
for (i = 0; i < pic_conf._chromaBands; i++) {
band1 = &_ctx._planes[1]._bands[i];
band2 = &_ctx._planes[2]._bands[i];
band2->width = band1->width;
band2->height = band1->height;
band2->mb_size = band1->mb_size;
band2->blk_size = band1->blk_size;
band2->is_halfpel = band1->is_halfpel;
band2->intra_base = band1->intra_base;
band2->inter_base = band1->inter_base;
band2->intra_scale = band1->intra_scale;
band2->inter_scale = band1->inter_scale;
band2->scan = band1->scan;
band2->inv_transform = band1->inv_transform;
band2->dc_transform = band1->dc_transform;
band2->is_2d_trans = band1->is_2d_trans;
band2->transform_size = band1->transform_size;
band2->_width = band1->_width;
band2->_height = band1->_height;
band2->_mbSize = band1->_mbSize;
band2->_blkSize = band1->_blkSize;
band2->_isHalfpel = band1->_isHalfpel;
band2->_intraBase = band1->_intraBase;
band2->_interBase = band1->_interBase;
band2->_intraScale = band1->_intraScale;
band2->_interScale = band1->_interScale;
band2->_scan = band1->_scan;
band2->_invTransform = band1->_invTransform;
band2->_dcTransform = band1->_dcTransform;
band2->_is2dTrans = band1->_is2dTrans;
band2->_transformSize = band1->_transformSize;
}
// reallocate internal structures if needed
if (blk_size_changed) {
result = IVIPlaneDesc::ff_ivi_init_tiles(_ctx.planes, pic_conf.tile_width,
pic_conf.tile_height);
result = IVIPlaneDesc::ff_ivi_init_tiles(_ctx._planes, pic_conf._tileWidth,
pic_conf._tileHeight);
if (result < 0) {
warning("Couldn't reallocate internal structures!");
return result;
}
}
if (_ctx.gop_flags & 8) {
if (_ctx.gb->getBits(3)) {
if (_ctx._gopFlags & 8) {
if (_ctx._gb->getBits(3)) {
warning("Alignment bits are not zero!");
return -1;
}
if (_ctx.gb->getBits1())
_ctx.gb->skipBitsLong(24); // skip transparency fill color
if (_ctx._gb->getBits1())
_ctx._gb->skipBitsLong(24); // skip transparency fill color
}
_ctx.gb->alignGetBits();
_ctx._gb->alignGetBits();
_ctx.gb->skipBits(23); // FIXME: unknown meaning
_ctx._gb->skipBits(23); // FIXME: unknown meaning
// skip GOP extension if any
if (_ctx.gb->getBits1()) {
if (_ctx._gb->getBits1()) {
do {
i = _ctx.gb->getBits(16);
i = _ctx._gb->getBits(16);
} while (i & 0x8000);
}
_ctx.gb->alignGetBits();
_ctx._gb->alignGetBits();
return 0;
}
@ -614,11 +616,11 @@ int Indeo5Decoder::skip_hdr_extension() {
int i, len;
do {
len = _ctx.gb->getBits(8);
if (8 * len > _ctx.gb->getBitsLeft())
len = _ctx._gb->getBits(8);
if (8 * len > _ctx._gb->getBitsLeft())
return -1;
for (i = 0; i < len; i++)
_ctx.gb->skipBits(8);
_ctx._gb->skipBits(8);
} while (len);
return 0;