Skip to content

Commit 51cf99e

Browse files
author
bstorm
committed
just saving some of what we've learned
1 parent 551d40a commit 51cf99e

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

adafruit_imageload/pnm/ppm/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@
3333
__version__ = "0.0.0-auto.0"
3434
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad.git"
3535

36+
import math
37+
3638

3739
def load(file, magic_number, header, bitmap=None, palette=None):
3840
"""Load pixel values (indices or colors) into a bitmap and for a binary
3941
ppm, return None for pallet."""
4042
width = header[0]
4143
height = header[1]
4244
max_colors = (header[2] + 1) ** 3
43-
bitmap = bitmap(width, height, max_colors)
45+
colors = math.log(header[2], 2)
46+
bitmap = bitmap(width, height, int(colors))
4447
palette = None
4548

4649
if bitmap:

adafruit_imageload/pnm/ppm/ppm_ascii.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ def load(file, width, height, max_colors, bitmap=None, palette=None):
6060
"BBB",
6161
pixel,
6262
0,
63-
int(triplet[0]),
64-
int(triplet[1]),
65-
int(triplet[2]),
63+
int("".join(["%c" % char for char in triplet[0]])),
64+
int("".join(["%c" % char for char in triplet[1]])),
65+
int("".join(["%c" % char for char in triplet[2]])),
6666
)
67-
bitmap[offset + x] = pixel
67+
bitmap[offset + x] = int.from_bytes(pixel, "little")
6868

6969
return bitmap, palette

0 commit comments

Comments
 (0)