Skip to content

Commit

Permalink
Merge pull request #4076 from melissalinkert/vsi-updates
Browse files Browse the repository at this point in the history
VSI: fix uncompressed BGR data
  • Loading branch information
dgault committed Nov 15, 2023
2 parents 0026ed8 + 97b60fd commit e1aaf58
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions components/formats-gpl/src/loci/formats/in/CellSensReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -405,6 +406,7 @@ public class CellSensReader extends FormatReader {
private int previousTag = 0;

private ArrayList<Pyramid> pyramids = new ArrayList<Pyramid>();
private boolean[] bgr;

private transient boolean expectETS = false;
private transient int channelCount = 0;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -633,6 +639,7 @@ public void close(boolean fileOnly) throws IOException {
pyramids.clear();
channelCount = 0;
zCount = 0;
bgr = null;
}
}

Expand Down Expand Up @@ -755,6 +762,7 @@ else if (zCount > 0) {

IFDList exifs = parser.getExifIFDs();

bgr = new boolean[seriesCount];
int index = 0;
for (int s=0; s<seriesCount; s++) {
CoreMetadata ms = new CoreMetadata();
Expand Down Expand Up @@ -1010,11 +1018,11 @@ private int getTileSize() {
}

/**
* Get an object representing the pyramid which contains the
* Get an index to the pyramid which contains the
* current series/resolution. Accounts for flattened resolutions
* as needed.
*/
private Pyramid getCurrentPyramid() {
private int getCurrentPyramidIndex() {
int resIndex = getResolution();
int pyramidIndex = getSeries();
if (hasFlattenedResolutions()) {
Expand All @@ -1032,8 +1040,16 @@ private Pyramid getCurrentPyramid() {
}
}
}
return pyramidIndex;
}

return pyramids.get(pyramidIndex);
/**
* Get an object representing the pyramid which contains the
* current series/resolution. Accounts for flattened resolutions
* as needed.
*/
private Pyramid getCurrentPyramid() {
return pyramids.get(getCurrentPyramidIndex());
}

/**
Expand Down Expand Up @@ -1224,7 +1240,8 @@ private void parseETSFile(RandomAccessInputStream etsFile, String file, int s)
backgroundColor.put(getCoreIndex(), color);

etsFile.skipBytes(4 * 10 - color.length); // background color
etsFile.skipBytes(4); // component order
int componentOrder = etsFile.readInt();
bgr[s] = componentOrder == 1 && compressionType.get(compressionType.size() - 1) == RAW;
boolean usePyramid = etsFile.readInt() != 0;

ms.rgb = ms.sizeC > 1;
Expand Down

0 comments on commit e1aaf58

Please sign in to comment.