Skip to content

Commit

Permalink
OIR: channel order and missing pixel block fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
melissalinkert committed Oct 26, 2023
1 parent 5692c44 commit 00b98ff
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion components/formats-gpl/src/loci/formats/in/OIRReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,9 @@ private void readXMLBlock(String file, RandomAccessInputStream s) throws FormatE
}
// total block length could include multiple strings of XML
int totalBlockLength = s.readInt();
LOGGER.debug("total block length = {}", totalBlockLength);
long end = s.getFilePointer() + totalBlockLength - 4;
LOGGER.debug("end = {}", end);
s.skipBytes(4);

while (s.getFilePointer() < end) {
Expand Down Expand Up @@ -735,6 +737,9 @@ else if (xmlLength < 0 || xmlLength >= (s.length() - s.getFilePointer())) {
long fp = s.getFilePointer();
String xml = s.readString(xmlLength).trim();
LOGGER.trace("xml = {}", xml);
if (!xml.startsWith("<?xml")) {
break;
}
if (isCurrentFile(file) || xml.indexOf("lut:LUT") > 0) {
parseXML(s, xml, fp);
}
Expand Down Expand Up @@ -1249,6 +1254,15 @@ private void parseImageProperties(Element root) throws FormatException {
parseChannel(channel, appendChannels);
}
}

// calls to parseChannel may have reset the channels list
// so there may be null elements that need to be removed
for (int i=0; i<channels.size(); i++) {
if (channels.get(i) == null) {
channels.remove(i);
i--;
}
}
}
}

Expand Down Expand Up @@ -1277,9 +1291,14 @@ private void parseChannel(Element channel, boolean appendChannels) {
channelName = name.getTextContent();
}

int index = Integer.parseInt(channel.getAttribute("order")) - 1;

if (id != null) {
boolean foundChannel = false;
for (Channel ch : channels) {
if (ch == null) {
continue;
}
if (ch.id.equals(id)) {
foundChannel = true;
if (laserId != null) {
Expand All @@ -1306,7 +1325,16 @@ private void parseChannel(Element channel, boolean appendChannels) {
}
}
}
channels.add(c);

while (index > channels.size()) {
channels.add(null);
}
if (index == channels.size()) {
channels.add(c);
}
else {
channels.set(index, c);
}
}
}
}
Expand Down

0 comments on commit 00b98ff

Please sign in to comment.