diff --git a/components/formats-gpl/src/loci/formats/in/FlexReader.java b/components/formats-gpl/src/loci/formats/in/FlexReader.java index 6b89bb01867..cc53bbd648a 100644 --- a/components/formats-gpl/src/loci/formats/in/FlexReader.java +++ b/components/formats-gpl/src/loci/formats/in/FlexReader.java @@ -251,8 +251,14 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h) new RandomAccessInputStream(getFileHandle(file.file))) { IFD ifd; if (file.offsets == null) { - ifd = file.ifds.get(imageNumber); - factor = 1d; + if (imageNumber < file.ifds.size()) { + ifd = file.ifds.get(imageNumber); + factor = 1d; + } + else { + Arrays.fill(buf, (byte) 0); + return buf; + } } else { // Only the first IFD was read. Hack the IFD to adjust the offset. @@ -1211,6 +1217,7 @@ private void groupFiles(String[] fileList, MetadataStore store) HashMap> v = new HashMap>(); Boolean firstCompressed = null; int firstIFDCount = 0; + String firstBarcode = null; for (String file : fileList) { LOGGER.warn("parsing {}", file); IFD firstIFD = null; @@ -1226,7 +1233,23 @@ private void groupFiles(String[] fileList, MetadataStore store) firstCompressed = compressed; firstIFDCount = ifdCount; } - if (compressed == firstCompressed && ifdCount == firstIFDCount) { + String xml = XMLTools.sanitizeXML(firstIFD.getIFDStringValue(FLEX)); + int barcodeIndex = xml.indexOf("Barcode"); + String barcode = ""; + if (barcodeIndex >= 0) { + int start = xml.indexOf(">", barcodeIndex) + 1; + int end = xml.indexOf("<", barcodeIndex); + if (start > 0 && end > 0) { + barcode = xml.substring(start, end); + } + } + if (firstBarcode == null) { + firstBarcode = barcode; + } + + if (compressed == firstCompressed && barcode.equals(firstBarcode) && + ifdCount <= firstIFDCount) + { int[] well = getWell(file); int field = getField(file); if (well[0] > nRows) nRows = well[0];