Skip to content

Commit

Permalink
Cleaned up compressor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedara committed Jan 19, 2025
1 parent c20e7dc commit 6727b24
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 135 deletions.
2 changes: 1 addition & 1 deletion tools/compresSmol/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CXX ?= g++

CXXFLAGS := -Werror -std=c++17 -pthread -O2
CXXFLAGS := -Werror -std=c++17 -pthread -O2 -Wunused

INCLUDES := -I .

Expand Down
1 change: 0 additions & 1 deletion tools/compresSmol/compresSmol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ int main(int argc, char *argv[])
size_t rawSizes = 0;
size_t totalImages = 0;
size_t invalidImages = 0;
ImagePrinter printer;
/*
std::vector<size_t> largeModeSizes(6);
std::vector<std::string> largeModeNames(6);
Expand Down
124 changes: 5 additions & 119 deletions tools/compresSmol/compressAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ void ShortCompressionInstruction::buildBytes()
}
}


void CompressionInstruction::buildBytes()
{
std::vector<unsigned char> currBytes;
Expand Down Expand Up @@ -274,50 +273,6 @@ std::vector<unsigned short> getSymsFromInstructions(std::vector<ShortCompression
return symvec;
}

std::vector<unsigned char> getLosFromInstructions(std::vector<CompressionInstruction> instructions)
{
std::vector<unsigned char> loVec;
for (CompressionInstruction instruction : instructions)
{
size_t readIndex = 0;

unsigned char currByte = instruction.bytes[readIndex];
loVec.push_back(currByte);
readIndex++;
// Extract length
if ((currByte & 0x80) == 0x80)
{
loVec.push_back(instruction.bytes[readIndex]);
readIndex++;
}

// Extract offset
currByte = instruction.bytes[readIndex];
loVec.push_back(currByte);
readIndex++;
if ((currByte & 0x80) == 0x80)
{
loVec.push_back(instruction.bytes[readIndex]);
readIndex++;
}
}
return loVec;
}

std::vector<unsigned char> getSymsFromInstructions(std::vector<CompressionInstruction> instructions)
{
std::vector<unsigned char> symVec;
for (CompressionInstruction instruction : instructions)
{
if (instruction.offset != 0)
symVec.push_back(instruction.firstSymbol);
else
for (unsigned char uc : instruction.symbols)
symVec.push_back(uc);
}
return symVec;
}

std::vector<unsigned short> decodeBytesShort(std::vector<unsigned char> *pLoVec, std::vector<unsigned short> *pSymVec)
{
std::vector<unsigned short> decodedImage;
Expand Down Expand Up @@ -360,66 +315,6 @@ std::vector<unsigned short> decodeBytesShort(std::vector<unsigned char> *pLoVec,
return decodedImage;
}

std::vector<unsigned char> decodeBytes(std::vector<unsigned char> *pLoVec, std::vector<unsigned char> *pSymVec, size_t lengthMod)
{
std::vector<unsigned char> decodedImage;
size_t loIndex = 0;
size_t symIndex = 0;
size_t runCount = 0;
size_t runPixels = 0;
size_t copyCount = 0;
size_t copyPixels = 0;
size_t rawCount = 0;
size_t rawPixels = 0;
while (loIndex < pLoVec->size())
{
size_t currLength = 0;
size_t currOffset = 0;
currLength += (*pLoVec)[loIndex] & 0x7f;
loIndex++;
if (((*pLoVec)[loIndex-1] & 0x80) == 0x80)
{
currLength += (*pLoVec)[loIndex] << 7;
loIndex++;
}
currOffset += (*pLoVec)[loIndex] & 0x7f;
loIndex++;
if (((*pLoVec)[loIndex-1] & 0x80) == 0x80)
{
currOffset += (*pLoVec)[loIndex] << 7;
loIndex++;
}
if (currLength != 0)
{
decodedImage.push_back((*pSymVec)[symIndex]);
symIndex++;
for (size_t i = 0; i < currLength; i++)
decodedImage.push_back(decodedImage[decodedImage.size() - currOffset]);
if (currOffset == 1)
{
runCount++;
runPixels += currLength;
}
else
{
copyCount++;
copyPixels += currLength;
}
}
else
{
for (size_t i = 0; i < currOffset; i++)
{
decodedImage.push_back((*pSymVec)[symIndex]);
symIndex++;
}
rawCount++;
rawPixels += currOffset;
}
}
return decodedImage;
}

bool verifyBytesShort(std::vector<unsigned char> *pLoVec, std::vector<unsigned short> *pSymVec, std::vector<unsigned short> *pImage)
{
std::vector<unsigned short> shorts = decodeBytesShort(pLoVec, pSymVec);
Expand Down Expand Up @@ -461,11 +356,13 @@ CompressedImage processImage(std::string fileName, InputSettings settings)
std::vector<unsigned char> input = readFileAsUC(fileName);
if (settings.useFrames)
{
/*
// Determine number of frames
size_t totalPixels = input.size()*2;
// Split input and append
size_t smallFrames = totalPixels/OVERWORLD_16X16;
size_t largeFrames = totalPixels/OVERWORLD_32X32;
*/
}
else
{
Expand All @@ -481,7 +378,6 @@ CompressedImage processImageFrames(std::string fileName, InputSettings settings)
std::vector<std::vector<unsigned char>> allInputs(4);
size_t totalSize = input.size();
size_t partialSize = totalSize/4;
size_t currIndex = 0;
size_t subIndex = 0;
size_t inputIndex = 0;
std::vector<size_t> frameOffsets;
Expand Down Expand Up @@ -724,11 +620,11 @@ bool verifyCompressionShort(CompressedImage *pInput, std::vector<unsigned short>

std::vector<unsigned short> decodeImageShort(CompressedImage *pInput)
{
DataVecsNew dataVecs = decodeDataVectorsNew(pInput);
DataVecs dataVecs = decodeDataVectorsNew(pInput);
return decodeBytesShort(&dataVecs.loVec, &dataVecs.symVec);
}

DataVecsNew decodeDataVectorsNew(CompressedImage *pInput)
DataVecs decodeDataVectorsNew(CompressedImage *pInput)
{
CompressedImage headerValues = readNewHeader(&pInput->headers);
size_t loSize = headerValues.loSize;
Expand Down Expand Up @@ -823,7 +719,7 @@ DataVecsNew decodeDataVectorsNew(CompressedImage *pInput)
for (size_t j = 0; j < 4; j++)
symVec[i] += (unsigned short)symNibbles[i*4 + j] << (j*4);

DataVecsNew returnData;
DataVecs returnData;
returnData.loVec = loVec;
returnData.symVec = symVec;
return returnData;
Expand Down Expand Up @@ -857,16 +753,6 @@ ShortCopy::ShortCopy(size_t index, size_t length, size_t offset, std::vector<uns
this->usSequence = usSequence;
}

void ImagePrinter::printImage(CompressedImage *image)
{
if (!printedHeaders)
{
printf("ImagePath LZsize NUsize LOencoded LOdelta SYMencoded SYMdelta\n");
printedHeaders = true;
}
printf("%s %zu %zu\n", image->fileName.c_str(), image->lzSize, image->compressedSize);
}

std::vector<unsigned char> getNormalizedCounts(std::vector<size_t> input)
{
std::vector<int> tempVec(16);
Expand Down
15 changes: 1 addition & 14 deletions tools/compresSmol/compressAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ struct InputSettings {
};

struct DataVecs {
std::vector<unsigned char> loVec;
std::vector<unsigned char> symVec;
};

struct DataVecsNew {
std::vector<unsigned char> loVec;
std::vector<unsigned short> symVec;
};
Expand All @@ -136,12 +131,6 @@ CompressedImage processImage(std::string fileName, InputSettings settings);
CompressedImage processImageFrames(std::string fileName, InputSettings settings);
CompressedImage processImageData(std::vector<unsigned char> input, InputSettings settings, std::string fileName);

class ImagePrinter {
bool printedHeaders = false;
public:
void printImage(CompressedImage *image);
};

std::vector<unsigned int> readFileAsUInt(std::string filePath);

size_t getCompressedSize(CompressedImage *pImage);
Expand All @@ -156,8 +145,6 @@ int findInitialState(EncodeCol encodeCol, unsigned char firstSymbol);
CompressedImage fillCompressVec(std::vector<unsigned char> loVec, std::vector<unsigned char> symVec, size_t lengthMod, bool loEncoded, bool symEncoded, bool symDelta, size_t byteSize, CompressionMode mode);
CompressedImage fillCompressVecNew(std::vector<unsigned char> loVec, std::vector<unsigned short> symVec, CompressionMode mode, size_t imageBytes);
std::vector<ShortCompressionInstruction> getShortInstructions(std::vector<ShortCopy> copies, size_t lengthMod);
std::vector<unsigned char> getLosFromInstructions(std::vector<CompressionInstruction> instructions);
std::vector<unsigned char> getSymsFromInstructions(std::vector<CompressionInstruction> instructions);
std::vector<unsigned char> getLosFromInstructions(std::vector<ShortCompressionInstruction> instructions);
std::vector<unsigned short> getSymsFromInstructions(std::vector<ShortCompressionInstruction> instructions);
std::vector<int> unpackFrequencies(unsigned int pInts[3]);
Expand All @@ -167,7 +154,7 @@ std::vector<unsigned int> getUIntVecFromData(CompressedImage *pImage);

std::vector<unsigned short> decodeBytesShort(std::vector<unsigned char> *pLoVec, std::vector<unsigned short> *pSymVec);
std::vector<unsigned short> decodeImageShort(CompressedImage *pInput);
DataVecsNew decodeDataVectorsNew(CompressedImage *pInput);
DataVecs decodeDataVectorsNew(CompressedImage *pInput);

size_t decodeNibbles(std::vector<DecodeCol> decodeTable, std::vector<unsigned int> *bits, int *currState, std::vector<unsigned char> *nibbleVec, size_t currBitIndex, size_t numNibbles);

Expand Down

0 comments on commit 6727b24

Please sign in to comment.