From 30e7e18fa2d1a462be260d695dab0dcf5b956550 Mon Sep 17 00:00:00 2001 From: Alec Miller Date: Wed, 5 Jun 2024 09:28:33 -0700 Subject: [PATCH] kram - re-enable libCompression, but disable miniz and libCompression on lodepng Too many failures of the src test suite trying to switch to miniz or libCompression as a custom ziib. May need to supply custom_inflate/deflate instead. iccp block on inter-a.png breaks miniZ. Did managed to advance +2, size -2 to get libCompression to gen similar decompress to miniZ. --- libkram/kram/KTXImage.cpp | 3 +-- libkram/kram/Kram.cpp | 18 ++++++++++++------ libkram/kram/KramZipHelper.cpp | 3 +-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libkram/kram/KTXImage.cpp b/libkram/kram/KTXImage.cpp index aee2287..047dbde 100644 --- a/libkram/kram/KTXImage.cpp +++ b/libkram/kram/KTXImage.cpp @@ -16,9 +16,8 @@ // for zstd decompress #include "zstd.h" -// Don't trust this see use in Kram.cpp with lodepng #ifndef USE_LIBCOMPRESSION -#define USE_LIBCOMPRESSION 0 // (KRAM_MAC || KRAM_IOS) +#define USE_LIBCOMPRESSION (KRAM_MAC || KRAM_IOS) #endif #if USE_LIBCOMPRESSION diff --git a/libkram/kram/Kram.cpp b/libkram/kram/Kram.cpp index cee9db7..2951a5b 100644 --- a/libkram/kram/Kram.cpp +++ b/libkram/kram/Kram.cpp @@ -27,8 +27,6 @@ #include "lodepng.h" #include "miniz.h" -// This doesn't work returns 121 for a 16K decode -// Just open the src directory #ifndef USE_LIBCOMPRESSION #define USE_LIBCOMPRESSION 0 // (KRAM_MAC || KRAM_IOS) #endif @@ -62,7 +60,11 @@ namespace kram { using namespace NAMESPACE_STL; -static bool useMiniZ = true; +// This fails with libCompression (see inter-a.png) +// and with miniZ for the ICCP block (see inter-a.png) +// lodepng passes 16K to the custom zlib decompress, but +// the data read isn't that big. +static bool useMiniZ = false; template void releaseVector(vector& v) @@ -423,12 +425,16 @@ unsigned LodepngDecompressUsingMiniz( KASSERT(*dstDataSize != 0); #if USE_LIBCOMPRESSION - // This call can't be replaced since lodepng doesn't pass size - // And it doesn't take a nullable dstData? + // this returns 121 dstSize instead of 16448 on 126 srcSize. + // Open src dir to see this. Have to advance by 2 to fix this. + if (srcDataSize <= 2) { + return MZ_DATA_ERROR; + } + char scratchBuffer[compression_decode_scratch_buffer_size(COMPRESSION_ZLIB)]; size_t bytesDecoded = compression_decode_buffer( (uint8_t*)*dstData, *dstDataSize, - (const uint8_t*)srcData, srcDataSize, + (const uint8_t*)srcData + 2, srcDataSize - 2, scratchBuffer, // scratch-buffer that could speed up to pass COMPRESSION_ZLIB); diff --git a/libkram/kram/KramZipHelper.cpp b/libkram/kram/KramZipHelper.cpp index bb2a427..f02d51f 100644 --- a/libkram/kram/KramZipHelper.cpp +++ b/libkram/kram/KramZipHelper.cpp @@ -9,9 +9,8 @@ // test for perf of this compared to one in miniz also see // comments about faster algs. // libcompress can only encode lvl 5, but here it's only decompress. -// Don't trust this. #ifndef USE_LIBCOMPRESSION -#define USE_LIBCOMPRESSION 0 // (KRAM_MAC || KRAM_IOS) +#define USE_LIBCOMPRESSION (KRAM_MAC || KRAM_IOS) #endif #if USE_LIBCOMPRESSION