Skip to content

Reduce memory usage for text creation: bitmap_label #76

Closed
@kmatch98

Description

@kmatch98

In order to reduce the amount of memory for displaying text, @FoamyGuy and I are developing a new "label" class that will use a bitmap instead of a group of TileGrids to store the text. Here is a proposed strategy for this new "bitmap_label" Class:

bitmap_label Class definition

  • Input parameters:

    • Make text a required parameter (Note: This will flag if someone creates a bitmap_label with no text, which doesn’t make any sense.)
    • For direct compatibility with label, keep the max_glyphs parameter, but ignore it.
  • Do we want to keep self._memorySaver? (Note: If so, update this to a class variable)

    • True - do not save the text value
    • False - save the text value
    • If we keep this option, then we need to create a getter for text, returns None if self._memorySaver == True.
  • Since the bitmap_label has limited edit capability after creation, minimize the instance variables that are stored

  • Add getters/setters for:

    • anchor_point
    • anchor_position
    • color
    • background_color
    • bounding_box (x,y, w,h)
  • Getters only (or does it regenerate from scratch if this is changed?)

    • font
    • line_spacing
    • text (returns None if text is not stored with _memory_saver option)
  • Add scale capability (this should be handled in the Group)

General steps for _init_ of a bitmap_label instance:

  1. Error-checking: If text is “”, raise an exception.
  2. Calculate the text box size, including any newlines and tabs
  3. Calculate the background box size, including padding
    Note: Negative padding cannot be used. (This would require adding a third color to the palette, which would inflate the bitmap_label bitmap memory usage.)
  4. Determine the bitmap size required by comparing the text box and background box max x,y dimensions.
  5. Determine start location of text in the bitmap
  6. Initialize the palette, TileGrid (self), Bitmap
  7. Draw the background fill, as required
  8. Place the text in the bitmap
  9. Set the TileGrid x,y placement based on anchor_point and anchor_position.
  10. Updated bounding_box values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions