Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for embedded #237

Closed
sle118 opened this issue Jan 27, 2016 · 8 comments
Closed

Support for embedded #237

sle118 opened this issue Jan 27, 2016 · 8 comments

Comments

@sle118
Copy link

sle118 commented Jan 27, 2016

I am working on getting stb image library working on the popular esp8266 iot platform, which is an embedded system. Although ram is limited on such device, the library has a number of potential use for interface designs on small oled screens. For example to display WiFi status icons, etc.

So far, jpg and gif work to a certain extent, but PNG triggers a software watchdog reset caused likely but a stack overflow.

There are challenges, notably with regards to stack space which is limited on embedded systems. Ideally, the library should move away from large local variables and leverage malloc instead. If this could benefit others, I will submit a PR when I am done.

@projectkk2glider
Copy link

Hi, we are starting to use stb_image.h in the OpenTX project. We encountered the same problem, the stack usage was in excess of 20kB. So I made some changes in opentx/opentx@bdb5005

If my solution seem acceptable to you, I can prepare a PR.

And thanks for the wonderful library!

@sle118
Copy link
Author

sle118 commented Feb 27, 2016

@projectkk2glider have you tried png formats? these files seem to be even more demanding and I haven't been able to make the decoder work on the esp8266.

I have implemented the library on Sming for the ESP8266 and can decode BPM, GIF and JPG (one decoder at a time).
https://github.com/sle118/Sming/tree/develop/samples/image_example

@nothings
Copy link
Owner

stb_image isn't really designed to be space efficient like embedded needs. it fully decodes intermediate steps so it uses like 1.5x as much memory as needed for jpg, and 2x as much memory for png, nevermind stack usage.

@sle118
Copy link
Author

sle118 commented Feb 28, 2016

With better stack management, it works well in the esp8266...

@projectkk2glider
Copy link

With my change the stack usage is less than 8kB both for PNG and JPG.

@nothings
Copy link
Owner

The thing is, on non-embedded platforms it's better to use the stack since you reduce heap fragmentation, so I'm not sure what the right thing to do is.

@projectkk2glider
Copy link

An option then, but the code will become ugly.

@nothings
Copy link
Owner

nothings commented Apr 2, 2016

A fix for this was submitted:
#253
and I'll merge it this weekend hopefully.

@nothings nothings closed this as completed Apr 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants