ScummVM API documentation
4xm_utils.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 VIDEO_4XM_UTILS_H
23#define VIDEO_4XM_UTILS_H
24
25#include "common/array.h"
26#include "common/compression/huffman.h"
27#include "common/debug.h"
28
29namespace Video {
30namespace FourXM {
31
33 const byte *data = nullptr;
34 uint32 size = 0;
35 uint32 mode = 0;
36 uint32 wordBitsLeft = 16;
37 uint32 wordIndex = 1;
38 uint32 controlWord = 0;
39 uint32 pairIndex = 0;
40 uint32 byteIndex = 0;
41 uint32 nibbleBitsLeft = 8;
42 uint32 nibbleWordIndex = 1;
43 uint32 nibbleWord = 0;
44 uint32 pairOffset = 0;
45 uint32 byteOffset = 0;
46 uint32 signedByteOffset = 0;
47 uint32 nibbleOffset = 0;
48 uint32 signedByteIndex = 0;
49 bool separateSignedByteStream = false;
50
51 RawDeltaReader() = default;
52 RawDeltaReader(const byte *ptr, uint32 len);
53 RawDeltaReader(const byte *ptr, uint32 len, uint32 streamBase, uint32 pairOff, uint32 byteOff,
54 uint32 signedByteOff, uint32 nibbleOff, uint32 controlOff);
55
56 bool valid() const;
57 uint32 readControl2();
58 uint16 readPair();
59 byte readByteIndex();
60 int8 readSignedByte();
61 uint32 readNibble();
62};
63
64template<typename HuffmanType>
65HuffmanType loadStatistics(const byte *&huff, uint &offset) {
66 Common::Array<uint32> freqs, symbols;
67
68 uint8 freq_first = huff[offset++];
69 do {
70 uint8 freq_last = huff[offset++];
71 if (freq_first <= freq_last) {
72 for (auto idx = freq_first; idx <= freq_last; ++idx) {
73 auto freq = huff[offset++];
74 if (freq != 0) {
75 freqs.push_back(freq);
76 symbols.push_back(idx);
77 }
78 }
79 }
80 freq_first = huff[offset++];
81 } while (freq_first != 0);
82
83 freqs.push_back(1);
84 symbols.push_back(256);
85
86 return HuffmanType::fromFrequencies(freqs.size(), freqs.data(), symbols.data());
87}
88
89void idct(int16_t block[64], int shift = 6);
90void buildRawMotionTables(int width, Common::Array<int> &fullOffsets, Common::Array<int> &expOffsets);
91void copyRawBlock(uint16 *dst, const uint16 *src, int stride, int width, int height, uint32 mode, int add = 0);
92void readRawCoefficients(RawDeltaReader &reader, int coeffs[3][64]);
93void transformRawCoefficients(int coeff[64], int dst[64], int scaleCode, bool chroma);
94void writeRawDctBlock(const int yBlock[64], const int cbBlock[64], const int crBlock[64],
95 uint16 *dst, int stride);
96
97inline int readInt(int value, unsigned n) {
98 if (n == 0)
99 return 0;
100 if ((value & (1 << (n - 1))) == 0)
101 value += 1 - (1 << n);
102 return value;
103}
104
105template<typename BitStream>
106inline int readInt(BitStream &bs, size_t n) {
107 return readInt(bs.getBits(n), n);
108}
109
110} // namespace FourXM
111} // namespace Video
112
113#endif // VIDEO_4XM_UTILS_H
const T * data() const
Definition: array.h:208
size_type size() const
Definition: array.h:316
void push_back(const T &element)
Definition: array.h:181
Definition: 4xm_utils.h:32