From f12d4ec94cdc6f16768af750de6efb1f6bf12c8c Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Sun, 3 Mar 2024 00:49:59 +0700 Subject: [PATCH] Correct StrongCRC32: reproduce RiceCRC behaviour when bytesPerLine < 4. --- src/GLideNHQ/TxUtil.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/GLideNHQ/TxUtil.cpp b/src/GLideNHQ/TxUtil.cpp index fe041ebea..a8a0c1548 100644 --- a/src/GLideNHQ/TxUtil.cpp +++ b/src/GLideNHQ/TxUtil.cpp @@ -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 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(pData - buf.data())); } catch (...) { DBG_INFO(80, wst("Error: StrongCRC32 exception!\n"));