displayio
– High level, display object compositing system
The displayio
module contains classes to define what objects to display. It is optimized for low memory use and, therefore, computes final pixel values for dirty regions as needed.
Separate modules manage transmitting the display contents to a display.
For more a more thorough explanation and guide for using displayio
, please refer to this Learn guide.
Type-checking shorthand for any kind of display bus. Not actually defined in CircuitPython.
Type-checking shorthand for any kind of framebuffer. Not actually defined in CircuitPython.
Type-checking shorthand for any kind of display. Not actually defined in CircuitPython.
The displayio.Group
that is the displayed serial terminal (REPL).
Releases any actively used displays so their buses and pins can be used again. This will also release the builtin display on boards that have one. You will need to reinitialize it yourself afterwards. This may take seconds to complete if an active EPaperDisplay is refreshing.
Use this once in your code.py if you initialize a display. Place it right before the initialization so the display is active as long as possible.
The colorspace for a ColorConverter
to operate in
The standard 24-bit colorspace. Bits 0-7 are blue, 8-15 are green, and 16-24 are red. (0xRRGGBB)
The standard 16-bit colorspace. Bits 0-4 are blue, bits 5-10 are green, and 11-15 are red (0bRRRRRGGGGGGBBBBB)
The swapped 16-bit colorspace. First, the high and low 8 bits of the number are swapped, then they are interpreted as for RGB565
The standard 15-bit colorspace. Bits 0-4 are blue, bits 5-9 are green, and 11-14 are red. The top bit is ignored. (0bxRRRRRGGGGGBBBBB)
The swapped 15-bit colorspace. First, the high and low 8 bits of the number are swapped, then they are interpreted as for RGB555
Stores values of a certain size in a 2D array
Bitmaps can be treated as read-only buffers. If the number of bits in a pixel is 8, 16, or 32; and the number of bytes per row is a multiple of 4, then the resulting memoryview will correspond directly with the bitmap’s contents. Otherwise, the bitmap data is packed into the memoryview with unspecified padding.
A Bitmap can be treated as a buffer, allowing its content to be viewed and modified using e.g., with ulab.numpy.frombuffer
, but the displayio.Bitmap.dirty
method must be used to inform displayio when a bitmap was modified through the buffer interface.
bitmaptools.arrayblit
can also be useful to move data efficiently into a Bitmap.
Create a Bitmap object with the given fixed size. Each pixel stores a value that is used to index into a corresponding palette. This enables differently colored sprites to share the underlying Bitmap. value_count is used to minimize the memory used to store the Bitmap.
Width of the bitmap. (read only)
Height of the bitmap. (read only)
Bits per Pixel of the bitmap. (read only)
Returns the value at the given index. The index can either be an x,y tuple or an int equal to y * width + x
.
This allows you to:
Sets the value at the given index. The index can either be an x,y tuple or an int equal to y * width + x
.
This allows you to:
Fills the bitmap with the supplied palette index value.
Inform displayio of bitmap updates done via the buffer protocol.
x1 (int) – Minimum x-value for rectangular bounding box to be considered as modified
y1 (int) – Minimum y-value for rectangular bounding box to be considered as modified
x2 (int) – Maximum x-value (exclusive) for rectangular bounding box to be considered as modified
y2 (int) – Maximum y-value (exclusive) for rectangular bounding box to be considered as modified
If x1 or y1 are not specified, they are taken as 0. If x2 or y2 are not specified, or are given as -1, they are taken as the width and height of the image. Thus, calling dirty() with the default arguments treats the whole bitmap as modified.
When a bitmap is modified through the buffer protocol, the display will not be properly updated unless the bitmap is notified of the “dirty rectangle” that encloses all modified pixels.
Release resources allocated by Bitmap.
Converts one color format to another.
Create a ColorConverter object to convert color formats.
colorspace (Colorspace) – The source colorspace, one of the Colorspace constants
dither (bool) – Adds random noise to dither the output image
Converts the given color to RGB565 according to the Colorspace
When True
the ColorConverter dithers the output by adding random noise when truncating to display bitdepth
Set the transparent color or index for the ColorConverter. This will raise an Exception if there is already a selected transparent index.
color (int) – The color to be transparent
Make the ColorConverter be opaque and have no transparent pixels.
color (int) – [IGNORED] Use any value
Manage a group of sprites and groups and how they are inter-related.
Create a Group of a given size and scale. Scale is in one dimension. For example, scale=2 leads to a layer’s pixel being 2x2 pixels when in the group.
True when the Group and all of its layers are not visible. When False, the Group’s layers are visible if they haven’t been hidden.
Scales each pixel within the Group in both directions. For example, when scale=2 each pixel will be represented by 2x2 pixels.
X position of the Group in the parent.
Y position of the Group in the parent.
Append a layer to the group. It will be drawn above other layers.
Insert a layer into the group.
Returns the index of the first copy of layer. Raises ValueError if not found.
Remove the ith item and return it.
Remove the first copy of layer. Raises ValueError if it is not present.
Returns the number of layers in a Group
Returns the value at the given index.
This allows you to:
Sets the value at the given index.
This allows you to:
Deletes the value at the given index.
This allows you to:
Sort the members of the group.
Loads values straight from disk. This minimizes memory use but can lead to much slower pixel load times. These load times may result in frame tearing where only part of the image is visible.
It’s easiest to use on a board with a built in display such as the Hallowing M0 Express.
import board import displayio import time import pulseio board.DISPLAY.brightness = 0 splash = displayio.Group() board.DISPLAY.root_group = splash odb = displayio.OnDiskBitmap('/sample.bmp') face = displayio.TileGrid(odb, pixel_shader=odb.pixel_shader) splash.append(face) # Wait for the image to load. board.DISPLAY.refresh(target_frames_per_second=60) # Fade up the backlight for i in range(100): board.DISPLAY.brightness = 0.01 * i time.sleep(0.05) # Wait forever while True: pass
Create an OnDiskBitmap object with the given file.
file (file) – The name of the bitmap file. For backwards compatibility, a file opened in binary mode may also be passed.
Older versions of CircuitPython required a file opened in binary mode. CircuitPython 7.0 modified OnDiskBitmap so that it takes a filename instead, and opens the file internally. A future version of CircuitPython will remove the ability to pass in an opened file.
Width of the bitmap. (read only)
Height of the bitmap. (read only)
The image’s pixel_shader. The type depends on the underlying bitmap’s structure. The pixel shader can be modified (e.g., to set the transparent pixel or, for palette shaded images, to update the palette.)
Map a pixel palette_index to a full color. Colors are transformed to the display’s format internally to save memory.
Create a Palette object to store a set number of colors.
When True
the Palette dithers the output color by adding random noise when truncating to display bitdepth
Returns the number of colors in a Palette
Return the pixel color at the given index as an integer.
Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1.
The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value). Value can be an int, bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)), bytearray, or a tuple or list of 3 integers.
This allows you to:
palette[0] = 0xFFFFFF # set using an integer palette[1] = b'\xff\xff\x00' # set using 3 bytes palette[2] = b'\xff\xff\x00\x00' # set using 4 bytes palette[3] = bytearray(b'\x00\x00\xFF') # set using a bytearay of 3 or 4 bytes palette[4] = (10, 20, 30) # set using a tuple of 3 integers
Makes the palette index transparent. The color is ignored.
Mark the given palette index as opaque.
A grid of tiles sourced out of one bitmap
Position a grid of tiles sourced from a bitmap and pixel_shader combination. Multiple grids can share bitmaps and pixel shaders.
A single tile grid is also known as a Sprite.
Create a TileGrid object. The bitmap is source for 2d pixels. The pixel_shader is used to convert the value and its location to a display native pixel color. This may be a simple color palette lookup, a gradient, a pattern or a color transformer.
When the total number of tiles is 256 or less, tile values are stored as single bytes (uint8_t). When the total number of tiles is more than 256, tile values are stored as double bytes (uint16_t).
tile_width and tile_height match the height of the bitmap by default.
bitmap (Bitmap,OnDiskBitmap) – The bitmap storing one or more tiles.
pixel_shader (ColorConverter,Palette) – The pixel shader that produces colors from values
width (int) – Width of the grid in tiles.
height (int) – Height of the grid in tiles.
tile_width (int) – Width of a single tile in pixels. Defaults to the full Bitmap and must evenly divide into the Bitmap’s dimensions.
tile_height (int) – Height of a single tile in pixels. Defaults to the full Bitmap and must evenly divide into the Bitmap’s dimensions.
default_tile (int) – Default tile index to show.
x (int) – Initial x position of the left edge within the parent.
y (int) – Initial y position of the top edge within the parent.
True when the TileGrid is hidden. This may be False even when a part of a hidden Group.
X position of the left edge in the parent.
Y position of the top edge in the parent.
Width of the tilegrid in tiles.
Height of the tilegrid in tiles.
Width of a single tile in pixels.
Height of a single tile in pixels.
If true, the left edge rendered will be the right edge of the right-most tile.
If true, the top edge rendered will be the bottom edge of the bottom-most tile.
If true, the TileGrid’s axis will be swapped. When combined with mirroring, any 90 degree rotation can be achieved along with the corresponding mirrored version.
Returns True if the first two values in touch_tuple
represent an x,y coordinate inside the tilegrid rectangle bounds.
The pixel shader of the tilegrid.
The bitmap of the tilegrid.
Returns the tile index at the given index. The index can either be an x,y tuple or an int equal to y * width + x
.
This allows you to:
Sets the tile index at the given index. The index can either be an x,y tuple or an int equal to y * width + x
.
This allows you to:
or:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4