Skip to content

Adafruit_LoadImage Buffer Management #1183

@ATMakersBill

Description

@ATMakersBill

Per @tannewt and @ATMakersBill's Discord Chat, loading multiple image files will be needed by many scenarios.

Right now, loadimage() allocates the pallete and bitmap objects for each file load. At best this means that the user will need to delete the bitmap object (which scales with widthXheight) before loading the next image. That will cause memory fragmentation depending on Python's memory management.

Scott is looking at reading directly from files to the Display's screenbuffer, which is great, but we can be certain that some will want to store bitmaps in memory and swap them.

My suggestion was to add an accessor to the 'bitmap' class that gets the buffer and an optional paramter to loadimage that let you pass in a buffer of appropriate size. If the size of the buffer was big enough, it would be reused. If not, there are several options (fail, warning, delete and reallocate) all of which have issues.

However, if you knew your bitmaps were the same widthXheightXdepth, it would let you do code like this:

image, palette = adafruit_imageload.load("/images/FILE1.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette)
#use Image/Palette
#LATER
buffer = image.getBuffer()  #already sized from previous call
image, palette = adafruit_imageload.load("/images/FILE2.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette, buffer)

`
There are likely better ways of handling this, but it might be a good place to start

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions