Comments (3)
This isn't always a generic decompress where the decompressed size is totally unknown. This is decoding known rows of known size, so the memory is allocated ahead of time. So the decompress should hand down the buffer to fill in.
I also couldn't get miniz to work either with this api.
from lodepng.
This does everything I'd expect for custom_zib, but is commented out by LODEPNG_NO_COMPILE_ZLIB. So I guess I'll leave in zlib by not setting that, and still supply the custom_zlib impl.
/*expected_size is expected output size, to avoid intermediate allocations. Set to 0 if not known. */
static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size,
const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) {
unsigned error;
if(settings->custom_zlib) {
ucvector v = ucvector_init(*out, *outsize);
if(expected_size) {
/*reserve the memory to avoid intermediate reallocations*/
ucvector_resize(&v, expected_size);
v.size = expected_size;
}
// this only happens on iccp block
if (*outsize == 0 && expected_size == 0) {
expected_size = 16*1024;
ucvector_resize(&v, expected_size);
}
error = settings->custom_zlib(&v.data, &v.size, in, insize, settings);
if(error) {
/*the custom zlib is allowed to have its own error codes, however, we translate it to code 110*/
error = 110;
/*if there's a max output size, and the custom zlib returned error, then indicate that error instead*/
if(settings->max_output_size && *outsize > settings->max_output_size) error = 109;
}
*out = v.data;
*outsize = v.size;
}
from lodepng.
Failures on iccp blocks (which passes 16K for size, even though ony 4506 bytes are decompressed). So then my decompressor returns an error. Not sure why this doesn't fail with the default zlib_decompress.
I did get libCompression working by +2 on ptr, and -2 on size. But then iccp block broke all this. So just went back to default decompress in lodepng.
https://github.com/alecazam/kram/blob/main/libkram/kram/Kram.cpp
// wrap miniz decompress, since it ignores crc checksum and is faster than default png
unsigned LodepngDecompressUsingMiniz(
unsigned char** dstData, size_t* dstDataSize,
const unsigned char* srcData, size_t srcDataSize,
const LodePNGDecompressSettings* settings)
{
// mz_ulong doesn't line up with size_t on Windows, but does on macOS
KASSERT(*dstDataSize != 0);
#if USE_LIBCOMPRESSION
// 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 + 2, srcDataSize - 2,
scratchBuffer, // scratch-buffer that could speed up to pass
COMPRESSION_ZLIB);
int result = MZ_OK;
if (bytesDecoded != *dstDataSize) {
result = MZ_DATA_ERROR;
*dstDataSize = 0;
}
#else
// This works.
mz_ulong bytesDecoded = *dstDataSize;
int result = mz_uncompress(*dstData, &bytesDecoded,
srcData, srcDataSize);
if (result != MZ_OK || bytesDecoded != *dstDataSize) {
*dstDataSize = 0;
}
else {
*dstDataSize = bytesDecoded;
}
#endif
return result;
}
from lodepng.
Related Issues (20)
- sdl2 HOT 6
- vulnerability Discover HOT 2
- what's mean of this define LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS and when should i define it
- code optimization
- Че за хрень 64 бит компиляция HOT 1
- Sudden increase in build size HOT 1
- Memory leaks in function benchmark.
- SEGV on unknown address in function pngdetail. HOT 2
- How to get a JSON string from the encoded image ? HOT 3
- Expected speed? HOT 6
- Fix warnings: `conversion from 'size_t' to 'unsigned short', possible loss of data` HOT 2
- chunk type is restricted to the decimal values 65 to 90 and 97 to 122
- Veracode discovered a race condition
- Consideration for changing the License to public domain
- allocate "reserved_size" extra memory
- Lodepng fails to open valid png image HOT 4
- Clarification on "filter_palette_zero"
- lodepng crashes ntdll.dll
- Encoding from RGB 24 frame buffers handling stride / pitch
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lodepng.