ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

indeo.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/scummsys.h"
00024 #include "graphics/surface.h"
00025 #include "image/codecs/codec.h"
00026 
00027 /* Common structures, macros, and base class shared by both Indeo4 and
00028  * Indeo5 decoders, derived from ffmpeg. We don't currently support Indeo5
00029  * decoding, but just in case we eventually need it, this is kept as a separate
00030  * file like it is in ffmpeg.
00031  *
00032  * Original copyright note: * Intel Indeo 4 (IV41, IV42, etc.) video decoder for ffmpeg
00033  * written, produced, and directed by Alan Smithee
00034  */
00035 
00036 #ifndef IMAGE_CODECS_INDEO_INDEO_H
00037 #define IMAGE_CODECS_INDEO_INDEO_H
00038 
00039 #include "image/codecs/indeo/get_bits.h"
00040 #include "image/codecs/indeo/vlc.h"
00041 
00042 namespace Image {
00043 namespace Indeo {
00044 
00048 enum {
00049     IVI4_FRAMETYPE_INTRA       = 0,
00050     IVI4_FRAMETYPE_INTRA1      = 1,  
00051     IVI4_FRAMETYPE_INTER       = 2,  
00052     IVI4_FRAMETYPE_BIDIR       = 3,  
00053     IVI4_FRAMETYPE_INTER_NOREF = 4,  
00054     IVI4_FRAMETYPE_NULL_FIRST  = 5,  
00055     IVI4_FRAMETYPE_NULL_LAST   = 6   
00056 };
00057 
00058 enum {
00059     IVI_MB_HUFF   = 0,      
00060     IVI_BLK_HUFF  = 1       
00061 };
00062 
00066 typedef void (InvTransformPtr)(const int32 *in, int16 *out, uint32 pitch, const uint8 *flags);
00067 typedef void (DCTransformPtr)(const int32 *in, int16 *out, uint32 pitch, int blkSize);
00068 
00069 typedef void (*IviMCFunc)(int16 *buf, const int16 *refBuf, uint32 pitch, int mcType);
00070 typedef void (*IviMCAvgFunc)(int16 *buf, const int16 *refBuf1, const int16 *refBuf2,
00071     uint32 pitch, int mcType, int mcType2);
00072 
00074 #define IVI_VLC_BITS 13
00075 #define IVI5_IS_PROTECTED 0x20
00076 
00080 #define IVI_TOSIGNED(val) (-(((val) >> 1) ^ -((val) & 1)))
00081 
00085 #define IVI_MBs_PER_TILE(tileWidth, tileHeight, mbSize) \
00086     ((((tileWidth) + (mbSize) - 1) / (mbSize)) * (((tileHeight) + (mbSize) - 1) / (mbSize)))
00087 
00091 struct IVIHuffDesc {
00092     int32       _numRows;
00093     uint8       _xBits[16];
00094 
00103     int createHuffFromDesc(VLC *vlc, bool flag) const;
00104 
00111     bool huffDescCompare(const IVIHuffDesc *desc2) const;
00112 
00118     void huffDescCopy(const IVIHuffDesc *src);
00119 };
00120 
00121 struct IVI45DecContext;
00122 
00126 struct IVIHuffTab {
00127 public:
00128     int32   _tabSel;    
00129 
00130     VLC *   _tab;       
00131 
00133     IVIHuffDesc _custDesc;  
00134     VLC         _custTab;   
00135 
00139     IVIHuffTab();
00140 
00150     int decodeHuffDesc(IVI45DecContext *ctx, int descCoded, int whichTab);
00151 };
00152 
00156 struct RVMapDesc {
00157     uint8     _eobSym; 
00158     uint8     _escSym; 
00159     uint8     _runtab[256];
00160     int8      _valtab[256];
00161 };
00162 
00166 struct IVIMbInfo {
00167     int16   _xPos;
00168     int16   _yPos;
00169     uint32  _bufOffs;   
00170     uint8   _type;      
00171     uint8   _cbp;       
00172     int8    _qDelta;    
00173     int8    _mvX;       
00174     int8    _mvY;       
00175     int8    _bMvX;      
00176     int8    _bMvY;      
00177 
00178     IVIMbInfo();
00179 };
00180 
00184 struct IVITile {
00185     int         _xPos;
00186     int         _yPos;
00187     int         _width;
00188     int         _height;
00189     int         _mbSize;
00190     bool        _isEmpty;
00191     int         _dataSize;  
00192     int         _numMBs;    
00193     IVIMbInfo * _mbs;       
00194     IVIMbInfo * _refMbs;    
00195 
00196     IVITile();
00197 };
00198 
00202 struct IVIBandDesc {
00203     int             _plane;         
00204     int             _bandNum;       
00205     int             _width;
00206     int             _height;
00207     int             _aHeight;       
00208     const uint8 *   _dataPtr;       
00209     int             _dataSize;      
00210     int16 *         _buf;           
00211     int16 *         _refBuf;        
00212     int16 *         _bRefBuf;       
00213     int16 *         _bufs[4];       
00214     int             _pitch;         
00215     bool            _isEmpty;
00216     int             _mbSize;        
00217     int             _blkSize;       
00218     uint8           _isHalfpel;     
00219     bool            _inheritMv;     
00220     bool            _inheritQDelta; 
00221     bool            _qdeltaPresent; 
00222     int             _quantMat;      
00223     int             _globQuant;     
00224     const uint8 *   _scan;          
00225     int             _scanSize;      
00226 
00227     IVIHuffTab      _blkVlc;        
00228 
00229     int             _numCorr;       
00230     uint8           _corr[61 * 2];  
00231     int             _rvmapSel;      
00232     RVMapDesc *     _rvMap;         
00233     int             _numTiles;      
00234     IVITile *       _tiles;         
00235     InvTransformPtr *_invTransform;
00236     int             _transformSize;
00237     DCTransformPtr *_dcTransform;
00238     bool            _is2dTrans;
00239     int32           _checksum;      
00240     int             _checksumPresent;
00241     int             _bufSize;       
00242     const uint16 *  _intraBase;     
00243     const uint16 *  _interBase;     
00244     const uint8 *   _intraScale;    
00245     const uint8 *   _interScale;    
00246 
00247     IVIBandDesc();
00248 
00249     int initTiles(IVITile *refTile, int p, int b, int tHeight, int tWidth);
00250 };
00251 
00252 struct IVIPicConfig {
00253     uint16      _picWidth;
00254     uint16      _picHeight;
00255     uint16      _chromaWidth;
00256     uint16      _chromaHeight;
00257     uint16      _tileWidth;
00258     uint16      _tileHeight;
00259     uint8       _lumaBands;
00260     uint8       _chromaBands;
00261 
00262     IVIPicConfig();
00263 
00267     bool ivi_pic_config_cmp(const IVIPicConfig &cfg2);
00268 };
00269 
00273 struct IVIPlaneDesc {
00274     uint16          _width;
00275     uint16          _height;
00276     uint8           _numBands;  
00277     IVIBandDesc *   _bands;     
00278 
00279     IVIPlaneDesc();
00280 
00281     static int initPlanes(IVIPlaneDesc *planes, const IVIPicConfig *cfg, bool isIndeo4);
00282 
00283     static int initTiles(IVIPlaneDesc *planes, int tileWidth, int tileHeight);
00284 
00290     static void freeBuffers(IVIPlaneDesc *planes);
00291 
00301     static int checkImageSize(unsigned int w, unsigned int h, int logOffset);
00302 };
00303 
00304 struct AVFrame {
00308     int _width, _height;
00309 
00310 #define AV_NUM_DATA_POINTERS 3
00311 
00323     uint8 *_data[AV_NUM_DATA_POINTERS];
00324 
00340     int _linesize[AV_NUM_DATA_POINTERS];
00341 
00345     AVFrame();
00346 
00350     ~AVFrame() { freeFrame(); }
00351 
00355     int setDimensions(uint16 width, uint16 height);
00356 
00360     int getBuffer(int flags);
00361 
00365     void freeFrame();
00366 };
00367 
00368 struct IVI45DecContext {
00369     friend struct IVIHuffTab;
00370 private:
00371     VLC_TYPE _tableData[8192 * 16][2];
00372     VLC _iviMbVlcTabs[8];           
00373     VLC _iviBlkVlcTabs[8];          
00374 public:
00375     GetBits *       _gb;
00376     RVMapDesc       _rvmapTabs[9];  
00377 
00378     uint32          _frameNum;
00379     int             _frameType;
00380     int             _prevFrameType; 
00381     uint32          _dataSize;      
00382     int             _isScalable;
00383     const uint8 *   _frameData;     
00384     int             _interScal;     
00385     uint32          _frameSize;     
00386     uint32          _picHdrSize;    
00387     uint8           _frameFlags;
00388     uint16          _checksum;      
00389 
00390     IVIPicConfig    _picConf;
00391     IVIPlaneDesc    _planes[3];     
00392 
00393     int             _bufSwitch;     
00394     int             _dstBuf;        
00395     int             _refBuf;        
00396     int             _ref2Buf;       
00397     int             _bRefBuf;       
00398 
00399     IVIHuffTab      _mbVlc;         
00400     IVIHuffTab      _blkVlc;        
00401     IVIHuffTab      _transVlc;      
00402 
00403     uint8           _rvmapSel;
00404     bool            _inImf;
00405     bool            _inQ;           
00406     uint8           _picGlobQuant;
00407     uint8           _unknown1;
00408 
00409     uint16          _gopHdrSize;
00410     uint8           _gopFlags;
00411     uint32          _lockWord;
00412 
00413     bool            _hasBFrames;
00414     bool            _hasTransp;     
00415     bool            _usesTiling;
00416     bool            _usesHaar;
00417     bool            _usesFullpel;
00418 
00419     bool            _gopInvalid;
00420     int             _bufInvalid[4];
00421 
00422     bool            _isIndeo4;
00423     uint32          _transKeyColor;
00424 
00425     AVFrame *       _pFrame;
00426     bool            _gotPFrame;
00427 
00428     IVI45DecContext();
00429 private:
00433     static const RVMapDesc _ff_ivi_rvmap_tabs[9];
00434 };
00435 
00436 class IndeoDecoderBase : public Codec {
00437 private:
00444     int decode_band(IVIBandDesc *band);
00445 
00453     void recomposeHaar(const IVIPlaneDesc *plane, uint8 *dst, const int dstPitch);
00454 
00462     void recompose53(const IVIPlaneDesc *plane, uint8 *dst, const int dstPitch);
00463 
00464     /*
00465      *  Convert and output the current plane.
00466      *  This conversion is done by adding back the bias value of 128
00467      *  (subtracted in the encoder) and clipping the result.
00468      *
00469      *  @param[in]   plane      Pointer to the descriptor of the plane being processed
00470      *  @param[out]  dst        Pointer to the buffer receiving converted pixels
00471      *  @param[in]   dstPitch   Pitch for moving to the next y line
00472      */
00473     void outputPlane(IVIPlaneDesc *plane, uint8 *dst, int dstPitch);
00474 
00483     int processEmptyTile(IVIBandDesc *band, IVITile *tile, int32 mvScale);
00484 
00485     /*
00486      *  Decode size of the tile data.
00487      *  The size is stored as a variable-length field having the following format:
00488      *  if (tile_data_size < 255) than this field is only one byte long
00489      *  if (tile_data_size >= 255) than this field four is byte long: 0xFF X1 X2 X3
00490      *  where X1-X3 is size of the tile data
00491      *
00492      *  @param[in,out]  gb  the GetBit context
00493      *  @returns    Size of the tile data in bytes
00494      */
00495     int decodeTileDataSize(GetBits *gb);
00496 
00497     /*
00498      *  Decode block data:
00499      *  extract huffman-coded transform coefficients from the bitstream,
00500      *  dequantize them, apply inverse transform and motion compensation
00501      *  in order to reconstruct the picture.
00502      *
00503      *  @param[in,out]  gb      The GetBit context
00504      *  @param[in]      band    Pointer to the band descriptor
00505      *  @param[in]      tile    Pointer to the tile descriptor
00506      *  @returns    Result code: 0 - OK, -1 = error (corrupted blocks data)
00507      */
00508     int decodeBlocks(GetBits *gb, IVIBandDesc *band, IVITile *tile);
00509 
00510     int iviMc(IVIBandDesc *band, IviMCFunc mc, IviMCAvgFunc mcAvg,
00511         int offs, int mvX, int mvY, int mvX2, int mvY2, int mcType, int mcType2);
00512 
00513     int decodeCodedBlocks(GetBits *gb, IVIBandDesc *band,
00514         IviMCFunc mc, IviMCAvgFunc mcAvg, int mvX, int mvY,
00515         int mvX2, int mvY2, int32 *prevDc, int isIntra,
00516         int mcType, int mcType2, uint32 quant, int offs);
00517 
00518     int iviDcTransform(IVIBandDesc *band, int32 *prevDc, int bufOffs,
00519         int blkSize);
00520 protected:
00521     IVI45DecContext _ctx;
00522     Graphics::PixelFormat _pixelFormat;
00523     Graphics::Surface _surface;
00524 
00528     static const uint8 _ffIviVerticalScan8x8[64];
00529     static const uint8 _ffIviHorizontalScan8x8[64];
00530     static const uint8 _ffIviDirectScan4x4[16];
00531 protected:
00535     virtual Graphics::PixelFormat getPixelFormat() const { return _pixelFormat; }
00536 
00541     virtual int decodePictureHeader() = 0;
00542 
00546     virtual void switchBuffers() = 0;
00547 
00548     virtual bool isNonNullFrame() const = 0;
00549 
00556     virtual int decodeBandHeader(IVIBandDesc *band) = 0;
00557 
00566     virtual int decodeMbInfo(IVIBandDesc *band, IVITile *tile) = 0;
00567 
00571     virtual int decodeTransparency() { return -1; }
00572 
00577     int decodeIndeoFrame();
00578 
00582     int scaleMV(int mv, int mvScale);
00583 public:
00584     IndeoDecoderBase(uint16 width, uint16 height, uint bitsPerPixel);
00585     virtual ~IndeoDecoderBase();
00586 };
00587 
00588 } // End of namespace Indeo
00589 } // End of namespace Image
00590 
00591 #endif


Generated on Sat May 25 2019 05:00:47 for ResidualVM by doxygen 1.7.1
curved edge   curved edge