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

OMEXMLReader: Handle BinData in non-Pixels elements such as Mask #2682

Merged
merged 2 commits into from Dec 6, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 30 additions & 21 deletions components/formats-bsd/src/loci/formats/in/OMEXMLReader.java
Expand Up @@ -338,67 +338,76 @@ class OMEXMLHandler extends BaseHandler {
private final StringBuilder xmlBuffer;
private String currentQName;
private Locator locator;
private boolean inPixels;

public OMEXMLHandler() {
xmlBuffer = new StringBuilder();
inPixels = false;
}

@Override
public void characters(char[] ch, int start, int length) {
if (currentQName.indexOf("BinData") < 0) {
if (currentQName.indexOf("BinData") < 0 || inPixels == false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!inPixels?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if fiddling anyway then maybe put it first given shortcut logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed fixes for these, thanks.

xmlBuffer.append(new String(ch, start, length));
}
}

@Override
public void endElement(String uri, String localName, String qName) {
if (qName.indexOf("Pixels") != -1) {
inPixels = false;
}

xmlBuffer.append("</");
xmlBuffer.append(qName);
xmlBuffer.append(">");
}

@Override
public void startElement(String ur, String localName, String qName,
public void startElement(String uri, String localName, String qName,
Attributes attributes)
{
currentQName = qName;

if (qName.indexOf("BinData") == -1) {
if (qName.indexOf("Pixels") != -1) {
inPixels = true;
}

if (qName.indexOf("BinData") != -1 && inPixels == true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just inPixels instead of inPixels == true?

binData.add(
new BinData(locator.getLineNumber(), locator.getColumnNumber()));
String compress = attributes.getValue("Compression");
compression.add(compress == null ? "" : compress);

xmlBuffer.append("<");
xmlBuffer.append(qName);
for (int i=0; i<attributes.getLength(); i++) {
String key = XMLTools.escapeXML(attributes.getQName(i));
String value = XMLTools.escapeXML(attributes.getValue(i));
if (key.equals("BigEndian")) {
String endian = value.toLowerCase();
if (!endian.equals("true") && !endian.equals("false")) {
// hack for files that specify 't' or 'f' instead of
// 'true' or 'false'
if (endian.startsWith("t")) endian = "true";
else if (endian.startsWith("f")) endian = "false";
}
value = endian;
}
if (key.equals("Length")) value = "0";
xmlBuffer.append(" ");
xmlBuffer.append(key);
xmlBuffer.append("=\"");
xmlBuffer.append(value);
xmlBuffer.append("\"");
}
xmlBuffer.append(">");
}
else {
binData.add(
new BinData(locator.getLineNumber(), locator.getColumnNumber()));
String compress = attributes.getValue("Compression");
compression.add(compress == null ? "" : compress);

} else {
xmlBuffer.append("<");
xmlBuffer.append(qName);
for (int i=0; i<attributes.getLength(); i++) {
String key = XMLTools.escapeXML(attributes.getQName(i));
String value = XMLTools.escapeXML(attributes.getValue(i));
if (key.equals("Length")) value = "0";
if (key.equals("BigEndian")) {
String endian = value.toLowerCase();
if (!endian.equals("true") && !endian.equals("false")) {
// hack for files that specify 't' or 'f' instead of
// 'true' or 'false'
if (endian.startsWith("t")) endian = "true";
else if (endian.startsWith("f")) endian = "false";
}
value = endian;
}
xmlBuffer.append(" ");
xmlBuffer.append(key);
xmlBuffer.append("=\"");
Expand Down