Skip to content

Commit

Permalink
Correct StrongCRC32: reproduce RiceCRC behaviour when bytesPerLine < 4.
Browse files Browse the repository at this point in the history
  • Loading branch information
gonetz committed Mar 2, 2024
1 parent 568a31f commit f12d4ec
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/GLideNHQ/TxUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,18 +515,27 @@ TxUtil::RiceCRC32_CI8(const uint8* src, int width, int height, int rowStride,
uint32
TxUtil::StrongCRC32(const uint8* src, int width, int height, int size, int rowStride)
{
/* NOTE: bytes_per_width must be equal or larger than 4 */

/* NOTE: bytesPerLine must be equal or larger than 4 */
const uint32 bytesPerLine = width << size >> 1;

u64 crc = UINT64_MAX;
std::vector<uint8> buf(height*rowStride);
uint8* pData = buf.data();
try {
int y = height - 1;
while (y >= 0) {
crc = XXH3_64bits_withSeed(src, bytesPerLine, crc);
for (int y = 0; y < height; ++y) {
if (bytesPerLine < 4) {
// bytesPerLine must be >= 4, but if it less than 4, reproduce RiceCRC behavior,
// that is read bytes before provided source address.
memcpy(pData, src - 4 + bytesPerLine, 4);
pData += 4;
}
else {
memcpy(pData, src, bytesPerLine);
pData += bytesPerLine;
}
src += rowStride;
--y;
}
crc = XXH3_64bits(buf.data(), static_cast<size_t>(pData - buf.data()));
}
catch (...) {
DBG_INFO(80, wst("Error: StrongCRC32 exception!\n"));
Expand Down

0 comments on commit f12d4ec

Please sign in to comment.