ScummVM API documentation
get_bits.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#ifndef IMAGE_CODECS_INDEO_GET_BITS_H
23#define IMAGE_CODECS_INDEO_GET_BITS_H
24
25#include "common/bitstream.h"
26
27namespace Image {
28namespace Indeo {
29
34public:
38 GetBits(const byte *dataPtr, uint32 dataSize) : Common::BitStreamMemory8LSB(new Common::BitStreamMemoryStream(dataPtr, dataSize), DisposeAfterUse::YES) {}
39
43 int getBitsLeft() const { return size() - pos(); }
44
53 template <int maxDepth, int bits>
54 int getVLC2(int16 (*table)[2]) {
55 int code;
56 int n, nbBits;
57 unsigned int index;
58
59 index = peekBits<bits>();
60 code = table[index][0];
61 n = table[index][1];
62
63 if (maxDepth > 1 && n < 0) {
64 skip(bits);
65 nbBits = -n;
66
67 index = peekBits(nbBits) + code;
68 code = table[index][0];
69 n = table[index][1];
70
71 if (maxDepth > 2 && n < 0) {
72 skip(nbBits);
73 nbBits = -n;
74
75 index = peekBits(nbBits) + code;
76 code = table[index][0];
77 n = table[index][1];
78 }
79 }
80
81 skip(n);
82 return code;
83 }
84};
85
86} // End of namespace Indeo
87} // End of namespace Image
88
89#endif
Definition: bitstream.h:55
void skip(uint32 n)
Definition: bitstream.h:283
uint32 pos() const
Definition: bitstream.h:308
uint32 size() const
Definition: bitstream.h:313
uint32 peekBits()
Definition: bitstream.h:188
Definition: get_bits.h:33
int getBitsLeft() const
Definition: get_bits.h:43
int getVLC2(int16(*table)[2])
Definition: get_bits.h:54
GetBits(const byte *dataPtr, uint32 dataSize)
Definition: get_bits.h:38
BitStreamImpl< BitStreamMemoryStream, uint64, 8, false, false > BitStreamMemory8LSB
Definition: bitstream.h:506
Definition: algorithm.h:29