From 8f0174e2efd3838e16760e6b33d2940835f6b085 Mon Sep 17 00:00:00 2001 From: swg08 Date: Sun, 7 Jan 2024 21:57:24 +0100 Subject: [PATCH 1/2] Issue 4110: Consider ZSTD_0 and ZSTD_1 compressed datasets to also be considered for pyramid level evaluation. Issue 4102: Fix an integer arithmetic issue by using floating point arithmetic. -> divide with floating point precision and make sure to round to up or down to the next integer value - not truncation rounding. --- .../src/loci/formats/in/ZeissCZIReader.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/formats-gpl/src/loci/formats/in/ZeissCZIReader.java b/components/formats-gpl/src/loci/formats/in/ZeissCZIReader.java index 1e71c08557b..3acd92c2568 100644 --- a/components/formats-gpl/src/loci/formats/in/ZeissCZIReader.java +++ b/components/formats-gpl/src/loci/formats/in/ZeissCZIReader.java @@ -734,7 +734,6 @@ protected void initFile(String id) throws FormatException, IOException { convertPixelType(planes.get(0).directoryEntry.pixelType); // remove any invalid SubBlocks - int bpp = FormatTools.getBytesPerPixel(getPixelType()); if (isRGB()) { bpp *= (getSizeC() / originalC); @@ -743,16 +742,18 @@ protected void initFile(String id) throws FormatException, IOException { for (int i=0; i= Integer.MAX_VALUE || size < 0) { // check for reduced resolution in the pyramid DimensionEntry[] entries = planes.get(i).directoryEntry.dimensionEntries; int pyramidType = planes.get(i).directoryEntry.pyramidType; - if ((pyramidType == 1 || pyramidType == 2 || compression == JPEGXR) && - (compression == JPEGXR || size == entries[0].storedSize * entries[1].storedSize * bpp)) + if (isCompressed || + ((pyramidType == 1 || pyramidType == 2 ) && (size == entries[0].storedSize * entries[1].storedSize * bpp))) { - int scale = planes.get(i).x / entries[0].storedSize; + // circumvent integer arithmetic rounding issue by using floating point precision calculation (see issue #4102) + int scale = (int)((double)planes.get(i).x / (double)entries[0].storedSize + 0.5); if (scale == 1 || (((scale % 2) == 0 || (scale % 3) == 0) && allowAutostitching())) { if (scale > 1 && scaleFactor == 0) { scaleFactor = scale % 2 == 0 ? 2 : 3; From f3b162f94d93f9d9c9c181bad851970f79cb1a43 Mon Sep 17 00:00:00 2001 From: swg08 <46338941+swg08@users.noreply.github.com> Date: Mon, 5 Feb 2024 23:27:12 +0100 Subject: [PATCH 2/2] Update ZeissCZIReader.java Change log level of ZSTD1 without hi/lo flag from warning to debug. Rationale: The image data is still usable and valid in that case. Changing to debug information. --- components/formats-gpl/src/loci/formats/in/ZeissCZIReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/formats-gpl/src/loci/formats/in/ZeissCZIReader.java b/components/formats-gpl/src/loci/formats/in/ZeissCZIReader.java index 4cb9a62b184..c05d47da625 100644 --- a/components/formats-gpl/src/loci/formats/in/ZeissCZIReader.java +++ b/components/formats-gpl/src/loci/formats/in/ZeissCZIReader.java @@ -4187,7 +4187,7 @@ public byte[] readPixelData(RandomAccessInputStream s, Region tile, byte[] buf) } } else { - LOGGER.warn("ZSTD-1 compression used, but no high/low byte unpacking"); + LOGGER.debug("ZSTD-1 compression used, but no high/low byte unpacking"); data = decoded; }