ScummVM API documentation
indeo.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include "common/scummsys.h"
23#include "graphics/surface.h"
24#include "image/codecs/codec.h"
25
26/* Common structures, macros, and base class shared by both Indeo4 and
27 * Indeo5 decoders, derived from ffmpeg. We don't currently support Indeo5
28 * decoding, but just in case we eventually need it, this is kept as a separate
29 * file like it is in ffmpeg.
30 *
31 * Original copyright note: * Intel Indeo 4 (IV41, IV42, etc.) video decoder for ffmpeg
32 * written, produced, and directed by Alan Smithee
33 */
34
35#ifndef IMAGE_CODECS_INDEO_INDEO_H
36#define IMAGE_CODECS_INDEO_INDEO_H
37
38#include "image/codecs/indeo/get_bits.h"
39#include "image/codecs/indeo/vlc.h"
40
41namespace Image {
42namespace Indeo {
43
47enum {
48 IVI4_FRAMETYPE_INTRA = 0,
49 IVI4_FRAMETYPE_INTRA1 = 1,
50 IVI4_FRAMETYPE_INTER = 2,
51 IVI4_FRAMETYPE_BIDIR = 3,
52 IVI4_FRAMETYPE_INTER_NOREF = 4,
53 IVI4_FRAMETYPE_NULL_FIRST = 5,
54 IVI4_FRAMETYPE_NULL_LAST = 6
55};
56
57enum {
58 IVI_MB_HUFF = 0,
59 IVI_BLK_HUFF = 1
60};
61
65typedef void (InvTransformPtr)(const int32 *in, int16 *out, uint32 pitch, const uint8 *flags);
66typedef void (DCTransformPtr)(const int32 *in, int16 *out, uint32 pitch, int blkSize);
67
68typedef void (*IviMCFunc)(int16 *buf, const int16 *refBuf, uint32 pitch, int mcType);
69typedef void (*IviMCAvgFunc)(int16 *buf, const int16 *refBuf1, const int16 *refBuf2,
70 uint32 pitch, int mcType, int mcType2);
71
73#define IVI_VLC_BITS 13
74#define IVI5_IS_PROTECTED 0x20
75
79#define IVI_TOSIGNED(val) (-(((val) >> 1) ^ -((val) & 1)))
80
84#define IVI_MBs_PER_TILE(tileWidth, tileHeight, mbSize) \
85 ((((tileWidth) + (mbSize) - 1) / (mbSize)) * (((tileHeight) + (mbSize) - 1) / (mbSize)))
86
91 int32 _numRows;
92 uint8 _xBits[16];
93
102 int createHuffFromDesc(VLC *vlc, bool flag) const;
103
110 bool huffDescCompare(const IVIHuffDesc *desc2) const;
111
117 void huffDescCopy(const IVIHuffDesc *src);
118};
119
120struct IVI45DecContext;
121
126public:
127 int32 _tabSel;
130
134
139
149 int decodeHuffDesc(IVI45DecContext *ctx, int descCoded, int whichTab);
150};
151
155struct RVMapDesc {
156 uint8 _eobSym;
157 uint8 _escSym;
158 uint8 _runtab[256];
159 int8 _valtab[256];
160};
161
165struct IVIMbInfo {
166 int16 _xPos;
167 int16 _yPos;
168 uint32 _bufOffs;
169 uint8 _type;
170 uint8 _cbp;
171 int8 _qDelta;
172 int8 _mvX;
173 int8 _mvY;
174 int8 _bMvX;
175 int8 _bMvY;
176
177 IVIMbInfo();
178};
179
183struct IVITile {
184 int _xPos;
185 int _yPos;
186 int _width;
187 int _height;
188 int _mbSize;
189 bool _isEmpty;
194
195 IVITile();
196};
197
202 int _plane;
204 int _width;
205 int _height;
207 const uint8 * _dataPtr;
209 int16 * _buf;
210 int16 * _refBuf;
211 int16 * _bRefBuf;
212 int16 * _bufs[4];
213 int _pitch;
214 bool _isEmpty;
223 const uint8 * _scan;
225
227
229 uint8 _corr[61 * 2];
234 InvTransformPtr *_invTransform;
235 int _transformSize;
236 DCTransformPtr *_dcTransform;
237 bool _is2dTrans;
238 int32 _checksum;
239 int _checksumPresent;
241 const uint16 * _intraBase;
242 const uint16 * _interBase;
243 const uint8 * _intraScale;
244 const uint8 * _interScale;
245
246 IVIBandDesc();
247
248 int initTiles(IVITile *refTile, int p, int b, int tHeight, int tWidth);
249};
250
252 uint16 _picWidth;
253 uint16 _picHeight;
254 uint16 _chromaWidth;
255 uint16 _chromaHeight;
256 uint16 _tileWidth;
257 uint16 _tileHeight;
258 uint8 _lumaBands;
259 uint8 _chromaBands;
260
261 IVIPicConfig();
262
267};
268
273 uint16 _width;
274 uint16 _height;
275 uint8 _numBands;
277
278 IVIPlaneDesc();
279
280 static int initPlanes(IVIPlaneDesc *planes, const IVIPicConfig *cfg, bool isIndeo4);
281
282 static int initTiles(IVIPlaneDesc *planes, int tileWidth, int tileHeight);
283
289 static void freeBuffers(IVIPlaneDesc *planes);
290
300 static int checkImageSize(unsigned int w, unsigned int h, int logOffset);
301};
302
303struct AVFrame {
307 int _width, _height;
308
309#define AV_NUM_DATA_POINTERS 3
322 uint8 *_data[AV_NUM_DATA_POINTERS];
323
339 int _linesize[AV_NUM_DATA_POINTERS];
340
345
350
354 int setDimensions(uint16 width, uint16 height);
355
359 int getBuffer(int flags);
360
364 void freeFrame();
365};
366
368 friend struct IVIHuffTab;
369private:
370 VLC_TYPE _tableData[8192 * 16][2];
371 VLC _iviMbVlcTabs[8];
372 VLC _iviBlkVlcTabs[8];
373public:
374 GetBits * _gb;
376
377 uint32 _frameNum;
378 int _frameType;
380 uint32 _dataSize;
381 int _isScalable;
382 const uint8 * _frameData;
384 uint32 _frameSize;
385 uint32 _picHdrSize;
386 uint8 _frameFlags;
387 uint16 _checksum;
388
389 IVIPicConfig _picConf;
391
397
401
402 uint8 _rvmapSel;
403 bool _inImf;
404 bool _inQ;
405 uint8 _picGlobQuant;
406 uint8 _unknown1;
407
408 uint16 _gopHdrSize;
409 uint8 _gopFlags;
410 uint32 _lockWord;
411
412 bool _hasBFrames;
414 bool _usesTiling;
415 bool _usesHaar;
416 bool _usesFullpel;
417
418 bool _gopInvalid;
419 int _bufInvalid[4];
420
421 bool _isIndeo4;
422 uint32 _transKeyColor;
423
424 AVFrame * _pFrame;
425 bool _gotPFrame;
426
428private:
432 static const RVMapDesc _ff_ivi_rvmap_tabs[9];
433};
434
435class IndeoDecoderBase : public Codec {
436private:
443 int decode_band(IVIBandDesc *band);
444
452 void recomposeHaar(const IVIPlaneDesc *plane, uint8 *dst, const int dstPitch);
453
461 void recompose53(const IVIPlaneDesc *plane, uint8 *dst, const int dstPitch);
462
463 /*
464 * Convert and output the current plane.
465 * This conversion is done by adding back the bias value of 128
466 * (subtracted in the encoder) and clipping the result.
467 *
468 * @param[in] plane Pointer to the descriptor of the plane being processed
469 * @param[out] dst Pointer to the buffer receiving converted pixels
470 * @param[in] dstPitch Pitch for moving to the next y line
471 */
472 void outputPlane(IVIPlaneDesc *plane, uint8 *dst, int dstPitch);
473
482 int processEmptyTile(IVIBandDesc *band, IVITile *tile, int32 mvScale);
483
484 /*
485 * Decode size of the tile data.
486 * The size is stored as a variable-length field having the following format:
487 * if (tile_data_size < 255) than this field is only one byte long
488 * if (tile_data_size >= 255) than this field four is byte long: 0xFF X1 X2 X3
489 * where X1-X3 is size of the tile data
490 *
491 * @param[in,out] gb the GetBit context
492 * @returns Size of the tile data in bytes
493 */
494 int decodeTileDataSize(GetBits *gb);
495
496 /*
497 * Decode block data:
498 * extract huffman-coded transform coefficients from the bitstream,
499 * dequantize them, apply inverse transform and motion compensation
500 * in order to reconstruct the picture.
501 *
502 * @param[in,out] gb The GetBit context
503 * @param[in] band Pointer to the band descriptor
504 * @param[in] tile Pointer to the tile descriptor
505 * @returns Result code: 0 - OK, -1 = error (corrupted blocks data)
506 */
507 int decodeBlocks(GetBits *gb, IVIBandDesc *band, IVITile *tile);
508
509 int iviMc(IVIBandDesc *band, IviMCFunc mc, IviMCAvgFunc mcAvg,
510 int offs, int mvX, int mvY, int mvX2, int mvY2, int mcType, int mcType2);
511
512 int decodeCodedBlocks(GetBits *gb, IVIBandDesc *band,
513 IviMCFunc mc, IviMCAvgFunc mcAvg, int mvX, int mvY,
514 int mvX2, int mvY2, int32 *prevDc, int isIntra,
515 int mcType, int mcType2, uint32 quant, int offs);
516
517 int iviDcTransform(IVIBandDesc *band, int32 *prevDc, int bufOffs,
518 int blkSize);
519protected:
520 IVI45DecContext _ctx;
521 uint16 _width;
522 uint16 _height;
523 uint _bitsPerPixel;
524 Graphics::PixelFormat _pixelFormat;
525 Graphics::Surface *_surface;
526
530 static const uint8 _ffIviVerticalScan8x8[64];
531 static const uint8 _ffIviHorizontalScan8x8[64];
532 static const uint8 _ffIviDirectScan4x4[16];
533protected:
537 Graphics::PixelFormat getPixelFormat() const override { return _pixelFormat; }
538
543 bool setOutputPixelFormat(const Graphics::PixelFormat &format) override {
544 if (format.bytesPerPixel != 2 && format.bytesPerPixel != 4)
545 return false;
546 _pixelFormat = format;
547 return true;
548 }
549
554 virtual int decodePictureHeader() = 0;
555
559 virtual void switchBuffers() = 0;
560
561 virtual bool isNonNullFrame() const = 0;
562
569 virtual int decodeBandHeader(IVIBandDesc *band) = 0;
570
579 virtual int decodeMbInfo(IVIBandDesc *band, IVITile *tile) = 0;
580
584 virtual int decodeTransparency() { return -1; }
585
591
595 int scaleMV(int mv, int mvScale);
596public:
597 IndeoDecoderBase(uint16 width, uint16 height, uint bitsPerPixel);
598 ~IndeoDecoderBase() override;
599};
600
601} // End of namespace Indeo
602} // End of namespace Image
603
604#endif
Definition: codec.h:57
Definition: get_bits.h:33
Definition: indeo.h:435
Graphics::PixelFormat getPixelFormat() const override
Definition: indeo.h:537
virtual int decodeMbInfo(IVIBandDesc *band, IVITile *tile)=0
static const uint8 _ffIviVerticalScan8x8[64]
Definition: indeo.h:530
virtual int decodePictureHeader()=0
bool setOutputPixelFormat(const Graphics::PixelFormat &format) override
Definition: indeo.h:543
virtual int decodeTransparency()
Definition: indeo.h:584
int scaleMV(int mv, int mvScale)
virtual int decodeBandHeader(IVIBandDesc *band)=0
virtual void switchBuffers()=0
Definition: pixelformat.h:138
Definition: surface.h:67
Definition: indeo.h:303
uint8 * _data[3]
Definition: indeo.h:322
int setDimensions(uint16 width, uint16 height)
int _width
Definition: indeo.h:307
~AVFrame()
Definition: indeo.h:349
int _linesize[3]
Definition: indeo.h:339
int getBuffer(int flags)
Definition: indeo.h:367
uint32 _dataSize
size of the frame data in bytes from picture header
Definition: indeo.h:380
uint32 _picHdrSize
picture header size in bytes
Definition: indeo.h:385
uint32 _frameSize
frame size in bytes
Definition: indeo.h:384
int _dstBuf
buffer index for the currently decoded frame
Definition: indeo.h:393
const uint8 * _frameData
input frame data pointer
Definition: indeo.h:382
int _refBuf
inter frame reference buffer index
Definition: indeo.h:394
uint16 _checksum
frame _checksum
Definition: indeo.h:387
IVIPlaneDesc _planes[3]
color planes
Definition: indeo.h:390
int _interScal
signals a sequence of scalable inter frames
Definition: indeo.h:383
int _bRefBuf
second reference frame buffer index
Definition: indeo.h:396
bool _inQ
flag for explicitly stored quantiser delta
Definition: indeo.h:404
IVIHuffTab _transVlc
current transparency table descriptor
Definition: indeo.h:400
int _prevFrameType
frame type of the previous frame
Definition: indeo.h:379
IVIHuffTab _blkVlc
current block table descriptor
Definition: indeo.h:399
RVMapDesc _rvmapTabs[9]
local corrected copy of the static rvmap tables
Definition: indeo.h:375
bool _hasTransp
transparency mode enabled
Definition: indeo.h:413
int _bufSwitch
used to switch between three buffers
Definition: indeo.h:392
int _ref2Buf
temporal storage for switching buffers
Definition: indeo.h:395
IVIHuffTab _mbVlc
current macroblock table descriptor
Definition: indeo.h:398
Definition: indeo.h:201
int _scanSize
size of the scantable
Definition: indeo.h:224
int _blkSize
block size
Definition: indeo.h:216
const uint8 * _dataPtr
ptr to the first byte of the band data
Definition: indeo.h:207
RVMapDesc * _rvMap
ptr to the RLE table for this band
Definition: indeo.h:231
int _bandNum
band number
Definition: indeo.h:203
int _numTiles
number of tiles in this band
Definition: indeo.h:232
int32 _checksum
for debug purposes
Definition: indeo.h:238
bool _qdeltaPresent
tells if Qdelta signal is present in the bitstream (Indeo5 only)
Definition: indeo.h:220
int _pitch
_pitch associated with the buffers above
Definition: indeo.h:213
int _rvmapSel
rvmap table selector
Definition: indeo.h:230
const uint8 * _interScale
quantization coefficient for inter blocks
Definition: indeo.h:244
int _mbSize
macroblock size
Definition: indeo.h:215
int _quantMat
dequant matrix index
Definition: indeo.h:221
int _bufSize
band buffer size in bytes
Definition: indeo.h:240
const uint8 * _scan
ptr to the scan pattern
Definition: indeo.h:223
int16 * _bufs[4]
array of pointers to the band buffers
Definition: indeo.h:212
int _aHeight
aligned band height
Definition: indeo.h:206
uint8 _corr[61 *2]
rvmap correction pairs
Definition: indeo.h:229
const uint8 * _intraScale
quantization coefficient for intra blocks
Definition: indeo.h:243
int _dataSize
size of the band data
Definition: indeo.h:208
int16 * _refBuf
pointer to the reference frame buffer (for motion compensation)
Definition: indeo.h:210
int16 * _buf
pointer to the output buffer for this band
Definition: indeo.h:209
int _globQuant
quant base for this band
Definition: indeo.h:222
const uint16 * _intraBase
quantization matrix for intra blocks
Definition: indeo.h:241
bool _inheritMv
tells if motion vector is inherited from reference macroblock
Definition: indeo.h:218
bool _inheritQDelta
tells if quantiser delta is inherited from reference macroblock
Definition: indeo.h:219
int _plane
plane number this band belongs to
Definition: indeo.h:202
uint8 _isHalfpel
precision of the motion compensation: 0 - fullpel, 1 - halfpel
Definition: indeo.h:217
IVIHuffTab _blkVlc
vlc table for decoding block data
Definition: indeo.h:226
IVITile * _tiles
array of tile descriptors
Definition: indeo.h:233
int _numCorr
number of correction entries
Definition: indeo.h:228
int16 * _bRefBuf
pointer to the second reference frame buffer (for motion compensation)
Definition: indeo.h:211
const uint16 * _interBase
quantization matrix for inter blocks
Definition: indeo.h:242
Definition: indeo.h:90
int createHuffFromDesc(VLC *vlc, bool flag) const
bool huffDescCompare(const IVIHuffDesc *desc2) const
void huffDescCopy(const IVIHuffDesc *src)
Definition: indeo.h:125
VLC * _tab
Definition: indeo.h:129
VLC _custTab
custom Huffman codebook descriptor
Definition: indeo.h:133
int decodeHuffDesc(IVI45DecContext *ctx, int descCoded, int whichTab)
IVIHuffTab()
vlc table for custom codebook
IVIHuffDesc _custDesc
pointer to the table associated with tab_sel
Definition: indeo.h:132
Definition: indeo.h:165
int8 _mvY
motion vector (y component)
Definition: indeo.h:173
int8 _bMvX
second motion vector (x component)
Definition: indeo.h:174
uint8 _type
macroblock type: 0 - INTRA, 1 - INTER
Definition: indeo.h:169
int8 _qDelta
quant delta
Definition: indeo.h:171
uint32 _bufOffs
address in the output buffer for this mb
Definition: indeo.h:168
int8 _mvX
motion vector (x component)
Definition: indeo.h:172
int8 _bMvY
second motion vector (y component)
Definition: indeo.h:175
uint8 _cbp
coded block pattern
Definition: indeo.h:170
Definition: indeo.h:251
bool ivi_pic_config_cmp(const IVIPicConfig &cfg2)
Definition: indeo.h:272
IVIBandDesc * _bands
array of band descriptors
Definition: indeo.h:276
static int checkImageSize(unsigned int w, unsigned int h, int logOffset)
uint8 _numBands
number of bands this plane subdivided into
Definition: indeo.h:275
static void freeBuffers(IVIPlaneDesc *planes)
Definition: indeo.h:183
int _dataSize
size of the data in bytes
Definition: indeo.h:190
IVIMbInfo * _mbs
array of macroblock descriptors
Definition: indeo.h:192
IVIMbInfo * _refMbs
ptr to the macroblock descriptors of the reference tile
Definition: indeo.h:193
int _numMBs
number of macroblocks in this tile
Definition: indeo.h:191
Definition: indeo.h:155
uint8 _escSym
escape symbol
Definition: indeo.h:157
uint8 _eobSym
end of block symbol
Definition: indeo.h:156
Definition: vlc.h:56