Skip to content

Commit f74c329

Browse files
author
bstorm
committed
Merge remote-tracking branch 'origin/master' into ppm
2 parents d2a2e32 + f47d201 commit f74c329

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ _build
44
.env
55
build*
66
bundles
7+
.idea/
8+
venv/
9+

adafruit_imageload/pnm/__init__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ def load(f, header, *, bitmap=None, palette=None):
4141
while True:
4242
# We have all we need at length 3
4343
if len(pnm_header) == 3:
44-
test_byte = f.read(1)
45-
if test_byte.isdigit():
46-
raise RuntimeError("Not supporting 16-bit colors at this time")
44+
f.read(1)
4745
break
4846
if magic_number.startswith(b"P1") or magic_number.startswith(b"P4"):
4947
if len(pnm_header) == 2:
@@ -57,13 +55,22 @@ def load(f, header, *, bitmap=None, palette=None):
5755
next_byte = f.read(1)
5856
if next_byte == b"#":
5957
while True:
60-
f.read(1)
58+
next_byte = f.read(1)
6159
if not next_byte:
6260
raise RuntimeError("Unsupported image format")
63-
if next_byte != b"\n":
61+
if next_byte == b"\n":
6462
break
6563
if next_byte.isdigit():
66-
pnm_header.append(int.from_bytes(next_byte, "big"))
64+
value = bytearray()
65+
while True:
66+
if not next_byte.isdigit():
67+
break
68+
value += next_byte
69+
next_byte = f.read(1)
70+
if not next_byte:
71+
raise RuntimeError("Unsupported image format")
72+
73+
pnm_header.append(int(value))
6774
continue
6875

6976
if not next_byte:

examples/images/netpbm_p1_mono.pbm

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
P1
2+
# This is an example bitmap of the letter "J" in a 2x2 grid
3+
13 21
4+
0 0 0 0 0 0 0 0 0 0 0 0 0
5+
0 0 0 0 0 1 0 0 0 0 0 1 0
6+
0 0 0 0 0 1 0 0 0 0 0 1 0
7+
0 0 0 0 0 1 0 0 0 0 0 1 0
8+
0 0 0 0 0 1 0 0 0 0 0 1 0
9+
0 0 0 0 0 1 0 0 0 0 0 1 0
10+
0 0 0 0 0 1 0 0 0 0 0 1 0
11+
0 1 0 0 0 1 0 1 0 0 0 1 0
12+
0 0 1 1 1 0 0 0 1 1 1 0 0
13+
0 0 0 0 0 0 0 0 0 0 0 0 0
14+
0 0 0 0 0 0 0 0 0 0 0 0 0
15+
0 0 0 0 0 1 0 0 0 0 0 1 0
16+
0 0 0 0 0 1 0 0 0 0 0 1 0
17+
0 0 0 0 0 1 0 0 0 0 0 1 0
18+
0 0 0 0 0 1 0 0 0 0 0 1 0
19+
0 0 0 0 0 1 0 0 0 0 0 1 0
20+
0 0 0 0 0 1 0 0 0 0 0 1 0
21+
0 1 0 0 0 1 0 1 0 0 0 1 0
22+
0 0 1 1 1 0 0 0 1 1 1 0 0
23+
0 0 0 0 0 0 0 0 0 0 0 0 0
24+
0 0 0 0 0 0 0 0 0 0 0 0 0

examples/images/netpbm_p4_mono.pbm

76 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)