From b8bfa77cc238a236e2470268cd70b036b4e6613e Mon Sep 17 00:00:00 2001 From: Yoshihiro OKUMURA Date: Wed, 12 Oct 2022 19:42:09 +0900 Subject: [PATCH] perform auto scalling if 16bit or gray scale thumbnail image. --- .../riken/neurodata/tools/BioFormatsImageThumbnail.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/jp/riken/neurodata/tools/BioFormatsImageThumbnail.java b/src/main/java/jp/riken/neurodata/tools/BioFormatsImageThumbnail.java index e3a9014..81044fc 100644 --- a/src/main/java/jp/riken/neurodata/tools/BioFormatsImageThumbnail.java +++ b/src/main/java/jp/riken/neurodata/tools/BioFormatsImageThumbnail.java @@ -21,7 +21,6 @@ import javax.imageio.stream.ImageOutputStream; import loci.common.DebugTools; import loci.formats.FormatException; -import loci.formats.FormatTools; import loci.formats.ImageReader; import loci.formats.gui.AWTImageTools; import loci.formats.gui.BufferedImageReader; @@ -179,13 +178,15 @@ public class BioFormatsImageThumbnail { // System.out.println("resolution: " + reader.getResolutionCount()); // System.out.println("thubmail series: " + series); ret = reader.openThumbImage(no); - if (!FormatTools.isFloatingPoint(reader.getPixelType())) { - // auto scalling floating point thumbnail. + final boolean is16bit = reader.getBitsPerPixel() > 8; + final boolean isGrayScale = ret.getSampleModel().getNumBands() == 1; + if (is16bit || isGrayScale) { + // perform auto scalling if 16bit or gray scale thumbnail image. ret = AWTImageTools.autoscale(ret); } } catch (final Throwable t) { for (Throwable e = t; e != null; e = e.getCause()) { - if (t instanceof OutOfMemoryError) { + if (e instanceof OutOfMemoryError) { throw new BioFormatsImageException("out of memory"); } }