diff --git a/CHANGELOG.md b/CHANGELOG.md index 693da9e99..f5432481e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Improvements - Reduce stderr noise in PIL and rasterio sources ([#1397](../../pull/1397)) - Harden OME tiff reader ([#1398](../../pull/1398)) +- Improve checks for formats we shouldn't read ([#1399](../../pull/1399)) ### Bug Fixes - Fix an issue emitting geojson annotations ([#1395](../../pull/1395)) diff --git a/docs/config_options.rst b/docs/config_options.rst index 2271087b0..2063870b1 100644 --- a/docs/config_options.rst +++ b/docs/config_options.rst @@ -1,7 +1,7 @@ Configuration Options ===================== -Some functionality of large_image is controlled through configuration parameters. These can be read or set via python using functions in the ``large_image.config`` module, `getConfig <./large_image/large_image.html#large_image.config.getConfig>`_ and `setConfig <./large_image/large_image.html#large_image.config.setConfig>`_. +Some functionality of large_image is controlled through configuration parameters. These can be read or set via python using functions in the ``large_image.config`` module, `getConfig <./_build/large_image/large_image.html#large_image.config.getConfig>`_ and `setConfig <./_build/large_image/large_image.html#large_image.config.setConfig>`_. Configuration parameters: diff --git a/sources/pil/large_image_source_pil/__init__.py b/sources/pil/large_image_source_pil/__init__.py index 5ac2fb726..12762c63f 100644 --- a/sources/pil/large_image_source_pil/__init__.py +++ b/sources/pil/large_image_source_pil/__init__.py @@ -14,6 +14,7 @@ # limitations under the License. ############################################################################# +import contextlib import json import math import os @@ -202,18 +203,17 @@ def _fromRawpy(self, largeImagePath): try: import rawpy - rgb = rawpy._rawpy.RawPy(1) - rgb.open_file(largeImagePath) - rgb = rgb.postprocess() - rgb = large_image.tilesource.utilities._imageToNumpy(rgb)[0] - if rgb.shape[2] == 2: - rgb = rgb[:, :, :1] - elif rgb.shape[2] > 3: - rgb = rgb[:, :, :3] - self._pilImage = PIL.Image.fromarray( - rgb.astype(np.uint8) if rgb.dtype != np.uint16 else rgb, - ('RGB' if rgb.dtype != np.uint16 else 'RGB;16') if rgb.shape[2] == 3 else - ('L' if rgb.dtype != np.uint16 else 'L;16')) + with contextlib.redirect_stderr(open(os.devnull, 'w')): + rgb = rawpy.imread(largeImagePath).postprocess() + rgb = large_image.tilesource.utilities._imageToNumpy(rgb)[0] + if rgb.shape[2] == 2: + rgb = rgb[:, :, :1] + elif rgb.shape[2] > 3: + rgb = rgb[:, :, :3] + self._pilImage = PIL.Image.fromarray( + rgb.astype(np.uint8) if rgb.dtype != np.uint16 else rgb, + ('RGB' if rgb.dtype != np.uint16 else 'RGB;16') if rgb.shape[2] == 3 else + ('L' if rgb.dtype != np.uint16 else 'L;16')) except Exception: pass diff --git a/sources/tifffile/large_image_source_tifffile/__init__.py b/sources/tifffile/large_image_source_tifffile/__init__.py index 0ce7aeb84..4bf1e8ec2 100644 --- a/sources/tifffile/large_image_source_tifffile/__init__.py +++ b/sources/tifffile/large_image_source_tifffile/__init__.py @@ -498,6 +498,8 @@ def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, **kwargs): if sidx not in self._zarrcache: if len(self._zarrcache) > 10: self._zarrcache = {} + if self.frames > 1: + series.keyframe.nodata = None za = zarr.open(series.aszarr(), mode='r') hasgbs = hasattr(za[0], 'get_basic_selection') self._zarrcache[sidx] = (za, hasgbs) diff --git a/test/test_source_base.py b/test/test_source_base.py index f2d45065c..e71152e45 100644 --- a/test/test_source_base.py +++ b/test/test_source_base.py @@ -84,7 +84,7 @@ 'skipTiles': r'(sample_image\.ptif|one_layer_missing_tiles)'}, 'tifffile': { 'read': r'', - 'noread': r'((\.(nc|nd2|yml|yaml|json|czi|png|jpg|jpeg|jp2|dcm|zarr\.db|zarr\.zip)$)' + + 'noread': r'((\.(nc|nd2|yml|yaml|json|czi|png|jpg|jpeg|jp2|dcm|zarr\.db|zarr\.zip)|(nokeyframe\.ome\.tiff|XY01\.ome\.tif)$)' + # noqa (r'|bad_axes' if sys.version_info < (3, 9) else '') + r')', },