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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just |
||
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("=\""); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!inPixels
?There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.