Skip to content

Commit

Permalink
kram - re-enable libCompression, but disable miniz and libCompression…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
alecazam committed Jun 5, 2024
1 parent b120e88 commit 30e7e18
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 1 addition & 2 deletions libkram/kram/KTXImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions libkram/kram/Kram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <typename T>
void releaseVector(vector<T>& v)
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions libkram/kram/KramZipHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 30e7e18

Please sign in to comment.