125 for (
size_t i = 0; i < 16; i++)
176 if (audioPacketLength > frameSize)
179 _bink->skip(audioPacketLength);
180 frameSize -= audioPacketLength;
183 size_t videoPacketStart =
_bink->pos();
184 size_t videoPacketEnd =
_bink->pos() + frameSize;
188 videoPacketStart, videoPacketEnd),
true);
216 for (
int i = 0; i < 3; i++) {
217 int planeIdx = ((i == 0) || !
_swapPlanes) ? i : (i ^ 3);
233 for (
int i = 0; i < 4; i++)
248 ctx.planeIdx = planeIdx;
249 ctx.destStart = _curPlanes[planeIdx].get();
250 ctx.destEnd = _curPlanes[planeIdx].get() + width * height;
251 ctx.prevStart = _oldPlanes[planeIdx].get();
252 ctx.prevEnd = _oldPlanes[planeIdx].get() + width * height;
255 for (
int i = 0; i < 64; i++) {
256 ctx.coordMap[i] = (i & 7) + (i >> 3) * ctx.pitch;
258 ctx.coordScaledMap1[i] = ((i & 7) * 2 + 0) + (((i >> 3) * 2 + 0) * ctx.pitch);
259 ctx.coordScaledMap2[i] = ((i & 7) * 2 + 1) + (((i >> 3) * 2 + 0) * ctx.pitch);
260 ctx.coordScaledMap3[i] = ((i & 7) * 2 + 0) + (((i >> 3) * 2 + 1) * ctx.pitch);
261 ctx.coordScaledMap4[i] = ((i & 7) * 2 + 1) + (((i >> 3) * 2 + 1) * ctx.pitch);
264 for (
int i = 0; i < kSourceMAX; i++) {
265 _bundles[i].countLength = _bundles[i].countLengths[isChroma ? 1 : 0];
267 readBundle(video, (
Source) i);
270 for (ctx.blockY = 0; ctx.blockY < blockHeight; ctx.blockY++) {
271 readBlockTypes (video, _bundles[kSourceBlockTypes]);
272 readBlockTypes (video, _bundles[kSourceSubBlockTypes]);
273 readColors (video, _bundles[kSourceColors]);
274 readPatterns (video, _bundles[kSourcePattern]);
275 readMotionValues(video, _bundles[kSourceXOff]);
276 readMotionValues(video, _bundles[kSourceYOff]);
277 readDCS (video, _bundles[kSourceIntraDC],
kDCStartBits,
false);
278 readDCS (video, _bundles[kSourceInterDC],
kDCStartBits,
true);
279 readRuns (video, _bundles[kSourceRun]);
281 ctx.dest = ctx.destStart + 8 * ctx.blockY * ctx.pitch;
282 ctx.prev = ctx.prevStart + 8 * ctx.blockY * ctx.pitch;
284 for (ctx.blockX = 0; ctx.blockX < blockWidth; ctx.blockX++, ctx.dest += 8, ctx.prev += 8) {
288 if ((ctx.blockY & 1) && (blockType == kBlockScaled)) {
350 if (source == kSourceColors) {
351 for (
int i = 0; i < 16; i++)
352 readHuffman(video, _colHighHuffman[i]);
357 if ((source != kSourceIntraDC) && (source != kSourceInterDC))
358 readHuffman(video, _bundles[source].huffman);
360 _bundles[source].curDec = _bundles[source].data.get();
361 _bundles[source].curPtr = _bundles[source].data.get();
367 if (huffman.
index == 0) {
370 for (
int i = 0; i < 16; i++)
381 std::memset(hasSymbol, 0, 16);
384 for (
int i = 0; i <= length; i++) {
386 hasSymbol[huffman.
symbols[i]] = 1;
389 for (
int i = 0; i < 16; i++)
390 if (hasSymbol[i] == 0)
398 byte tmp1[16], tmp2[16];
399 byte *in = tmp1, *out = tmp2;
403 for (
int i = 0; i < 16; i++)
406 for (
int i = 0; i <= depth; i++) {
409 for (
int j = 0; j < 16; j += (size << 1))
410 mergeHuffmanSymbols(video, out + j, in + j, size);
415 std::memcpy(huffman.
symbols, in, 16);
419 const byte *src2 = src + size;
431 }
while (size && size2);
453 if (largestFrameSize > fileSize)
464 if ((fpsNum == 0) || (fpsDen == 0))
473 if (audioTrackCount > 1) {
474 warning(
"More than one audio track found. Using the first one");
479 if (audioTrackCount > 0) {
482 _bink->skip(4 * audioTrackCount);
485 for (
uint32 i = 0; i < audioTrackCount; i++) {
494 _bink->skip(4 * audioTrackCount);
499 for (
uint32 i = 0; i < frameCount; i++) {
588 for (
int i = 0; i < kSourceMAX; i++) {
589 _bundles[i].data.reset(
new byte[blocks * 64]);
590 _bundles[i].dataEnd = _bundles[i].data.get() + blocks * 64;
597 for (
int i = 0; i < 2; i++) {
598 int width = MAX<uint32>(cw[i], 8);
600 _bundles[kSourceBlockTypes ].countLengths[i] =
Common::intLog2((width >> 3) + 511) + 1;
601 _bundles[kSourceSubBlockTypes].countLengths[i] =
Common::intLog2(((width + 7) >> 4) + 511) + 1;
602 _bundles[kSourceColors ].countLengths[i] =
Common::intLog2((cbw[i]) * 64 + 511) + 1;
603 _bundles[kSourceIntraDC ].countLengths[i] =
Common::intLog2((width >> 3) + 511) + 1;
604 _bundles[kSourceInterDC ].countLengths[i] =
Common::intLog2((width >> 3) + 511) + 1;
605 _bundles[kSourceXOff ].countLengths[i] =
Common::intLog2((width >> 3) + 511) + 1;
606 _bundles[kSourceYOff ].countLengths[i] =
Common::intLog2((width >> 3) + 511) + 1;
607 _bundles[kSourcePattern ].countLengths[i] =
Common::intLog2((cbw[i] << 3) + 511) + 1;
608 _bundles[kSourceRun ].countLengths[i] =
Common::intLog2((cbw[i]) * 48 + 511) + 1;
613 for (
int i = 0; i < 16; i++)
622 if ((source < kSourceXOff) || (source == kSourceRun))
623 return *_bundles[source].curPtr++;
625 if ((source == kSourceXOff) || (source == kSourceYOff))
626 return (
int8) *_bundles[source].curPtr++;
628 int16 ret = *
reinterpret_cast<int16 *
>(_bundles[source].curPtr);
630 _bundles[source].curPtr += 2;
650 for (
int j = 0; j < 8; j++, dest += ctx.
pitch, prev += ctx.
pitch)
651 std::memcpy(dest, prev, 8);
658 for (
int j = 0; j < 16; j++, dest += ctx.
pitch, prev += ctx.
pitch)
659 std::memcpy(dest, prev, 16);
667 int run = getBundleValue(kSourceRun) + 1;
675 byte v = getBundleValue(kSourceColors);
676 for (
int j = 0; j < run; j++, scan++)
683 for (
int j = 0; j < run; j++, scan++)
700 std::memset(block, 0, 64 *
sizeof(
int16));
702 block[0] = getBundleValue(kSourceIntraDC);
704 readDCTCoeffs(*ctx.
video, block,
true);
711 for (
int j = 0; j < 8; j++, dest1 += (ctx.
pitch << 1) - 16, dest2 += (ctx.
pitch << 1) - 16, src += 8) {
713 for (
int i = 0; i < 8; i++, dest1 += 2, dest2 += 2)
714 dest1[0] = dest1[1] = dest2[0] = dest2[1] = src[i];
720 byte v = getBundleValue(kSourceColors);
723 for (
int i = 0; i < 16; i++, dest += ctx.
pitch)
724 std::memset(dest, v, 16);
730 for (
int i = 0; i < 2; i++)
731 col[i] = getBundleValue(kSourceColors);
735 for (
int j = 0; j < 8; j++, dest1 += (ctx.
pitch << 1) - 16, dest2 += (ctx.
pitch << 1) - 16) {
736 byte v = getBundleValue(kSourcePattern);
738 for (
int i = 0; i < 8; i++, dest1 += 2, dest2 += 2, v >>= 1)
739 dest1[0] = dest1[1] = dest2[0] = dest2[1] = col[v & 1];
748 for (
int j = 0; j < 8; j++, dest1 += (ctx.
pitch << 1) - 16, dest2 += (ctx.
pitch << 1) - 16) {
749 std::memcpy(row, _bundles[kSourceColors].curPtr, 8);
751 for (
int i = 0; i < 8; i++, dest1 += 2, dest2 += 2)
752 dest1[0] = dest1[1] = dest2[0] = dest2[1] = row[i];
754 _bundles[kSourceColors].curPtr += 8;
767 blockScaledIntra(ctx);
771 blockScaledFill(ctx);
775 blockScaledPattern(ctx);
792 int8 xOff = getBundleValue(kSourceXOff);
793 int8 yOff = getBundleValue(kSourceYOff);
800 for (
int j = 0; j < 8; j++, dest += ctx.
pitch, prev += ctx.
pitch)
801 std::memcpy(dest, prev, 8);
809 int run = getBundleValue(kSourceRun) + 1;
817 byte v = getBundleValue(kSourceColors);
818 for (
int j = 0; j < run; j++)
822 for (
int j = 0; j < run; j++)
823 ctx.
dest[ctx.
coordMap[*scan++]] = getBundleValue(kSourceColors);
828 ctx.
dest[ctx.
coordMap[*scan++]] = getBundleValue(kSourceColors);
837 std::memset(block, 0, 64 *
sizeof(
int16));
839 readResidue(*ctx.
video, block, v);
843 for (
int i = 0; i < 8; i++, dst += ctx.
pitch, src += 8)
844 for (
int j = 0; j < 8; j++)
850 std::memset(block, 0, 64 *
sizeof(
int16));
852 block[0] = getBundleValue(kSourceIntraDC);
854 readDCTCoeffs(*ctx.
video, block,
true);
860 byte v = getBundleValue(kSourceColors);
863 for (
int i = 0; i < 8; i++, dest += ctx.
pitch)
864 std::memset(dest, v, 8);
871 std::memset(block, 0, 64 *
sizeof(
int16));
873 block[0] = getBundleValue(kSourceInterDC);
875 readDCTCoeffs(*ctx.
video, block,
false);
883 for (
int i = 0; i < 2; i++)
884 col[i] = getBundleValue(kSourceColors);
887 for (
int i = 0; i < 8; i++, dest += ctx.
pitch - 8) {
888 byte v = getBundleValue(kSourcePattern);
890 for (
int j = 0; j < 8; j++, v >>= 1)
891 *dest++ = col[v & 1];
897 byte *data = _bundles[kSourceColors].curPtr;
898 for (
int i = 0; i < 8; i++, dest += ctx.
pitch, data += 8)
899 std::memcpy(dest, data, 8);
901 _bundles[kSourceColors].curPtr += 64;
905 uint32 n = readBundleCount(video, bundle);
916 std::memset(bundle.
curDec, v, n);
920 while (bundle.
curDec < decEnd)
925 uint32 n = readBundleCount(video, bundle);
938 v = (v ^ sign) - sign;
941 std::memset(bundle.
curDec, v, n);
952 v = (v ^ sign) - sign;
957 }
while (bundle.
curDec < decEnd);
962 uint32 n = readBundleCount(video, bundle);
973 std::memset(bundle.
curDec, v, n);
990 std::memset(bundle.
curDec, last, run);
995 }
while (bundle.
curDec < decEnd);
999 uint32 n = readBundleCount(video, bundle);
1008 while (bundle.
curDec < decEnd) {
1009 v = getHuffmanSymbol(video, bundle.
huffman);
1010 v |= getHuffmanSymbol(video, bundle.
huffman) << 4;
1017 uint32 n = readBundleCount(video, bundle);
1026 _colLastVal = getHuffmanSymbol(video, _colHighHuffman[_colLastVal]);
1029 v = getHuffmanSymbol(video, bundle.
huffman);
1030 v = (_colLastVal << 4) | v;
1033 int sign = ((
int8) v) >> 7;
1034 v = ((v & 0x7F) ^ sign) - sign;
1038 std::memset(bundle.
curDec, v, n);
1044 while (bundle.
curDec < decEnd) {
1045 _colLastVal = getHuffmanSymbol(video, _colHighHuffman[_colLastVal]);
1048 v = getHuffmanSymbol(video, bundle.
huffman);
1049 v = (_colLastVal << 4) | v;
1052 int sign = ((
int8) v) >> 7;
1053 v = ((v & 0x7F) ^ sign) - sign;
1061 uint32 length = readBundleCount(video, bundle);
1070 v = (v ^ sign) - sign;
1076 for (
uint32 i = 0; i < length; i += 8) {
1077 uint32 length2 = MIN<uint32>(length - i, 8);
1083 for (
uint32 j = 0; j < length2; j++) {
1087 v2 = (v2 ^ sign) - sign;
1093 if ((v < -32768) || (v > 32767))
1098 for (
uint32 j = 0; j < length2; j++)
1102 bundle.
curDec =
reinterpret_cast<byte *
>(dest);
1120 res =
CLIP(res, -32768, 32767);
1133 int coefList[128];
int modeList[128];
1134 coefList[listEnd] = 4; modeList[listEnd++] = 0;
1135 coefList[listEnd] = 24; modeList[listEnd++] = 0;
1136 coefList[listEnd] = 44; modeList[listEnd++] = 0;
1137 coefList[listEnd] = 1; modeList[listEnd++] = 3;
1138 coefList[listEnd] = 2; modeList[listEnd++] = 3;
1139 coefList[listEnd] = 3; modeList[listEnd++] = 3;
1142 for (
int mask = 1 << (MAX<int>(bits, 0)); bits >= 0; mask >>= 1, bits--) {
1143 int listPos = listStart;
1145 while (listPos < listEnd) {
1147 if (!(modeList[listPos] | coefList[listPos]) || !video.
bits->
getBit()) {
1152 int ccoef = coefList[listPos];
1153 int mode = modeList[listPos];
1157 coefList[listPos] = ccoef + 4;
1158 modeList[listPos] = 1;
1162 coefList[listPos] = 0;
1163 modeList[listPos++] = 0;
1165 for (
int i = 0; i < 4; i++, ccoef++) {
1167 coefList[--listStart] = ccoef;
1168 modeList[ listStart] = 3;
1177 t = (t ^ sign) - sign;
1180 coefIdx[coefCount++] = ccoef;
1186 modeList[listPos] = 2;
1187 for (
int i = 0; i < 3; i++) {
1189 coefList[listEnd] = ccoef;
1190 modeList[listEnd++] = 2;
1202 t = (t ^ sign) - sign;
1205 coefIdx[coefCount++] = ccoef;
1206 coefList[listPos] = 0;
1207 modeList[listPos++] = 0;
1215 block[0] =
dequant(block[0], quant[0],
true);
1217 for (
int i = 0; i < coefCount; i++) {
1218 int idx = coefIdx[i];
1227 int nzCoeffCount = 0;
1232 int coefList[128];
int modeList[128];
1233 coefList[listEnd] = 4; modeList[listEnd++] = 0;
1234 coefList[listEnd] = 24; modeList[listEnd++] = 0;
1235 coefList[listEnd] = 44; modeList[listEnd++] = 0;
1236 coefList[listEnd] = 0; modeList[listEnd++] = 2;
1238 for (
int mask = 1 << video.
bits->
getBits(3); mask; mask >>= 1) {
1240 for (
int i = 0; i < nzCoeffCount; i++) {
1243 if (block[nzCoeff[i]] < 0)
1244 block[nzCoeff[i]] -= mask;
1246 block[nzCoeff[i]] += mask;
1252 int listPos = listStart;
1253 while (listPos < listEnd) {
1255 if (!(coefList[listPos] | modeList[listPos]) || !video.
bits->
getBit()) {
1260 int ccoef = coefList[listPos];
1261 int mode = modeList[listPos];
1265 coefList[listPos] = ccoef + 4;
1266 modeList[listPos] = 1;
1270 coefList[listPos] = 0;
1271 modeList[listPos++] = 0;
1274 for (
int i = 0; i < 4; i++, ccoef++) {
1276 coefList[--listStart] = ccoef;
1277 modeList[ listStart] = 3;
1279 nzCoeff[nzCoeffCount++] =
binkScan[ccoef];
1282 block[
binkScan[ccoef]] = (mask ^ sign) - sign;
1292 modeList[listPos] = 2;
1293 for (
int i = 0; i < 3; i++) {
1295 coefList[listEnd] = ccoef;
1296 modeList[listEnd++] = 2;
1301 nzCoeff[nzCoeffCount++] =
binkScan[ccoef];
1304 block[
binkScan[ccoef]] = (mask ^ sign) - sign;
1306 coefList[listPos] = 0;
1307 modeList[listPos++] = 0;
1322 _audioBuffered(0, _info.sampleRate) {
1326 delete _audioStream;
1330 return _audioStream;
1334 while (_audioBuffered < endTime && _curFrame < frames.size()) {
1335 const VideoFrame &frame = frames[_curFrame++];
1339 uint32 audioPacketLength = 0;
1341 for (
size_t i = 0; i < audioTracks.size(); i++) {
1345 if (audioPacketLength > frameSize)
1348 frameSize -= audioPacketLength;
1351 bink.
skip(audioPacketLength);
1359 if (audioPacketLength < 4)
1368 int outSize = _info.frameLen * _info.channels;
1370 while (bits.
pos() < bits.
size()) {
1372 memset(out.
get(), 0, outSize * 2);
1374 audioBlock(bits, out.
get());
1378 if (bits.
pos() & 0x1F)
1379 bits.
skip(32 - (bits.
pos() & 0x1F));
1382 _audioBuffered = _audioBuffered.addFrames(sampleCount);
1386 if (_curFrame >= frames.size())
1387 _audioStream->finish();
1393 float f = ldexpf(bits.
getBits(23), power - 23);
1402 return !_audioStream->isFinished();
1407 audioBlockDCT (bits);
1409 audioBlockRDFT(bits);
1412 _info.frameLen, _info.channels);
1415 int count = _info.overlapLen * _info.channels;
1417 for (
int i = 0; i < count; i++) {
1418 out[i] = (_info.prevCoeffs[i] * (count - i) + out[i] * i) >> shift;
1422 std::memcpy(_info.prevCoeffs, out + _info.blockSize, _info.overlapLen * _info.channels *
sizeof(*out));
1424 _info.first =
false;
1430 for (
uint8 i = 0; i < _info.channels; i++) {
1431 float *coeffs = _info.coeffsPtr[i];
1433 readAudioCoeffs(bits, coeffs);
1437 _info.dct->calc(coeffs);
1439 for (
uint32 j = 0; j < _info.frameLen; j++)
1440 coeffs[j] *= (_info.frameLen / 2.0f);
1446 for (
uint8 i = 0; i < _info.channels; i++) {
1447 float *coeffs = _info.coeffsPtr[i];
1449 readAudioCoeffs(bits, coeffs);
1451 _info.rdft->calc(coeffs);
1456 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64
1460 coeffs[0] = getFloat(bits) * _info.root;
1461 coeffs[1] = getFloat(bits) * _info.root;
1465 for (
uint32 i = 0; i < _info.bandCount; i++) {
1469 quant[i] = expf(
MIN(value, 95) * 0.15289164787221953823f) * _info.root;
1476 for (k = 0; _info.bands[k] < 1; k++)
1481 while (i < _info.frameLen) {
1489 j =
MIN(j, _info.frameLen);
1494 std::memset(coeffs + i, 0, (j - i) *
sizeof(*coeffs));
1496 while (_info.bands[k] * 2 < i)
1502 if (_info.bands[k] * 2 == i)
1505 int coeff = bits.
getBits(width);
1509 coeffs[i] = -q * coeff;
1511 coeffs[i] = q * coeff;
1530 #define IDCT_TRANSFORM(dest,s0,s1,s2,s3,s4,s5,s6,s7,d0,d1,d2,d3,d4,d5,d6,d7,munge,src) {\ 1531 const int a0 = (src)[s0] + (src)[s4]; \ 1532 const int a1 = (src)[s0] - (src)[s4]; \ 1533 const int a2 = (src)[s2] + (src)[s6]; \ 1534 const int a3 = (A1*((src)[s2] - (src)[s6])) >> 11; \ 1535 const int a4 = (src)[s5] + (src)[s3]; \ 1536 const int a5 = (src)[s5] - (src)[s3]; \ 1537 const int a6 = (src)[s1] + (src)[s7]; \ 1538 const int a7 = (src)[s1] - (src)[s7]; \ 1539 const int b0 = a4 + a6; \ 1540 const int b1 = (A3*(a5 + a7)) >> 11; \ 1541 const int b2 = ((A4*a5) >> 11) - b0 + b1; \ 1542 const int b3 = (A1*(a6 - a4) >> 11) - b2; \ 1543 const int b4 = ((A2*a7) >> 11) + b3 - b1; \ 1544 (dest)[d0] = munge(a0+a2 +b0); \ 1545 (dest)[d1] = munge(a1+a3-a2+b2); \ 1546 (dest)[d2] = munge(a1-a3+a2+b3); \ 1547 (dest)[d3] = munge(a0-a2 -b4); \ 1548 (dest)[d4] = munge(a0-a2 +b4); \ 1549 (dest)[d5] = munge(a1-a3+a2-b3); \ 1550 (dest)[d6] = munge(a1+a3-a2-b2); \ 1551 (dest)[d7] = munge(a0+a2 -b0); \ 1555 #define MUNGE_NONE(x) (x) 1556 #define IDCT_COL(dest,src) IDCT_TRANSFORM(dest,0,8,16,24,32,40,48,56,0,8,16,24,32,40,48,56,MUNGE_NONE,src) 1558 #define MUNGE_ROW(x) (((x) + 0x7F)>>8) 1559 #define IDCT_ROW(dest,src) IDCT_TRANSFORM(dest,0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,MUNGE_ROW,src) 1563 if ((src[8] | src[16] | src[24] | src[32] | src[40] | src[48] | src[56]) == 0) {
1581 for (i = 0; i < 8; i++)
1583 for (i = 0; i < 8; i++) {
1584 IDCT_ROW( (&block[8*i]), (&temp[8*i]) );
1593 for (i = 0; i < 8; i++, dest += ctx.
pitch, block += 8)
1594 for (j = 0; j < 8; j++)
1595 dest[j] += block[j];
1601 for (i = 0; i < 8; i++)
1603 for (i = 0; i < 8; i++) {
1609 _width(width),
_height(height), _curFrame(-1), _frameCount(frameCount), _frameRate(frameRate), _swapPlanes(swapPlanes), _hasAlpha(hasAlpha),
_id(id) {
1624 std::memset(
_curPlanes[0].
get(), 0, width * height );
1625 std::memset(
_curPlanes[1].
get(), 0, (width >> 1) * (height >> 1));
1626 std::memset(
_curPlanes[2].
get(), 0, (width >> 1) * (height >> 1));
1627 std::memset(
_curPlanes[3].
get(), 255, width * height );
1628 std::memset(
_oldPlanes[0].
get(), 0, width * height );
1629 std::memset(
_oldPlanes[1].
get(), 0, (width >> 1) * (height >> 1));
1630 std::memset(
_oldPlanes[2].
get(), 0, (width >> 1) * (height >> 1));
1631 std::memset(
_oldPlanes[3].
get(), 255, width * height );
Common::ScopedPtr< Graphics::Surface > _surface
The video's surface.
static const uint32 kBIKkID
#define MKTAG(a0, a1, a2, a3)
A wrapper macro used around four character constants, like 'DATA', to ensure portability.
Huffman huffman
Huffman codebook.
void readPatterns(VideoFrame &video, Bundle &bundle)
static const uint32 binkIntraQuant[16][64]
int countLength
Length of number of entries to decode (in bits) for the current plane.
static int intLog2(uint32 v)
static const uint32 binkHuffmanCodes[16][16]
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
void readHuffman(VideoFrame &video, Huffman &huffman)
Read the symbols for a Huffman code.
static const uint16 kAudioFlagStereo
PacketizedAudioStream * makePacketizedPCMStream(int rate, byte flags, int channels)
Creates a PacketizedAudioStream that will automatically queue packets as individual AudioStreams like...
An abstract representation of an audio track.
Luminance values range from [0, 255].
void readResidue(VideoFrame &video, int16 *block, int masksCount)
Reads 8x8 block with residue after motion compensation.
static const uint32 kKB2fID
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
A simple rational class that holds fractions.
void blockMotion(DecodeContext &ctx)
void reset(PointerType o=0)
Resets the pointer with the new value.
PointerType release()
Returns the plain pointer value and releases ScopedPtr.
uint32 readBundleCount(VideoFrame &video, Bundle &bundle)
Read a count value out of a bundle.
static const uint32 kKB2kID
void addTrack(Track *track, bool isExternal=false)
Define a track to be used by this class.
static int16 dequant(int16 in, uint32 quant, bool dc)
static const uint32 kKB2gID
void decodePacket(Graphics::Surface &surface, VideoFrame &frame)
Decode a video packet.
bool _needCopy
Is new frame content available that needs to by copied?
(Inverse) Discrete Cosine Transforms.
void blockRaw(DecodeContext &ctx)
virtual size_t pos() const =0
Return the stream position in bits.
void readAudioCoeffs(Common::BitStream &bits, float *coeffs)
void blockScaledPattern(DecodeContext &ctx)
void readRuns(VideoFrame &video, Bundle &bundle)
Implementing the reading stream interfaces for plain memory blocks.
static const uint32 kBIKfID
static const uint32 kBIKhID
bool canBufferData() const
Decoding PCM (Pulse Code Modulation).
void blockScaledSkip(DecodeContext &ctx)
byte * curPtr
Pointer to the data that wasn't yet read.
static const uint8 rleLengthTab[16]
size_t pos() const
Return the stream position in bits.
void audioBlockRDFT(Common::BitStream &bits)
Decode a RDFT'd audio block.
Utility templates and functions for working with strings and streams.
static const uint8 binkPatterns[16][64]
BitStreamImpl< 32, true, false > BitStream32LELSB
32-bit little-endian data, LSB to MSB.
void blockScaledIntra(DecodeContext &ctx)
void blockRun(DecodeContext &ctx)
void initVideo()
Create a surface for video of these dimensions.
int32 getBundleValue(Source source)
Get a direct value out of a bundle.
uint32 _audioTrack
Audio track to use.
void blockScaledFill(DecodeContext &ctx)
Basic exceptions to throw.
void blockScaledRun(DecodeContext &ctx)
void IDCTPut(DecodeContext &ctx, int16 *block)
(Inverse) Discrete Cosine Transforms.
void readBlockTypes(VideoFrame &video, Bundle &bundle)
bool _hasAlpha
Do video frames have alpha?
static const uint32 kBIKiID
Source
IDs for different data types used in Bink video codec.
void initBundles()
Initialize the bundles.
Utility templates and functions.
void readColors(VideoFrame &video, Bundle &bundle)
BlockType
Bink video block types.
static const uint32 kDCStartBits
Decoding RAD Game Tools' Bink videos.
#define IDCT_COL(dest, src)
static const uint32 kBIKgID
Decode a Huffman'd bitstream.
virtual uint32 getBit()=0
Read a bit from the bit stream.
virtual size_t skip(ptrdiff_t offset)
Skip the specified number of bytes, adding that offset to the current position in the stream...
Simple memory based 'stream', which implements the ReadStream interface for a plain memory block...
std::vector< VideoFrame > _frames
All video frames.
bool _swapPlanes
Are the planes ordered (A)YVU instead of (A)YUV?
uint32 _id
The BIK FourCC.
An abstract representation of a video track.
Efficient YUV to RGB conversion.
BinkAudioTrack(size_t index, AudioInfo &audio)
Common::ScopedArray< byte > _curPlanes[4]
The 4 color planes, YUVA, current frame.
float * coeffsPtr[kAudioChannelsMax]
void warning(const char *s,...)
static const uint16 kAudioFlagDCT
Basic reading stream interfaces.
virtual size_t pos() const =0
Obtains the current value of the stream position indicator of the stream.
static const uint32 kKB2aID
byte * curDec
Pointer to the data that wasn't yet decoded.
void blockFill(DecodeContext &ctx)
void blockPattern(DecodeContext &ctx)
static const uint32 kBIKbID
Sound::AudioStream * getAudioStream() const
void skip(size_t n)
Skip the specified amount of bits.
sound is 16 bits wide (default: 8bit)
Generic audio input stream.
#define XOREOS_FALLTHROUGH
Common::ScopedPtr< Common::SeekableReadStream > _bink
PointerType get() const
Returns the plain pointer value.
void initHuffman()
Initialize the Huffman decoders.
void readMotionValues(VideoFrame &video, Bundle &bundle)
int countLengths[2]
Lengths of number of entries to decode (in bits).
Data structure used for decoding a single Bink data type.
size_t size() const
Return the stream size in bits.
float coeffs[16 *kAudioBlockSizeMax]
An image surface, in BGRA format.
void readDCS(VideoFrame &video, Bundle &bundle, int startBits, bool hasSign)
Decompressing Huffman codes.
samples are in native endianness
(Inverse) Real Discrete Fourier Transform.
virtual void skip(size_t n)=0
Skip the specified amount of bits.
static const uint8 binkHuffmanLengths[16][16]
byte * dataEnd
Pointer to the data end end.
UString debugTag(uint32 tag, bool trim)
Create an elaborate string from an integer tag, for debugging purposes.
static const uint32 kKB2iID
void readBundle(VideoFrame &video, Source source)
Read/Initialize a bundle for decoding a plane.
void decodeNextTrackFrame(VideoTrack &track)
Decode enough data for the next frame.
Timestamps allow specifying points in time and measuring time intervals with a sub-millisecond granul...
void blockInter(DecodeContext &ctx)
byte symbols[16]
Huffman symbol => Bink symbol translation list.
int _curFrame
Current Frame.
static void floatToInt16Interleave(int16 *dst, const float **src, uint32 length, uint8 channels)
byte getHuffmanSymbol(VideoFrame &video, Huffman &huffman)
Read and translate a symbol out of a Huffman code.
virtual uint32 getBits(size_t n)=0
Read a multi-bit value from the bit stream.
static const uint8 binkScan[64]
Bink DCT and residue 8x8 block scan order.
Static data used for decoding RAD Game Tools' Bink videos.
void load()
Load a Bink file.
void checkAudioBuffer(AudioTrack &track, const Common::Timestamp &endTime)
Ensure that there is enough audio buffered in the given track to reach the given timestamp.
void IDCTAdd(DecodeContext &ctx, int16 *block)
static const int kAudioChannelsMax
A template implementing a bit stream for different data memory layouts.
void blockScaledRaw(DecodeContext &ctx)
Data structure for decoding and translating Huffman'd data.
A scoped array pointer, allowing array-y access and array deletion.
const uint16 binkCriticalFreqs[25]
#define IDCT_ROW(dest, src)
void audioBlock(Common::BitStream &bits, int16 *out)
Decode an audio block.
BinkVideoTrack(uint32 width, uint32 height, uint32 frameCount, const Common::Rational &frameRate, bool swapPlanes, bool hasAlpha, uint32 id)
SeekableSubReadStream provides access to a SeekableReadStream restricted to the range [begin...
void decodeAudio(Common::SeekableReadStream &bink, const std::vector< VideoFrame > &frames, const std::vector< AudioInfo > &audioTracks, const Common::Timestamp &endTime)
Decode audio data up to endTime.
(Inverse) Real Discrete Fourier Transform.
T CLIP(T v, T amin, T amax)
void blockResidue(DecodeContext &ctx)
void decodePlane(VideoFrame &video, int planeIdx, bool isChroma)
Decode a plane.
static const uint32 kKB2jID
static void IDCTCol(int16 *dest, const int16 *src)
Common::ScopedArray< byte > _oldPlanes[4]
The 4 color planes, YUVA, last frame.
float getFloat(Common::BitStream &bits)
Interface for a seekable & readable data stream.
void initAudioTrack(AudioInfo &audio)
static const uint32 kKB2dID
Bink(Common::SeekableReadStream *bink)
static const uint32 binkInterQuant[16][64]
void audioBlockDCT(Common::BitStream &bits)
Decode a DCT'd audio block.
void blockSkip(DecodeContext &ctx)
std::vector< AudioInfo > _audioTracks
All audio tracks.
int index
Index of the Huffman codebook to use.
static const uint32 kKB2hID
virtual size_t size() const =0
Return the stream size in bits.
void blockIntra(DecodeContext &ctx)
void blockScaled(DecodeContext &ctx)
void readDCTCoeffs(VideoFrame &video, int16 *block, bool isIntra)
Reads 8x8 block of DCT coefficients.
void SWAP(T &a, T &b)
Template method which swaps the values of its two parameters.
static const uint32 kVideoFlagAlpha
void mergeHuffmanSymbols(VideoFrame &video, byte *dst, const byte *src, int size)
Merge two Huffman symbol lists.
Sound decoding utility functions.