From 0db8e6c4a3d898ab250aa813a24170e76b00a46a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 15 Jan 2023 12:50:19 +0100 Subject: [PATCH] TgaImporter: simplify RLE detection. --- src/MagnumPlugins/TgaImporter/TgaImporter.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp index 643a560ce..4dced365f 100644 --- a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp +++ b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp @@ -97,11 +97,11 @@ Containers::Optional TgaImporter::doImage2D(UnsignedInt, UnsignedIn return {}; } + /* RLE encoding. Reference: http://www.paulbourke.net/dataformats/tga/ */ + const bool rle = (header.imageType & 8); + /* Color */ - bool rle = false; - if(header.imageType == 2 || header.imageType == 10) { - /* Reference: http://www.paulbourke.net/dataformats/tga/ */ - rle = header.imageType == 10; + if((header.imageType & ~8) == 2) { switch(header.bpp) { case 24: format = PixelFormat::RGB8Unorm; @@ -115,11 +115,7 @@ Containers::Optional TgaImporter::doImage2D(UnsignedInt, UnsignedIn } /* Grayscale */ - } else if(header.imageType == 3 || header.imageType == 11) { - /* I only discovered this by accident when using ImageMagick's - mogrify -compression RunLengthEncoded file.tga - as far as I could find, it's not documented in any TGA specs */ - rle = header.imageType == 11; + } else if((header.imageType & ~8) == 3) { format = PixelFormat::R8Unorm; if(header.bpp != 8) { Error() << "Trade::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp;