Use color images as dictionary keys, not bitmaps.
This commit is contained in:
parent
c32415d843
commit
48b179e2e0
2 changed files with 10 additions and 11 deletions
|
|
@ -164,18 +164,17 @@ class Image(object):
|
|||
def isspace(self):
|
||||
return not _is_nonblank(self.bitmap)
|
||||
|
||||
def tostring(self):
|
||||
"""Serialize the image as a string."""
|
||||
height, width, *_ = self.shape
|
||||
shape = '{}x{}'.format(height, width).encode('latin1')
|
||||
bitmap = np.packbits(self.bitmap).tostring()
|
||||
return shape + b':' + bitmap
|
||||
def serialize(self):
|
||||
"""Serialize the image as some hashable object."""
|
||||
bitmap = self.data.astype(np.uint8).tostring()
|
||||
return self.shape, bitmap
|
||||
|
||||
@classmethod
|
||||
def fromstring(cls, data):
|
||||
"""Deserialize an image from a string."""
|
||||
# TODO
|
||||
raise NotImplementedError
|
||||
def deserialize(cls, obj):
|
||||
"""Deserialize an image."""
|
||||
shape, data = obj
|
||||
array = np.fromstring(data, dtype=np.uint8).reshape(shape)
|
||||
return cls(array)
|
||||
|
||||
def unframe(self, width=2):
|
||||
return Image(self.data[width:-width,width:-width])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue