Skip to content

Commit 149061c

Browse files
author
Matt Land
committed
working, white/black
1 parent 61d3849 commit 149061c

2 files changed

Lines changed: 54 additions & 14 deletions

File tree

adafruit_imageload/pnm/__init__.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,25 @@ def load(file, header, *, bitmap=None, palette=None):
4242
# We have all we need at length 3
4343
if len(pnm_header) == 3:
4444
break
45-
if len(pnm_header) == 2:
45+
if len(pnm_header) == 2 and (
46+
magic_number.startswith(b"P1") or magic_number.startswith(b"P4")
47+
):
48+
bitmap = bitmap(pnm_header[0], pnm_header[1], 1)
49+
if palette:
50+
palette = palette(1)
51+
palette[0] = 0xFFFFFF
4652
if magic_number.startswith(b"P1"):
4753
from . import pbm_ascii
4854

49-
bitmap = bitmap(pnm_header[0], pnm_header[1], 1)
5055
return pbm_ascii.load(
5156
file, pnm_header[0], pnm_header[1], bitmap=bitmap, palette=palette
5257
)
53-
if magic_number.startswith(b"P4"):
54-
from . import pbm_binary
5558

56-
bitmap = bitmap(pnm_header[0], pnm_header[1], 1)
57-
return pbm_binary.load(
58-
file, pnm_header[0], pnm_header[1], bitmap=bitmap, palette=palette
59-
)
59+
from . import pbm_binary
60+
61+
return pbm_binary.load(
62+
file, pnm_header[0], pnm_header[1], bitmap=bitmap, palette=palette
63+
)
6064

6165
next_byte = file.read(1)
6266
if next_byte == b"#":
@@ -85,15 +89,11 @@ def load(file, header, *, bitmap=None, palette=None):
8589
if magic_number.startswith(b"P2") or magic_number.startswith(b"P5"):
8690
from . import pgm
8791

88-
return pgm.load(
89-
file, magic_number, pnm_header, bitmap=bitmap, palette=palette
90-
)
92+
return pgm.load(file, magic_number, pnm_header, bitmap=bitmap, palette=palette)
9193

9294
if magic_number.startswith(b"P3") or magic_number.startswith(b"P6"):
9395
from . import ppm
9496

95-
return ppm.load(
96-
file, magic_number, pnm_header, bitmap=bitmap, palette=palette
97-
)
97+
return ppm.load(file, magic_number, pnm_header, bitmap=bitmap, palette=palette)
9898

9999
raise RuntimeError("Unsupported image format")

docs/pbm_test_code.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Testing script for PBM
3+
Tested with Feather M4 Express and 2.4" Featherwing
4+
1. Flash board to 4x
5+
2. add 'adafruit_ili9341.mpy' for 4x firmware to /lib/ on board
6+
3. add /examples/images to /images on board
7+
4. copy ./adafruit_imageload to /lib/ on the board
8+
5. paste this file into code.py
9+
10+
"""
11+
12+
import board
13+
import displayio
14+
import adafruit_ili9341
15+
import adafruit_imageload
16+
17+
spi = board.SPI()
18+
tft_cs = board.D9
19+
tft_dc = board.D10
20+
21+
displayio.release_displays()
22+
display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs)
23+
24+
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
25+
26+
# Make the display context
27+
splash = displayio.Group(max_size=10)
28+
display.show(splash)
29+
30+
31+
bitmap, palette = adafruit_imageload.load(
32+
"images/netpbm_p1_mono.pbm", bitmap=displayio.Bitmap, palette=displayio.Palette
33+
)
34+
35+
36+
bg_sprite = displayio.TileGrid(bitmap, pixel_shader=palette, x=0, y=0)
37+
splash.append(bg_sprite)
38+
39+
while True:
40+
pass

0 commit comments

Comments
 (0)