Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OIR: channel order and missing pixel block fixes #4111

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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