diff --git a/doc/changelog.dox b/doc/changelog.dox index 4140f41e8..c6642fd1a 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -135,6 +135,13 @@ See also: now expect that the mesh is indexed (instead of silently not doing anything) +@subsubsection changelog-latest-changes-plugins Plugins + +- @ref Trade::TgaImporter "TgaImporter" and + @ref Trade::TgaImageConverter "TgaImageConverter" plugins now operate on + the generic @ref PixelFormat instead of GL-specific @ref GL::PixelFormat / + @ref GL::PixelType + @subsection changelog-latest-buildsystem Build system - The core @ref Magnum library is not depending on OpenGL anymore, all @@ -321,6 +328,9 @@ See also: - Configuration value reader/writers are now for only @ref Magnum::MeshPrimitive and @ref Magnum::MeshIndexType, not for @ref GL::MeshPrimitive or @ref GL::MeshIndexType +- The @ref Trade::TgaImageConverter "TgaImageConverter" plugin no longer + accepts GL-specific pixel formats, only the non-deprecated values from the + generic @ref PixelFormat enum - The @ref Image::pixelSize(), @ref ImageView::pixelSize(), @ref Trade::ImageData::pixelSize() and @ref BufferImage::pixelSize() functions now return @ref UnsignedInt instead of @cpp std::size_t @ce. diff --git a/src/MagnumPlugins/AnyImageConverter/Test/Test.cpp b/src/MagnumPlugins/AnyImageConverter/Test/Test.cpp index a1da15d26..55db7ca9b 100644 --- a/src/MagnumPlugins/AnyImageConverter/Test/Test.cpp +++ b/src/MagnumPlugins/AnyImageConverter/Test/Test.cpp @@ -73,7 +73,7 @@ namespace { 5, 6, 7, 6, 7, 8, 0, 0 }; - const ImageView2D Image{PixelFormat::RGB, PixelType::UnsignedByte, {2, 3}, Data}; + const ImageView2D Image{PixelFormat::RGB8Unorm, {2, 3}, Data}; } void AnyImageConverterTest::tga() { diff --git a/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp b/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp index 479147b23..c3ea70c81 100644 --- a/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp +++ b/src/MagnumPlugins/MagnumFontConverter/MagnumFontConverter.cpp @@ -102,7 +102,7 @@ std::vector>> MagnumFontConverter std::copy(confStr.begin(), confStr.end(), confData.begin()); /* Save cache image */ - Image2D image(PixelFormat::Red, PixelType::UnsignedByte); + Image2D image{PixelFormat::R8Unorm}; cache.texture().image(0, image); auto tgaData = Trade::TgaImageConverter().exportToData(image); diff --git a/src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterGLTest.cpp b/src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterGLTest.cpp index 51be8748f..edfb1b316 100644 --- a/src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterGLTest.cpp +++ b/src/MagnumPlugins/MagnumFontConverter/Test/MagnumFontConverterGLTest.cpp @@ -136,8 +136,7 @@ void MagnumFontConverterGLTest::exportFont() { Containers::Optional image = importer->image2D(0); CORRADE_VERIFY(image); CORRADE_COMPARE(image->size(), Vector2i(256)); - CORRADE_COMPARE(image->format(), PixelFormat::Red); - CORRADE_COMPARE(image->type(), PixelType::UnsignedByte); + CORRADE_COMPARE(image->format(), PixelFormat::R8Unorm); } }}} diff --git a/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index 97a14bd42..40ae8625a 100644 --- a/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/MagnumPlugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -44,7 +44,6 @@ struct TgaImageConverterTest: TestSuite::Tester { explicit TgaImageConverterTest(); void wrongFormat(); - void wrongType(); void rgb(); void rgba(); @@ -71,19 +70,18 @@ namespace { }; const ImageView2D OriginalRGB{PixelStorage{}.setSkip({0, 1, 0}), - PixelFormat::RGB, PixelType::UnsignedByte, {2, 3}, OriginalDataRGB}; + PixelFormat::RGB8Unorm, {2, 3}, OriginalDataRGB}; constexpr char OriginalDataRGBA[] = { 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, 4, 5, 6, 7, 5, 6, 7, 8, 6, 7, 8, 9 }; - const ImageView2D OriginalRGBA{PixelFormat::RGBA, PixelType::UnsignedByte, {2, 3}, OriginalDataRGBA}; + const ImageView2D OriginalRGBA{PixelFormat::RGBA8Unorm, {2, 3}, OriginalDataRGBA}; } TgaImageConverterTest::TgaImageConverterTest() { addTests({&TgaImageConverterTest::wrongFormat, - &TgaImageConverterTest::wrongType, &TgaImageConverterTest::rgb, &TgaImageConverterTest::rgba}); @@ -100,13 +98,7 @@ TgaImageConverterTest::TgaImageConverterTest() { } void TgaImageConverterTest::wrongFormat() { - ImageView2D image{ - #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) - PixelFormat::RG, - #else - PixelFormat::LuminanceAlpha, - #endif - PixelType::UnsignedByte, {}, nullptr}; + ImageView2D image{PixelFormat::RG8Unorm, {}, nullptr}; std::ostringstream out; Error redirectError{&out}; @@ -114,29 +106,7 @@ void TgaImageConverterTest::wrongFormat() { std::unique_ptr converter = _converterManager.instantiate("TgaImageConverter"); const auto data = converter->exportToData(image); CORRADE_VERIFY(!data); - #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) - CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::exportToData(): unsupported color format GL::PixelFormat::RG\n"); - #else - CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::exportToData(): unsupported color format GL::PixelFormat::LuminanceAlpha\n"); - #endif -} - -void TgaImageConverterTest::wrongType() { - ImageView2D image{ - #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) - PixelFormat::Red, - #else - PixelFormat::Luminance, - #endif - PixelType::Float, {}, nullptr}; - - std::ostringstream out; - Error redirectError{&out}; - - std::unique_ptr converter = _converterManager.instantiate("TgaImageConverter"); - const auto data = converter->exportToData(image); - CORRADE_VERIFY(!data); - CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::exportToData(): unsupported color type GL::PixelType::Float\n"); + CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::exportToData(): unsupported pixel format PixelFormat::RG8Unorm\n"); } void TgaImageConverterTest::rgb() { @@ -154,8 +124,7 @@ void TgaImageConverterTest::rgb() { CORRADE_COMPARE(converted->storage().alignment(), 1); CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); - CORRADE_COMPARE(converted->format(), PixelFormat::RGB); - CORRADE_COMPARE(converted->type(), PixelType::UnsignedByte); + CORRADE_COMPARE(converted->format(), PixelFormat::RGB8Unorm); CORRADE_COMPARE_AS(converted->data(), Containers::arrayView(ConvertedDataRGB), TestSuite::Compare::Container); } @@ -175,8 +144,7 @@ void TgaImageConverterTest::rgba() { CORRADE_COMPARE(converted->storage().alignment(), 4); CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); - CORRADE_COMPARE(converted->format(), PixelFormat::RGBA); - CORRADE_COMPARE(converted->type(), PixelType::UnsignedByte); + CORRADE_COMPARE(converted->format(), PixelFormat::RGBA8Unorm); CORRADE_COMPARE_AS(converted->data(), Containers::arrayView(OriginalDataRGBA), TestSuite::Compare::Container); } diff --git a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp index e31386323..ae2107d0b 100644 --- a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.cpp @@ -46,25 +46,6 @@ TgaImageConverter::TgaImageConverter(PluginManager::AbstractManager& manager, co auto TgaImageConverter::doFeatures() const -> Features { return Feature::ConvertData; } Containers::Array TgaImageConverter::doExportToData(const ImageView2D& image) { - if(image.format() != PixelFormat::RGB && - image.format() != PixelFormat::RGBA - #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) - && image.format() != PixelFormat::Red - #endif - #ifdef MAGNUM_TARGET_GLES2 - && image.format() != PixelFormat::Luminance - #endif - ) - { - Error() << "Trade::TgaImageConverter::exportToData(): unsupported color format" << image.format(); - return nullptr; - } - - if(image.type() != PixelType::UnsignedByte) { - Error() << "Trade::TgaImageConverter::exportToData(): unsupported color type" << image.type(); - return nullptr; - } - /* Initialize data buffer */ const auto pixelSize = UnsignedByte(image.pixelSize()); Containers::Array data{Containers::ValueInit, sizeof(Implementation::TgaHeader) + pixelSize*image.size().product()}; @@ -72,19 +53,16 @@ Containers::Array TgaImageConverter::doExportToData(const ImageView2D& ima /* Fill header */ auto header = reinterpret_cast(data.begin()); switch(image.format()) { - case PixelFormat::RGB: - case PixelFormat::RGBA: + case PixelFormat::RGB8Unorm: + case PixelFormat::RGBA8Unorm: header->imageType = 2; break; - #if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) - case PixelFormat::Red: - #endif - #ifdef MAGNUM_TARGET_GLES2 - case PixelFormat::Luminance: - #endif + case PixelFormat::R8Unorm: header->imageType = 3; break; - default: CORRADE_ASSERT_UNREACHABLE(); /* LCOV_EXCL_LINE */ + default: + Error() << "Trade::TgaImageConverter::exportToData(): unsupported pixel format" << image.format(); + return nullptr; } header->bpp = pixelSize*8; header->width = UnsignedShort(Utility::Endianness::littleEndian(image.size().x())); @@ -101,11 +79,11 @@ Containers::Array TgaImageConverter::doExportToData(const ImageView2D& ima std::copy_n(imageData + y*rowStride, rowSize, data.begin() + sizeof(Implementation::TgaHeader) + y*rowSize); } else std::copy_n(imageData, pixelSize*image.size().product(), data.begin() + sizeof(Implementation::TgaHeader)); - if(image.format() == PixelFormat::RGB) { + if(image.format() == PixelFormat::RGB8Unorm) { auto pixels = reinterpret_cast*>(data.begin()+sizeof(Implementation::TgaHeader)); std::transform(pixels, pixels + image.size().product(), pixels, [](Math::Vector3 pixel) { return Math::swizzle<'b', 'g', 'r'>(pixel); }); - } else if(image.format() == PixelFormat::RGBA) { + } else if(image.format() == PixelFormat::RGBA8Unorm) { auto pixels = reinterpret_cast*>(data.begin()+sizeof(Implementation::TgaHeader)); std::transform(pixels, pixels + image.size().product(), pixels, [](Math::Vector4 pixel) { return Math::swizzle<'b', 'g', 'r', 'a'>(pixel); }); diff --git a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h index 1fb5fcd7f..76b724c33 100644 --- a/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h +++ b/src/MagnumPlugins/TgaImageConverter/TgaImageConverter.h @@ -55,9 +55,8 @@ namespace Magnum { namespace Trade { @brief TGA image converter plugin Creates Truevision TGA (`*.tga`) files from images with format -@ref PixelFormat::RGB, @ref PixelFormat::RGBA or @ref PixelFormat::Red (or -@ref PixelFormat::Luminance in OpenGL ES 2.0 and WebGL 1.0) and type -@ref PixelType::UnsignedByte. +@ref PixelFormat::RGB8Unorm, @ref PixelFormat::RGBA8Unorm or +@ref PixelFormat::R8Unorm. This plugin depends on the @ref Trade library and is built if `WITH_TGAIMAGECONVERTER` is enabled when building Magnum. To use as a dynamic diff --git a/src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp b/src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp index 4bc95f1aa..982e720e5 100644 --- a/src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/MagnumPlugins/TgaImporter/Test/TgaImporterTest.cpp @@ -140,9 +140,8 @@ void TgaImporterTest::colorBits24() { Containers::Optional image = importer->image2D(0); CORRADE_VERIFY(image); CORRADE_COMPARE(image->storage().alignment(), 1); - CORRADE_COMPARE(image->format(), PixelFormat::RGB); + CORRADE_COMPARE(image->format(), PixelFormat::RGB8Unorm); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); - CORRADE_COMPARE(image->type(), PixelType::UnsignedByte); CORRADE_COMPARE_AS(image->data(), Containers::arrayView(pixels), TestSuite::Compare::Container); } @@ -165,9 +164,8 @@ void TgaImporterTest::colorBits32() { Containers::Optional image = importer->image2D(0); CORRADE_VERIFY(image); CORRADE_COMPARE(image->storage().alignment(), 4); - CORRADE_COMPARE(image->format(), PixelFormat::RGBA); + CORRADE_COMPARE(image->format(), PixelFormat::RGBA8Unorm); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); - CORRADE_COMPARE(image->type(), PixelType::UnsignedByte); CORRADE_COMPARE_AS(image->data(), Containers::arrayView(pixels), TestSuite::Compare::Container); } @@ -185,13 +183,8 @@ void TgaImporterTest::grayscaleBits8() { Containers::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 - CORRADE_COMPARE(image->format(), PixelFormat::Luminance); - #endif + CORRADE_COMPARE(image->format(), PixelFormat::R8Unorm); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); - CORRADE_COMPARE(image->type(), PixelType::UnsignedByte); CORRADE_COMPARE_AS(image->data(), Containers::arrayView(data).suffix(18), TestSuite::Compare::Container); } diff --git a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp index 5d61b4621..28eca38ba 100644 --- a/src/MagnumPlugins/TgaImporter/TgaImporter.cpp +++ b/src/MagnumPlugins/TgaImporter/TgaImporter.cpp @@ -37,11 +37,6 @@ #include "Magnum/Trade/ImageData.h" #include "MagnumPlugins/TgaImporter/TgaHeader.h" -#ifdef MAGNUM_TARGET_GLES2 -#include "Magnum/Context.h" -#include "Magnum/Extensions.h" -#endif - namespace Magnum { namespace Trade { TgaImporter::TgaImporter() = default; @@ -87,10 +82,10 @@ Containers::Optional TgaImporter::doImage2D(UnsignedInt) { if(header.imageType == 2) { switch(header.bpp) { case 24: - format = PixelFormat::RGB; + format = PixelFormat::RGB8Unorm; break; case 32: - format = PixelFormat::RGBA; + format = PixelFormat::RGBA8Unorm; break; default: Error() << "Trade::TgaImporter::image2D(): unsupported color bits-per-pixel:" << header.bpp; @@ -99,14 +94,7 @@ Containers::Optional TgaImporter::doImage2D(UnsignedInt) { /* Grayscale */ } else if(header.imageType == 3) { - #if defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) - format = Context::hasCurrent() && Context::current().isExtensionSupported() ? - PixelFormat::Red : PixelFormat::Luminance; - #elif !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2)) - format = PixelFormat::Red; - #else - format = PixelFormat::Luminance; - #endif + format = PixelFormat::R8Unorm; if(header.bpp != 8) { Error() << "Trade::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp; return Containers::NullOpt; @@ -126,17 +114,17 @@ Containers::Optional TgaImporter::doImage2D(UnsignedInt) { if((size.x()*header.bpp/8)%4 != 0) storage.setAlignment(1); - if(format == PixelFormat::RGB) { + if(format == PixelFormat::RGB8Unorm) { auto pixels = reinterpret_cast*>(data.data()); std::transform(pixels, pixels + size.product(), pixels, [](Math::Vector3 pixel) { return Math::swizzle<'b', 'g', 'r'>(pixel); }); - } else if(format == PixelFormat::RGBA) { + } else if(format == PixelFormat::RGBA8Unorm) { auto pixels = reinterpret_cast*>(data.data()); std::transform(pixels, pixels + size.product(), pixels, [](Math::Vector4 pixel) { return Math::swizzle<'b', 'g', 'r', 'a'>(pixel); }); } - return ImageData2D{storage, format, PixelType::UnsignedByte, size, std::move(data)}; + return ImageData2D{storage, format, size, std::move(data)}; } }} diff --git a/src/MagnumPlugins/TgaImporter/TgaImporter.h b/src/MagnumPlugins/TgaImporter/TgaImporter.h index 6901e8973..a9f2720af 100644 --- a/src/MagnumPlugins/TgaImporter/TgaImporter.h +++ b/src/MagnumPlugins/TgaImporter/TgaImporter.h @@ -68,15 +68,10 @@ need to request the `TgaImporter` component of the `Magnum` package and link to the `Magnum::TgaImporter` target. See @ref building, @ref cmake and @ref plugins for more information. -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}. 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 @extension{EXT,texture_rg} is not supported and in -WebGL 1.0, grayscale images use @ref PixelFormat::Luminance instead of -@ref PixelFormat::Red. +The images are imported with @ref PixelFormat::RGB8Unorm, +@ref PixelFormat::RGBA8Unorm or @ref PixelFormat::R8Unorm, respectively. Images +are imported with default @ref PixelStorage parameters except for alignment, +which may be changed to `1` if the data require it. */ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { public: