Skip to content

Commit

Permalink
Use seed to calculate checksum of mipmap tiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
gonetz committed Apr 21, 2024
1 parent 7e3204f commit ba3733a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 63 deletions.
8 changes: 4 additions & 4 deletions src/GLideNHQ/TxFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,19 +572,19 @@ TxFilter::hirestex(uint64 g64crc, Checksum r_crc64, uint16 *palette, N64FormatSi
}

uint64
TxFilter::checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette)
TxFilter::checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed)
{
if (_options & (HIRESTEXTURES_MASK|DUMP_TEX))
return TxUtil::checksum64(src, width, height, size, rowStride, palette);
return TxUtil::checksum64(src, width, height, size, rowStride, palette, seed);

return 0;
}

uint64
TxFilter::checksum64strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette)
TxFilter::checksum64strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed)
{
if (_options & (HIRESTEXTURES_MASK | DUMP_TEX))
return TxUtil::checksum64strong(src, width, height, size, rowStride, palette);
return TxUtil::checksum64strong(src, width, height, size, rowStride, palette, seed);

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/GLideNHQ/TxFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class TxFilter
uint16 *palette,
N64FormatSize n64FmtSz,
GHQTexInfo *info);
uint64 checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette);
uint64 checksum64strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette);
uint64 checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed);
uint64 checksum64strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed);
boolean dmptx(uint8 *src, int width, int height, int rowStridePixel,
ColorFormat gfmt, N64FormatSize n64FmtSz, Checksum r_crc64, boolean isStrongCrc);
boolean dmptxMipmap(uint8 *src, int width, int height, int rowStridePixel,
Expand Down
8 changes: 4 additions & 4 deletions src/GLideNHQ/TxFilterExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ txfilter_hirestex(uint64 g64crc, Checksum r_crc64, uint16 *palette, N64FormatSiz
}

TAPI uint64 TAPIENTRY
txfilter_checksum(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette)
txfilter_checksum(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed)
{
if (txFilter)
return txFilter->checksum64(src, width, height, size, rowStride, palette);
return txFilter->checksum64(src, width, height, size, rowStride, palette, seed);

return 0;
}

TAPI uint64 TAPIENTRY
txfilter_checksum_strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette)
txfilter_checksum_strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed)
{
if (txFilter)
return txFilter->checksum64strong(src, width, height, size, rowStride, palette);
return txFilter->checksum64strong(src, width, height, size, rowStride, palette, seed);

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/GLideNHQ/TxFilterExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ TAPI boolean TAPIENTRY
txfilter_hirestex(uint64 g64crc, Checksum r_crc64, uint16 *palette, N64FormatSize n64FmtSz, GHQTexInfo *info);

TAPI uint64 TAPIENTRY
txfilter_checksum(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette);
txfilter_checksum(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed);

TAPI uint64 TAPIENTRY
txfilter_checksum_strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette);
txfilter_checksum_strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed);

TAPI boolean TAPIENTRY
txfilter_dmptx(uint8 *src, int width, int height, int rowStridePixel, uint16 gfmt, N64FormatSize n64FmtSz, Checksum r_crc64);
Expand Down
62 changes: 31 additions & 31 deletions src/GLideNHQ/TxUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ TxUtil::sizeofTx(int width, int height, ColorFormat format)
}

