kikuchan / pngle

Pngle - PNG Loader for Embedding
MIT License
109 stars 20 forks source link

Problem to get it run on Teensy 4.0 #2

Closed faytv closed 3 years ago

faytv commented 3 years ago

hello @kikuchan,

I'm not sure if it's an issue, but I don't know how to ask anywhere else. Your Code sounds like exactly what I'm looking for to use on my project so, I tried.

I'm using a Teensy 4.0 and added your project as Arduino Library. I got no errors while compiling, so it looked good at first. My PNG file is stored in the RAM of my Controller, so I don't need a stream on my first tests. I just call pngle_feed() with my framebuffer and file length, but I always get -1 (Uninitialized) as return. I also tried to use one of the example files for testing, because my files are much bigger (800x600px), but I always got the same result.

Any Ideas what could be wrong?

pngle_t *pngle = pngle_new(); pngle_set_draw_callback(pngle, on_draw);

int fed = pngle_feed(pngle, pngFrameBuf, filesize); pngle_destroy(pngle);

kikuchan commented 3 years ago

Thank you for trying to use it. :)

If pngle_error() says Uninitialized, it means the pngle is NULL. pngle_new() returns NULL if underlying calloc() returned NULL, it usually means out of memory. (otherwise, memory/stack corruption perhaps)

Teensy 4.0 only has 1024 KiB RAM, and pngle consumes ~42 KiB at least since PNG format itself requires a lot of memory by design, and including Arduino Library usually costs RAM too, so watch out. Especially if you are trying to allocate a fullcolor (3 bytes for each pixel) 800x600 framebuffer in RAM directly, for example, it costs 1407 KiB and it exceeds RAM instantly.

faytv commented 3 years ago

Thanks for your answer. 42KiB sounds not to much, but it helps to understand where I have to search for. My framebuffer is only 480KiB because it's only 4bit grayscale, for an ePaper display. The problem could be that the RAM is splittet in two 512KiB sectors. I will check tomorrow if I have to manually set which RAM block I want to use.

thanks for now

faytv commented 3 years ago

ok, I got it. With this splitted RAM block, my framebuffer is to large. Unfortunately I was not able to arrange it. Now I packed two pixels in one Byte to half my framebuffer and it works as it should :)

thanks for your help, great library

kikuchan commented 3 years ago

Congrats! 🎉 I'm glad to hear that.

Have a nice hack!