lovyan03 / LovyanGFX

SPI LCD graphics library for ESP32 (ESP-IDF/ArduinoESP32) / ESP8266 (ArduinoESP8266) / SAMD51(Seeed ArduinoSAMD51)
Other
1.16k stars 206 forks source link

Save memory with mass storage cache #379

Closed PM04290 closed 1 year ago

PM04290 commented 1 year ago

Carefully written requests are more likely to be given priority. 丁寧に記述された要望は優先して対応される可能性が高くなります。 On application like dialog menu or other, we need very often the same image/text, and on large application we can't store it in cache (buffer) because of memory foot print.

Is your feature request related to a problem? Please describe. I am allways in problem with heap memory on large application, so it's difficult to use PNG file who needs more than 47k memory.

Describe the solution you'd like I have imagine a solution to ease the memory is to store Sprite on mass storage like SPIFFS, to re-use the same image at each time we need without memory usage (or less); I dream of a function that does this : sprite.dumpToDisk(SPIFFS,"filename.dump"); and the read one sprite.createFromDump(SPIFFS,"filename.dump", width, height); // like createFromBmp

Describe alternatives you've considered with my memory problem, i have consider many solutions, like using another image format, but i d'ont know what format use less memory.

Additional context on U.I, the time to refresh screen is not very important, so we can use SPIFFS or SDcard to store/load image, and the time to do that is very low.

tobozo commented 1 year ago

hi,

if you don't mind the bloat, feel free to vampirize the logic from ESP32-Chimera-Core's ScreenShot Service, the snapBMP() function sounds like what you're looking for.

PM04290 commented 1 year ago

i don't want scpecifically a BMP format, just a memory dump off a Sprite, to re-use later. i don't see anay Lovyan call in the project Chimere and i prefer to use lovyan in production version.

tobozo commented 1 year ago

Chimera-Core uses LovyanGFX, snapBMP is just a design pattern you could use to implement your own capture and restore from sprite.

PM04290 commented 1 year ago

@tobozo are you confirm that readRectRGB function read buffer of Sprite ant do a SPI reading panel ?

tobozo commented 1 year ago

I haven't tried but readRectRGB is in LGFXBase so it shoud be relative to the object and cover both tft and sprite.

You can verify this by filling a sprite in white and calling sprite.readRectRGB() when the display is totally black, then print back the buffer to the display.

[edit] btw you already have access to the pixels when using sprite.getBuffer()

PM04290 commented 1 year ago

i have just tested readRectRBG() with a clone off Chimera SnapShoot BMP.... the BMP is totaly black. i'ill try somting with getBuffer()

tobozo commented 1 year ago

sprite.bufferLength() can be handy too

tobozo commented 1 year ago

I made an example to load/save sprite from filesystem or stream.

The saved file has more than a copy of the buffer, it also holds width/height/buffer_size so that the bit depth can be guessed when reloading the sprite, and the stream can loaded directly into the sprite buffer.

PM04290 commented 1 year ago

great, i'll test it today.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 1 year ago

This issue has been automatically closed because it has not had recent activity. Thank you for your contributions.