From 74d643e60de7e647a9484b3709ec85e532a9642c Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Mon, 23 Sep 2024 16:23:07 -0500 Subject: [PATCH 1/2] Fix `--fill-value` to use setFillColor(...) API ...so now this option can be used with all readers. --- .../bioformats2raw/BioTekReader.java | 2 +- .../bioformats2raw/Converter.java | 12 +++--------- .../bioformats2raw/MetaxpressReader.java | 4 ++-- .../bioformats2raw/MiraxReader.java | 17 ++++++++++++----- .../bioformats2raw/ND2PlateReader.java | 2 +- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/BioTekReader.java b/src/main/java/com/glencoesoftware/bioformats2raw/BioTekReader.java index b201a6d4..9822e681 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/BioTekReader.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/BioTekReader.java @@ -176,7 +176,7 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) { FormatTools.checkPlaneParameters(this, no, buf.length, x, y, w, h); - Arrays.fill(buf, (byte) 0); + Arrays.fill(buf, getFillColor()); BioTekWell well = wells.get(getWellIndex(getSeries())); String file = well.getFile(getFieldIndex(getSeries()), getZCTCoords(no)); diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java index ca54f63e..71e50f69 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java @@ -708,8 +708,7 @@ public void setOverwrite(boolean canOverwrite) { */ @Option( names = "--fill-value", - description = "Default value to fill in for missing tiles (0-255)" + - " (currently .mrxs only)", + description = "Default value to fill in for missing tiles (0-255)", defaultValue = Option.NULL_VALUE ) public void setFillValue(Short tileFill) { @@ -1251,11 +1250,6 @@ public void convert() // First find which reader class we need Class readerClass = getBaseReaderClass(); - if (!readerClass.equals(MiraxReader.class) && fillValue != null) { - throw new IllegalArgumentException( - "--fill-value not yet supported for " + readerClass); - } - // Now with our found type instantiate our queue of readers for use // during conversion boolean savedMemoFile = false; @@ -1264,8 +1258,8 @@ public void convert() Memoizer memoizer; try { reader = (IFormatReader) readerClass.getConstructor().newInstance(); - if (fillValue != null && reader instanceof MiraxReader) { - ((MiraxReader) reader).setFillValue(fillValue.byteValue()); + if (fillValue != null) { + reader.setFillColor(fillValue.byteValue()); } memoizer = createMemoizer(reader); } diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/MetaxpressReader.java b/src/main/java/com/glencoesoftware/bioformats2raw/MetaxpressReader.java index 3927fb9a..6bdb6f9b 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/MetaxpressReader.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/MetaxpressReader.java @@ -114,12 +114,12 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) planeReader.openBytes(0, buf, x, y, w, h); } catch (IOException e) { - Arrays.fill(buf, (byte) 0); + Arrays.fill(buf, getFillColor()); } s.stop("openBytes(0) on " + file); } else { - Arrays.fill(buf, (byte) 0); + Arrays.fill(buf, getFillColor()); } return buf; diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/MiraxReader.java b/src/main/java/com/glencoesoftware/bioformats2raw/MiraxReader.java index 1fbe7b11..941b69fd 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/MiraxReader.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/MiraxReader.java @@ -131,7 +131,6 @@ public class MiraxReader extends FormatReader { JPEG2000CodecOptions.getDefaultOptions(); private boolean fluorescence = false; - private Byte fillValue = null; private transient JPEGXRCodec jpegxrCodec = new JPEGXRCodec(); @@ -217,7 +216,7 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) // set background color to black instead of the stored fill color // this is to match the default behavior of Pannoramic Viewer - Arrays.fill(buf, getFillValue()); + Arrays.fill(buf, getFillColor()); if (tileCache == null) { tileCache = CacheBuilder.newBuilder() @@ -1057,9 +1056,10 @@ else if (name.equals("VIMSLIDE_POSITION_BUFFER")) { * Set the fill value for missing tiles. * * @param fill the fill value, or null to use the reader's default value + * @deprecated used setFillColor(Byte) */ public void setFillValue(Byte fill) { - fillValue = fill; + setFillColor(fill); } /** @@ -1069,10 +1069,17 @@ public void setFillValue(Byte fill) { * for brightfield. * * @return fill value for missing tiles + * @deprecated use getFillColor() */ public byte getFillValue() { - if (fillValue != null) { - return fillValue; + return getFillColor(); + } + + @Override + public Byte getFillColor() { + Byte color = getFillColor(); + if (color != null) { + return color; } return fluorescence ? (byte) 0 : (byte) 255; } diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/ND2PlateReader.java b/src/main/java/com/glencoesoftware/bioformats2raw/ND2PlateReader.java index e40d9b9c..97467299 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/ND2PlateReader.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/ND2PlateReader.java @@ -90,7 +90,7 @@ public String[] getSeriesUsedFiles(boolean noPixels) { public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) throws FormatException, IOException { - Arrays.fill(buf, (byte) 0); + Arrays.fill(buf, getFillColor()); int fileIndex = getFileIndex(getSeries()); if (fileIndex >= 0 && fileIndex < files.length) { From e3dd7ca5345b1a5ff02ff7d3dc4fe2fa4e93f8da Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Mon, 30 Sep 2024 10:55:01 -0500 Subject: [PATCH 2/2] Fix getFillColor() implementation --- .../java/com/glencoesoftware/bioformats2raw/MiraxReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/MiraxReader.java b/src/main/java/com/glencoesoftware/bioformats2raw/MiraxReader.java index 941b69fd..4c1c1529 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/MiraxReader.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/MiraxReader.java @@ -1077,7 +1077,7 @@ public byte getFillValue() { @Override public Byte getFillColor() { - Byte color = getFillColor(); + Byte color = super.getFillColor(); if (color != null) { return color; }