Skip to content

Commit 1665ecf

Browse files
committed
Image displaying now, but colors are inversed
1 parent ff9113d commit 1665ecf

1 file changed

Lines changed: 9 additions & 62 deletions

File tree

adafruit_imageload/pnm/pgm/__init__.py

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -58,73 +58,20 @@ def load(file, magic_number, header, *, bitmap=None, palette=None):
5858
break
5959
pixel += bit
6060

61-
bitmap[x, y] = int(pixel)
62-
colors.add(int(pixel))
61+
int_pixel = int("".join(["%c" % char for char in pixel]))
62+
bitmap[x, y] = int_pixel
63+
colors.add(int_pixel)
6364
if palette:
6465
palette = palette(len(colors))
6566
for counter, color in enumerate(colors):
66-
color_int = int(f'{hex(color)}{hex(color)[2:]}{hex(color)[2:]}', 16) # HACK: is there a better way?
67-
palette[counter] = color_int
67+
color_bytearray = bytearray()
68+
for i in range(3):
69+
color_bytearray += bytes([color])
70+
palette[counter] = color_bytearray
6871
return bitmap, palette
6972

7073

7174
if magic_number == b'P5':
72-
raise NotImplementedError("Nope")
75+
raise NotImplementedError("This is a Binary file")
7376

74-
raise NotImplementedError("no")
75-
76-
# Assign bits to bitmap
77-
78-
# create pallete
79-
80-
# create bitmap
81-
82-
# Loop through lines using line width and build
83-
84-
# Return bitmap
85-
86-
# Example bitmap object:
87-
# [
88-
# [(222), (33), (5), (76), (55), (82)]
89-
# ]
90-
91-
92-
93-
# if bitmap:
94-
# minimum_color_depth = 1
95-
# while colors > 2 ** minimum_color_depth:
96-
# minimum_color_depth *= 2
97-
98-
# bitmap = bitmap(width, height, colors)
99-
# f.seek(data_start)
100-
# line_size = width // (8 // color_depth)
101-
# if line_size % 4 != 0:
102-
# line_size += (4 - line_size % 4)
103-
104-
# packed_pixels = None
105-
# if color_depth != minimum_color_depth and minimum_color_depth == 2:
106-
# target_line_size = width // 4
107-
# if target_line_size % 4 != 0:
108-
# target_line_size += (4 - target_line_size % 4)
109-
110-
# packed_pixels = bytearray(target_line_size)
111-
112-
# for line in range(height-1,-1,-1):
113-
# chunk = f.read(line_size)
114-
# if packed_pixels:
115-
# original_pixels_per_byte = 8 // color_depth
116-
# packed_pixels_per_byte = 8 // minimum_color_depth
117-
118-
# for i in range(width // packed_pixels_per_byte):
119-
# packed_pixels[i] = 0
120-
121-
# for i in range(width):
122-
# pi = i // packed_pixels_per_byte
123-
# ci = i // original_pixels_per_byte
124-
# packed_pixels[pi] |= ((chunk[ci] >> (8 - color_depth*(i % original_pixels_per_byte + 1))) & 0x3) << (8 - minimum_color_depth*(i % packed_pixels_per_byte + 1))
125-
126-
# bitmap._load_row(line, packed_pixels)
127-
# else:
128-
# bitmap._load_row(line, chunk)
129-
130-
# return bitmap, palette
77+
raise NotImplementedError("Was not able to send image")

0 commit comments

Comments
 (0)