diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6cd77e3..3288e14 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,4 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace +exclude: \.png$ diff --git a/adafruit_pixel_framebuf.py b/adafruit_pixel_framebuf.py index 4da9be9..ba5cb95 100755 --- a/adafruit_pixel_framebuf.py +++ b/adafruit_pixel_framebuf.py @@ -54,6 +54,18 @@ class PixelFramebuffer(adafruit_framebuf.FrameBuffer): """ NeoPixel and Dotstar FrameBuffer for easy drawing and text on a grid of either kind of pixel + + :param strip: An object that implements the Neopixel or Dotstar protocol. + :param width: Framebuffer width. + :param height: Framebuffer height. + :param orientation: Orientation of the strip pixels - HORIZONTAL (default) or VERTICAL. + :param alternating: Whether the strip alternates direction from row to row (default True). + :param reverse_x: Whether the strip X origin is on the right side (default False). + :param reverse_y: Whether the strip Y origin is on the bottom (default False). + :param tuple top: (x, y) coordinates of grid top left corner (Optional) + :param tuple bottom: (x, y) coordinates of grid bottom right corner (Optional) + :param int rotation: A value of 0-3 representing the rotation of the framebuffer (default 0) + """ def __init__( @@ -96,7 +108,7 @@ def blit(self): raise NotImplementedError() def display(self): - """Copy the raw buffer to the grid and show""" + """Copy the raw buffer changes to the grid and show""" for _y in range(self._height): for _x in range(self._width): index = (_y * self.stride + _x) * 3 diff --git a/examples/blinka_16x16.png b/examples/blinka_16x16.png new file mode 100644 index 0000000..290a48c Binary files /dev/null and b/examples/blinka_16x16.png differ diff --git a/examples/blinka_16x16.png.license b/examples/blinka_16x16.png.license new file mode 100644 index 0000000..ee58873 --- /dev/null +++ b/examples/blinka_16x16.png.license @@ -0,0 +1,2 @@ +# SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams, written for Adafruit Industries +# SPDX-License-Identifier: MIT diff --git a/examples/pixel_framebuf_16x16_animation.py b/examples/pixel_framebuf_16x16_animation.py index c422c0b..35a2bd1 100755 --- a/examples/pixel_framebuf_16x16_animation.py +++ b/examples/pixel_framebuf_16x16_animation.py @@ -23,7 +23,7 @@ pixel_framebuf.line(0, 0, pixel_width - 1, pixel_height - 1, 0x00FF00) pixel_framebuf.line(0, pixel_width - 1, pixel_height - 1, 0, 0x00FF00) pixel_framebuf.fill_rect(2, 3, 12, 10, 0x000000) - pixel_framebuf.text(text, 16 - i, 4, 0xFFFF00) + pixel_framebuf.text(text, pixel_width - i, 4, 0xFFFF00) pixel_framebuf.rect(1, 2, 14, 12, 0xFF0000) pixel_framebuf.line(0, 2, 0, 14, 0x000088) pixel_framebuf.line(pixel_width - 1, 2, pixel_width - 1, 14, 0x000088) diff --git a/examples/pixel_framebuf_pillow_image.py b/examples/pixel_framebuf_pillow_image.py new file mode 100644 index 0000000..155d43c --- /dev/null +++ b/examples/pixel_framebuf_pillow_image.py @@ -0,0 +1,38 @@ +# SPDX-FileCopyrightText: 2020 Melissa LeBlanc-Williams, written for Adafruit Industries +# SPDX-License-Identifier: MIT +""" +Be sure to check the learn guides for more usage information. + +This example is for use on (Linux) computers that are using CPython with +Adafruit Blinka to support CircuitPython libraries. CircuitPython does +not support PIL/pillow (python imaging library)! + +Author(s): Melissa LeBlanc-Williams for Adafruit Industries +""" +import board +import neopixel +from PIL import Image +from adafruit_pixel_framebuf import PixelFramebuffer + +pixel_pin = board.D18 +pixel_width = 16 +pixel_height = 16 + +pixels = neopixel.NeoPixel( + pixel_pin, pixel_width * pixel_height, brightness=0.1, auto_write=False, +) + +pixel_framebuf = PixelFramebuffer(pixels, pixel_width, pixel_height, reverse_x=True,) + +# Make a black background in RGBA Mode +image = Image.new("RGBA", (pixel_width, pixel_height)) + +# Open the icon +icon = Image.open("blinka_16x16.png") + +# Alpha blend the icon onto the background +image.alpha_composite(icon) + +# Convert the image to RGB and display it +pixel_framebuf.image(image.convert("RGB")) +pixel_framebuf.display() diff --git a/requirements.txt b/requirements.txt index 345592e..bbef95c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,5 @@ # SPDX-License-Identifier: MIT Adafruit-Blinka -adafruit-circuitpython-framebuf +adafruit-circuitpython-framebuf>=1.4.2 adafruit-circuitpython-led-animation diff --git a/setup.py b/setup.py index f157d3e..0769433 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ author_email="circuitpython@adafruit.com", install_requires=[ "Adafruit-Blinka", - "adafruit-circuitpython-framebuf", + "adafruit-circuitpython-framebuf>=1.4.2", "adafruit-circuitpython-led-animation", ], # Choose your license