Skip to content

Commit

Permalink
Numpy 1.23 __array_interface__ as in Pillow 9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bigcat88 committed Jul 2, 2022
1 parent 6f20ca9 commit 0786242
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions pillow_heif/heif.py
Expand Up @@ -172,21 +172,16 @@ def unload(self):
if self._handle is not None:
self._img_data.clear()

class _ArrayData: # pylint: disable=too-few-public-methods
def __init__(self, new):
self.__array_interface__ = new

def __array__(self, dtype=None):
@property
def __array_interface__(self):
"""Numpy array interface support"""
import numpy as np # pylint: disable=import-outside-toplevel

shape = (self.size[1], self.size[0])
if MODE_INFO[self.mode][0] > 1:
shape += (MODE_INFO[self.mode][0],)
typestr = MODE_INFO[self.mode][5]
data = bytes(self._get_pure_data())
new = {"shape": shape, "typestr": typestr, "version": 3, "data": data}
return np.array(self._ArrayData(new), dtype) # noqa
return {"shape": shape, "typestr": typestr, "version": 3, "data": data}

def _color(self) -> HeifColorspace:
return MODE_INFO[self.mode][2]
Expand Down

0 comments on commit 0786242

Please sign in to comment.