Skip to content

Commit

Permalink
Fix alpha-blending on Unicorn HAT HD device
Browse files Browse the repository at this point in the history
  • Loading branch information
rm-hull committed May 26, 2019
1 parent 0adf502 commit 8e847e8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ChangeLog
+------------+------------------------------------------------------------------------+------------+
| Version | Description | Date |
+============+========================================================================+============+
| *upcoming* | * Fix alpha-channel blending for Unicorn Hat HD display | TBC |
+------------+------------------------------------------------------------------------+------------+
| **1.3.0** | * Add support for Pimoroni's Unicorn Hat HD | 2019/05/26 |
+------------+------------------------------------------------------------------------+------------+
| **1.2.0** | * Add option to control if 8x8 blocks are arranged in reverse order | 2019/04/20 |
Expand Down
2 changes: 1 addition & 1 deletion luma/led_matrix/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def display(self, image):

for idx, (r, g, b, a) in enumerate(image.getdata()):
offset = idx * 3
brightness = int(a / 255.0) if a != 0xFF else normalized_brightness
brightness = a / 255.0 if a != 255 else normalized_brightness
buf[offset] = int(r * brightness)
buf[offset + 1] = int(g * brightness)
buf[offset + 2] = int(b * brightness)
Expand Down
17 changes: 17 additions & 0 deletions tests/reference/data/demo_unicornhathd_alphablend.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8,
32, 16, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 16, 8,
32, 16, 8, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 16, 8,
32, 16, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 16, 8,
32, 16, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 16, 8,
32, 16, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 16, 8,
32, 16, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 16, 8,
32, 16, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8, 32, 16, 8
]
8 changes: 8 additions & 0 deletions tests/test_unicornhathd.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ def test_display():
with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline="white")
serial.data.assert_called_once_with([0x72] + get_json_data('demo_unicornhathd'))


def test_alpha_blending():
device = unicornhathd(serial)
serial.reset_mock()
with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline=(255, 128, 64, 32))
serial.data.assert_called_once_with([0x72] + get_json_data('demo_unicornhathd_alphablend'))

0 comments on commit 8e847e8

Please sign in to comment.