lvandeve / lodepng

PNG encoder and decoder in C and C++.
zlib License
2.06k stars 421 forks source link

support for customize inflate #81

Open kanryu opened 5 years ago

kanryu commented 5 years ago

hi,

I tried to customize inflate () in your library, but actually I could not. Because custom_inflate will always be 0.

Therefore, I propose to add lodepng_decoder_settings_user_regist() API. Calling this API before actually handling png first will customize the initialization by lodepng_decoder_settings_init() and will be able to use custom_inflate etc.

Another suggestion is to add size_t outbuffsize to the custom_inflate function. In other deflate implementations such as libdeflate, the memory size secured in the output destination buffer is required as a parameter. If you give 0 to this you can not actually return an error.

// initial setting
LodePNGDecoderSettings decoderSettings = { 0 };
lodepng_decoder_settings_init(&decoderSettings);
decoderSettings.zlibsettings.custom_inflate = my_custom_inflate;
lodepng_decoder_settings_user_regist(&decoderSettings);
// begin decoding
error = lodepng_decode32_file(&image, &width, &height, filename);