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
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (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, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 /* Intel Indeo 4 decompressor, derived from ffmpeg.
24 *
25 * Original copyright note: * Intel Indeo 4 (IV41, IV42, etc.) video decoder for ffmpeg
26 * written, produced, and directed by Alan Smithee
27 */
28
29 #include "common/algorithm.h"
30 #include "common/debug.h"
31 #include "common/memstream.h"
32 #include "common/rect.h"
33 #include "common/textconsole.h"
34 #include "graphics/yuv_to_rgb.h"
35 #include "image/codecs/indeo4.h"
36 #include "image/codecs/indeo/indeo_dsp.h"
37 #include "image/codecs/indeo/mem.h"
38
39 namespace Image {
40
41 #define IVI4_PIC_SIZE_ESC 7
42
Indeo4Decoder(uint16 width,uint16 height,uint bitsPerPixel)43 Indeo4Decoder::Indeo4Decoder(uint16 width, uint16 height, uint bitsPerPixel) :
44 IndeoDecoderBase(width, height, bitsPerPixel) {
45 _ctx._isIndeo4 = true;
46 _ctx._refBuf = 1;
47 _ctx._bRefBuf = 3;
48 _ctx._pFrame = new AVFrame();
49 }
50
isIndeo4(Common::SeekableReadStream & stream)51 bool Indeo4Decoder::isIndeo4(Common::SeekableReadStream &stream) {
52 // Less than 16 bytes? This can't be right
53 if (stream.size() < 16)
54 return false;
55
56 // Read in the start of the data
57 byte buffer[16];
58 stream.read(buffer, 16);
59 stream.seek(-16, SEEK_CUR);
60
61 // Validate the first 18-bit word has the correct identifier
62 Indeo::GetBits gb(buffer, 16 * 8);
63 bool isIndeo4 = gb.getBits(18) == 0x3FFF8;
64
65 return isIndeo4;
66 }
67
decodeFrame(Common::SeekableReadStream & stream)68 const Graphics::Surface *Indeo4Decoder::decodeFrame(Common::SeekableReadStream &stream) {
69 // Not Indeo 4? Fail
70 if (!isIndeo4(stream))
71 return nullptr;
72
73 // Set up the frame data buffer
74 byte *frameData = new byte[stream.size()];
75 stream.read(frameData, stream.size());
76 _ctx._frameData = frameData;
77 _ctx._frameSize = stream.size();
78
79 // Set up the GetBits instance for reading the data
80 _ctx._gb = new GetBits(_ctx._frameData, _ctx._frameSize);
81
82 // Decode the frame
83 int err = decodeIndeoFrame();
84
85 // Free the bit reader and frame buffer
86 delete _ctx._gb;
87 _ctx._gb = nullptr;
88 delete[] frameData;
89 _ctx._frameData = nullptr;
90 _ctx._frameSize = 0;
91
92 return (err < 0) ? nullptr : &_surface;
93 }
94
decodePictureHeader()95 int Indeo4Decoder::decodePictureHeader() {
96 int pic_size_indx, i, p;
97 IVIPicConfig picConf;
98
99 if (_ctx._gb->getBits(18) != 0x3FFF8) {
100 warning("Invalid picture start code!");
101 return -1;
102 }
103
104 _ctx._prevFrameType = _ctx._frameType;
105 _ctx._frameType = _ctx._gb->getBits(3);
106 if (_ctx._frameType == 7) {
107 warning("Invalid frame type: %d", _ctx._frameType);
108 return -1;
109 }
110
111 if (_ctx._frameType == IVI4_FRAMETYPE_BIDIR)
112 _ctx._hasBFrames = true;
113
114 _ctx._hasTransp = _ctx._gb->getBit();
115 if (_ctx._hasTransp && _surface.format.aBits() == 0) {
116 // Surface is 4 bytes per pixel, but only RGB. So promote the
117 // surface to full RGBA, and convert all the existing pixels
118 _pixelFormat = Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
119 _surface.convertToInPlace(_pixelFormat);
120 }
121
122 // unknown bit: Mac decoder ignores this bit, XANIM returns error
123 if (_ctx._gb->getBit()) {
124 warning("Sync bit is set!");
125 return -1;
126 }
127
128 _ctx._dataSize = _ctx._gb->getBit() ? _ctx._gb->getBits(24) : 0;
129
130 // null frames don't contain anything else so we just return
131 if (_ctx._frameType >= IVI4_FRAMETYPE_NULL_FIRST) {
132 warning("Null frame encountered!");
133 return 0;
134 }
135
136 // Check key lock status. If enabled - ignore lock word.
137 // Usually we have to prompt the user for the password, but
138 // we don't do that because Indeo 4 videos can be decoded anyway
139 if (_ctx._gb->getBit()) {
140 _ctx._gb->skip(32);
141 warning("Password-protected clip!");
142 }
143
144 pic_size_indx = _ctx._gb->getBits(3);
145 if (pic_size_indx == IVI4_PIC_SIZE_ESC) {
146 picConf._picHeight = _ctx._gb->getBits(16);
147 picConf._picWidth = _ctx._gb->getBits(16);
148 } else {
149 picConf._picHeight = _ivi4_common_pic_sizes[pic_size_indx * 2 + 1];
150 picConf._picWidth = _ivi4_common_pic_sizes[pic_size_indx * 2];
151 }
152
153 // Decode tile dimensions.
154 _ctx._usesTiling = _ctx._gb->getBit();
155 if (_ctx._usesTiling) {
156 picConf._tileHeight = scaleTileSize(picConf._picHeight, _ctx._gb->getBits(4));
157 picConf._tileWidth = scaleTileSize(picConf._picWidth, _ctx._gb->getBits(4));
158 } else {
159 picConf._tileHeight = picConf._picHeight;
160 picConf._tileWidth = picConf._picWidth;
161 }
162
163 // Decode chroma subsampling. We support only 4:4 aka YVU9.
164 if (_ctx._gb->getBits(2)) {
165 warning("Only YVU9 picture format is supported!");
166 return -1;
167 }
168 picConf._chromaHeight = (picConf._picHeight + 3) >> 2;
169 picConf._chromaWidth = (picConf._picWidth + 3) >> 2;
170
171 // decode subdivision of the planes
172 picConf._lumaBands = decodePlaneSubdivision();
173 picConf._chromaBands = 0;
174 if (picConf._lumaBands)
175 picConf._chromaBands = decodePlaneSubdivision();
176 _ctx._isScalable = picConf._lumaBands != 1 || picConf._chromaBands != 1;
177 if (_ctx._isScalable && (picConf._lumaBands != 4 || picConf._chromaBands != 1)) {
178 warning("Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d",
179 picConf._lumaBands, picConf._chromaBands);
180 return -1;
181 }
182
183 // check if picture layout was changed and reallocate buffers
184 if (picConf.ivi_pic_config_cmp(_ctx._picConf)) {
185 if (IVIPlaneDesc::initPlanes(_ctx._planes, &picConf, 1)) {
186 warning("Couldn't reallocate color planes!");
187 _ctx._picConf._lumaBands = 0;
188 return -2;
189 }
190
191 _ctx._picConf = picConf;
192
193 // set default macroblock/block dimensions
194 for (p = 0; p <= 2; p++) {
195 for (i = 0; i < (!p ? picConf._lumaBands : picConf._chromaBands); i++) {
196 _ctx._planes[p]._bands[i]._mbSize = !p ? (!_ctx._isScalable ? 16 : 8) : 4;
197 _ctx._planes[p]._bands[i]._blkSize = !p ? 8 : 4;
198 }
199 }
200
201 if (IVIPlaneDesc::initTiles(_ctx._planes, _ctx._picConf._tileWidth,
202 _ctx._picConf._tileHeight)) {
203 warning("Couldn't reallocate internal structures!");
204 return -2;
205 }
206 }
207
208 _ctx._frameNum = _ctx._gb->getBit() ? _ctx._gb->getBits(20) : 0;
209
210 // skip decTimeEst field if present
211 if (_ctx._gb->getBit())
212 _ctx._gb->skip(8);
213
214 // decode macroblock and block huffman codebooks
215 if (_ctx._mbVlc.decodeHuffDesc(&_ctx, _ctx._gb->getBit(), IVI_MB_HUFF) ||
216 _ctx._blkVlc.decodeHuffDesc(&_ctx, _ctx._gb->getBit(), IVI_BLK_HUFF))
217 return -1;
218
219 _ctx._rvmapSel = _ctx._gb->getBit() ? _ctx._gb->getBits(3) : 8;
220
221 _ctx._inImf = _ctx._gb->getBit();
222 _ctx._inQ = _ctx._gb->getBit();
223
224 _ctx._picGlobQuant = _ctx._gb->getBits(5);
225
226 // TODO: ignore this parameter if unused
227 _ctx._unknown1 = _ctx._gb->getBit() ? _ctx._gb->getBits(3) : 0;
228
229 _ctx._checksum = _ctx._gb->getBit() ? _ctx._gb->getBits(16) : 0;
230
231 // skip picture header extension if any
232 while (_ctx._gb->getBit()) {
233 _ctx._gb->skip(8);
234 }
235
236 if (_ctx._gb->getBit()) {
237 warning("Bad blocks bits encountered!");
238 }
239
240 _ctx._gb->align();
241
242 return 0;
243 }
244
switchBuffers()245 void Indeo4Decoder::switchBuffers() {
246 int isPrevRef = 0, isRef = 0;
247
248 switch (_ctx._prevFrameType) {
249 case IVI4_FRAMETYPE_INTRA:
250 case IVI4_FRAMETYPE_INTRA1:
251 case IVI4_FRAMETYPE_INTER:
252 isPrevRef = 1;
253 break;
254 }
255
256 switch (_ctx._frameType) {
257 case IVI4_FRAMETYPE_INTRA:
258 case IVI4_FRAMETYPE_INTRA1:
259 case IVI4_FRAMETYPE_INTER:
260 isRef = 1;
261 break;
262
263 default:
264 break;
265 }
266
267 if (isPrevRef && isRef) {
268 SWAP(_ctx._dstBuf, _ctx._refBuf);
269 } else if (isPrevRef) {
270 SWAP(_ctx._refBuf, _ctx._bRefBuf);
271 SWAP(_ctx._dstBuf, _ctx._refBuf);
272 }
273 }
274
isNonNullFrame() const275 bool Indeo4Decoder::isNonNullFrame() const {
276 return _ctx._frameType < IVI4_FRAMETYPE_NULL_FIRST;
277 }
278
decodeBandHeader(IVIBandDesc * band)279 int Indeo4Decoder::decodeBandHeader(IVIBandDesc *band) {
280 int plane, bandNum, indx, transformId, scanIndx;
281 int i;
282 int quantMat;
283
284 plane = _ctx._gb->getBits(2);
285 bandNum = _ctx._gb->getBits(4);
286 if (band->_plane != plane || band->_bandNum != bandNum) {
287 warning("Invalid band header sequence!");
288 return -1;
289 }
290
291 band->_isEmpty = _ctx._gb->getBit();
292 if (!band->_isEmpty) {
293 int old_blk_size = band->_blkSize;
294 // skip header size
295 // If header size is not given, header size is 4 bytes.
296 if (_ctx._gb->getBit())
297 _ctx._gb->skip(16);
298
299 band->_isHalfpel = _ctx._gb->getBits(2);
300 if (band->_isHalfpel >= 2) {
301 warning("Invalid/unsupported mv resolution: %d!",
302 band->_isHalfpel);
303 return -1;
304 }
305 if (!band->_isHalfpel)
306 _ctx._usesFullpel = true;
307
308 band->_checksumPresent = _ctx._gb->getBit();
309 if (band->_checksumPresent)
310 band->_checksum = _ctx._gb->getBits(16);
311
312 indx = _ctx._gb->getBits(2);
313 if (indx == 3) {
314 warning("Invalid block size!");
315 return -1;
316 }
317 band->_mbSize = 16 >> indx;
318 band->_blkSize = 8 >> (indx >> 1);
319
320 band->_inheritMv = _ctx._gb->getBit();
321 band->_inheritQDelta = _ctx._gb->getBit();
322
323 band->_globQuant = _ctx._gb->getBits(5);
324
325 if (!_ctx._gb->getBit() || _ctx._frameType == IVI4_FRAMETYPE_INTRA) {
326 transformId = _ctx._gb->getBits(5);
327 if ((uint)transformId >= FF_ARRAY_ELEMS(_transforms) ||
328 !_transforms[transformId]._invTrans) {
329 warning("Transform %d", transformId);
330 return -3;
331 }
332 if ((transformId >= 7 && transformId <= 9) ||
333 transformId == 17) {
334 warning("DCT transform");
335 return -3;
336 }
337
338 if (transformId < 10 && band->_blkSize < 8) {
339 warning("wrong transform size!");
340 return -1;
341 }
342 if ((transformId >= 0 && transformId <= 2) || transformId == 10)
343 _ctx._usesHaar = true;
344
345 band->_invTransform = _transforms[transformId]._invTrans;
346 band->_dcTransform = _transforms[transformId]._dcTrans;
347 band->_is2dTrans = _transforms[transformId]._is2dTrans;
348
349 if (transformId < 10)
350 band->_transformSize = 8;
351 else
352 band->_transformSize = 4;
353
354 if (band->_blkSize != band->_transformSize) {
355 warning("transform and block size mismatch (%d != %d)", band->_transformSize, band->_blkSize);
356 return -1;
357 }
358
359 scanIndx = _ctx._gb->getBits(4);
360 if (scanIndx == 15) {
361 warning("Custom scan pattern encountered!");
362 return -1;
363 }
364 if (scanIndx > 4 && scanIndx < 10) {
365 if (band->_blkSize != 4) {
366 warning("mismatching scan table!");
367 return -1;
368 }
369 } else if (band->_blkSize != 8) {
370 warning("mismatching scan table!");
371 return -1;
372 }
373
374 band->_scan = _scan_index_to_tab[scanIndx];
375 band->_scanSize = band->_blkSize;
376
377 quantMat = _ctx._gb->getBits(5);
378 if (quantMat == 31) {
379 warning("Custom quant matrix encountered!");
380 return -1;
381 }
382 if ((uint)quantMat >= FF_ARRAY_ELEMS(_quant_index_to_tab)) {
383 warning("Quantization matrix %d", quantMat);
384 return -1;
385 }
386 band->_quantMat = quantMat;
387 } else {
388 if (old_blk_size != band->_blkSize) {
389 warning("The band block size does not match the configuration inherited");
390 return -1;
391 }
392 }
393 if (_quant_index_to_tab[band->_quantMat] > 4 && band->_blkSize == 4) {
394 warning("Invalid quant matrix for 4x4 block encountered!");
395 band->_quantMat = 0;
396 return -1;
397 }
398 if (band->_scanSize != band->_blkSize) {
399 warning("mismatching scan table!");
400 return -1;
401 }
402 if (band->_transformSize == 8 && band->_blkSize < 8) {
403 warning("mismatching _transformSize!");
404 return -1;
405 }
406
407 // decode block huffman codebook
408 if (!_ctx._gb->getBit())
409 band->_blkVlc._tab = _ctx._blkVlc._tab;
410 else
411 if (band->_blkVlc.decodeHuffDesc(&_ctx, 1, IVI_BLK_HUFF))
412 return -1;
413
414 // select appropriate rvmap table for this band
415 band->_rvmapSel = _ctx._gb->getBit() ? _ctx._gb->getBits(3) : 8;
416
417 // decode rvmap probability corrections if any
418 band->_numCorr = 0; // there is no corrections
419 if (_ctx._gb->getBit()) {
420 band->_numCorr = _ctx._gb->getBits(8); // get number of correction pairs
421 if (band->_numCorr > 61) {
422 warning("Too many corrections: %d",
423 band->_numCorr);
424 return -1;
425 }
426
427 // read correction pairs
428 for (i = 0; i < band->_numCorr * 2; i++)
429 band->_corr[i] = _ctx._gb->getBits(8);
430 }
431 }
432
433 if (band->_blkSize == 8) {
434 band->_intraBase = &_ivi4_quant_8x8_intra[_quant_index_to_tab[band->_quantMat]][0];
435 band->_interBase = &_ivi4_quant_8x8_inter[_quant_index_to_tab[band->_quantMat]][0];
436 } else {
437 band->_intraBase = &_ivi4_quant_4x4_intra[_quant_index_to_tab[band->_quantMat]][0];
438 band->_interBase = &_ivi4_quant_4x4_inter[_quant_index_to_tab[band->_quantMat]][0];
439 }
440
441 // Indeo 4 doesn't use scale tables
442 band->_intraScale = NULL;
443 band->_interScale = NULL;
444
445 _ctx._gb->align();
446
447 if (!band->_scan) {
448 warning("band->_scan not set");
449 return -1;
450 }
451
452 return 0;
453 }
454
decodeMbInfo(IVIBandDesc * band,IVITile * tile)455 int Indeo4Decoder::decodeMbInfo(IVIBandDesc *band, IVITile *tile) {
456 int x, y, mvX, mvY, mvDelta, offs, mbOffset, blksPerMb,
457 mvScale, mbTypeBits, s;
458 IVIMbInfo *mb, *refMb;
459 int row_offset = band->_mbSize * band->_pitch;
460
461 mb = tile->_mbs;
462 refMb = tile->_refMbs;
463 offs = tile->_yPos * band->_pitch + tile->_xPos;
464
465 blksPerMb = band->_mbSize != band->_blkSize ? 4 : 1;
466 mbTypeBits = _ctx._frameType == IVI4_FRAMETYPE_BIDIR ? 2 : 1;
467
468 // scale factor for motion vectors
469 mvScale = (_ctx._planes[0]._bands[0]._mbSize >> 3) - (band->_mbSize >> 3);
470 mvX = mvY = 0;
471
472 if (((tile->_width + band->_mbSize - 1) / band->_mbSize) * ((tile->_height + band->_mbSize - 1) / band->_mbSize) != tile->_numMBs) {
473 warning("numMBs mismatch %d %d %d %d", tile->_width, tile->_height, band->_mbSize, tile->_numMBs);
474 return -1;
475 }
476
477 for (y = tile->_yPos; y < tile->_yPos + tile->_height; y += band->_mbSize) {
478 mbOffset = offs;
479
480 for (x = tile->_xPos; x < tile->_xPos + tile->_width; x += band->_mbSize) {
481 mb->_xPos = x;
482 mb->_yPos = y;
483 mb->_bufOffs = mbOffset;
484 mb->_bMvX = mb->_bMvY = 0;
485
486 if (_ctx._gb->getBit()) {
487 if (_ctx._frameType == IVI4_FRAMETYPE_INTRA) {
488 warning("Empty macroblock in an INTRA picture!");
489 return -1;
490 }
491 mb->_type = 1; // empty macroblocks are always INTER
492 mb->_cbp = 0; // all blocks are empty
493
494 mb->_qDelta = 0;
495 if (!band->_plane && !band->_bandNum && _ctx._inQ) {
496 mb->_qDelta = _ctx._gb->getVLC2<1>(_ctx._mbVlc._tab->_table,
497 IVI_VLC_BITS);
498 mb->_qDelta = IVI_TOSIGNED(mb->_qDelta);
499 }
500
501 mb->_mvX = mb->_mvY = 0; // no motion vector coded
502 if (band->_inheritMv && refMb) {
503 // motion vector inheritance
504 if (mvScale) {
505 mb->_mvX = scaleMV(refMb->_mvX, mvScale);
506 mb->_mvY = scaleMV(refMb->_mvY, mvScale);
507 } else {
508 mb->_mvX = refMb->_mvX;
509 mb->_mvY = refMb->_mvY;
510 }
511 }
512 } else {
513 if (band->_inheritMv) {
514 // copy mb_type from corresponding reference mb
515 if (!refMb) {
516 warning("refMb unavailable");
517 return -1;
518 }
519 mb->_type = refMb->_type;
520 } else if (_ctx._frameType == IVI4_FRAMETYPE_INTRA ||
521 _ctx._frameType == IVI4_FRAMETYPE_INTRA1) {
522 mb->_type = 0; // mb_type is always INTRA for intra-frames
523 } else {
524 mb->_type = _ctx._gb->getBits(mbTypeBits);
525 }
526
527 mb->_cbp = _ctx._gb->getBits(blksPerMb);
528
529 mb->_qDelta = 0;
530 if (band->_inheritQDelta) {
531 if (refMb) mb->_qDelta = refMb->_qDelta;
532 } else if (mb->_cbp || (!band->_plane && !band->_bandNum &&
533 _ctx._inQ)) {
534 mb->_qDelta = _ctx._gb->getVLC2<1>(_ctx._mbVlc._tab->_table,
535 IVI_VLC_BITS);
536 mb->_qDelta = IVI_TOSIGNED(mb->_qDelta);
537 }
538
539 if (!mb->_type) {
540 mb->_mvX = mb->_mvY = 0; // there is no motion vector in intra-macroblocks
541 } else {
542 if (band->_inheritMv) {
543 if (refMb) {
544 // motion vector inheritance
545 if (mvScale) {
546 mb->_mvX = scaleMV(refMb->_mvX, mvScale);
547 mb->_mvY = scaleMV(refMb->_mvY, mvScale);
548 } else {
549 mb->_mvX = refMb->_mvX;
550 mb->_mvY = refMb->_mvY;
551 }
552 }
553 } else {
554 // decode motion vector deltas
555 mvDelta = _ctx._gb->getVLC2<1>(_ctx._mbVlc._tab->_table,
556 IVI_VLC_BITS);
557 mvY += IVI_TOSIGNED(mvDelta);
558 mvDelta = _ctx._gb->getVLC2<1>(_ctx._mbVlc._tab->_table,
559 IVI_VLC_BITS);
560 mvX += IVI_TOSIGNED(mvDelta);
561 mb->_mvX = mvX;
562 mb->_mvY = mvY;
563 if (mb->_type == 3) {
564 mvDelta = _ctx._gb->getVLC2<1>(
565 _ctx._mbVlc._tab->_table,
566 IVI_VLC_BITS);
567 mvY += IVI_TOSIGNED(mvDelta);
568 mvDelta = _ctx._gb->getVLC2<1>(
569 _ctx._mbVlc._tab->_table,
570 IVI_VLC_BITS);
571 mvX += IVI_TOSIGNED(mvDelta);
572 mb->_bMvX = -mvX;
573 mb->_bMvY = -mvY;
574 }
575 }
576 if (mb->_type == 2) {
577 mb->_bMvX = -mb->_mvX;
578 mb->_bMvY = -mb->_mvY;
579 mb->_mvX = 0;
580 mb->_mvY = 0;
581 }
582 }
583 }
584
585 s = band->_isHalfpel;
586 if (mb->_type)
587 if (x + (mb->_mvX >> s) + (y + (mb->_mvY >> s))*band->_pitch < 0 ||
588 x + ((mb->_mvX + s) >> s) + band->_mbSize - 1
589 + (y + band->_mbSize - 1 + ((mb->_mvY + s) >> s))*band->_pitch > band->_bufSize - 1) {
590 warning("motion vector %d %d outside reference", x*s + mb->_mvX, y*s + mb->_mvY);
591 return -1;
592 }
593
594 mb++;
595 if (refMb)
596 refMb++;
597 mbOffset += band->_mbSize;
598 }
599
600 offs += row_offset;
601 }
602
603 _ctx._gb->align();
604 return 0;
605 }
606
decodeRLETransparency(VLC_TYPE (* table)[2])607 int Indeo4Decoder::decodeRLETransparency(VLC_TYPE (*table)[2]) {
608 const uint32 startPos = _ctx._gb->pos();
609
610 _ctx._gb->align();
611
612 bool runIsOpaque = _ctx._gb->getBit();
613 bool nextRunIsOpaque = !runIsOpaque;
614
615 uint32 *pixel = (uint32 *)_surface.getPixels();
616 const int surfacePixelPitch = _surface.pitch / _surface.format.bytesPerPixel;
617 const int surfacePadding = surfacePixelPitch - _surface.w;
618 const uint32 *endOfVisibleRow = pixel + _surface.w;
619 const uint32 *endOfVisibleArea = pixel + surfacePixelPitch * _surface.h - surfacePadding;
620
621 const int codecAlignedWidth = (_surface.w + 31) & ~31;
622 const int codecPaddingSize = codecAlignedWidth - _surface.w;
623
624 int numPixelsToRead = codecAlignedWidth * _surface.h;
625 int numPixelsToSkip = 0;
626 while (numPixelsToRead > 0) {
627 int value = _ctx._gb->getVLC2<1>(table, IVI_VLC_BITS);
628
629 if (value == -1) {
630 warning("Transparency VLC code read failed");
631 return -1;
632 }
633
634 if (value == 0) {
635 value = 255;
636 nextRunIsOpaque = runIsOpaque;
637 }
638
639 numPixelsToRead -= value;
640
641 debugN(9, "%d%s ", value, runIsOpaque ? "O" : "T");
642
643 // The rest of the transparency data must be consumed but it will not
644 // participate in writing any more pixels
645 if (pixel == endOfVisibleArea) {
646 debug(5, "Indeo4: Done writing transparency, but still need to consume %d pixels", numPixelsToRead + value);
647 continue;
648 }
649
650 // If a run ends in the padding area of a row, the next run needs to
651 // be partially consumed by the remaining pixels of the padding area
652 if (numPixelsToSkip) {
653 value -= numPixelsToSkip;
654 if (value < 0) {
655 numPixelsToSkip = -value;
656 value = 0;
657 } else {
658 numPixelsToSkip = 0;
659 }
660 }
661
662 while (value > 0) {
663 const int length = MIN<int>(value, endOfVisibleRow - pixel);
664 if (!runIsOpaque) {
665 Common::fill(pixel, pixel + length, _ctx._transKeyColor);
666 }
667 value -= length;
668 pixel += length;
669
670 if (pixel == endOfVisibleRow) {
671 pixel += surfacePadding;
672 endOfVisibleRow += surfacePixelPitch;
673 value -= codecPaddingSize;
674
675 if (value < 0) {
676 numPixelsToSkip = -value;
677 break;
678 }
679
680 if (pixel == endOfVisibleArea) {
681 break;
682 }
683 }
684 }
685
686 runIsOpaque = nextRunIsOpaque;
687 nextRunIsOpaque = !runIsOpaque;
688 }
689
690 debugN(9, "\n");
691
692 if (numPixelsToRead != 0) {
693 warning("Wrong number of transparency pixels read; delta = %d", numPixelsToRead);
694 }
695
696 _ctx._gb->align();
697
698 return (_ctx._gb->pos() - startPos) / 8;
699 }
700
decodeTransparency()701 int Indeo4Decoder::decodeTransparency() {
702 if (_ctx._gb->getBits(2) != 3 || _ctx._gb->getBits(3) != 0) {
703 warning("Invalid transparency marker");
704 return -1;
705 }
706
707 Common::Rect drawRect;
708
709 for (int numRects = _ctx._gb->getBits(8); numRects; --numRects) {
710 const int x1 = _ctx._gb->getBits(16);
711 const int y1 = _ctx._gb->getBits(16);
712 const int x2 = x1 + _ctx._gb->getBits(16);
713 const int y2 = y1 + _ctx._gb->getBits(16);
714 drawRect.extend(Common::Rect(x1, y1, x2, y2));
715 }
716
717 debug(4, "Indeo4: Transparency rect is (%d, %d, %d, %d)", drawRect.left, drawRect.top, drawRect.right, drawRect.bottom);
718
719 if (_ctx._gb->getBit()) { /* @350 */
720 /* @358 */
721 _ctx._transKeyColor = _surface.format.ARGBToColor(0, _ctx._gb->getBits(8), _ctx._gb->getBits(8), _ctx._gb->getBits(8));
722 debug(4, "Indeo4: Key color is %08x", _ctx._transKeyColor);
723 /* @477 */
724 }
725
726 if (_ctx._gb->getBit() == 0) { /* @4D9 */
727 warning("Invalid transparency band?");
728 return -1;
729 }
730
731 IVIHuffDesc huffDesc;
732
733 const int numHuffRows = huffDesc._numRows = _ctx._gb->getBits(4);
734 if (numHuffRows == 0 || numHuffRows > IVI_VLC_BITS - 1) {
735 warning("Invalid codebook row count %d", numHuffRows);
736 return -1;
737 }
738
739 for (int i = 0; i < numHuffRows; ++i) {
740 huffDesc._xBits[i] = _ctx._gb->getBits(4);
741 }
742
743 /* @5E2 */
744 _ctx._gb->align();
745
746 IVIHuffTab &huffTable = _ctx._transVlc;
747
748 if (huffDesc.huffDescCompare(&huffTable._custDesc) || !huffTable._custTab._table) {
749 if (huffTable._custTab._table) {
750 huffTable._custTab.freeVlc();
751 }
752
753 huffTable._custDesc = huffDesc;
754 huffTable._tabSel = 7;
755 huffTable._tab = &huffTable._custTab;
756 if (huffTable._custDesc.createHuffFromDesc(huffTable._tab, false)) {
757 // reset faulty description
758 huffTable._custDesc._numRows = 0;
759 warning("Error while initializing transparency VLC table");
760 return -1;
761 }
762 }
763
764 // FIXME: The transparency plane can be split, apparently for local decoding
765 // mode (y459.avi in Titanic has the scalable flag and its transparency
766 // plane seems to be decoded successfully, so the split transparency plane
767 // does not seem to be related to scaling mode). This adds complexity to the
768 // implementation, so avoid supporting unless it turns out to actually be
769 // necessary for correct decoding of game videos.
770 assert(!_ctx._usesTiling);
771
772 assert(_surface.format.bytesPerPixel == 4);
773 assert((_surface.pitch % 4) == 0);
774
775 const uint32 startByte = _ctx._gb->pos() / 8;
776
777 /* @68D */
778 const bool useFillTransparency = _ctx._gb->getBit();
779 if (useFillTransparency) {
780 /* @6F2 */
781 const bool runIsOpaque = _ctx._gb->getBit();
782 if (!runIsOpaque) {
783 // It should only be necessary to draw transparency here since the
784 // data from the YUV planes gets drawn to the output surface on each
785 // frame, which resets the surface pixels to be fully opaque
786 _surface.fillRect(Common::Rect(_surface.w, _surface.h), _ctx._transKeyColor);
787 }
788
789 // No alignment here
790 } else {
791 /* @7BF */
792 const bool hasDataSize = _ctx._gb->getBit();
793 if (hasDataSize) { /* @81A */
794 /* @822 */
795 int expectedSize = _ctx._gb->getBits(8);
796 if (expectedSize == 0xFF) {
797 expectedSize = _ctx._gb->getBits(24);
798 }
799
800 expectedSize -= ((_ctx._gb->pos() + 7) / 8) - startByte;
801
802 const int bytesRead = decodeRLETransparency(huffTable._tab->_table);
803 if (bytesRead == -1) {
804 // A more specific warning should have been emitted already
805 return -1;
806 } else if (bytesRead != expectedSize) {
807 warning("Mismatched read %u != %u", bytesRead, expectedSize);
808 return -1;
809 }
810 } else {
811 /* @95B */
812 if (decodeRLETransparency(huffTable._tab->_table) == -1) {
813 warning("Transparency data read failure");
814 return -1;
815 }
816 }
817
818 _ctx._gb->align();
819 }
820
821 return 0;
822 }
823
scaleTileSize(int defSize,int sizeFactor)824 int Indeo4Decoder::scaleTileSize(int defSize, int sizeFactor) {
825 return sizeFactor == 15 ? defSize : (sizeFactor + 1) << 5;
826 }
827
decodePlaneSubdivision()828 int Indeo4Decoder::decodePlaneSubdivision() {
829 int i;
830
831 switch (_ctx._gb->getBits(2)) {
832 case 3:
833 return 1;
834
835 case 2:
836 for (i = 0; i < 4; i++)
837 if (_ctx._gb->getBits(2) != 3)
838 return 0;
839 return 4;
840
841 default:
842 return 0;
843 }
844 }
845
846 /*------------------------------------------------------------------------*/
847
848 /**
849 * Indeo 4 8x8 scan (zigzag) patterns
850 */
851 static const uint8 ivi4AlternateScan8x8[64] = {
852 0, 8, 1, 9, 16, 24, 2, 3, 17, 25, 10, 11, 32, 40, 48, 56,
853 4, 5, 6, 7, 33, 41, 49, 57, 18, 19, 26, 27, 12, 13, 14, 15,
854 34, 35, 43, 42, 50, 51, 59, 58, 20, 21, 22, 23, 31, 30, 29, 28,
855 36, 37, 38, 39, 47, 46, 45, 44, 52, 53, 54, 55, 63, 62, 61, 60
856 };
857
858 static const uint8 ivi4AlternateScan4x4[16] = {
859 0, 1, 4, 5, 8, 12, 2, 3, 9, 13, 6, 7, 10, 11, 14, 15
860 };
861
862 static const uint8 ivi4VerticalScan4x4[16] = {
863 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15
864 };
865
866 static const uint8 ivi4HorizontalScan4x4[16] = {
867 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
868 };
869
870 const uint Indeo4Decoder::_ivi4_common_pic_sizes[14] = {
871 640, 480, 320, 240, 160, 120, 704, 480, 352, 240, 352, 288, 176, 144
872 };
873
874 Indeo4Decoder::Transform Indeo4Decoder::_transforms[18] = {
875 { IndeoDSP::ffIviInverseHaar8x8, IndeoDSP::ffIviDcHaar2d, 1 },
876 { IndeoDSP::ffIviRowHaar8, IndeoDSP::ffIviDcHaar2d, 0 },
877 { IndeoDSP::ffIviColHaar8, IndeoDSP::ffIviDcHaar2d, 0 },
878 { IndeoDSP::ffIviPutPixels8x8, IndeoDSP::ffIviPutDcPixel8x8, 1 },
879 { IndeoDSP::ffIviInverseSlant8x8, IndeoDSP::ffIviDcSlant2d, 1 },
880 { IndeoDSP::ffIviRowSlant8, IndeoDSP::ffIviDcRowSlant, 1 },
881 { IndeoDSP::ffIviColSlant8, IndeoDSP::ffIviDcColSlant, 1 },
882 { NULL, NULL, 0 }, // inverse DCT 8x8
883 { NULL, NULL, 0 }, // inverse DCT 8x1
884 { NULL, NULL, 0 }, // inverse DCT 1x8
885 { IndeoDSP::ffIviInverseHaar4x4, IndeoDSP::ffIviDcHaar2d, 1 },
886 { IndeoDSP::ffIviInverseSlant4x4, IndeoDSP::ffIviDcSlant2d, 1 },
887 { NULL, NULL, 0 }, // no transform 4x4
888 { IndeoDSP::ffIviRowHaar4, IndeoDSP::ffIviDcHaar2d, 0 },
889 { IndeoDSP::ffIviColHaar4, IndeoDSP::ffIviDcHaar2d, 0 },
890 { IndeoDSP::ffIviRowSlant4, IndeoDSP::ffIviDcRowSlant, 0 },
891 { IndeoDSP::ffIviColSlant4, IndeoDSP::ffIviDcColSlant, 0 },
892 { NULL, NULL, 0 }, // inverse DCT 4x4
893 };
894
895 const uint8 *const Indeo4Decoder::_scan_index_to_tab[15] = {
896 // for 8x8 transforms
897 ffZigZagDirect,
898 ivi4AlternateScan8x8,
899 _ffIviHorizontalScan8x8,
900 _ffIviVerticalScan8x8,
901 ffZigZagDirect,
902
903 // for 4x4 transforms
904 _ffIviDirectScan4x4,
905 ivi4AlternateScan4x4,
906 ivi4VerticalScan4x4,
907 ivi4HorizontalScan4x4,
908 _ffIviDirectScan4x4,
909
910 // TODO: check if those are needed
911 _ffIviHorizontalScan8x8,
912 _ffIviHorizontalScan8x8,
913 _ffIviHorizontalScan8x8,
914 _ffIviHorizontalScan8x8,
915 _ffIviHorizontalScan8x8
916 };
917
918 /**
919 * Indeo 4 dequant tables
920 */
921 const uint16 Indeo4Decoder::_ivi4_quant_8x8_intra[9][64] = {
922 {
923 43, 342, 385, 470, 555, 555, 598, 726,
924 342, 342, 470, 513, 555, 598, 726, 769,
925 385, 470, 555, 555, 598, 726, 726, 811,
926 470, 470, 555, 555, 598, 726, 769, 854,
927 470, 555, 555, 598, 683, 726, 854, 1025,
928 555, 555, 598, 683, 726, 854, 1025, 1153,
929 555, 555, 598, 726, 811, 982, 1195, 1451,
930 555, 598, 726, 811, 982, 1195, 1451, 1793
931 },
932 {
933 86, 1195, 2390, 2390, 4865, 4865, 4865, 4865,
934 1195, 1195, 2390, 2390, 4865, 4865, 4865, 4865,
935 2390, 2390, 4865, 4865, 6827, 6827, 6827, 6827,
936 2390, 2390, 4865, 4865, 6827, 6827, 6827, 6827,
937 4865, 4865, 6827, 6827, 6827, 6827, 6827, 6827,
938 4865, 4865, 6827, 6827, 6827, 6827, 6827, 6827,
939 4865, 4865, 6827, 6827, 6827, 6827, 6827, 6827,
940 4865, 4865, 6827, 6827, 6827, 6827, 6827, 6827
941 },
942 {
943 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835,
944 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835,
945 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835,
946 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835,
947 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835,
948 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835,
949 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835,
950 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835
951 },
952 {
953 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414,
954 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414,
955 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414,
956 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414,
957 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414,
958 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414,
959 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414,
960 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414
961 },
962 {
963 897, 897, 897, 897, 897, 897, 897, 897,
964 1067, 1067, 1067, 1067, 1067, 1067, 1067, 1067,
965 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238,
966 1409, 1409, 1409, 1409, 1409, 1409, 1409, 1409,
967 1579, 1579, 1579, 1579, 1579, 1579, 1579, 1579,
968 1750, 1750, 1750, 1750, 1750, 1750, 1750, 1750,
969 1921, 1921, 1921, 1921, 1921, 1921, 1921, 1921,
970 2091, 2091, 2091, 2091, 2091, 2091, 2091, 2091
971 },
972 {
973 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707,
974 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707,
975 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414,
976 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414,
977 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414,
978 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414,
979 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414,
980 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414
981 },
982 {
983 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390,
984 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390,
985 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390,
986 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390,
987 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390,
988 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390,
989 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390,
990 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390
991 },
992 {
993 22, 171, 214, 257, 257, 299, 299, 342,
994 171, 171, 257, 257, 299, 299, 342, 385,
995 214, 257, 257, 299, 299, 342, 342, 385,
996 257, 257, 257, 299, 299, 342, 385, 427,
997 257, 257, 299, 299, 342, 385, 427, 513,
998 257, 299, 299, 342, 385, 427, 513, 598,
999 299, 299, 299, 385, 385, 470, 598, 726,
1000 299, 299, 385, 385, 470, 598, 726, 897
1001 },
1002 {
1003 86, 598, 1195, 1195, 2390, 2390, 2390, 2390,
1004 598, 598, 1195, 1195, 2390, 2390, 2390, 2390,
1005 1195, 1195, 2390, 2390, 3414, 3414, 3414, 3414,
1006 1195, 1195, 2390, 2390, 3414, 3414, 3414, 3414,
1007 2390, 2390, 3414, 3414, 3414, 3414, 3414, 3414,
1008 2390, 2390, 3414, 3414, 3414, 3414, 3414, 3414,
1009 2390, 2390, 3414, 3414, 3414, 3414, 3414, 3414,
1010 2390, 2390, 3414, 3414, 3414, 3414, 3414, 3414
1011 }
1012 };
1013
1014 const uint16 Indeo4Decoder::_ivi4_quant_8x8_inter[9][64] = {
1015 {
1016 427, 427, 470, 427, 427, 427, 470, 470,
1017 427, 427, 470, 427, 427, 427, 470, 470,
1018 470, 470, 470, 470, 470, 470, 470, 470,
1019 427, 427, 470, 470, 427, 427, 470, 470,
1020 427, 427, 470, 427, 427, 427, 470, 470,
1021 427, 427, 470, 427, 427, 427, 470, 470,
1022 470, 470, 470, 470, 470, 470, 470, 470,
1023 470, 470, 470, 470, 470, 470, 470, 470
1024 },
1025 {
1026 1707, 1707, 2433, 2433, 3414, 3414, 3414, 3414,
1027 1707, 1707, 2433, 2433, 3414, 3414, 3414, 3414,
1028 2433, 2433, 3414, 3414, 4822, 4822, 4822, 4822,
1029 2433, 2433, 3414, 3414, 4822, 4822, 4822, 4822,
1030 3414, 3414, 4822, 4822, 3414, 3414, 3414, 3414,
1031 3414, 3414, 4822, 4822, 3414, 3414, 3414, 3414,
1032 3414, 3414, 4822, 4822, 3414, 3414, 3414, 3414,
1033 3414, 3414, 4822, 4822, 3414, 3414, 3414, 3414
1034 },
1035 {
1036 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281,
1037 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281,
1038 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281,
1039 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281,
1040 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281,
1041 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281,
1042 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281,
1043 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281
1044 },
1045 {
1046 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433,
1047 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433,
1048 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433,
1049 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433,
1050 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433,
1051 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433,
1052 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433,
1053 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433
1054 },
1055 {
1056 1195, 1195, 1195, 1195, 1195, 1195, 1195, 1195,
1057 1195, 1195, 1195, 1195, 1195, 1195, 1195, 1195,
1058 1281, 1281, 1281, 1281, 1281, 1281, 1281, 1281,
1059 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238,
1060 1195, 1195, 1195, 1195, 1195, 1195, 1195, 1195,
1061 1195, 1195, 1195, 1195, 1195, 1195, 1195, 1195,
1062 1281, 1281, 1281, 1281, 1281, 1281, 1281, 1281,
1063 1281, 1281, 1281, 1281, 1281, 1281, 1281, 1281
1064 },
1065 {
1066 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433,
1067 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433,
1068 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414,
1069 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414,
1070 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433,
1071 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433,
1072 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433,
1073 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433
1074 },
1075 {
1076 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707,
1077 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707,
1078 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707,
1079 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707,
1080 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707,
1081 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707,
1082 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707,
1083 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707
1084 },
1085 {
1086 86, 171, 171, 214, 214, 214, 214, 257,
1087 171, 171, 214, 214, 214, 214, 257, 257,
1088 171, 214, 214, 214, 214, 257, 257, 257,
1089 214, 214, 214, 214, 257, 257, 257, 299,
1090 214, 214, 214, 257, 257, 257, 299, 299,
1091 214, 214, 257, 257, 257, 299, 299, 299,
1092 214, 257, 257, 257, 299, 299, 299, 342,
1093 257, 257, 257, 299, 299, 299, 342, 342
1094 },
1095 {
1096 854, 854, 1195, 1195, 1707, 1707, 1707, 1707,
1097 854, 854, 1195, 1195, 1707, 1707, 1707, 1707,
1098 1195, 1195, 1707, 1707, 2390, 2390, 2390, 2390,
1099 1195, 1195, 1707, 1707, 2390, 2390, 2390, 2390,
1100 1707, 1707, 2390, 2390, 1707, 1707, 1707, 1707,
1101 1707, 1707, 2390, 2390, 1707, 1707, 1707, 1707,
1102 1707, 1707, 2390, 2390, 1707, 1707, 1707, 1707,
1103 1707, 1707, 2390, 2390, 1707, 1707, 1707, 1707
1104 }
1105 };
1106
1107 const uint16 Indeo4Decoder::_ivi4_quant_4x4_intra[5][16] = {
1108 {
1109 22, 214, 257, 299,
1110 214, 257, 299, 342,
1111 257, 299, 342, 427,
1112 299, 342, 427, 513
1113 },
1114 {
1115 129, 1025, 1451, 1451,
1116 1025, 1025, 1451, 1451,
1117 1451, 1451, 2049, 2049,
1118 1451, 1451, 2049, 2049
1119 },
1120 {
1121 43, 171, 171, 171,
1122 43, 171, 171, 171,
1123 43, 171, 171, 171,
1124 43, 171, 171, 171
1125 },
1126 {
1127 43, 43, 43, 43,
1128 171, 171, 171, 171,
1129 171, 171, 171, 171,
1130 171, 171, 171, 171
1131 },
1132 {
1133 43, 43, 43, 43,
1134 43, 43, 43, 43,
1135 43, 43, 43, 43,
1136 43, 43, 43, 43
1137 }
1138 };
1139
1140 const uint16 Indeo4Decoder::_ivi4_quant_4x4_inter[5][16] = {
1141 {
1142 107, 214, 257, 299,
1143 214, 257, 299, 299,
1144 257, 299, 299, 342,
1145 299, 299, 342, 342
1146 },
1147 {
1148 513, 1025, 1238, 1238,
1149 1025, 1025, 1238, 1238,
1150 1238, 1238, 1451, 1451,
1151 1238, 1238, 1451, 1451
1152 },
1153 {
1154 43, 171, 171, 171,
1155 43, 171, 171, 171,
1156 43, 171, 171, 171,
1157 43, 171, 171, 171
1158 },
1159 {
1160 43, 43, 43, 43,
1161 171, 171, 171, 171,
1162 171, 171, 171, 171,
1163 171, 171, 171, 171
1164 },
1165 {
1166 43, 43, 43, 43,
1167 43, 43, 43, 43,
1168 43, 43, 43, 43,
1169 43, 43, 43, 43
1170 }
1171 };
1172
1173 const uint8 Indeo4Decoder::_quant_index_to_tab[22] = {
1174 0, 1, 0, 2, 1, 3, 0, 4, 1, 5, 0, 1, 6, 7, 8, // for 8x8 quant matrixes
1175 0, 1, 2, 2, 3, 3, 4 // for 4x4 quant matrixes
1176 };
1177
1178 } // End of namespace Image
1179