diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 48f7d4d6a7728dfdc813088fb9a642d1ce870c76..5f69fee25e6ee762e13bfe2b3d049dde0c365706 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -1670,7 +1670,7 @@ API(API_DISP_PIXEL, int epic_disp_pixel( * :param w: image width * :param h: image height * :param img: image data (rgb565) - * :param alpah: 8 bit alpha channel. Currently unused. + * :param alpha: 8 bit alpha channel. Currently unused. */ API(API_DISP_BLIT, int epic_disp_blit( int16_t x, diff --git a/pycardium/modules/py/display.py b/pycardium/modules/py/display.py index 20616e14757fb03b5e51fd9ffe462803150ac4cd..1c94d47b35844db5272447265c94389c2eac918b 100644 --- a/pycardium/modules/py/display.py +++ b/pycardium/modules/py/display.py @@ -122,18 +122,67 @@ class Display: def blit(self, x, y, w, h, img, rgb565=False, alpha=None): """ - Blit an image to the display + Draws an image on the display. - :param x: top left X coordinate - :param y: top left Y coordinate - :param w: image width - :param h: image height - :param img: a byte buffer with pixel data (RGB) - :param alpha: alpha mask for `img` - :param rgb565: Set to `True` if the data supplied is in rgb565 format + :param x: X coordinate + :param y: Y coordinate + :param w: Image width + :param h: Image height + :param img: Buffer with pixel data. Default format is RGB with 8 bits per channel. + :param alpha: Alpha mask for `img` + :param rgb565: Set to `True` if the data supplied is in rgb565 format instead of 8 bit RGB. .. note:: - The alpha channel is not implemented yet. + Alpha mask support is not yet implemented. + + .. versionadded:: 1.17 + + **Example with RGB data:** + + .. code-block:: python + + import display + import color + + # Draw a blue 32x20 pixel rectangle: + # Each pixel is 3 bytes big. Order is red, green, blue + img = bytes(color.BLUE) * 32 * 20 + with display.open() as d: + d.clear() + d.blit(10, 10, 32, 20, img) + d.update() + + + **Example with rgb565 data:** + + .. code-block:: python + + import array + import display + + # Draw a green 32x20 pixel rectangle: + # 0x07E0 has all bits for green set to 1. Order is RRRR RGGG GGGB BBBB + img = array.array('H', [0x07E0 for x in range(32 * 20)]) + with display.open() as d: + d.clear() + d.blit(10, 10, 32, 20, img, rgb565=True) + d.update() + + + **Example with a MicroPython FrameBuffer:** + + .. code-block:: python + + import framebuf + import display + + # Create a 160x80 pixel frame buffer and write "Hello World" on the display + f = framebuf.FrameBuffer(bytearray(160 * 80 * 2), 160, 80, framebuf.RGB565) + with display.open() as d: + f.text("Hello World", 0, 0, 0xF800) # red + d.blit(0, 0, 160, 80, f, rgb565=True) + d.update() + """