diff options
author | Paul Gilbert | 2016-09-05 23:00:08 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-09-10 10:08:10 -0400 |
commit | 5f0962696f97df2cce27d065d99b04243de59334 (patch) | |
tree | 001c83f1550677226cf264d6dc6a3c9ceaa70e2f /image/codecs/indeo4.cpp | |
parent | 73e79031865a71dd5ced18fe3269f79ceba6e08c (diff) | |
download | scummvm-rg350-5f0962696f97df2cce27d065d99b04243de59334.tar.gz scummvm-rg350-5f0962696f97df2cce27d065d99b04243de59334.tar.bz2 scummvm-rg350-5f0962696f97df2cce27d065d99b04243de59334.zip |
IMAGE: Added Indeo4Decoder decodePictureHeader, and lots of dependencies
Diffstat (limited to 'image/codecs/indeo4.cpp')
-rw-r--r-- | image/codecs/indeo4.cpp | 198 |
1 files changed, 191 insertions, 7 deletions
diff --git a/image/codecs/indeo4.cpp b/image/codecs/indeo4.cpp index 465e3adc49..bce9b5ad78 100644 --- a/image/codecs/indeo4.cpp +++ b/image/codecs/indeo4.cpp @@ -24,7 +24,7 @@ /* Intel Indeo 4 decompressor, derived from ffmpeg. * - * Original copyright note: * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg + * Original copyright note: * Intel Indeo 3 (IV41, IV42, etc.) video decoder for ffmpeg * written, produced, and directed by Alan Smithee */ @@ -33,19 +33,22 @@ #include "common/stream.h" #include "common/textconsole.h" #include "common/util.h" - #include "graphics/yuv_to_rgb.h" - #include "image/codecs/indeo4.h" -#include "image/codecs/indeo/get_bits.h" namespace Image { +#define IVI4_PIC_SIZE_ESC 7 + Indeo4Decoder::Indeo4Decoder(uint16 width, uint16 height) { _pixelFormat = g_system->getScreenFormat(); _surface = new Graphics::ManagedSurface(); _surface->create(width, height, _pixelFormat); - + _ctx.gb = nullptr; + _ctx.pic_conf.pic_width = _ctx.pic_conf.pic_height = 0; + _ctx.is_indeo4 = true; + _ctx.show_indeo4_info = false; + _ctx.b_ref_buf = 3; // buffer 2 is used for scalability mode } Indeo4Decoder::~Indeo4Decoder() { @@ -72,10 +75,191 @@ bool Indeo4Decoder::isIndeo4(Common::SeekableReadStream &stream) { const Graphics::Surface *Indeo4Decoder::decodeFrame(Common::SeekableReadStream &stream) { // Not Indeo 4? Fail if (!isIndeo4(stream)) - return 0; + return nullptr; + + // Set up the GetBits instance for reading the stream + _ctx.gb = new GetBits(stream); + + // Decode the header + int err = decodePictureHeader(); + + delete _ctx.gb; + _ctx.gb = nullptr; // TODO - return nullptr; + err = -1; + return (err < 0) ? nullptr : &_surface->rawSurface(); } +int Indeo4Decoder::decodePictureHeader() { + int pic_size_indx, i, p; + IVIPicConfig pic_conf; + + 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); + return -1; + } + + if (_ctx.frame_type == IVI4_FRAMETYPE_BIDIR) + _ctx.has_b_frames = 1; + + _ctx.has_transp = _ctx.gb->getBits1(); + + // unknown bit: Mac decoder ignores this bit, XANIM returns error + if (_ctx.gb->getBits1()) { + warning("Sync bit is set!"); + return -1; + } + + _ctx.data_size = _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) { + warning("Null frame encountered!"); + return 0; + } + + // 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); + warning("Password-protected clip!"); + } + + 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); + } 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]; + } + + // 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)); + } else { + pic_conf.tile_height = pic_conf.pic_height; + pic_conf.tile_width = pic_conf.pic_width; + } + + // Decode chroma subsampling. We support only 4:4 aka YVU9. + 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; + + // 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)) { + warning("Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d", + pic_conf.luma_bands, pic_conf.chroma_bands); + 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)) { + warning("Couldn't reallocate color planes!"); + _ctx.pic_conf.luma_bands = 0; + return -2; + } + + _ctx.pic_conf = pic_conf; + + // 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; + } + } + + if (IVIPlaneDesc::ff_ivi_init_tiles(_ctx.planes, _ctx.pic_conf.tile_width, + _ctx.pic_conf.tile_height)) { + warning("Couldn't reallocate internal structures!"); + return -2; + } + } + + _ctx.frame_num = _ctx.gb->getBits1() ? _ctx.gb->getBits(20) : 0; + + // skip decTimeEst field if present + if (_ctx.gb->getBits1()) + _ctx.gb->skipBits(8); + + // decode macroblock and block huffman codebooks + if (_ctx.mb_vlc.ff_ivi_dec_huff_desc(_ctx.gb, _ctx.gb->getBits1(), IVI_MB_HUFF) || + _ctx.blk_vlc.ff_ivi_dec_huff_desc(_ctx.gb, _ctx.gb->getBits1(), IVI_BLK_HUFF)) + return -1; + + _ctx.rvmap_sel = _ctx.gb->getBits1() ? _ctx.gb->getBits(3) : 8; + + _ctx.in_imf = _ctx.gb->getBits1(); + _ctx.in_q = _ctx.gb->getBits1(); + + _ctx.pic_glob_quant = _ctx.gb->getBits(5); + + // TODO: ignore this parameter if unused + _ctx.unknown1 = _ctx.gb->getBits1() ? _ctx.gb->getBits(3) : 0; + + _ctx.checksum = _ctx.gb->getBits1() ? _ctx.gb->getBits(16) : 0; + + // skip picture header extension if any + while (_ctx.gb->getBits1()) { + warning("Pic hdr extension encountered!"); + _ctx.gb->skipBits(8); + } + + if (_ctx.gb->getBits1()) { + warning("Bad blocks bits encountered!"); + } + + _ctx.gb->alignGetBits(); + + return 0; +} + +int Indeo4Decoder::scaleTileSize(int def_size, int size_factor) { + return size_factor == 15 ? def_size : (size_factor + 1) << 5; +} + +int Indeo4Decoder::decodePlaneSubdivision() { + int i; + + switch (_ctx.gb->getBits(2)) { + case 3: + return 1; + case 2: + for (i = 0; i < 4; i++) + if (_ctx.gb->getBits(2) != 3) + return 0; + return 4; + default: + return 0; + } +} + +/*------------------------------------------------------------------------*/ + +const uint Indeo4Decoder::_ivi4_common_pic_sizes[14] = { + 640, 480, 320, 240, 160, 120, 704, 480, 352, 240, 352, 288, 176, 144 +}; + } // End of namespace Image |