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

PixelBuf implements an RGB[W] bytearray abstraction.

class pixelbuf.PixelBuf(size, buf, byteorder=BGR, brightness=0, rawbuf=None, offset=0, dotstar=False, auto_write=False, write_function=None, write_args=None)

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

When given a second bytearray (rawbuf), changing brightness adjusts the brightness of all members of buf.

When only given buf, brightness applies to the next pixel assignment.

When dotstar is True, and bpp is 4, the 4th value in a tuple/list is the individual pixel brightness (0-1). Not compatible with RGBW Byteorders. Compatible ByteOrder classes are bpp=3, or bpp=4 and has_luminosity=True (g LBGR).

  • size (~int) – Number of pixelsx
  • buf (~bytearray) – Bytearray to store pixel data in
  • byteorder (ByteOrder) – Byte order constant from _pixelbuf
  • brightness (~float) – Brightness (0 to 1.0, default 1.0)
  • rawbuf (~bytearray) – Bytearray to store raw pixel colors in
  • offset (~int) – Offset from start of buffer (default 0)
  • dotstar (~bool) – Dotstar mode (default False)
  • auto_write (~bool) – Whether to automatically write pixels (Default False)
  • write_function (~callable) – (optional) Callable to use to send pixels
  • write_args (~list) – (optional) Tuple or list of args to pass to write_function. The PixelBuf instance is appended after these args.

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


Float value between 0 and 1. Output brightness. If the PixelBuf was allocated with two both a buf and a rawbuf, setting this value causes a recomputation of the values in buf. If only a buf was provided, then the brightness only applies to future pixel changes. In DotStar mode


Whether to automatically write the pixels after each update.


(read-only) bytearray of pixel data after brightness adjustment. If an offset was provided then this bytearray is the subset of the bytearray passed in that represents the actual pixels.


ByteOrder class for the buffer (read-only)


Call the associated write function to display the pixels.


Returns the pixel value at the given index.

__setitem__(index, value)

Sets the pixel value at the given index.