From 6b927b97f52324e7ee9ee0f6d6c0a283f53868a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 13 May 2015 21:52:39 +0200 Subject: [PATCH] TgaImporter, TgaImageConverter: don't bother with BGR(A). Swizzle to RGB/RGBA on all platforms. Usability over (minor) performance benefits. Otherwise we would be like the ugly mess called QImage (in Qt4 at least). --- .../Test/TgaImageConverterTest.cpp | 8 -------- .../TgaImageConverter/TgaImageConverter.cpp | 15 ++------------- .../TgaImageConverter/TgaImageConverter.h | 3 +-- .../TgaImporter/Test/TgaImporterTest.cpp | 16 ---------------- src/MagnumPlugins/TgaImporter/TgaImporter.cpp | 19 +++---------------- src/MagnumPlugins/TgaImporter/TgaImporter.h | 13 +++++-------- 6 files changed, 11 insertions(+), 63 deletions(-) diff --git a/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index 4ba6bbd56..f97e2eb87 100644 --- a/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -56,11 +56,7 @@ namespace { 5, 6, 7, 6, 7, 8 }; - #ifndef MAGNUM_TARGET_GLES - const ImageReference2D original(ColorFormat::BGR, ColorType::UnsignedByte, {2, 3}, originalData); - #else const ImageReference2D original(ColorFormat::RGB, ColorType::UnsignedByte, {2, 3}, originalData); - #endif } TgaImageConverterTest::TgaImageConverterTest() { @@ -101,11 +97,7 @@ void TgaImageConverterTest::data() { CORRADE_VERIFY(converted); CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); - #ifndef MAGNUM_TARGET_GLES - CORRADE_COMPARE(converted->format(), ColorFormat::BGR); - #else CORRADE_COMPARE(converted->format(), ColorFormat::RGB); - #endif CORRADE_COMPARE(converted->type(), ColorType::UnsignedByte); CORRADE_COMPARE((std::string{converted->data(), 2*3*3}), (std::string{original.data(), 2*3*3})); diff --git a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp index 811ded4de..5994c36e8 100644 --- a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp @@ -25,6 +25,7 @@ #include "TgaImageConverter.h" +#include #include #include #include @@ -32,13 +33,9 @@ #include "Magnum/ColorFormat.h" #include "Magnum/Image.h" -#include "MagnumPlugins/TgaImporter/TgaHeader.h" - -#ifdef MAGNUM_TARGET_GLES -#include #include "Magnum/Math/Swizzle.h" #include "Magnum/Math/Vector4.h" -#endif +#include "MagnumPlugins/TgaImporter/TgaHeader.h" namespace Magnum { namespace Trade { @@ -49,15 +46,9 @@ TgaImageConverter::TgaImageConverter(PluginManager::AbstractManager& manager, st auto TgaImageConverter::doFeatures() const -> Features { return Feature::ConvertData; } Containers::Array TgaImageConverter::doExportToData(const ImageReference2D& image) const { - #ifndef MAGNUM_TARGET_GLES - if(image.format() != ColorFormat::BGR && - image.format() != ColorFormat::BGRA && - image.format() != ColorFormat::Red) - #else if(image.format() != ColorFormat::RGB && image.format() != ColorFormat::RGBA && image.format() != ColorFormat::Red) - #endif { Error() << "Trade::TgaImageConverter::exportToData(): unsupported color format" << image.format(); return nullptr; @@ -82,7 +73,6 @@ Containers::Array TgaImageConverter::doExportToData(const ImageReference2D /* Fill data */ std::copy(image.data(), image.data()+pixelSize*image.size().product(), data.begin()+sizeof(TgaHeader)); - #ifdef MAGNUM_TARGET_GLES if(image.format() == ColorFormat::RGB) { auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaHeader)); std::transform(pixels, pixels + image.size().product(), pixels, @@ -92,7 +82,6 @@ Containers::Array TgaImageConverter::doExportToData(const ImageReference2D std::transform(pixels, pixels + image.size().product(), pixels, [](Math::Vector4 pixel) { return Math::swizzle<'b', 'g', 'r', 'a'>(pixel); }); } - #endif return data; } diff --git a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h index c9a3a94bd..1bfb283f7 100644 --- a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h +++ b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h @@ -51,8 +51,7 @@ namespace Magnum { namespace Trade { /** @brief TGA image converter plugin -Supports images with format @ref ColorFormat::BGR, @ref ColorFormat::BGRA -(@ref ColorFormat::RGB/@ref ColorFormat::RGBA on OpenGL ES) or +Supports images with format @ref ColorFormat::RGB, @ref ColorFormat::RGBA or @ref ColorFormat::Red and type @ref ColorType::UnsignedByte. This plugin is built if `WITH_TGAIMAGECONVERTER` is enabled when building diff --git a/src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp b/src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp index b84293b80..20594b2fc 100644 --- a/src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp @@ -132,24 +132,16 @@ void TgaImporterTest::colorBits24() { 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 CORRADE_VERIFY(importer.openData(data)); std::optional image = importer.image2D(0); CORRADE_VERIFY(image); - #ifndef MAGNUM_TARGET_GLES - CORRADE_COMPARE(image->format(), ColorFormat::BGR); - #else CORRADE_COMPARE(image->format(), ColorFormat::RGB); - #endif CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), ColorType::UnsignedByte); CORRADE_COMPARE((std::string{image->data(), 2*3*3}), @@ -164,24 +156,16 @@ void TgaImporterTest::colorBits32() { 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 CORRADE_VERIFY(importer.openData(data)); std::optional image = importer.image2D(0); CORRADE_VERIFY(image); - #ifndef MAGNUM_TARGET_GLES - CORRADE_COMPARE(image->format(), ColorFormat::BGRA); - #else CORRADE_COMPARE(image->format(), ColorFormat::RGBA); - #endif CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), ColorType::UnsignedByte); CORRADE_COMPARE((std::string{image->data(), 2*3*3}), diff --git a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp index eccf0cc1f..5578655fa 100644 --- a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp +++ b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp @@ -25,20 +25,17 @@ #include "TgaImporter.h" +#include #include #include #include #include #include "Magnum/ColorFormat.h" -#include "Magnum/Trade/ImageData.h" -#include "MagnumPlugins/TgaImporter/TgaHeader.h" - -#ifdef MAGNUM_TARGET_GLES -#include #include "Magnum/Math/Swizzle.h" #include "Magnum/Math/Vector4.h" -#endif +#include "Magnum/Trade/ImageData.h" +#include "MagnumPlugins/TgaImporter/TgaHeader.h" #ifdef MAGNUM_TARGET_GLES2 #include "Magnum/Context.h" @@ -104,18 +101,10 @@ std::optional TgaImporter::doImage2D(UnsignedInt) { if(header.imageType == 2) { switch(header.bpp) { case 24: - #ifndef MAGNUM_TARGET_GLES - format = ColorFormat::BGR; - #else format = ColorFormat::RGB; - #endif break; case 32: - #ifndef MAGNUM_TARGET_GLES - format = ColorFormat::BGRA; - #else format = ColorFormat::RGBA; - #endif break; default: Error() << "Trade::TgaImporter::image2D(): unsupported color bits-per-pixel:" << header.bpp; @@ -147,7 +136,6 @@ std::optional TgaImporter::doImage2D(UnsignedInt) { Vector2i size(header.width, header.height); - #ifdef MAGNUM_TARGET_GLES if(format == ColorFormat::RGB) { auto pixels = reinterpret_cast*>(data); std::transform(pixels, pixels + size.product(), pixels, @@ -157,7 +145,6 @@ std::optional TgaImporter::doImage2D(UnsignedInt) { std::transform(pixels, pixels + size.product(), pixels, [](Math::Vector4 pixel) { return Math::swizzle<'b', 'g', 'r', 'a'>(pixel); }); } - #endif return ImageData2D(format, ColorType::UnsignedByte, size, data); } diff --git a/src/MagnumPlugins/TgaImporter/TgaImporter.h b/src/MagnumPlugins/TgaImporter/TgaImporter.h index e53244744..0680fb090 100644 --- a/src/MagnumPlugins/TgaImporter/TgaImporter.h +++ b/src/MagnumPlugins/TgaImporter/TgaImporter.h @@ -62,14 +62,11 @@ of another plugin, you need to request `TgaImporter` component of `Magnum` package in CMake and link to `${MAGNUM_TGAIMPORTER_LIBRARIES}`. See @ref building, @ref cmake and @ref plugins for more information. -The images are imported with @ref ColorType::UnsignedByte and @ref ColorFormat::BGR, -@ref ColorFormat::BGRA or @ref ColorFormat::Red, respectively. Grayscale images -require extension @extension{ARB,texture_rg}. - -In OpenGL ES BGR and BGRA images are converted to @ref ColorFormat::RGB -and @ref ColorFormat::RGBA. In OpenGL ES 2.0, if @es_extension{EXT,texture_rg} -is not supported, grayscale images use @ref ColorFormat::Luminance instead of -@ref ColorFormat::Red. +The images are imported with @ref ColorType::UnsignedByte and @ref ColorFormat::RGB, +@ref ColorFormat::RGBA or @ref ColorFormat::Red, respectively. Grayscale images +require extension @extension{ARB,texture_rg}. In OpenGL ES 2.0, if +@es_extension{EXT,texture_rg} is not supported, grayscale images use +@ref ColorFormat::Luminance instead of @ref ColorFormat::Red. */ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { public: