diff --git a/source/lzb.cpp b/source/lzb.cpp index 87212ef..72c17c3 100644 --- a/source/lzb.cpp +++ b/source/lzb.cpp @@ -59,7 +59,9 @@ int LZB_Compress(unsigned char* pDest, unsigned char* pSource, int sourceSize) { candidateData = LongestMatch(sourceData, dictionaryData); - if (0 == candidateData.size) + // If no match, or the match is too small, then take the next byte + // and emit as literal + if ((0 == candidateData.size)) // || (candidateData.size < 4)) { candidateData.size = 1; candidateData.pData = sourceData.pData; @@ -161,7 +163,22 @@ int Old_LZB_Compress(unsigned char* pDest, unsigned char* pSource, int sourceSiz } else { - candidate_data.size++; + if (0 == candidate_data.size) + { + candidate_data.size++; + } + else + { + processedBytes--; + + //if (candidate_data.size > 1) + //{ + // processedBytes -= (candidate_data.size - 1); + // candidate_data.size = 1; + //} + } + + // Add Dictionary bytesInDictionary = AddDictionary(candidate_data, bytesInDictionary); @@ -177,6 +194,7 @@ int Old_LZB_Compress(unsigned char* pDest, unsigned char* pSource, int sourceSiz bytesEmitted += EmitLiteral(pDest + bytesEmitted, candidate_data); } bLastEmitIsLiteral = true; + //MatchOffset = -1; } } } @@ -518,7 +536,7 @@ void LZB_Decompress(unsigned char* pDest, unsigned char* pSource, int destSize) u16 opcode = *pSource++; opcode |= ((u16)(*pSource++))<<8; - //printf("%04X:", (unsigned int)(pSource-pOriginalSource)); +// printf("%04X:", (unsigned int)(pSource-pOriginalSource)); if (opcode & 0x8000) @@ -541,7 +559,7 @@ void LZB_Decompress(unsigned char* pDest, unsigned char* pSource, int destSize) decompressedBytes += opcode; - //printf("%04X:Dic %04X %s\n",decompressedBytes, (unsigned int)opcode, overlapped); +// printf("%04X:Dic %04X %s\n",decompressedBytes, (unsigned int)opcode, overlapped); } else { @@ -550,7 +568,7 @@ void LZB_Decompress(unsigned char* pDest, unsigned char* pSource, int destSize) decompressedBytes += opcode; pSource += opcode; - //printf("%04X:Lit %04X\n",decompressedBytes, (unsigned int)opcode); +// printf("%04X:Lit %04X\n",decompressedBytes, (unsigned int)opcode); } } } diff --git a/source/main.cpp b/source/main.cpp index f62b9d4..a7325d1 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -113,6 +113,25 @@ int main(int argc, char* argv[]) const std::vector& c1Datas = c2data.GetPixelMaps(); + #if 1 + unsigned char workbuffer[64*1024]; + for (int idx = 0; idx < frameCount; ++idx) + { + int compressedSize = LZB_Compress(workbuffer, c1Datas[ idx ], 32 * 1024); + printf("compressedSize = %d\n", compressedSize); + unsigned char validationBuffer[ 32 * 1024 ]; + LZB_Decompress(validationBuffer, workbuffer, 32 * 1024); + if (0 == memcmp(c1Datas[ idx ], validationBuffer, 32*1024)) + { + printf("Decompression Validated\n"); + } + else + { + printf("Decompression Corrupted\n"); + } + } + + #else unsigned char workbuffer[64*1024]; unsigned char workbuffer2[64*1024]; @@ -140,6 +159,7 @@ int main(int argc, char* argv[]) } } + #endif } }