PixelBuf – A fast RGB[W] pixel buffer for LED and similar devices

PixelBuf implements an RGB[W] bytearray abstraction.

class pixelbuf.PixelBuf(size, *, byteorder="BGR", brightness=0, auto_write=False, header=b"", trailer=b"")

Create a PixelBuf object of the specified size, byteorder, and bits per pixel.

When brightness is less than 1.0, a second buffer will be used to store the color values before they are adjusted for brightness.

When P (pwm duration) is present as the 4th character of the byteorder string, the 4th value in the tuple/list for a pixel is the individual pixel brightness (0.0-1.0) and will enable a Dotstar compatible 1st byte in the output buffer (buf).

Parameters:
  • size (~int) – Number of pixelsx
  • byteorder (~str) – Byte order string (such as “BGR” or “PBGR”)
  • brightness (~float) – Brightness (0 to 1.0, default 1.0)
  • auto_write (~bool) – Whether to automatically write pixels (Default False)
  • header (bytes) – Sequence of bytes to always send before pixel values.
  • trailer (bytes) – Sequence of bytes to always send after pixel values.
bpp

The number of bytes per pixel in the buffer (read-only)

brightness

Float value between 0 and 1. Output brightness.

When brightness is less than 1.0, a second buffer will be used to store the color values before they are adjusted for brightness.

auto_write

Whether to automatically write the pixels after each update.

byteorder

byteorder string for the buffer (read-only)

show()

Transmits the color data to the pixels so that they are shown. This is done automatically when auto_write is True.

pixelbuf.fill(color)

Fills the given pixelbuf with the given color.

pixelbuf.__getitem__(index)

Returns the pixel value at the given index as a tuple of (Red, Green, Blue[, White]) values between 0 and 255.

pixelbuf.__setitem__(index, value)

Sets the pixel value at the given index. Value can either be a tuple of (Red, Green, Blue [, White]) values between 0 and 255 or an integer where the red, green and blue values are packed into the lower three bytes (0xRRGGBB).