From 2e11cac220fe0f2e258eaee90bfc0d11c9dd4826 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 17 Sep 2020 13:28:10 -0600 Subject: [PATCH 1/3] Added better documentation, example improvement --- adafruit_pixel_framebuf.py | 14 +++++++++++++- examples/pixel_framebuf_16x16_animation.py | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) 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/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) From e743453d826926bacd7371962416da37ea0e9b00 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 18 Sep 2020 13:28:17 -0600 Subject: [PATCH 2/3] Added new example. Requires fixed version of adafruit_framebuf --- .pre-commit-config.yaml | 1 + examples/blinka_16x16.png | Bin 0 -> 3178 bytes examples/blinka_16x16.png.license | 2 ++ examples/pixel_framebuf_pillow_image.py | 38 ++++++++++++++++++++++++ requirements.txt | 2 +- setup.py | 2 +- 6 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 examples/blinka_16x16.png create mode 100644 examples/blinka_16x16.png.license create mode 100644 examples/pixel_framebuf_pillow_image.py 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/examples/blinka_16x16.png b/examples/blinka_16x16.png new file mode 100644 index 0000000000000000000000000000000000000000..290a48cb936dd85079f6c9e73fb443006d36c242 GIT binary patch literal 3178 zcmV-w43+bVP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb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_Lrc00000 literal 0 HcmV?d00001 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_pillow_image.py b/examples/pixel_framebuf_pillow_image.py new file mode 100644 index 0000000..52db007 --- /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 adafruit_pixel_framebuf import PixelFramebuffer +from PIL import Image + +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 From deaa4427521a054cbcf0c55f18d95ca73ca66f7b Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 18 Sep 2020 13:37:36 -0600 Subject: [PATCH 3/3] Fixed import order --- examples/pixel_framebuf_pillow_image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pixel_framebuf_pillow_image.py b/examples/pixel_framebuf_pillow_image.py index 52db007..155d43c 100644 --- a/examples/pixel_framebuf_pillow_image.py +++ b/examples/pixel_framebuf_pillow_image.py @@ -11,8 +11,8 @@ """ import board import neopixel -from adafruit_pixel_framebuf import PixelFramebuffer from PIL import Image +from adafruit_pixel_framebuf import PixelFramebuffer pixel_pin = board.D18 pixel_width = 16