#pragma once
#include "BuildSettings.h"
#include <vector>
#include <iosfwd>
#include "Snd_defs.h"
#include "BitReader.h"
OPENMPT_NAMESPACE_BEGIN
struct ModSample;
class ITCompression
{
public:
ITCompression(const ModSample &sample, bool it215, std::ostream *f, SmpLength maxLength = 0);
size_t GetCompressedSize() const { return packedTotalLength; }
enum : size_t { bufferSize = 2 + 0xFFFF }; enum : size_t { blockSize = 0x8000 };
protected:
std::vector<int8> bwt; uint8 *packedData; std::ostream *file; void *sampleData; const ModSample &mptSample; size_t packedLength; size_t packedTotalLength; SmpLength baseLength;
int8 bitPos; int8 remBits; uint8 byteVal;
bool is215;
template<typename T>
static void CopySample(void *target, const void *source, SmpLength offset, SmpLength length, SmpLength skip);
template<typename T>
void Deltafy();
template<typename Properties>
void Compress(const void *data, SmpLength offset, SmpLength actualLength);
static int8 GetWidthChangeSize(int8 w, bool is16);
template<typename Properties>
void SquishRecurse(int8 sWidth, int8 lWidth, int8 rWidth, int8 width, SmpLength offset, SmpLength length);
static int8 ConvertWidth(int8 curWidth, int8 newWidth);
void WriteBits(int8 width, int v);
void WriteByte(uint8 v);
};
class ITDecompression
{
public:
ITDecompression(FileReader &file, ModSample &sample, bool it215);
protected:
BitReader bitFile;
ModSample &mptSample;
SmpLength writtenSamples; SmpLength writePos; SmpLength curLength; unsigned int mem1, mem2; bool is215;
template<typename Properties>
void Uncompress(typename Properties::sample_t *target);
static void ChangeWidth(int &curWidth, int width);
template<typename Properties>
void Write(int v, int topbit, typename Properties::sample_t *target);
};
OPENMPT_NAMESPACE_END