From b3b13103713b238d368a0d0dea5cfd993b651f01 Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 2 Feb 2018 16:07:10 -0500 Subject: [PATCH 1/2] handle garbled files with jpg compression problem. --- src/openslide-vendor-aperio.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/openslide-vendor-aperio.c b/src/openslide-vendor-aperio.c index 650401de6..031018a2a 100644 --- a/src/openslide-vendor-aperio.c +++ b/src/openslide-vendor-aperio.c @@ -159,9 +159,32 @@ static bool decode_tile(struct level *l, break; default: // not for us? fallback - return _openslide_tiff_read_tile(tiffl, tiff, dest, + + if (!_openslide_tiff_read_tile(tiffl, tiff, dest, tile_col, tile_row, - err); + err)) { + + // In some Aperio images, one tile (typically 0, 0), in one or more levels, + // is partly overwritten with some unknown data. This seems to happen + // from byte 0 or byte 1 of the tile data. Such garbled tiles are + // impossible to read, so just return false! + // The other half of this fix/hack consists of calling render_missing_tile + // if _openslide_tiff_read_tile_data returns false. + void *buf; + int32_t buflen; + if (_openslide_tiff_read_tile_data(tiffl, tiff, + &buf, &buflen, + tile_col, tile_row, + err)) { + const unsigned char *bytes = buf; + if (bytes[0] == 0x11 || (bytes[0] == 0xff && bytes[1] == 0x11)) { + return render_missing_tile(l, tiff, dest, tile_col, tile_row, err); + } else { + return false; + } + } + } + return true; } // read raw tile From de6a3fb3a29779f15f0c3677a0edc7e0cfca282d Mon Sep 17 00:00:00 2001 From: Peter Date: Wed, 13 Jun 2018 18:43:37 -0400 Subject: [PATCH 2/2] Set openslide cache to 0 for no caching. --- src/openslide.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openslide.c b/src/openslide.c index d32c8e236..2fd339eb3 100644 --- a/src/openslide.c +++ b/src/openslide.c @@ -344,8 +344,8 @@ openslide_t *openslide_open(const char *filename) { osr->property_names = strv_from_hashtable_keys(osr->properties); // start cache - osr->cache = _openslide_cache_create(_OPENSLIDE_USEFUL_CACHE_SIZE); - //osr->cache = _openslide_cache_create(0); + //osr->cache = _openslide_cache_create(_OPENSLIDE_USEFUL_CACHE_SIZE); + osr->cache = _openslide_cache_create(0); return osr; }