bitbank2 / PNGenc

An embedded-friendly PNG encoder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing data in compressed stream

Raphael-Boichot opened this issue · comments

Hello again.

So, I'm using the library on Pi Pico to record the stream from a camera to SD card. For some reason I need to upscale images between 2x and 10x and I deal with that during encoding. I can process pretty large images.

What I get is confusing. On the same run, continuously recording, I can get perfect images like this :
clean

Or completely broken images like these:
truncated_1
Truncated_2

Broken images have always too short uncompressed data compared to WIDTH*HEIGHT.
I've checked the image with https://www.nayuki.io/page/png-file-chunk-inspector and the error is always the same, but data can be more or less damaged.

Do you have an idea of what could be the error and side question: can I bound the memory usage during the call ? I indeed suspect memory issues even I I have plenty of memory left after compiling (about 60 extra kB).

image
Here the typical error. There is no pattern between images. I've tried different upscaling factors, different compression levels, different palettes, it's overall always the same.

I'll take a look

Some more infos: if I write single color image, no problem. If I upscale a fully random image, it's getting worse:
0008117

So the issue depends on the complexity of the data to encode.

0008163

But this works, strange... Maybe my upscaler code is triggering some issue

OK, I got the issue: when png.addLine(ucLine) is repeated several times with the same data, the code has unexpected output. Here's a minimal code to reproduce the bug :
code.txt

It appears only at certain resolutions and for certain compressing levels
0008193

After some more tests, I think this is an issue with the filesystem or some variable initialization. The first image is always good whatever the used parameters and the issue appears always after consecutive recordings.
Looks like something is not initialized again at the end of conversion/writing. If I soft reboot the Pi pico, first image is good again.

Problem fixed: incompatibility between PNGenc and my TFT library