mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Improve consistency within the LZHAM library
Make CRC32 consistence with ADLER32
This commit is contained in:
parent
5532a5ff35
commit
90d87897f8
@ -8,6 +8,6 @@ namespace lzham
|
||||
uint adler32(const void* pBuf, size_t buflen, uint adler32 = cInitAdler32);
|
||||
|
||||
const uint cInitCRC32 = 0U;
|
||||
uint crc32(uint crc, const lzham_uint8 *ptr, size_t buf_len);
|
||||
uint crc32(const void* pBuf, size_t buflen, uint crc32 = cInitCRC32);
|
||||
|
||||
} // namespace lzham
|
||||
|
18
r5dev/thirdparty/lzham/lzham_checksum.cpp
vendored
18
r5dev/thirdparty/lzham/lzham_checksum.cpp
vendored
@ -53,19 +53,21 @@ namespace lzham
|
||||
0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
|
||||
};
|
||||
|
||||
uint crc32(uint crc, const lzham_uint8 *ptr, size_t buf_len)
|
||||
uint crc32(const void* pBuf, size_t buflen, uint crc32)
|
||||
{
|
||||
if (!ptr)
|
||||
if (!pBuf)
|
||||
return cInitCRC32;
|
||||
|
||||
crc = ~crc;
|
||||
while (buf_len--)
|
||||
crc32 = ~crc32;
|
||||
const uint8* buffer = static_cast<const uint8*>(pBuf);
|
||||
|
||||
while (buflen--)
|
||||
{
|
||||
lzham_uint8 b = *ptr++;
|
||||
crc = (crc >> 4) ^ s_crc32[(crc & 0xF) ^ (b & 0xF)];
|
||||
crc = (crc >> 4) ^ s_crc32[(crc & 0xF) ^ (b >> 4)];
|
||||
uint8 b = *buffer++;
|
||||
crc32 = (crc32 >> 4) ^ s_crc32[(crc32 & 0xF) ^ (b & 0xF)];
|
||||
crc32 = (crc32 >> 4) ^ s_crc32[(crc32 & 0xF) ^ (b >> 4)];
|
||||
}
|
||||
return ~crc;
|
||||
return ~crc32;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1547,7 +1547,7 @@ namespace lzham
|
||||
m_start_of_block_state = m_state;
|
||||
|
||||
m_src_adler32 = adler32(pBuf, buf_len, m_src_adler32);
|
||||
m_src_crc32 = crc32(m_src_adler32, (const lzham_uint8*)pBuf, buf_len);
|
||||
m_src_crc32 = crc32(pBuf, buf_len, m_src_crc32);
|
||||
|
||||
m_block_start_dict_ofs = m_accel.get_lookahead_pos() & (m_accel.get_max_dict_size() - 1);
|
||||
|
||||
|
@ -31,7 +31,7 @@ namespace lzham
|
||||
int LZHAM_CDECL lzham_lib_z_uncompress(unsigned char *pDest, lzham_z_ulong *pDest_len, const unsigned char *pSource, lzham_z_ulong source_len);
|
||||
|
||||
const char * LZHAM_CDECL lzham_lib_z_error(int err);
|
||||
lzham_z_ulong lzham_lib_z_adler32(lzham_z_ulong adler, const unsigned char *ptr, size_t buf_len);
|
||||
lzham_z_ulong LZHAM_CDECL lzham_lib_z_adler32(lzham_z_ulong adler, const lzham_uint8*ptr, size_t buf_len);
|
||||
lzham_z_ulong LZHAM_CDECL lzham_lib_z_crc32(lzham_z_ulong crc, const lzham_uint8 *ptr, size_t buf_len);
|
||||
|
||||
} // namespace lzham
|
||||
|
@ -193,7 +193,7 @@ namespace lzham
|
||||
size_t bytes_to_copy = LZHAM_MIN((size_t)(m_flush_n - copy_ofs), cBytesToMemCpyPerIteration); \
|
||||
LZHAM_MEMCPY(m_pOut_buf + copy_ofs, m_pFlush_src + copy_ofs, bytes_to_copy); \
|
||||
m_decomp_adler32 = adler32(m_pFlush_src + copy_ofs, bytes_to_copy, m_decomp_adler32); \
|
||||
m_decomp_crc32 = crc32(m_decomp_crc32, m_pFlush_src + copy_ofs, bytes_to_copy); \
|
||||
m_decomp_crc32 = crc32(m_pFlush_src + copy_ofs, bytes_to_copy, m_decomp_crc32); \
|
||||
copy_ofs += bytes_to_copy; \
|
||||
} \
|
||||
} \
|
||||
@ -1146,7 +1146,7 @@ namespace lzham
|
||||
{
|
||||
if (unbuffered)
|
||||
{
|
||||
m_decomp_crc32 = crc32(cInitCRC32, pDst, dst_ofs);
|
||||
m_decomp_crc32 = crc32(pDst, dst_ofs, cInitCRC32);
|
||||
}
|
||||
|
||||
//if (m_file_src_file_crc32 != m_decomp_crc32)
|
||||
@ -1576,14 +1576,14 @@ namespace lzham
|
||||
return NULL;
|
||||
}
|
||||
|
||||
lzham_z_ulong lzham_lib_z_adler32(lzham_z_ulong adler, const unsigned char *ptr, size_t buf_len)
|
||||
lzham_z_ulong LZHAM_CDECL lzham_lib_z_adler32(lzham_z_ulong adler, const lzham_uint8 *ptr, size_t buf_len)
|
||||
{
|
||||
return adler32(ptr, buf_len, adler);
|
||||
}
|
||||
|
||||
lzham_z_ulong LZHAM_CDECL lzham_lib_z_crc32(lzham_z_ulong crc, const lzham_uint8 *ptr, size_t buf_len)
|
||||
{
|
||||
return crc32(crc, ptr, buf_len);
|
||||
return crc32(ptr, buf_len, crc);
|
||||
}
|
||||
|
||||
} // namespace lzham
|
||||
|
Loading…
x
Reference in New Issue
Block a user