#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

View File

@ -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

View File

@ -76,7 +76,9 @@ public class TGAImageReaderTest extends ImageReaderAbstractTest<TGAImageReader>
new TestData(getClassLoaderResource("/tga/XING_B32.TGA"), new Dimension(240, 164)), // Uncompressed 32 bit BGRA bottom/up
new TestData(getClassLoaderResource("/tga/XING_T16.TGA"), new Dimension(240, 164)), // Uncompressed 16 bit BGR top/down
new TestData(getClassLoaderResource("/tga/XING_T24.TGA"), new Dimension(240, 164)), // Uncompressed 24 bit BGR top/down
new TestData(getClassLoaderResource("/tga/XING_T32.TGA"), new Dimension(240, 164)) // Uncompressed 32 bit BGRA top/down
new TestData(getClassLoaderResource("/tga/XING_T32.TGA"), new Dimension(240, 164)), // Uncompressed 32 bit BGRA top/down
new TestData(getClassLoaderResource("/tga/autodesk-3dsmax-extsize494.tga"), new Dimension(440, 200)) // RLE compressed 32 bit BGRA bottom/up
);
}