Skip to content

Commit

Permalink
Add NumPy shape attribute for pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
kg583 committed Sep 12, 2023
1 parent 889ddba commit 7d8dcf1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 1 addition & 6 deletions tivars/PIL/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ def encode(self, bufsize):
"""

img = self._T()
shape = img.height, img.width

if img.pixel_type != int:
shape += 3,

img.load_array(np.asarray(self.im).reshape(shape).tolist())
img.load_array(np.asarray(self.im).reshape(img.np_shape).tolist())
data = img.export().bytes()

return len(data), 0, data
10 changes: 9 additions & 1 deletion tivars/types/picture.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ class PictureEntry(SizedEntry):
The type of a single pixel
"""

np_shape = (height, width, 3)
"""
The shape of this image as a NumPy array
"""

has_color = True
"""
Whether this picture has color
Expand Down Expand Up @@ -233,10 +238,11 @@ class TIMonoPicture(PictureEntry):

data_width = width // 8
data_height = height
data_offset = 0

pil_mode = "L"
pixel_type = int
np_shape = (height, width)

has_color = False

_type_id = 0x07
Expand Down Expand Up @@ -288,6 +294,7 @@ class TIPicture(PictureEntry, register=True):

pil_mode = "RGB"
pixel_type = RGB
np_shape = (height, width, 3)

_type_id = 0x07

Expand Down Expand Up @@ -353,6 +360,7 @@ class TIImage(PictureEntry, register=True):

pil_mode = "RGB"
pixel_type = RGB
np_shape = (height, width, 3)

leading_bytes = b'\x81'

Expand Down

0 comments on commit 7d8dcf1

Please sign in to comment.