#466 TGA extension size fix for 3ds max files

This commit is contained in:
Harald Kuhr
2020-08-07 11:24:55 +02:00
parent 9dae58d5a6
commit 49c7cd1979
3 changed files with 9 additions and 6 deletions
@@ -72,8 +72,9 @@ final class TGAExtensions {
static TGAExtensions read(final ImageInputStream stream) throws IOException {
int extSize = stream.readUnsignedShort();
// Should always be 495 for version 2.0, no newer version exists...
if (extSize < EXT_AREA_SIZE) {
// Should always be 495 for version 2.0, no newer version exists.
// NOTE: Known AutoDesk 3ds Max issue, extension area size field is 494, but still good.
if (extSize < EXT_AREA_SIZE - 1) {
throw new IIOException(String.format("TGA Extension Area size less than %d: %d", EXT_AREA_SIZE, extSize));
}
@@ -89,10 +90,10 @@ final class TGAExtensions {
// Software version (* 100) short + single byte ASCII (ie. 101 'b' for 1.01b)
int softwareVersion = stream.readUnsignedShort();
int softwareLetter = stream.readByte();
char softwareLetter = (char) stream.readByte();
extensions.softwareVersion = softwareVersion != 0 && softwareLetter != ' '
? String.format("%d.%d%d", softwareVersion / 100, softwareVersion % 100, softwareLetter).trim()
extensions.softwareVersion = softwareVersion != 0 || softwareLetter != ' '
? String.format("%d.%d%s", softwareVersion / 100, softwareVersion % 100, softwareLetter).trim()
: null;
extensions.backgroundColor = stream.readInt(); // ARGB