uint64
TxUtil::checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette)
TxUtil::checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed)
{
/* Rice CRC32 for now. We can switch this to Jabo MD5 or
* any other custom checksum.
Expand All @@ -88,35 +88,35 @@ TxUtil::checksum64(uint8 *src, int width, int height, int size, int rowStride, u

if (!src) return 0;

uint64 crc64Ret = 0;
uint64 crc64Ret = 0U;

if (palette) {
uint32 crc32 = 0, cimax = 0;
switch (size & 0xff) {
case 1:
if (RiceCRC32_CI8(src, width, height, rowStride, &crc32, &cimax)) {
crc64Ret = (uint64)RiceCRC32(palette, cimax + 1, 1, 2, 512);
if (RiceCRC32_CI8(src, width, height, rowStride, &crc32, &cimax, seed)) {
crc64Ret = (uint64)RiceCRC32(palette, cimax + 1, 1, 2, 512, 0);
crc64Ret <<= 32;
crc64Ret |= (uint64)crc32;
}
break;
case 0:
if (RiceCRC32_CI4(src, width, height, rowStride, &crc32, &cimax)) {
crc64Ret = (uint64)RiceCRC32(palette, cimax + 1, 1, 2, 32);
if (RiceCRC32_CI4(src, width, height, rowStride, &crc32, &cimax, seed)) {
crc64Ret = (uint64)RiceCRC32(palette, cimax + 1, 1, 2, 32, 0);
crc64Ret <<= 32;
crc64Ret |= (uint64)crc32;
}
}
}
if (!crc64Ret) {
crc64Ret = (uint64)RiceCRC32(src, width, height, size, rowStride);
if (crc64Ret == 0U) {
crc64Ret = (uint64)RiceCRC32(src, width, height, size, rowStride, seed);
}

return crc64Ret;
}

uint64
TxUtil::checksum64strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette)
TxUtil::checksum64strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed)
{
/* XXH3_64bits for strong 32bit texture hash. */
/* Returned value is 64bits: hi=palette crc32 low=texture crc32 */
Expand All @@ -130,23 +130,23 @@ TxUtil::checksum64strong(uint8 *src, int width, int height, int size, int rowStr
uint32 crc32 = 0, cimax = 0;
switch (size & 0xff) {
case 1:
if (StrongCRC32_CI8(src, width, height, rowStride, &crc32, &cimax)) {
crc64Ret = StrongCRC32(palette, cimax + 1, 1, 2, 512);
if (StrongCRC32_CI8(src, width, height, rowStride, &crc32, &cimax, seed)) {
crc64Ret = StrongCRC32(palette, cimax + 1, 1, 2, 512, 0);
crc64Ret <<= 32;
crc64Ret |= crc32;
}
break;
case 0:
if (StrongCRC32_CI4(src, width, height, rowStride, &crc32, &cimax)) {
crc64Ret = StrongCRC32(palette, cimax + 1, 1, 2, 32);
if (StrongCRC32_CI4(src, width, height, rowStride, &crc32, &cimax, seed)) {
crc64Ret = StrongCRC32(palette, cimax + 1, 1, 2, 32, 0);
crc64Ret <<= 32;
crc64Ret |= crc32;
}
}
}

if (!crc64Ret) {
crc64Ret = StrongCRC32(src, width, height, size, rowStride);
crc64Ret = StrongCRC32(src, width, height, size, rowStride, seed);
}

return crc64Ret;
Expand All @@ -167,11 +167,11 @@ TxUtil::checksum64strong(uint8 *src, int width, int height, int size, int rowStr
* bpl);
*/
uint32
TxUtil::RiceCRC32(const uint8* src, int width, int height, int size, int rowStride)
TxUtil::RiceCRC32(const uint8* src, int width, int height, int size, int rowStride, uint64 seed)
{
/* NOTE: bytes_per_width must be equal or larger than 4 */

uint32 crc32Ret = 0;
uint32 crc32Ret = static_cast<u32>(seed & 0xFFFFFFFF);
const uint32 bytesPerLine = width << size >> 1;

try {
Expand All @@ -183,7 +183,7 @@ TxUtil::RiceCRC32(const uint8* src, int width, int height, int size, int rowStri

mov ecx, dword ptr [src];
mov eax, dword ptr [height];
mov edx, 0;
mov edx, dword ptr [crc32Ret];
dec eax;

loop2:
Expand Down Expand Up @@ -274,11 +274,11 @@ uint8 CalculateMaxCI4b(const uint8* src, uint32 width, uint32 height, uint32 row

boolean
TxUtil::RiceCRC32_CI4(const uint8* src, int width, int height, int rowStride,
uint32* crc32, uint32* cimax)
uint32* crc32, uint32* cimax, uint64 seed)
{
/* NOTE: bytes_per_width must be equal or larger than 4 */

uint32 crc32Ret = 0;
uint32 crc32Ret = static_cast<u32>(seed & 0xFFFFFFFF);
uint32 cimaxRet = 0;
const uint32 bytes_per_width = width >> 1;

Expand All @@ -294,7 +294,7 @@ TxUtil::RiceCRC32_CI4(const uint8* src, int width, int height, int rowStride,

mov ecx, dword ptr [src];
mov eax, dword ptr [height];
mov edx, 0;
mov edx, dword ptr [crc32Ret];
mov edi, 0;
dec eax;

Expand Down Expand Up @@ -395,7 +395,7 @@ TxUtil::RiceCRC32_CI4(const uint8* src, int width, int height, int rowStride,
pop ebx;
}
#else
crc32Ret = RiceCRC32(src, width, height, 0, rowStride);
crc32Ret = RiceCRC32(src, width, height, 0, rowStride, seed);
cimaxRet = CalculateMaxCI4b(src, width, height, rowStride);
#endif
} catch(...) {
Expand All @@ -410,11 +410,11 @@ TxUtil::RiceCRC32_CI4(const uint8* src, int width, int height, int rowStride,

boolean
TxUtil::RiceCRC32_CI8(const uint8* src, int width, int height, int rowStride,
uint32* crc32, uint32* cimax)
uint32* crc32, uint32* cimax, uint64 seed)
{
/* NOTE: bytes_per_width must be equal or larger than 4 */

uint32 crc32Ret = 0;
uint32 crc32Ret = static_cast<u32>(seed & 0xFFFFFFFF);
uint32 cimaxRet = 0;

/* 8bit CI */
Expand All @@ -428,7 +428,7 @@ TxUtil::RiceCRC32_CI8(const uint8* src, int width, int height, int rowStride,

mov ecx, dword ptr [src];
mov eax, dword ptr [height];
mov edx, 0;
mov edx, dword ptr[crc32Ret];
mov edi, 0;
dec eax;

Expand Down Expand Up @@ -497,7 +497,7 @@ TxUtil::RiceCRC32_CI8(const uint8* src, int width, int height, int rowStride,
pop ebx;
}
#else
crc32Ret = RiceCRC32(src, width, height, 1, rowStride);
crc32Ret = RiceCRC32(src, width, height, 1, rowStride, seed);
cimaxRet = CalculateMaxCI8b(src, width, height, rowStride);
#endif
} catch(...) {
Expand All @@ -511,7 +511,7 @@ 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)
TxUtil::StrongCRC32(const uint8* src, int width, int height, int size, int rowStride, uint64 seed)
{
/* NOTE: bytesPerLine must be equal or larger than 4 */
const uint32 bytesPerLine = width << size >> 1;
Expand All @@ -533,7 +533,7 @@ TxUtil::StrongCRC32(const uint8* src, int width, int height, int size, int rowSt
}
src += rowStride;
}
crc = XXH3_64bits(buf.data(), static_cast<size_t>(pData - buf.data()));
crc = XXH3_64bits_withSeed(buf.data(), static_cast<size_t>(pData - buf.data()), seed);
}
catch (...) {
DBG_INFO(80, wst("Error: StrongCRC32 exception!\n"));
Expand All @@ -544,13 +544,13 @@ TxUtil::StrongCRC32(const uint8* src, int width, int height, int size, int rowSt

boolean
TxUtil::StrongCRC32_CI4(const uint8* src, int width, int height, int rowStride,
uint32* crc32, uint32* cimax)
uint32* crc32, uint32* cimax, uint64 seed)
{
/* NOTE: bytes_per_width must be equal or larger than 4 */

/* 4bit CI */
try {
uint32 crc32Ret = StrongCRC32(src, width, height, 0, rowStride);
uint32 crc32Ret = StrongCRC32(src, width, height, 0, rowStride, seed);
uint32 cimaxRet = CalculateMaxCI4b(src, width, height, rowStride);
*crc32 = crc32Ret;
*cimax = cimaxRet;
Expand All @@ -563,13 +563,13 @@ TxUtil::StrongCRC32_CI4(const uint8* src, int width, int height, int rowStride,

boolean
TxUtil::StrongCRC32_CI8(const uint8* src, int width, int height, int rowStride,
uint32* crc32, uint32* cimax)
uint32* crc32, uint32* cimax, uint64 seed)
{
/* NOTE: bytes_per_width must be equal or larger than 4 */

/* 8bit CI */
try {
uint32 crc32Ret = StrongCRC32(src, width, height, 1, rowStride);
uint32 crc32Ret = StrongCRC32(src, width, height, 1, rowStride, seed);
uint32 cimaxRet = CalculateMaxCI8b(src, width, height, rowStride);
*crc32 = crc32Ret;
*cimax = cimaxRet;
Expand Down
16 changes: 8 additions & 8 deletions src/GLideNHQ/TxUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@
class TxUtil
{
private:
static uint32 RiceCRC32(const uint8* src, int width, int height, int size, int rowStride);
static uint32 RiceCRC32(const uint8* src, int width, int height, int size, int rowStride, uint64 seed);
static boolean RiceCRC32_CI4(const uint8* src, int width, int height, int rowStride,
uint32* crc32, uint32* cimax);
uint32* crc32, uint32* cimax, uint64 seed);
static boolean RiceCRC32_CI8(const uint8* src, int width, int height, int rowStride,
uint32* crc32, uint32* cimax);
static uint32 StrongCRC32(const uint8* src, int width, int height, int size, int rowStride);
uint32* crc32, uint32* cimax, uint64 seed);
static uint32 StrongCRC32(const uint8* src, int width, int height, int size, int rowStride, uint64 seed);
static boolean StrongCRC32_CI4(const uint8* src, int width, int height, int rowStride,
uint32* crc32, uint32* cimax);
uint32* crc32, uint32* cimax, uint64 seed);
static boolean StrongCRC32_CI8(const uint8* src, int width, int height, int rowStride,
uint32* crc32, uint32* cimax);
uint32* crc32, uint32* cimax, uint64 seed);
public:
static int sizeofTx(int width, int height, ColorFormat format);
static uint32 checksumTx(uint8 *data, int width, int height, ColorFormat format);
static uint64 checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette);
static uint64 checksum64strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette);
static uint64 checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed);
static uint64 checksum64strong(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette, uint64 seed);
static uint32 getNumberofProcessors();
};

Expand Down
Loading

0 comments on commit ba3733a

Please sign in to comment.