diff --git a/src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp b/src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp index b7c837049..1db66974b 100644 --- a/src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp @@ -146,6 +146,7 @@ void TgaImporterTest::colorBits24() { std::optional image = importer.image2D(0); CORRADE_VERIFY(image); + CORRADE_COMPARE(image->storage().alignment(), 1); CORRADE_COMPARE(image->format(), PixelFormat::RGB); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), PixelType::UnsignedByte); @@ -170,6 +171,7 @@ void TgaImporterTest::colorBits32() { std::optional image = importer.image2D(0); CORRADE_VERIFY(image); + CORRADE_COMPARE(image->storage().alignment(), 4); CORRADE_COMPARE(image->format(), PixelFormat::RGBA); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), PixelType::UnsignedByte); @@ -189,6 +191,7 @@ void TgaImporterTest::grayscaleBits8() { std::optional image = importer.image2D(0); CORRADE_VERIFY(image); + CORRADE_COMPARE(image->storage().alignment(), 1); #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(image->format(), PixelFormat::Red); #else diff --git a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp index 9a8ceb5e3..ffc3f2709 100644 --- a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp +++ b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp @@ -136,6 +136,11 @@ std::optional TgaImporter::doImage2D(UnsignedInt) { Containers::Array data{dataSize}; in->read(data, dataSize); + /* Adjust pixel storage if row size is not four byte aligned */ + PixelStorage storage; + if((header.width*header.bpp/8)%4 != 0) + storage.setAlignment(1); + Vector2i size(header.width, header.height); if(format == PixelFormat::RGB) { @@ -148,7 +153,7 @@ std::optional TgaImporter::doImage2D(UnsignedInt) { [](Math::Vector4 pixel) { return Math::swizzle<'b', 'g', 'r', 'a'>(pixel); }); } - return ImageData2D{format, PixelType::UnsignedByte, size, std::move(data)}; + return ImageData2D{storage, format, PixelType::UnsignedByte, size, std::move(data)}; } }} diff --git a/src/MagnumPlugins/TgaImporter/TgaImporter.h b/src/MagnumPlugins/TgaImporter/TgaImporter.h index 4c3e80c71..e8cd587ea 100644 --- a/src/MagnumPlugins/TgaImporter/TgaImporter.h +++ b/src/MagnumPlugins/TgaImporter/TgaImporter.h @@ -64,9 +64,13 @@ package in CMake and link to `${MAGNUM_TGAIMPORTER_LIBRARIES}`. See The images are imported with @ref PixelType::UnsignedByte and @ref PixelFormat::RGB, @ref PixelFormat::RGBA or @ref PixelFormat::Red, respectively. Grayscale images -require extension @extension{ARB,texture_rg}. In OpenGL ES 2.0, if -@es_extension{EXT,texture_rg} is not supported and in WebGL 1.0, grayscale -images use @ref PixelFormat::Luminance instead of @ref PixelFormat::Red. +require extension @extension{ARB,texture_rg}. Imported images are imported with +default @ref PixelStorage parameters except for alignment, which may be changed +to `1` if the data require it. + +In OpenGL ES 2.0, if @es_extension{EXT,texture_rg} is not supported and in +WebGL 1.0, grayscale images use @ref PixelFormat::Luminance instead of +@ref PixelFormat::Red. */ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { public: