Speeding up image drawing

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
nitko12
Posts: 2
Joined: Tue Oct 27, 2020 8:19 pm

Speeding up image drawing

Post by nitko12 » Tue Oct 27, 2020 8:25 pm

Hi,

we have recently created a MicroPython compatible board featuring an e-paper display.

See inkplate.io for more info, but came across an issue with MicroPython image drawing from sd card, which is unbearably slow,

here's the code in question:
https://github.com/e-radionicacom/Inkpl ... te.py#L852

Has anyone got a suggestion on how to speed it up?

User avatar
jimmo
Posts: 2015
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Speeding up image drawing

Post by jimmo » Wed Oct 28, 2020 1:06 am

nitko12 wrote:
Tue Oct 27, 2020 8:25 pm
Has anyone got a suggestion on how to speed it up?
Simple suggestion that might give you an easy boost -- add @micropython.native to the top of the function.

But the real problem here is that there's just so much to do here. Even if that function itself was faster, it still calls self.drawPixel for every pixel and that calls writePixel (maybe could directly call writePixel instead?) which itself needs to call self.width() self.height() and then do a bunch of extra work. I could imagine that inlining writePixel's behavior into drawImageFile would help (i.e. only figuring out if you're using self.ipm.pixel or self.ipg.pixel once rather than for every pixel).

Also reading from the file is going to create a lot of buffers. Instead of f.read(), try using f.readinto() to re-use the same buffer.

With any optimisation thing though, you need to measure first. Find out how long the function takes to call (time.ticks_ms and time.ticks_diff), then measure it if you comment out the call to drawPixel. Then you'll know which part to focus on first.

Here's a useful talk on some optimisation tips -- https://www.youtube.com/watch?v=hHec4qL00x0

nitko12
Posts: 2
Joined: Tue Oct 27, 2020 8:19 pm

Re: Speeding up image drawing

Post by nitko12 » Wed Oct 28, 2020 8:04 pm

Thanks,

we'll look into that :)

If anything else comes to mind, please let us know, as were pretty new with MicroPython.

User avatar
jimmo
Posts: 2015
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Speeding up image drawing

Post by jimmo » Wed Oct 28, 2020 11:50 pm

Great, would be very interested to hear your results and I think it could be a really good case study to share with the community!

Post Reply