diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 7f084bacd..67806a31b 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -95,15 +95,26 @@ void TgaImporterTest::bits24() { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0, 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8 }; + #ifndef MAGNUM_TARGET_GLES + const char* pixels = data + 18; + #else + const char pixels[] = { + 3, 2, 1, 4, 3, 2, 5, 4, 3, 6, 5, 4, 7, 6, 5, 8, 7, 6 + }; + #endif std::istringstream in(string(data, sizeof(data))); TgaImporter importer; CORRADE_VERIFY(importer.open(in)); auto image = importer.image2D(0); + #ifndef MAGNUM_TARGET_GLES CORRADE_VERIFY(image->components() == AbstractImage::Components::BGR); + #else + CORRADE_VERIFY(image->components() == AbstractImage::Components::RGB); + #endif CORRADE_COMPARE(image->dimensions(), Math::Vector2(2, 3)); CORRADE_VERIFY(image->type() == TypeTraits::imageType()); - CORRADE_COMPARE(string(static_cast(image->data()), 2*3*3), string(data + 18, 2*3*3)); + CORRADE_COMPARE(string(static_cast(image->data()), 2*3*3), string(pixels, 2*3*3)); } void TgaImporterTest::bits32() { @@ -111,15 +122,26 @@ void TgaImporterTest::bits32() { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 32, 0, 1, 2, 3, 1, 2, 3, 4, 1, 3, 4, 5, 1, 4, 5, 6, 1, 5, 6, 7, 1, 6, 7, 8, 1 }; + #ifndef MAGNUM_TARGET_GLES + const char* pixels = data + 18; + #else + const char pixels[] = { + 3, 2, 1, 1, 4, 3, 2, 1, 5, 4, 3, 1, 6, 5, 4, 1, 7, 6, 5, 1, 8, 7, 6, 1 + }; + #endif std::istringstream in(string(data, sizeof(data))); TgaImporter importer; CORRADE_VERIFY(importer.open(in)); auto image = importer.image2D(0); + #ifndef MAGNUM_TARGET_GLES CORRADE_VERIFY(image->components() == AbstractImage::Components::BGRA); + #else + CORRADE_VERIFY(image->components() == AbstractImage::Components::RGBA); + #endif CORRADE_COMPARE(image->dimensions(), Math::Vector2(2, 3)); CORRADE_VERIFY(image->type() == TypeTraits::imageType()); - CORRADE_COMPARE(string(static_cast(image->data()), 2*3*3), string(data + 18, 2*3*3)); + CORRADE_COMPARE(string(static_cast(image->data()), 2*3*3), string(pixels, 2*3*3)); } }}}} diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 1b8bae143..0364ec621 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -15,9 +15,11 @@ #include "TgaImporter.h" +#include #include #include "Math/Vector2.h" +#include "Math/Swizzle.h" #include "Trade/ImageData.h" using namespace std; @@ -76,10 +78,18 @@ bool TgaImporter::open(istream& in, const string& name) { AbstractImage::Components components; switch(header.bpp) { case 24: + #ifndef MAGNUM_TARGET_GLES components = AbstractImage::Components::BGR; + #else + components = AbstractImage::Components::RGB; + #endif break; case 32: + #ifndef MAGNUM_TARGET_GLES components = AbstractImage::Components::BGRA; + #else + components = AbstractImage::Components::RGBA; + #endif break; default: Error() << "TgaImporter: unsupported bits-per-pixel:" << int(header.bpp); @@ -92,6 +102,18 @@ bool TgaImporter::open(istream& in, const string& name) { Math::Vector2 dimensions(header.width, header.height); + #ifdef MAGNUM_TARGET_GLES + if(components == AbstractImage::Components::RGB) { + Math::Vector3* data = reinterpret_cast*>(buffer); + std::transform(data, data + dimensions.product(), data, + [](Math::Vector3 pixel) { return Math::swizzle<'b', 'g', 'r'>(pixel); }); + } else /* RGBA */ { + Math::Vector4* data = reinterpret_cast*>(buffer); + std::transform(data, data + dimensions.product(), data, + [](Math::Vector4 pixel) { return Math::swizzle<'b', 'g', 'r', 'a'>(pixel); }); + } + #endif + _image = new ImageData2D(name, dimensions, components, buffer); return true; }