mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-05-28 00:00:03 -04:00
Fix bug in 0-terminated ASCII string parsing + test.
This commit is contained in:
+1
@@ -162,6 +162,7 @@ final class TGAExtensions {
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
if (data[i] == 0) {
|
||||
len = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-11
@@ -393,27 +393,22 @@ final class TGAImageReader extends ImageReaderBase {
|
||||
|
||||
// Read header
|
||||
header = TGAHeader.read(imageInput);
|
||||
|
||||
// System.err.println("header: " + header);
|
||||
|
||||
imageInput.flushBefore(imageInput.getStreamPosition());
|
||||
|
||||
// Read footer, if 2.0 format (ends with TRUEVISION-XFILE\0)
|
||||
skipToEnd(imageInput);
|
||||
imageInput.seek(imageInput.getStreamPosition() - 26);
|
||||
|
||||
long extOffset = imageInput.readInt();
|
||||
/*long devOffset = */imageInput.readInt(); // Ignored for now
|
||||
long extOffset = imageInput.readUnsignedInt();
|
||||
/*long devOffset = */imageInput.readUnsignedInt(); // Ignored for now
|
||||
|
||||
byte[] magic = new byte[18];
|
||||
imageInput.readFully(magic);
|
||||
|
||||
if (Arrays.equals(magic, TGA.MAGIC)) {
|
||||
if (extOffset > 0) {
|
||||
imageInput.seek(extOffset);
|
||||
int extSize = imageInput.readUnsignedShort();
|
||||
extensions = extSize == 0 ? null : TGAExtensions.read(imageInput, extSize);
|
||||
}
|
||||
if (Arrays.equals(magic, TGA.MAGIC) && extOffset > 0) {
|
||||
imageInput.seek(extOffset);
|
||||
int extSize = imageInput.readUnsignedShort();
|
||||
extensions = extSize == 0 ? null : TGAExtensions.read(imageInput, extSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -296,7 +296,7 @@ final class TGAMetadata extends AbstractMetadata {
|
||||
}
|
||||
|
||||
if (extensions != null) {
|
||||
appendTextEntry(text, "Software", extensions.getSoftwareVersion() == null ? extensions.getSoftware() : extensions.getSoftware() + " " + extensions.getSoftwareVersion());
|
||||
appendTextEntry(text, "Software", extensions.getSoftwareVersion() == null ? extensions.getSoftware() : (extensions.getSoftware() + " " + extensions.getSoftwareVersion()));
|
||||
appendTextEntry(text, "Artist", extensions.getAuthorName());
|
||||
appendTextEntry(text, "UserComment", extensions.getAuthorComments());
|
||||
}
|
||||
@@ -305,7 +305,7 @@ final class TGAMetadata extends AbstractMetadata {
|
||||
}
|
||||
|
||||
private void appendTextEntry(final IIOMetadataNode parent, final String keyword, final String value) {
|
||||
if (value != null) {
|
||||
if (value != null && !value.isEmpty()) {
|
||||
IIOMetadataNode textEntry = new IIOMetadataNode("TextEntry");
|
||||
parent.appendChild(textEntry);
|
||||
textEntry.setAttribute("keyword", keyword);
|
||||
|
||||
Reference in New Issue
Block a user