From feeb527f1a2098bde1ab20a2d0800d58507030fa Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Tue, 8 Aug 2023 10:16:35 -0500 Subject: [PATCH 1/2] VSI: handle BGR data Fixes #3819 --- .../src/loci/formats/in/CellSensReader.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/components/formats-gpl/src/loci/formats/in/CellSensReader.java b/components/formats-gpl/src/loci/formats/in/CellSensReader.java index c07af03329f..d1f0558e981 100644 --- a/components/formats-gpl/src/loci/formats/in/CellSensReader.java +++ b/components/formats-gpl/src/loci/formats/in/CellSensReader.java @@ -42,6 +42,7 @@ import loci.formats.FormatReader; import loci.formats.FormatTools; import loci.formats.IFormatReader; +import loci.formats.ImageTools; import loci.formats.MetadataTools; import loci.formats.codec.Codec; import loci.formats.codec.CodecOptions; @@ -405,6 +406,7 @@ public class CellSensReader extends FormatReader { private int previousTag = 0; private ArrayList pyramids = new ArrayList(); + private boolean[] bgr; private transient boolean expectETS = false; private transient int channelCount = 0; @@ -536,8 +538,8 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) Region intersection = null; byte[] tileBuf = null; - int pixel = - getRGBChannelCount() * FormatTools.getBytesPerPixel(getPixelType()); + int bpp = FormatTools.getBytesPerPixel(getPixelType()); + int pixel = getRGBChannelCount() * bpp; int outputRowLen = w * pixel; Pyramid pyramid = getCurrentPyramid(); @@ -588,6 +590,10 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) } } + if (bgr[getCurrentPyramidIndex()]) { + ImageTools.bgrToRgb(buf, isInterleaved(), bpp, getRGBChannelCount()); + } + return buf; } else { @@ -633,6 +639,7 @@ public void close(boolean fileOnly) throws IOException { pyramids.clear(); channelCount = 0; zCount = 0; + bgr = null; } } @@ -755,6 +762,7 @@ else if (zCount > 0) { IFDList exifs = parser.getExifIFDs(); + bgr = new boolean[seriesCount]; int index = 0; for (int s=0; s 1; From 97b60fd83d4d42a8bdd015657b629802cb277a46 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Tue, 8 Aug 2023 12:05:08 -0500 Subject: [PATCH 2/2] Restrict BGR swapping to uncompressed data only Other compression types appear to handle this internally without requiring correction. --- components/formats-gpl/src/loci/formats/in/CellSensReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/formats-gpl/src/loci/formats/in/CellSensReader.java b/components/formats-gpl/src/loci/formats/in/CellSensReader.java index d1f0558e981..04cf9190152 100644 --- a/components/formats-gpl/src/loci/formats/in/CellSensReader.java +++ b/components/formats-gpl/src/loci/formats/in/CellSensReader.java @@ -1241,7 +1241,7 @@ private void parseETSFile(RandomAccessInputStream etsFile, String file, int s) etsFile.skipBytes(4 * 10 - color.length); // background color int componentOrder = etsFile.readInt(); - bgr[s] = componentOrder == 1; + bgr[s] = componentOrder == 1 && compressionType.get(compressionType.size() - 1) == RAW; boolean usePyramid = etsFile.readInt() != 0; ms.rgb = ms.sizeC > 1;