Skip to content

Commit

Permalink
Don't read in RGB mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Milk committed Dec 11, 2023
1 parent 283e46a commit 3d3ea4a
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions lazyslide/readers/vips.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ def vips2numpy(
)


def buffer2numpy(
buffer,
) -> np.ndarray:
"""Converts a VIPS image into a numpy array"""
return np.ndarray(
buffer=buffer,
dtype=VIPS_FORMAT_TO_DTYPE[buffer.format],
shape=[buffer.height, buffer.width, buffer.bands],
)


class VipsReader(ReaderBase):
def __init__(
self,
Expand Down Expand Up @@ -111,21 +100,23 @@ def get_patch(
patch = cropped
else:
patch = cropped.gravity(pos, width, height, background=bg)

return vips2numpy(patch) # self._rgba_to_rgb(patch)
patch = vips2numpy(patch)
return self._rgba_to_rgb(patch)

def get_level(self, level):
level = self.translate_level(level)
img = self._get_vips_level(level)
img = vips2numpy(img)
return img # self._rgba_to_rgb(img)
return self._rgba_to_rgb(img)

def _get_vips_level(self, level=0):
"""Lazy load and load only one for all image level"""
handler = self.__level_vips_handler.get(level)
if handler is None:
handler = vips.Image.new_from_file(
str(self.file), fail=True, level=level, rgb=True
str(self.file),
fail=True,
level=level,
)
self.__level_vips_handler[level] = handler
if self.caching:
Expand Down

0 comments on commit 3d3ea4a

Please sign in to comment.