22#ifndef VIDEO_4XM_UTILS_H
23#define VIDEO_4XM_UTILS_H
25#include "common/array.h"
26#include "common/compression/huffman.h"
27#include "common/debug.h"
33 const byte *data =
nullptr;
36 uint32 wordBitsLeft = 16;
38 uint32 controlWord = 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;
53 RawDeltaReader(
const byte *ptr, uint32 len, uint32 streamBase, uint32 pairOff, uint32 byteOff,
54 uint32 signedByteOff, uint32 nibbleOff, uint32 controlOff);
57 uint32 readControl2();
60 int8 readSignedByte();
64template<
typename HuffmanType>
65HuffmanType loadStatistics(
const byte *&huff, uint &offset) {
68 uint8 freq_first = huff[offset++];
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++];
80 freq_first = huff[offset++];
81 }
while (freq_first != 0);
86 return HuffmanType::fromFrequencies(freqs.
size(), freqs.
data(), symbols.
data());
89void idct(int16_t block[64],
int shift = 6);
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);
97inline int readInt(
int value,
unsigned n) {
100 if ((value & (1 << (n - 1))) == 0)
101 value += 1 - (1 << n);
105template<
typename BitStream>
106inline int readInt(BitStream &bs,
size_t n) {
107 return readInt(bs.getBits(n), n);
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