From 14306f47c5b2d799292daf7f15a61ae130979e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 13 Dec 2011 15:32:00 +0100 Subject: [PATCH 002/112] TGA importer plugin. --- src/Plugins/TGAImporter/CMakeLists.txt | 2 + src/Plugins/TGAImporter/TGAImporter.conf | 4 ++ src/Plugins/TGAImporter/TGAImporter.cpp | 67 ++++++++++++++++++++++++ src/Plugins/TGAImporter/TGAImporter.h | 63 ++++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 src/Plugins/TGAImporter/CMakeLists.txt create mode 100644 src/Plugins/TGAImporter/TGAImporter.conf create mode 100644 src/Plugins/TGAImporter/TGAImporter.cpp create mode 100644 src/Plugins/TGAImporter/TGAImporter.h diff --git a/src/Plugins/TGAImporter/CMakeLists.txt b/src/Plugins/TGAImporter/CMakeLists.txt new file mode 100644 index 000000000..79482c1ca --- /dev/null +++ b/src/Plugins/TGAImporter/CMakeLists.txt @@ -0,0 +1,2 @@ +corrade_add_plugin(TGAImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TGAImporter.conf TGAImporter.cpp) +target_link_libraries(TGAImporter ${MAGNUM_LIBRARY}) diff --git a/src/Plugins/TGAImporter/TGAImporter.conf b/src/Plugins/TGAImporter/TGAImporter.conf new file mode 100644 index 000000000..02be1f4ce --- /dev/null +++ b/src/Plugins/TGAImporter/TGAImporter.conf @@ -0,0 +1,4 @@ +author=Vladimír Vondruš + +[metadata] +name=TGA image importer diff --git a/src/Plugins/TGAImporter/TGAImporter.cpp b/src/Plugins/TGAImporter/TGAImporter.cpp new file mode 100644 index 000000000..f02d7c803 --- /dev/null +++ b/src/Plugins/TGAImporter/TGAImporter.cpp @@ -0,0 +1,67 @@ +/* + Copyright © 2010, 2011 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "TGAImporter.h" + +#include "Math/Vector2.h" +#include "Image.h" + +using namespace std; +using namespace Corrade::Utility; + +PLUGIN_REGISTER(Magnum::Plugins::TGAImporter::TGAImporter, "cz.mosra.magnum.AbstractImporter/0.1") + +namespace Magnum { namespace Plugins { namespace TGAImporter { + +bool TGAImporter::open(std::istream& in) { + if(_image) close(); + if(!in.good()) return false; + + Header header; + in.read(reinterpret_cast(&header), sizeof(Header)); + + ColorFormat colorFormat; + + switch(header.bpp) { + case 24: + colorFormat = ColorFormat::BGR; + break; + case 32: + colorFormat = ColorFormat::BGRA; + break; + default: + Error() << "TGATexture: unsupported bits-per-pixel:" << (int) header.bpp; + return false; + } + + size_t size = header.width*header.height*header.bpp/8; + GLubyte* buffer = new GLubyte[size]; + in.read(reinterpret_cast(buffer), size); + + Math::Vector2 dimensions(header.width, header.height); + + _image = shared_ptr(new Image2D(dimensions, colorFormat, buffer)); + return true; +} + +void TGAImporter::close() { + _image = shared_ptr(); +} + +shared_ptr TGAImporter::image2D(size_t id) { + return _image; +} + +}}} diff --git a/src/Plugins/TGAImporter/TGAImporter.h b/src/Plugins/TGAImporter/TGAImporter.h new file mode 100644 index 000000000..b3507d1d3 --- /dev/null +++ b/src/Plugins/TGAImporter/TGAImporter.h @@ -0,0 +1,63 @@ +#ifndef Magnum_Plugins_TGAImporter_TGAImporter_h +#define Magnum_Plugins_TGAImporter_TGAImporter_h +/* + Copyright © 2010, 2011 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +/** @file + * @brief Class Magnum::TGAImporter + */ + +#include "AbstractImporter.h" + +#include "Magnum.h" + +namespace Magnum { namespace Plugins { namespace TGAImporter { + +class TGAImporter: public AbstractImporter { + public: + TGAImporter(Corrade::PluginManager::AbstractPluginManager* manager = 0, const std::string& plugin = ""): AbstractImporter(manager, plugin) {} + + inline virtual ~TGAImporter() { close(); } + + bool open(std::istream& in); + void close(); + + inline size_t image2DCount() const { return _image ? 1 : 0; } + inline std::shared_ptr image2D(size_t id); + + private: + #pragma pack(1) + struct Header { + GLbyte identsize; /**< @brief Size of ID field that follows header (0) */ + GLbyte colorMapType; /**< @brief 0 = None, 1 = paletted */ + GLbyte imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ + unsigned short colorMapStart; /**< @brief First color map entry */ + unsigned short colorMapLength; /**< @brief Number of colors */ + unsigned char colorMapBpp; /**< @brief Bits per palette entry */ + unsigned short beginX; /**< @brief Image x origin */ + unsigned short beginY; /**< @brief Image y origin */ + unsigned short width; /**< @brief Image width */ + unsigned short height; /**< @brief Image height */ + GLbyte bpp; /**< @brief Bits per pixel (8 16, 24, 32) */ + GLbyte descriptor; /**< @brief Image descriptor */ + }; + #pragma pack(8) + + std::shared_ptr _image; +}; + +}}} + +#endif From 8823b2cc7262441fbb263c5f004432f6f637a0f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 9 Jan 2012 19:08:25 +0100 Subject: [PATCH 003/112] TGAImporter: think about endianness! --- src/Plugins/TGAImporter/TGAImporter.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Plugins/TGAImporter/TGAImporter.cpp b/src/Plugins/TGAImporter/TGAImporter.cpp index f02d7c803..f2547164e 100644 --- a/src/Plugins/TGAImporter/TGAImporter.cpp +++ b/src/Plugins/TGAImporter/TGAImporter.cpp @@ -15,6 +15,7 @@ #include "TGAImporter.h" +#include "Utility/Endianness.h" #include "Math/Vector2.h" #include "Image.h" @@ -32,8 +33,11 @@ bool TGAImporter::open(std::istream& in) { Header header; in.read(reinterpret_cast(&header), sizeof(Header)); - ColorFormat colorFormat; + /* Convert to machine endian */ + header.width = Endianness::littleEndian(header.width); + header.height = Endianness::littleEndian(header.height); + ColorFormat colorFormat; switch(header.bpp) { case 24: colorFormat = ColorFormat::BGR; From 95082834a44a9bbc9666d034270bad9d766090cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 9 Jan 2012 19:09:51 +0100 Subject: [PATCH 004/112] TGAImporter: just-to-be-safe static_assert for header size --- src/Plugins/TGAImporter/TGAImporter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Plugins/TGAImporter/TGAImporter.cpp b/src/Plugins/TGAImporter/TGAImporter.cpp index f2547164e..8d341ad84 100644 --- a/src/Plugins/TGAImporter/TGAImporter.cpp +++ b/src/Plugins/TGAImporter/TGAImporter.cpp @@ -26,6 +26,8 @@ PLUGIN_REGISTER(Magnum::Plugins::TGAImporter::TGAImporter, "cz.mosra.magnum.Abst namespace Magnum { namespace Plugins { namespace TGAImporter { +static_assert(sizeof(TGAImporter::Header) == 18, "TGAImporter: header size is not 18 bytes"); + bool TGAImporter::open(std::istream& in) { if(_image) close(); if(!in.good()) return false; From 1dbb3c8c9cf76eb19a93d9beeed9bcde7422ed28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 9 Jan 2012 19:10:43 +0100 Subject: [PATCH 005/112] TGAImporter: doc/debug output fixes. --- src/Plugins/TGAImporter/TGAImporter.cpp | 2 +- src/Plugins/TGAImporter/TGAImporter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugins/TGAImporter/TGAImporter.cpp b/src/Plugins/TGAImporter/TGAImporter.cpp index 8d341ad84..315540565 100644 --- a/src/Plugins/TGAImporter/TGAImporter.cpp +++ b/src/Plugins/TGAImporter/TGAImporter.cpp @@ -48,7 +48,7 @@ bool TGAImporter::open(std::istream& in) { colorFormat = ColorFormat::BGRA; break; default: - Error() << "TGATexture: unsupported bits-per-pixel:" << (int) header.bpp; + Error() << "TGAImporter: unsupported bits-per-pixel:" << (int) header.bpp; return false; } diff --git a/src/Plugins/TGAImporter/TGAImporter.h b/src/Plugins/TGAImporter/TGAImporter.h index b3507d1d3..279596689 100644 --- a/src/Plugins/TGAImporter/TGAImporter.h +++ b/src/Plugins/TGAImporter/TGAImporter.h @@ -50,7 +50,7 @@ class TGAImporter: public AbstractImporter { unsigned short beginY; /**< @brief Image y origin */ unsigned short width; /**< @brief Image width */ unsigned short height; /**< @brief Image height */ - GLbyte bpp; /**< @brief Bits per pixel (8 16, 24, 32) */ + GLbyte bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ GLbyte descriptor; /**< @brief Image descriptor */ }; #pragma pack(8) From e8534aa5b604a33d00f6cb14b04dc93563b6a237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 9 Jan 2012 19:11:17 +0100 Subject: [PATCH 006/112] TGAImporter: making header structure public. --- src/Plugins/TGAImporter/TGAImporter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/TGAImporter/TGAImporter.h b/src/Plugins/TGAImporter/TGAImporter.h index 279596689..cd3ad3ad1 100644 --- a/src/Plugins/TGAImporter/TGAImporter.h +++ b/src/Plugins/TGAImporter/TGAImporter.h @@ -37,7 +37,6 @@ class TGAImporter: public AbstractImporter { inline size_t image2DCount() const { return _image ? 1 : 0; } inline std::shared_ptr image2D(size_t id); - private: #pragma pack(1) struct Header { GLbyte identsize; /**< @brief Size of ID field that follows header (0) */ @@ -55,6 +54,7 @@ class TGAImporter: public AbstractImporter { }; #pragma pack(8) + private: std::shared_ptr _image; }; From 22705e9632e0bdc54d9f4544395562d71e828ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 9 Jan 2012 19:12:16 +0100 Subject: [PATCH 007/112] TGAImporter: Don't inline non-inlined function. --- src/Plugins/TGAImporter/TGAImporter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/TGAImporter/TGAImporter.h b/src/Plugins/TGAImporter/TGAImporter.h index cd3ad3ad1..dcdffc3c3 100644 --- a/src/Plugins/TGAImporter/TGAImporter.h +++ b/src/Plugins/TGAImporter/TGAImporter.h @@ -35,7 +35,7 @@ class TGAImporter: public AbstractImporter { void close(); inline size_t image2DCount() const { return _image ? 1 : 0; } - inline std::shared_ptr image2D(size_t id); + std::shared_ptr image2D(size_t id); #pragma pack(1) struct Header { From 1fb857985d4715673954e9abae1fe8d1da5ac670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 9 Jan 2012 19:13:27 +0100 Subject: [PATCH 008/112] TGAImporter: hardened file opening, added unit tests. --- src/Plugins/TGAImporter/CMakeLists.txt | 7 ++ src/Plugins/TGAImporter/TGAImporter.cpp | 10 ++ src/Plugins/TGAImporter/Test/CMakeLists.txt | 2 + .../TGAImporter/Test/TGAImporterTest.cpp | 98 +++++++++++++++++++ .../TGAImporter/Test/TGAImporterTest.h | 35 +++++++ 5 files changed, 152 insertions(+) create mode 100644 src/Plugins/TGAImporter/Test/CMakeLists.txt create mode 100644 src/Plugins/TGAImporter/Test/TGAImporterTest.cpp create mode 100644 src/Plugins/TGAImporter/Test/TGAImporterTest.h diff --git a/src/Plugins/TGAImporter/CMakeLists.txt b/src/Plugins/TGAImporter/CMakeLists.txt index 79482c1ca..e69d1f923 100644 --- a/src/Plugins/TGAImporter/CMakeLists.txt +++ b/src/Plugins/TGAImporter/CMakeLists.txt @@ -1,2 +1,9 @@ corrade_add_plugin(TGAImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TGAImporter.conf TGAImporter.cpp) target_link_libraries(TGAImporter ${MAGNUM_LIBRARY}) + +if(BUILD_TESTS) + add_library(TGAImporterTestLib TGAImporter.cpp) + target_link_libraries(TGAImporterTestLib ${MAGNUM_LIBRARY} ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) + enable_testing() + add_subdirectory(Test) +endif() diff --git a/src/Plugins/TGAImporter/TGAImporter.cpp b/src/Plugins/TGAImporter/TGAImporter.cpp index 315540565..b73434062 100644 --- a/src/Plugins/TGAImporter/TGAImporter.cpp +++ b/src/Plugins/TGAImporter/TGAImporter.cpp @@ -39,6 +39,16 @@ bool TGAImporter::open(std::istream& in) { header.width = Endianness::littleEndian(header.width); header.height = Endianness::littleEndian(header.height); + if(header.colorMapType != 0) { + Error() << "TGAImporter: paletted files are not supported"; + return false; + } + + if(header.imageType != 2) { + Error() << "TGAImporter: non-RGB files are not supported"; + return false; + } + ColorFormat colorFormat; switch(header.bpp) { case 24: diff --git a/src/Plugins/TGAImporter/Test/CMakeLists.txt b/src/Plugins/TGAImporter/Test/CMakeLists.txt new file mode 100644 index 000000000..791ea97db --- /dev/null +++ b/src/Plugins/TGAImporter/Test/CMakeLists.txt @@ -0,0 +1,2 @@ +corrade_add_test(TGAImporterTest TGAImporterTest.h TGAImporterTest.cpp) +target_link_libraries(TGAImporterTest TGAImporterTestLib) diff --git a/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp b/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp new file mode 100644 index 000000000..809dc1623 --- /dev/null +++ b/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp @@ -0,0 +1,98 @@ +/* + Copyright © 2010, 2011 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "TGAImporterTest.h" + +#include + +#include "Utility/Debug.h" +#include "../TGAImporter.h" + +using namespace std; +using namespace Corrade::Utility; + +QTEST_APPLESS_MAIN(Magnum::Plugins::TGAImporter::Test::TGAImporterTest) + +namespace Magnum { namespace Plugins { namespace TGAImporter { namespace Test { + +void TGAImporterTest::paletted() { + const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + istringstream in(string(data, sizeof(data))); + + ostringstream debug; + Error::setOutput(&debug); + + TGAImporter importer; + QVERIFY(!importer.open(in)); + QCOMPARE(debug.str().c_str(), "TGAImporter: paletted files are not supported\n"); +} + +void TGAImporterTest::nonRgb() { + const char data[] = { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + istringstream in(string(data, sizeof(data))); + + ostringstream debug; + Error::setOutput(&debug); + + TGAImporter importer; + QVERIFY(!importer.open(in)); + QCOMPARE(debug.str().c_str(), "TGAImporter: non-RGB files are not supported\n"); +} + +void TGAImporterTest::bits16() { + const char data[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 }; + istringstream in(string(data, sizeof(data))); + + ostringstream debug; + Error::setOutput(&debug); + + TGAImporter importer; + QVERIFY(!importer.open(in)); + QCOMPARE(debug.str().c_str(), "TGAImporter: unsupported bits-per-pixel: 16\n"); +} + +void TGAImporterTest::bits24() { + const char data[] = { + 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 + }; + std::istringstream in(string(data, sizeof(data))); + + TGAImporter importer; + QVERIFY(importer.open(in)); + auto image = importer.image2D(0); + QVERIFY(image->colorFormat() == ColorFormat::BGR); + QVERIFY(image->dimensions() == Math::Vector2(2, 3)); + QVERIFY(image->type() == TypeTraits::glType()); + QVERIFY(string(static_cast(image->data())) == string(data + 18, 2*3*3)); +} + +void TGAImporterTest::bits32() { + const char data[] = { + 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 + }; + std::istringstream in(string(data, sizeof(data))); + + TGAImporter importer; + QVERIFY(importer.open(in)); + auto image = importer.image2D(0); + QVERIFY(image->colorFormat() == ColorFormat::BGRA); + QVERIFY(image->dimensions() == Math::Vector2(2, 3)); + QVERIFY(image->type() == TypeTraits::glType()); + QVERIFY(string(static_cast(image->data()), 2*3*3) == string(data + 18, 2*3*3)); +} + +}}}} diff --git a/src/Plugins/TGAImporter/Test/TGAImporterTest.h b/src/Plugins/TGAImporter/Test/TGAImporterTest.h new file mode 100644 index 000000000..5e912bfee --- /dev/null +++ b/src/Plugins/TGAImporter/Test/TGAImporterTest.h @@ -0,0 +1,35 @@ +#ifndef Magnum_Plugins_TGAImporter_Test_TGAImporterTest_h +#define Magnum_Plugins_TGAImporter_Test_TGAImporterTest_h +/* + Copyright © 2010, 2011 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Plugins { namespace TGAImporter { namespace Test { + +class TGAImporterTest: public QObject { + Q_OBJECT + + private slots: + void paletted(); + void nonRgb(); + void bits16(); + void bits24(); + void bits32(); +}; + +}}}} + +#endif From 82816ac8458dc8eec481cb6ac5b9c78ba53c3362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 11 Jan 2012 18:54:24 +0100 Subject: [PATCH 009/112] Happy New Year. --- src/Plugins/TGAImporter/TGAImporter.cpp | 2 +- src/Plugins/TGAImporter/TGAImporter.h | 2 +- src/Plugins/TGAImporter/Test/TGAImporterTest.cpp | 2 +- src/Plugins/TGAImporter/Test/TGAImporterTest.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugins/TGAImporter/TGAImporter.cpp b/src/Plugins/TGAImporter/TGAImporter.cpp index b73434062..7d1574f72 100644 --- a/src/Plugins/TGAImporter/TGAImporter.cpp +++ b/src/Plugins/TGAImporter/TGAImporter.cpp @@ -1,5 +1,5 @@ /* - Copyright © 2010, 2011 Vladimír Vondruš + Copyright © 2010, 2011, 2012 Vladimír Vondruš This file is part of Magnum. diff --git a/src/Plugins/TGAImporter/TGAImporter.h b/src/Plugins/TGAImporter/TGAImporter.h index dcdffc3c3..40933ff48 100644 --- a/src/Plugins/TGAImporter/TGAImporter.h +++ b/src/Plugins/TGAImporter/TGAImporter.h @@ -1,7 +1,7 @@ #ifndef Magnum_Plugins_TGAImporter_TGAImporter_h #define Magnum_Plugins_TGAImporter_TGAImporter_h /* - Copyright © 2010, 2011 Vladimír Vondruš + Copyright © 2010, 2011, 2012 Vladimír Vondruš This file is part of Magnum. diff --git a/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp b/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp index 809dc1623..5cba1938e 100644 --- a/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp +++ b/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp @@ -1,5 +1,5 @@ /* - Copyright © 2010, 2011 Vladimír Vondruš + Copyright © 2010, 2011, 2012 Vladimír Vondruš This file is part of Magnum. diff --git a/src/Plugins/TGAImporter/Test/TGAImporterTest.h b/src/Plugins/TGAImporter/Test/TGAImporterTest.h index 5e912bfee..7b2b18c83 100644 --- a/src/Plugins/TGAImporter/Test/TGAImporterTest.h +++ b/src/Plugins/TGAImporter/Test/TGAImporterTest.h @@ -1,7 +1,7 @@ #ifndef Magnum_Plugins_TGAImporter_Test_TGAImporterTest_h #define Magnum_Plugins_TGAImporter_Test_TGAImporterTest_h /* - Copyright © 2010, 2011 Vladimír Vondruš + Copyright © 2010, 2011, 2012 Vladimír Vondruš This file is part of Magnum. From 53170e04377d46fc255b162f1cf1a537e7f8ef26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 25 Jan 2012 20:53:04 +0100 Subject: [PATCH 010/112] TGAImporter: adopted to Magnum changes, allow direct file opening. --- src/Plugins/TGAImporter/TGAImporter.cpp | 7 +++++++ src/Plugins/TGAImporter/TGAImporter.h | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Plugins/TGAImporter/TGAImporter.cpp b/src/Plugins/TGAImporter/TGAImporter.cpp index 7d1574f72..f38c5162f 100644 --- a/src/Plugins/TGAImporter/TGAImporter.cpp +++ b/src/Plugins/TGAImporter/TGAImporter.cpp @@ -28,6 +28,13 @@ namespace Magnum { namespace Plugins { namespace TGAImporter { static_assert(sizeof(TGAImporter::Header) == 18, "TGAImporter: header size is not 18 bytes"); +bool TGAImporter::TGAImporter::open(const string& filename) { + ifstream in(filename.c_str()); + bool status = open(in); + in.close(); + return status; +} + bool TGAImporter::open(std::istream& in) { if(_image) close(); if(!in.good()) return false; diff --git a/src/Plugins/TGAImporter/TGAImporter.h b/src/Plugins/TGAImporter/TGAImporter.h index 40933ff48..80db81947 100644 --- a/src/Plugins/TGAImporter/TGAImporter.h +++ b/src/Plugins/TGAImporter/TGAImporter.h @@ -28,10 +28,12 @@ namespace Magnum { namespace Plugins { namespace TGAImporter { class TGAImporter: public AbstractImporter { public: TGAImporter(Corrade::PluginManager::AbstractPluginManager* manager = 0, const std::string& plugin = ""): AbstractImporter(manager, plugin) {} - inline virtual ~TGAImporter() { close(); } + inline int features() const { return OpenFile|OpenStream; } + bool open(std::istream& in); + bool open(const std::string& filename); void close(); inline size_t image2DCount() const { return _image ? 1 : 0; } From 65986a1cef8479eef85586d7b2d942998b5dc75e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 26 Jan 2012 20:00:50 +0100 Subject: [PATCH 011/112] Adapted to Magnum changes. --- src/Plugins/TGAImporter/TGAImporter.cpp | 6 +++--- src/Plugins/TGAImporter/Test/TGAImporterTest.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Plugins/TGAImporter/TGAImporter.cpp b/src/Plugins/TGAImporter/TGAImporter.cpp index f38c5162f..40c7ccbc5 100644 --- a/src/Plugins/TGAImporter/TGAImporter.cpp +++ b/src/Plugins/TGAImporter/TGAImporter.cpp @@ -56,13 +56,13 @@ bool TGAImporter::open(std::istream& in) { return false; } - ColorFormat colorFormat; + AbstractTexture::ColorFormat colorFormat; switch(header.bpp) { case 24: - colorFormat = ColorFormat::BGR; + colorFormat = AbstractTexture::ColorFormat::BGR; break; case 32: - colorFormat = ColorFormat::BGRA; + colorFormat = AbstractTexture::ColorFormat::BGRA; break; default: Error() << "TGAImporter: unsupported bits-per-pixel:" << (int) header.bpp; diff --git a/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp b/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp index 5cba1938e..f1600d3e9 100644 --- a/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp +++ b/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp @@ -73,7 +73,7 @@ void TGAImporterTest::bits24() { TGAImporter importer; QVERIFY(importer.open(in)); auto image = importer.image2D(0); - QVERIFY(image->colorFormat() == ColorFormat::BGR); + QVERIFY(image->colorFormat() == AbstractTexture::ColorFormat::BGR); QVERIFY(image->dimensions() == Math::Vector2(2, 3)); QVERIFY(image->type() == TypeTraits::glType()); QVERIFY(string(static_cast(image->data())) == string(data + 18, 2*3*3)); @@ -89,7 +89,7 @@ void TGAImporterTest::bits32() { TGAImporter importer; QVERIFY(importer.open(in)); auto image = importer.image2D(0); - QVERIFY(image->colorFormat() == ColorFormat::BGRA); + QVERIFY(image->colorFormat() == AbstractTexture::ColorFormat::BGRA); QVERIFY(image->dimensions() == Math::Vector2(2, 3)); QVERIFY(image->type() == TypeTraits::glType()); QVERIFY(string(static_cast(image->data()), 2*3*3) == string(data + 18, 2*3*3)); From ea853308f88194b1b1fd8c09a4a1d023bed0a6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 27 Jan 2012 01:18:14 +0100 Subject: [PATCH 012/112] Adapted to Magnum changes, renamed namespace Plugins to Trade. --- src/Plugins/TGAImporter/TGAImporter.cpp | 6 +++--- src/Plugins/TGAImporter/TGAImporter.h | 12 +++++------- src/Plugins/TGAImporter/Test/TGAImporterTest.cpp | 4 ++-- src/Plugins/TGAImporter/Test/TGAImporterTest.h | 6 +++--- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Plugins/TGAImporter/TGAImporter.cpp b/src/Plugins/TGAImporter/TGAImporter.cpp index 40c7ccbc5..199536620 100644 --- a/src/Plugins/TGAImporter/TGAImporter.cpp +++ b/src/Plugins/TGAImporter/TGAImporter.cpp @@ -17,14 +17,14 @@ #include "Utility/Endianness.h" #include "Math/Vector2.h" -#include "Image.h" +#include "Trade/Image.h" using namespace std; using namespace Corrade::Utility; -PLUGIN_REGISTER(Magnum::Plugins::TGAImporter::TGAImporter, "cz.mosra.magnum.AbstractImporter/0.1") +PLUGIN_REGISTER(Magnum::Trade::TGAImporter::TGAImporter, "cz.mosra.magnum.Trade.AbstractImporter/0.1") -namespace Magnum { namespace Plugins { namespace TGAImporter { +namespace Magnum { namespace Trade { namespace TGAImporter { static_assert(sizeof(TGAImporter::Header) == 18, "TGAImporter: header size is not 18 bytes"); diff --git a/src/Plugins/TGAImporter/TGAImporter.h b/src/Plugins/TGAImporter/TGAImporter.h index 80db81947..1e93c53bd 100644 --- a/src/Plugins/TGAImporter/TGAImporter.h +++ b/src/Plugins/TGAImporter/TGAImporter.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Plugins_TGAImporter_TGAImporter_h -#define Magnum_Plugins_TGAImporter_TGAImporter_h +#ifndef Magnum_Trade_TGAImporter_TGAImporter_h +#define Magnum_Trade_TGAImporter_TGAImporter_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,14 +16,12 @@ */ /** @file - * @brief Class Magnum::TGAImporter + * @brief Class Magnum::Trade::TGAImporter::TGAImporter */ -#include "AbstractImporter.h" +#include "Trade/AbstractImporter.h" -#include "Magnum.h" - -namespace Magnum { namespace Plugins { namespace TGAImporter { +namespace Magnum { namespace Trade { namespace TGAImporter { class TGAImporter: public AbstractImporter { public: diff --git a/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp b/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp index f1600d3e9..3db36c206 100644 --- a/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp +++ b/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp @@ -23,9 +23,9 @@ using namespace std; using namespace Corrade::Utility; -QTEST_APPLESS_MAIN(Magnum::Plugins::TGAImporter::Test::TGAImporterTest) +QTEST_APPLESS_MAIN(Magnum::Trade::TGAImporter::Test::TGAImporterTest) -namespace Magnum { namespace Plugins { namespace TGAImporter { namespace Test { +namespace Magnum { namespace Trade { namespace TGAImporter { namespace Test { void TGAImporterTest::paletted() { const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; diff --git a/src/Plugins/TGAImporter/Test/TGAImporterTest.h b/src/Plugins/TGAImporter/Test/TGAImporterTest.h index 7b2b18c83..5f4a25ec4 100644 --- a/src/Plugins/TGAImporter/Test/TGAImporterTest.h +++ b/src/Plugins/TGAImporter/Test/TGAImporterTest.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Plugins_TGAImporter_Test_TGAImporterTest_h -#define Magnum_Plugins_TGAImporter_Test_TGAImporterTest_h +#ifndef Magnum_Trade_TGAImporter_Test_TGAImporterTest_h +#define Magnum_Trade_TGAImporter_Test_TGAImporterTest_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -17,7 +17,7 @@ #include -namespace Magnum { namespace Plugins { namespace TGAImporter { namespace Test { +namespace Magnum { namespace Trade { namespace TGAImporter { namespace Test { class TGAImporterTest: public QObject { Q_OBJECT From e6b5a982a436a0dc2a2ddefcae73722396bbda31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 8 Feb 2012 22:33:55 +0100 Subject: [PATCH 013/112] Fixed linker errors with MinGW32 build. --- src/Plugins/TGAImporter/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Plugins/TGAImporter/CMakeLists.txt b/src/Plugins/TGAImporter/CMakeLists.txt index e69d1f923..07c9e288d 100644 --- a/src/Plugins/TGAImporter/CMakeLists.txt +++ b/src/Plugins/TGAImporter/CMakeLists.txt @@ -7,3 +7,7 @@ if(BUILD_TESTS) enable_testing() add_subdirectory(Test) endif() + +if(WIN32) + target_link_libraries(TGAImporter ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) +endif() From 1c51409fb445a65efea8fcc85f6e4e495582f475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 14 Feb 2012 00:38:30 +0100 Subject: [PATCH 014/112] TGAImporter: adapted to Magnum changes. --- src/Plugins/TGAImporter/TGAImporter.cpp | 7 ++++--- src/Plugins/TGAImporter/TGAImporter.h | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Plugins/TGAImporter/TGAImporter.cpp b/src/Plugins/TGAImporter/TGAImporter.cpp index 199536620..4602a9e99 100644 --- a/src/Plugins/TGAImporter/TGAImporter.cpp +++ b/src/Plugins/TGAImporter/TGAImporter.cpp @@ -75,15 +75,16 @@ bool TGAImporter::open(std::istream& in) { Math::Vector2 dimensions(header.width, header.height); - _image = shared_ptr(new Image2D(dimensions, colorFormat, buffer)); + _image = new Image2D(dimensions, colorFormat, buffer); return true; } void TGAImporter::close() { - _image = shared_ptr(); + delete _image; + _image = nullptr; } -shared_ptr TGAImporter::image2D(size_t id) { +Image2D* TGAImporter::image2D(size_t id) { return _image; } diff --git a/src/Plugins/TGAImporter/TGAImporter.h b/src/Plugins/TGAImporter/TGAImporter.h index 1e93c53bd..d614f84a3 100644 --- a/src/Plugins/TGAImporter/TGAImporter.h +++ b/src/Plugins/TGAImporter/TGAImporter.h @@ -25,7 +25,7 @@ namespace Magnum { namespace Trade { namespace TGAImporter { class TGAImporter: public AbstractImporter { public: - TGAImporter(Corrade::PluginManager::AbstractPluginManager* manager = 0, const std::string& plugin = ""): AbstractImporter(manager, plugin) {} + TGAImporter(Corrade::PluginManager::AbstractPluginManager* manager = 0, const std::string& plugin = ""): AbstractImporter(manager, plugin), _image(nullptr) {} inline virtual ~TGAImporter() { close(); } inline int features() const { return OpenFile|OpenStream; } @@ -35,7 +35,7 @@ class TGAImporter: public AbstractImporter { void close(); inline size_t image2DCount() const { return _image ? 1 : 0; } - std::shared_ptr image2D(size_t id); + Image2D* image2D(size_t id); #pragma pack(1) struct Header { @@ -55,7 +55,7 @@ class TGAImporter: public AbstractImporter { #pragma pack(8) private: - std::shared_ptr _image; + Image2D* _image; }; }}} From e5cf6c7c933ad8585984a8a47f4a71f62e6f7328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 23 Feb 2012 14:41:16 +0100 Subject: [PATCH 015/112] Adapted to Magnum changes. --- src/Plugins/TGAImporter/TGAImporter.cpp | 6 +++--- src/Plugins/TGAImporter/TGAImporter.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Plugins/TGAImporter/TGAImporter.cpp b/src/Plugins/TGAImporter/TGAImporter.cpp index 4602a9e99..480fac98c 100644 --- a/src/Plugins/TGAImporter/TGAImporter.cpp +++ b/src/Plugins/TGAImporter/TGAImporter.cpp @@ -17,7 +17,7 @@ #include "Utility/Endianness.h" #include "Math/Vector2.h" -#include "Trade/Image.h" +#include "Trade/ImageData.h" using namespace std; using namespace Corrade::Utility; @@ -75,7 +75,7 @@ bool TGAImporter::open(std::istream& in) { Math::Vector2 dimensions(header.width, header.height); - _image = new Image2D(dimensions, colorFormat, buffer); + _image = new ImageData2D(colorFormat, dimensions, buffer); return true; } @@ -84,7 +84,7 @@ void TGAImporter::close() { _image = nullptr; } -Image2D* TGAImporter::image2D(size_t id) { +ImageData2D* TGAImporter::image2D(size_t id) { return _image; } diff --git a/src/Plugins/TGAImporter/TGAImporter.h b/src/Plugins/TGAImporter/TGAImporter.h index d614f84a3..ff8b8afe1 100644 --- a/src/Plugins/TGAImporter/TGAImporter.h +++ b/src/Plugins/TGAImporter/TGAImporter.h @@ -35,7 +35,7 @@ class TGAImporter: public AbstractImporter { void close(); inline size_t image2DCount() const { return _image ? 1 : 0; } - Image2D* image2D(size_t id); + ImageData2D* image2D(size_t id); #pragma pack(1) struct Header { @@ -55,7 +55,7 @@ class TGAImporter: public AbstractImporter { #pragma pack(8) private: - Image2D* _image; + ImageData2D* _image; }; }}} From f17de6a63d431519e7f0632a19202fdb867e8261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 3 Mar 2012 23:58:54 +0100 Subject: [PATCH 016/112] Renamed TGAImporter -> TgaImporter. --- src/Plugins/TGAImporter/CMakeLists.txt | 13 ------- src/Plugins/TGAImporter/Test/CMakeLists.txt | 2 -- src/Plugins/TgaImporter/CMakeLists.txt | 13 +++++++ src/Plugins/TgaImporter/Test/CMakeLists.txt | 2 ++ .../Test/TgaImporterTest.cpp} | 34 +++++++++---------- .../Test/TgaImporterTest.h} | 8 ++--- .../TgaImporter.conf} | 0 .../TgaImporter.cpp} | 22 ++++++------ .../TgaImporter.h} | 14 ++++---- 9 files changed, 54 insertions(+), 54 deletions(-) delete mode 100644 src/Plugins/TGAImporter/CMakeLists.txt delete mode 100644 src/Plugins/TGAImporter/Test/CMakeLists.txt create mode 100644 src/Plugins/TgaImporter/CMakeLists.txt create mode 100644 src/Plugins/TgaImporter/Test/CMakeLists.txt rename src/Plugins/{TGAImporter/Test/TGAImporterTest.cpp => TgaImporter/Test/TgaImporterTest.cpp} (79%) rename src/Plugins/{TGAImporter/Test/TGAImporterTest.h => TgaImporter/Test/TgaImporterTest.h} (78%) rename src/Plugins/{TGAImporter/TGAImporter.conf => TgaImporter/TgaImporter.conf} (100%) rename src/Plugins/{TGAImporter/TGAImporter.cpp => TgaImporter/TgaImporter.cpp} (77%) rename src/Plugins/{TGAImporter/TGAImporter.h => TgaImporter/TgaImporter.h} (85%) diff --git a/src/Plugins/TGAImporter/CMakeLists.txt b/src/Plugins/TGAImporter/CMakeLists.txt deleted file mode 100644 index 07c9e288d..000000000 --- a/src/Plugins/TGAImporter/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -corrade_add_plugin(TGAImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TGAImporter.conf TGAImporter.cpp) -target_link_libraries(TGAImporter ${MAGNUM_LIBRARY}) - -if(BUILD_TESTS) - add_library(TGAImporterTestLib TGAImporter.cpp) - target_link_libraries(TGAImporterTestLib ${MAGNUM_LIBRARY} ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) - enable_testing() - add_subdirectory(Test) -endif() - -if(WIN32) - target_link_libraries(TGAImporter ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) -endif() diff --git a/src/Plugins/TGAImporter/Test/CMakeLists.txt b/src/Plugins/TGAImporter/Test/CMakeLists.txt deleted file mode 100644 index 791ea97db..000000000 --- a/src/Plugins/TGAImporter/Test/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -corrade_add_test(TGAImporterTest TGAImporterTest.h TGAImporterTest.cpp) -target_link_libraries(TGAImporterTest TGAImporterTestLib) diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt new file mode 100644 index 000000000..d776849f9 --- /dev/null +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -0,0 +1,13 @@ +corrade_add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf TgaImporter.cpp) +target_link_libraries(TgaImporter ${MAGNUM_LIBRARY}) + +if(BUILD_TESTS) + add_library(TgaImporterTestLib TgaImporter.cpp) + target_link_libraries(TgaImporterTestLib ${MAGNUM_LIBRARY} ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) + enable_testing() + add_subdirectory(Test) +endif() + +if(WIN32) + target_link_libraries(TgaImporter ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) +endif() diff --git a/src/Plugins/TgaImporter/Test/CMakeLists.txt b/src/Plugins/TgaImporter/Test/CMakeLists.txt new file mode 100644 index 000000000..04005d2cf --- /dev/null +++ b/src/Plugins/TgaImporter/Test/CMakeLists.txt @@ -0,0 +1,2 @@ +corrade_add_test(TgaImporterTest TgaImporterTest.h TgaImporterTest.cpp) +target_link_libraries(TgaImporterTest TgaImporterTestLib) diff --git a/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp similarity index 79% rename from src/Plugins/TGAImporter/Test/TGAImporterTest.cpp rename to src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 3db36c206..231839da9 100644 --- a/src/Plugins/TGAImporter/Test/TGAImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -13,64 +13,64 @@ GNU Lesser General Public License version 3 for more details. */ -#include "TGAImporterTest.h" +#include "TgaImporterTest.h" #include #include "Utility/Debug.h" -#include "../TGAImporter.h" +#include "../TgaImporter.h" using namespace std; using namespace Corrade::Utility; -QTEST_APPLESS_MAIN(Magnum::Trade::TGAImporter::Test::TGAImporterTest) +QTEST_APPLESS_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) -namespace Magnum { namespace Trade { namespace TGAImporter { namespace Test { +namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { -void TGAImporterTest::paletted() { +void TgaImporterTest::paletted() { const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; istringstream in(string(data, sizeof(data))); ostringstream debug; Error::setOutput(&debug); - TGAImporter importer; + TgaImporter importer; QVERIFY(!importer.open(in)); - QCOMPARE(debug.str().c_str(), "TGAImporter: paletted files are not supported\n"); + QCOMPARE(debug.str().c_str(), "TgaImporter: paletted files are not supported\n"); } -void TGAImporterTest::nonRgb() { +void TgaImporterTest::nonRgb() { const char data[] = { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; istringstream in(string(data, sizeof(data))); ostringstream debug; Error::setOutput(&debug); - TGAImporter importer; + TgaImporter importer; QVERIFY(!importer.open(in)); - QCOMPARE(debug.str().c_str(), "TGAImporter: non-RGB files are not supported\n"); + QCOMPARE(debug.str().c_str(), "TgaImporter: non-RGB files are not supported\n"); } -void TGAImporterTest::bits16() { +void TgaImporterTest::bits16() { const char data[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 }; istringstream in(string(data, sizeof(data))); ostringstream debug; Error::setOutput(&debug); - TGAImporter importer; + TgaImporter importer; QVERIFY(!importer.open(in)); - QCOMPARE(debug.str().c_str(), "TGAImporter: unsupported bits-per-pixel: 16\n"); + QCOMPARE(debug.str().c_str(), "TgaImporter: unsupported bits-per-pixel: 16\n"); } -void TGAImporterTest::bits24() { +void TgaImporterTest::bits24() { const char data[] = { 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 }; std::istringstream in(string(data, sizeof(data))); - TGAImporter importer; + TgaImporter importer; QVERIFY(importer.open(in)); auto image = importer.image2D(0); QVERIFY(image->colorFormat() == AbstractTexture::ColorFormat::BGR); @@ -79,14 +79,14 @@ void TGAImporterTest::bits24() { QVERIFY(string(static_cast(image->data())) == string(data + 18, 2*3*3)); } -void TGAImporterTest::bits32() { +void TgaImporterTest::bits32() { const char data[] = { 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 }; std::istringstream in(string(data, sizeof(data))); - TGAImporter importer; + TgaImporter importer; QVERIFY(importer.open(in)); auto image = importer.image2D(0); QVERIFY(image->colorFormat() == AbstractTexture::ColorFormat::BGRA); diff --git a/src/Plugins/TGAImporter/Test/TGAImporterTest.h b/src/Plugins/TgaImporter/Test/TgaImporterTest.h similarity index 78% rename from src/Plugins/TGAImporter/Test/TGAImporterTest.h rename to src/Plugins/TgaImporter/Test/TgaImporterTest.h index 5f4a25ec4..b1a8f2554 100644 --- a/src/Plugins/TGAImporter/Test/TGAImporterTest.h +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Trade_TGAImporter_Test_TGAImporterTest_h -#define Magnum_Trade_TGAImporter_Test_TGAImporterTest_h +#ifndef Magnum_Trade_TgaImporter_Test_TgaImporterTest_h +#define Magnum_Trade_TgaImporter_Test_TgaImporterTest_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -17,9 +17,9 @@ #include -namespace Magnum { namespace Trade { namespace TGAImporter { namespace Test { +namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { -class TGAImporterTest: public QObject { +class TgaImporterTest: public QObject { Q_OBJECT private slots: diff --git a/src/Plugins/TGAImporter/TGAImporter.conf b/src/Plugins/TgaImporter/TgaImporter.conf similarity index 100% rename from src/Plugins/TGAImporter/TGAImporter.conf rename to src/Plugins/TgaImporter/TgaImporter.conf diff --git a/src/Plugins/TGAImporter/TGAImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp similarity index 77% rename from src/Plugins/TGAImporter/TGAImporter.cpp rename to src/Plugins/TgaImporter/TgaImporter.cpp index 480fac98c..49785ccf1 100644 --- a/src/Plugins/TGAImporter/TGAImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -13,7 +13,7 @@ GNU Lesser General Public License version 3 for more details. */ -#include "TGAImporter.h" +#include "TgaImporter.h" #include "Utility/Endianness.h" #include "Math/Vector2.h" @@ -22,20 +22,20 @@ using namespace std; using namespace Corrade::Utility; -PLUGIN_REGISTER(Magnum::Trade::TGAImporter::TGAImporter, "cz.mosra.magnum.Trade.AbstractImporter/0.1") +PLUGIN_REGISTER(Magnum::Trade::TgaImporter::TgaImporter, "cz.mosra.magnum.Trade.AbstractImporter/0.1") -namespace Magnum { namespace Trade { namespace TGAImporter { +namespace Magnum { namespace Trade { namespace TgaImporter { -static_assert(sizeof(TGAImporter::Header) == 18, "TGAImporter: header size is not 18 bytes"); +static_assert(sizeof(TgaImporter::Header) == 18, "TgaImporter: header size is not 18 bytes"); -bool TGAImporter::TGAImporter::open(const string& filename) { +bool TgaImporter::TgaImporter::open(const string& filename) { ifstream in(filename.c_str()); bool status = open(in); in.close(); return status; } -bool TGAImporter::open(std::istream& in) { +bool TgaImporter::open(std::istream& in) { if(_image) close(); if(!in.good()) return false; @@ -47,12 +47,12 @@ bool TGAImporter::open(std::istream& in) { header.height = Endianness::littleEndian(header.height); if(header.colorMapType != 0) { - Error() << "TGAImporter: paletted files are not supported"; + Error() << "TgaImporter: paletted files are not supported"; return false; } if(header.imageType != 2) { - Error() << "TGAImporter: non-RGB files are not supported"; + Error() << "TgaImporter: non-RGB files are not supported"; return false; } @@ -65,7 +65,7 @@ bool TGAImporter::open(std::istream& in) { colorFormat = AbstractTexture::ColorFormat::BGRA; break; default: - Error() << "TGAImporter: unsupported bits-per-pixel:" << (int) header.bpp; + Error() << "TgaImporter: unsupported bits-per-pixel:" << (int) header.bpp; return false; } @@ -79,12 +79,12 @@ bool TGAImporter::open(std::istream& in) { return true; } -void TGAImporter::close() { +void TgaImporter::close() { delete _image; _image = nullptr; } -ImageData2D* TGAImporter::image2D(size_t id) { +ImageData2D* TgaImporter::image2D(size_t id) { return _image; } diff --git a/src/Plugins/TGAImporter/TGAImporter.h b/src/Plugins/TgaImporter/TgaImporter.h similarity index 85% rename from src/Plugins/TGAImporter/TGAImporter.h rename to src/Plugins/TgaImporter/TgaImporter.h index ff8b8afe1..fe9a99144 100644 --- a/src/Plugins/TGAImporter/TGAImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Trade_TGAImporter_TGAImporter_h -#define Magnum_Trade_TGAImporter_TGAImporter_h +#ifndef Magnum_Trade_TgaImporter_TgaImporter_h +#define Magnum_Trade_TgaImporter_TgaImporter_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,17 +16,17 @@ */ /** @file - * @brief Class Magnum::Trade::TGAImporter::TGAImporter + * @brief Class Magnum::Trade::TgaImporter::TgaImporter */ #include "Trade/AbstractImporter.h" -namespace Magnum { namespace Trade { namespace TGAImporter { +namespace Magnum { namespace Trade { namespace TgaImporter { -class TGAImporter: public AbstractImporter { +class TgaImporter: public AbstractImporter { public: - TGAImporter(Corrade::PluginManager::AbstractPluginManager* manager = 0, const std::string& plugin = ""): AbstractImporter(manager, plugin), _image(nullptr) {} - inline virtual ~TGAImporter() { close(); } + TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager = 0, const std::string& plugin = ""): AbstractImporter(manager, plugin), _image(nullptr) {} + inline virtual ~TgaImporter() { close(); } inline int features() const { return OpenFile|OpenStream; } From 02f1f32edacc89293bc6de8e83e54bca48ec9a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 Mar 2012 23:55:28 +0100 Subject: [PATCH 017/112] Adapted to Corrade changes. --- src/Plugins/TgaImporter/TgaImporter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 49785ccf1..71416541c 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -22,7 +22,8 @@ using namespace std; using namespace Corrade::Utility; -PLUGIN_REGISTER(Magnum::Trade::TgaImporter::TgaImporter, "cz.mosra.magnum.Trade.AbstractImporter/0.1") +PLUGIN_REGISTER(TgaImporter, Magnum::Trade::TgaImporter::TgaImporter, + "cz.mosra.magnum.Trade.AbstractImporter/0.1") namespace Magnum { namespace Trade { namespace TgaImporter { From 391cb0fa9a6321bd0c77c67a808d72eaa955bf25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 Mar 2012 23:55:48 +0100 Subject: [PATCH 018/112] TgaImporter: error output everywhere where it makes sense. --- src/Plugins/TgaImporter/TgaImporter.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 71416541c..25b74a7b4 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -31,6 +31,10 @@ static_assert(sizeof(TgaImporter::Header) == 18, "TgaImporter: header size is no bool TgaImporter::TgaImporter::open(const string& filename) { ifstream in(filename.c_str()); + if(!in.good()) { + Error() << "TgaImporter: cannot open file" << filename; + return false; + } bool status = open(in); in.close(); return status; @@ -38,7 +42,10 @@ bool TgaImporter::TgaImporter::open(const string& filename) { bool TgaImporter::open(std::istream& in) { if(_image) close(); - if(!in.good()) return false; + if(!in.good()) { + Error() << "TgaImporter: cannot read input stream"; + return false; + } Header header; in.read(reinterpret_cast(&header), sizeof(Header)); From 595f23b06ea45e091bcc76bc985e3c6654bad6e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 2 Apr 2012 04:29:23 +0200 Subject: [PATCH 019/112] Adapted to Magnum changes. --- src/Plugins/TgaImporter/Test/TgaImporterTest.cpp | 8 ++++---- src/Plugins/TgaImporter/TgaImporter.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 231839da9..2adf5bd56 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -73,9 +73,9 @@ void TgaImporterTest::bits24() { TgaImporter importer; QVERIFY(importer.open(in)); auto image = importer.image2D(0); - QVERIFY(image->colorFormat() == AbstractTexture::ColorFormat::BGR); + QVERIFY(image->components() == AbstractImage::Components::BGR); QVERIFY(image->dimensions() == Math::Vector2(2, 3)); - QVERIFY(image->type() == TypeTraits::glType()); + QVERIFY(image->type() == TypeTraits::imageType()); QVERIFY(string(static_cast(image->data())) == string(data + 18, 2*3*3)); } @@ -89,9 +89,9 @@ void TgaImporterTest::bits32() { TgaImporter importer; QVERIFY(importer.open(in)); auto image = importer.image2D(0); - QVERIFY(image->colorFormat() == AbstractTexture::ColorFormat::BGRA); + QVERIFY(image->components() == AbstractImage::Components::BGRA); QVERIFY(image->dimensions() == Math::Vector2(2, 3)); - QVERIFY(image->type() == TypeTraits::glType()); + QVERIFY(image->type() == TypeTraits::imageType()); QVERIFY(string(static_cast(image->data()), 2*3*3) == string(data + 18, 2*3*3)); } diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 25b74a7b4..359f6158f 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -64,13 +64,13 @@ bool TgaImporter::open(std::istream& in) { return false; } - AbstractTexture::ColorFormat colorFormat; + AbstractImage::Components components; switch(header.bpp) { case 24: - colorFormat = AbstractTexture::ColorFormat::BGR; + components = AbstractImage::Components::BGR; break; case 32: - colorFormat = AbstractTexture::ColorFormat::BGRA; + components = AbstractImage::Components::BGRA; break; default: Error() << "TgaImporter: unsupported bits-per-pixel:" << (int) header.bpp; @@ -83,7 +83,7 @@ bool TgaImporter::open(std::istream& in) { Math::Vector2 dimensions(header.width, header.height); - _image = new ImageData2D(colorFormat, dimensions, buffer); + _image = new ImageData2D(dimensions, components, buffer); return true; } From eab9b132506b63473e5ffc63779a9cc6c0e47410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 15 May 2012 12:48:07 +0200 Subject: [PATCH 020/112] TgaImporter: test for opening inexistent files. --- src/Plugins/TgaImporter/Test/TgaImporterTest.cpp | 9 +++++++++ src/Plugins/TgaImporter/Test/TgaImporterTest.h | 1 + 2 files changed, 10 insertions(+) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 2adf5bd56..a237555d0 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -27,6 +27,15 @@ QTEST_APPLESS_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { +void TgaImporterTest::openInexistent() { + ostringstream debug; + Error::setOutput(&debug); + + TgaImporter importer; + QVERIFY(!importer.open("inexistent.file")); + QCOMPARE(debug.str().c_str(), "TgaImporter: cannot open file inexistent.file\n"); +} + void TgaImporterTest::paletted() { const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; istringstream in(string(data, sizeof(data))); diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.h b/src/Plugins/TgaImporter/Test/TgaImporterTest.h index b1a8f2554..f4647c681 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.h +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.h @@ -23,6 +23,7 @@ class TgaImporterTest: public QObject { Q_OBJECT private slots: + void openInexistent(); void paletted(); void nonRgb(); void bits16(); From 1f4e6022ac318e7c348da4b5f74739937fc2aa75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 15 May 2012 12:49:38 +0200 Subject: [PATCH 021/112] TgaImporter: check if the file is long enough. Prevents undefined behavior when opening e.g. empty files. --- src/Plugins/TgaImporter/Test/TgaImporterTest.cpp | 12 ++++++++++++ src/Plugins/TgaImporter/Test/TgaImporterTest.h | 1 + src/Plugins/TgaImporter/TgaImporter.cpp | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index a237555d0..29db4bc52 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -36,6 +36,18 @@ void TgaImporterTest::openInexistent() { QCOMPARE(debug.str().c_str(), "TgaImporter: cannot open file inexistent.file\n"); } +void TgaImporterTest::openShort() { + const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + istringstream in(string(data, sizeof(data))); + + ostringstream debug; + Error::setOutput(&debug); + + TgaImporter importer; + QVERIFY(!importer.open(in)); + QCOMPARE(debug.str().c_str(), "TgaImporter: the file is too short: 17 bytes\n"); +} + void TgaImporterTest::paletted() { const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; istringstream in(string(data, sizeof(data))); diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.h b/src/Plugins/TgaImporter/Test/TgaImporterTest.h index f4647c681..e4d0f1fac 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.h +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.h @@ -24,6 +24,7 @@ class TgaImporterTest: public QObject { private slots: void openInexistent(); + void openShort(); void paletted(); void nonRgb(); void bits16(); diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 359f6158f..a8c49a176 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -47,6 +47,15 @@ bool TgaImporter::open(std::istream& in) { return false; } + /* Check if the file is long enough */ + in.seekg(0, istream::end); + streampos filesize = in.tellg(); + in.seekg(0, istream::beg); + if(filesize < streampos(sizeof(Header))) { + Error() << "TgaImporter: the file is too short:" << filesize << "bytes"; + return false; + } + Header header; in.read(reinterpret_cast(&header), sizeof(Header)); From 2d063825c39695b400643a9b2f3e31fb2183f822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 15 May 2012 12:50:32 +0200 Subject: [PATCH 022/112] TgaImporter: minor cleanup --- src/Plugins/TgaImporter/TgaImporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index a8c49a176..ec37e8443 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -40,7 +40,7 @@ bool TgaImporter::TgaImporter::open(const string& filename) { return status; } -bool TgaImporter::open(std::istream& in) { +bool TgaImporter::open(istream& in) { if(_image) close(); if(!in.good()) { Error() << "TgaImporter: cannot read input stream"; From 1c17bf3eed162d93a9cf2fcfd0a553c9a6dcea37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 May 2012 20:19:45 +0200 Subject: [PATCH 023/112] Doc++ --- src/Plugins/TgaImporter/TgaImporter.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index fe9a99144..095dbc11e 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -21,10 +21,15 @@ #include "Trade/AbstractImporter.h" -namespace Magnum { namespace Trade { namespace TgaImporter { +namespace Magnum { namespace Trade { +/** @brief TGA importer */ +namespace TgaImporter { + +/** @brief TGA importer plugin */ class TgaImporter: public AbstractImporter { public: + /** @copydoc AbstractImporter::AbstractImporter() */ TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager = 0, const std::string& plugin = ""): AbstractImporter(manager, plugin), _image(nullptr) {} inline virtual ~TgaImporter() { close(); } @@ -38,6 +43,7 @@ class TgaImporter: public AbstractImporter { ImageData2D* image2D(size_t id); #pragma pack(1) + /** @brief TGA file header */ struct Header { GLbyte identsize; /**< @brief Size of ID field that follows header (0) */ GLbyte colorMapType; /**< @brief 0 = None, 1 = paletted */ From 38ccb3cbafbf2499f07c716db1652cd7bb9ff993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 22 May 2012 14:32:22 +0200 Subject: [PATCH 024/112] Documented directories containing namespaces. --- src/Plugins/TgaImporter/TgaImporter.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 095dbc11e..1f3a342d8 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -21,10 +21,7 @@ #include "Trade/AbstractImporter.h" -namespace Magnum { namespace Trade { - -/** @brief TGA importer */ -namespace TgaImporter { +namespace Magnum { namespace Trade { namespace TgaImporter { /** @brief TGA importer plugin */ class TgaImporter: public AbstractImporter { From a0941a674b8d46715637d678aacce63a4918980b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 22 May 2012 17:24:03 +0200 Subject: [PATCH 025/112] Doc++ --- src/Plugins/TgaImporter/TgaImporter.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 1f3a342d8..4b369903d 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -48,12 +48,12 @@ class TgaImporter: public AbstractImporter { unsigned short colorMapStart; /**< @brief First color map entry */ unsigned short colorMapLength; /**< @brief Number of colors */ unsigned char colorMapBpp; /**< @brief Bits per palette entry */ - unsigned short beginX; /**< @brief Image x origin */ - unsigned short beginY; /**< @brief Image y origin */ - unsigned short width; /**< @brief Image width */ - unsigned short height; /**< @brief Image height */ + unsigned short beginX; /**< @brief %Image x origin */ + unsigned short beginY; /**< @brief %Image y origin */ + unsigned short width; /**< @brief %Image width */ + unsigned short height; /**< @brief %Image height */ GLbyte bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ - GLbyte descriptor; /**< @brief Image descriptor */ + GLbyte descriptor; /**< @brief %Image descriptor */ }; #pragma pack(8) From 3910f88219722637e87f463f8c263144e2d55ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 23 May 2012 00:27:36 +0200 Subject: [PATCH 026/112] Compiling with -fvisibility=hidden. TGA importer plugin is used by COLLADA importer plugin, exporting symbols for it. --- src/Plugins/TgaImporter/TgaImporter.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 4b369903d..8aa30cdc7 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -21,10 +21,22 @@ #include "Trade/AbstractImporter.h" +#ifdef _WIN32 + #ifdef TgaImporter_EXPORTS + #define TGAIMPORTER_EXPORT __declspec(dllexport) + #else + #define TGAIMPORTER_EXPORT __declspec(dllimport) + #endif + #define TGAIMPORTER_LOCAL +#else + #define TGAIMPORTER_EXPORT __attribute__ ((visibility ("default"))) + #define TGAIMPORTER_LOCAL __attribute__ ((visibility ("hidden"))) +#endif + namespace Magnum { namespace Trade { namespace TgaImporter { /** @brief TGA importer plugin */ -class TgaImporter: public AbstractImporter { +class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { public: /** @copydoc AbstractImporter::AbstractImporter() */ TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager = 0, const std::string& plugin = ""): AbstractImporter(manager, plugin), _image(nullptr) {} @@ -41,7 +53,7 @@ class TgaImporter: public AbstractImporter { #pragma pack(1) /** @brief TGA file header */ - struct Header { + struct TGAIMPORTER_LOCAL Header { GLbyte identsize; /**< @brief Size of ID field that follows header (0) */ GLbyte colorMapType; /**< @brief 0 = None, 1 = paletted */ GLbyte imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ From d7d6d6bff05491f0d30e2910644de31f1df0c7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 23 May 2012 02:01:41 +0200 Subject: [PATCH 027/112] Reuse already compiled objects for unit test libraries. Speeds up compilation like infinity times. CMake 2.8.8 is required for OBJECT library target. --- src/Plugins/TgaImporter/CMakeLists.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt index d776849f9..eaf138d32 100644 --- a/src/Plugins/TgaImporter/CMakeLists.txt +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -1,8 +1,13 @@ -corrade_add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf TgaImporter.cpp) +add_library(TgaImporterObjects OBJECT TgaImporter.cpp) +if(USE_FPIC) + set_target_properties(TgaImporterObjects PROPERTIES COMPILE_FLAGS -fPIC) +endif() + +corrade_add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf $) target_link_libraries(TgaImporter ${MAGNUM_LIBRARY}) if(BUILD_TESTS) - add_library(TgaImporterTestLib TgaImporter.cpp) + add_library(TgaImporterTestLib $) target_link_libraries(TgaImporterTestLib ${MAGNUM_LIBRARY} ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) enable_testing() add_subdirectory(Test) From 010ee7429a9e642645743d609d7fa81d190fe8fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 23 May 2012 09:32:02 +0200 Subject: [PATCH 028/112] Using more portable CMAKE_SHARED_LIBRARY_CXX_FLAGS instead of -fPIC. --- src/Plugins/TgaImporter/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt index eaf138d32..59531ee85 100644 --- a/src/Plugins/TgaImporter/CMakeLists.txt +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -1,7 +1,5 @@ add_library(TgaImporterObjects OBJECT TgaImporter.cpp) -if(USE_FPIC) - set_target_properties(TgaImporterObjects PROPERTIES COMPILE_FLAGS -fPIC) -endif() +set_target_properties(TgaImporterObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) corrade_add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf $) target_link_libraries(TgaImporter ${MAGNUM_LIBRARY}) From 192fab0d6c49f9a85cebb70d50dece12240a0f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 23 May 2012 10:38:59 +0200 Subject: [PATCH 029/112] Exclude visibility macros from documentation. --- src/Plugins/TgaImporter/TgaImporter.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 8aa30cdc7..421a0d032 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -21,6 +21,7 @@ #include "Trade/AbstractImporter.h" +#ifndef DOXYGEN_GENERATING_OUTPUT #ifdef _WIN32 #ifdef TgaImporter_EXPORTS #define TGAIMPORTER_EXPORT __declspec(dllexport) @@ -32,6 +33,7 @@ #define TGAIMPORTER_EXPORT __attribute__ ((visibility ("default"))) #define TGAIMPORTER_LOCAL __attribute__ ((visibility ("hidden"))) #endif +#endif namespace Magnum { namespace Trade { namespace TgaImporter { From 186adfbd7353d7bac09ac4348f76fb0a291f5a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 23 May 2012 17:38:31 +0200 Subject: [PATCH 030/112] Fixed plugin registration after recent object library changes. --- src/Plugins/TgaImporter/CMakeLists.txt | 2 +- src/Plugins/TgaImporter/TgaImporter.cpp | 3 --- .../TgaImporterPluginRegistration.cpp | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/Plugins/TgaImporter/TgaImporterPluginRegistration.cpp diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt index 59531ee85..601cba762 100644 --- a/src/Plugins/TgaImporter/CMakeLists.txt +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -1,7 +1,7 @@ add_library(TgaImporterObjects OBJECT TgaImporter.cpp) set_target_properties(TgaImporterObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) -corrade_add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf $) +corrade_add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf $ TgaImporterPluginRegistration.cpp) target_link_libraries(TgaImporter ${MAGNUM_LIBRARY}) if(BUILD_TESTS) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index ec37e8443..b137901e6 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -22,9 +22,6 @@ using namespace std; using namespace Corrade::Utility; -PLUGIN_REGISTER(TgaImporter, Magnum::Trade::TgaImporter::TgaImporter, - "cz.mosra.magnum.Trade.AbstractImporter/0.1") - namespace Magnum { namespace Trade { namespace TgaImporter { static_assert(sizeof(TgaImporter::Header) == 18, "TgaImporter: header size is not 18 bytes"); diff --git a/src/Plugins/TgaImporter/TgaImporterPluginRegistration.cpp b/src/Plugins/TgaImporter/TgaImporterPluginRegistration.cpp new file mode 100644 index 000000000..a408bef17 --- /dev/null +++ b/src/Plugins/TgaImporter/TgaImporterPluginRegistration.cpp @@ -0,0 +1,19 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "TgaImporter.h" + +PLUGIN_REGISTER(TgaImporter, Magnum::Trade::TgaImporter::TgaImporter, + "cz.mosra.magnum.Trade.AbstractImporter/0.1") From 7d277b81e7128c6b9c913539a6a25c331a0c24b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 23 May 2012 17:48:37 +0200 Subject: [PATCH 031/112] Hide static_assert from documentation. --- src/Plugins/TgaImporter/TgaImporter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index b137901e6..599392a2e 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -24,7 +24,9 @@ using namespace Corrade::Utility; namespace Magnum { namespace Trade { namespace TgaImporter { +#ifndef DOXYGEN_GENERATING_OUTPUT static_assert(sizeof(TgaImporter::Header) == 18, "TgaImporter: header size is not 18 bytes"); +#endif bool TgaImporter::TgaImporter::open(const string& filename) { ifstream in(filename.c_str()); From 18e9e7aa939cbd5bc29e43d1117e882f1bcdd3be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 28 May 2012 17:14:16 +0200 Subject: [PATCH 032/112] Adapted to Magnum changes. --- src/Plugins/TgaImporter/Test/TgaImporterTest.cpp | 1 - src/Plugins/TgaImporter/TgaImporter.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 29db4bc52..be277984d 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -21,7 +21,6 @@ #include "../TgaImporter.h" using namespace std; -using namespace Corrade::Utility; QTEST_APPLESS_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 599392a2e..c6fcf795d 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -20,7 +20,6 @@ #include "Trade/ImageData.h" using namespace std; -using namespace Corrade::Utility; namespace Magnum { namespace Trade { namespace TgaImporter { From a211db25c73340acb2febe1f1ca24c3eb865855c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 28 May 2012 17:15:02 +0200 Subject: [PATCH 033/112] Added documentation TODO. --- src/Plugins/TgaImporter/TgaImporter.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 421a0d032..f5522a67a 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -55,6 +55,7 @@ class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { #pragma pack(1) /** @brief TGA file header */ + /** @todoc Enable @c INLINE_SIMPLE_STRUCTS again when unclosed <component> in tagfile is fixed*/ struct TGAIMPORTER_LOCAL Header { GLbyte identsize; /**< @brief Size of ID field that follows header (0) */ GLbyte colorMapType; /**< @brief 0 = None, 1 = paletted */ From f4ff7de6117b6e19b3fb755ff9e974bb8534cf0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 1 Jun 2012 11:58:34 +0200 Subject: [PATCH 034/112] Revert "Adapted to Magnum changes." Don't commit without testing. This reverts commit e709ad800bb7ca4b63ddab4b4e8b3ae1f8113fb7. --- src/Plugins/TgaImporter/TgaImporter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index c6fcf795d..599392a2e 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -20,6 +20,7 @@ #include "Trade/ImageData.h" using namespace std; +using namespace Corrade::Utility; namespace Magnum { namespace Trade { namespace TgaImporter { From 6f3c2ac5ec189071d66cd690c4001c806540eb02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 23 Jun 2012 04:05:19 +0200 Subject: [PATCH 035/112] Adapted to Magnum changes. --- src/Plugins/TgaImporter/TgaImporter.cpp | 2 +- src/Plugins/TgaImporter/TgaImporter.h | 6 +++--- src/Plugins/TgaImporter/TgaImporterPluginRegistration.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 599392a2e..7a9f70d5b 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -100,7 +100,7 @@ void TgaImporter::close() { _image = nullptr; } -ImageData2D* TgaImporter::image2D(size_t id) { +ImageData2D* TgaImporter::image2D(unsigned int id) { return _image; } diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index f5522a67a..daab490bc 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -44,14 +44,14 @@ class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager = 0, const std::string& plugin = ""): AbstractImporter(manager, plugin), _image(nullptr) {} inline virtual ~TgaImporter() { close(); } - inline int features() const { return OpenFile|OpenStream; } + inline Features features() const { return Feature::OpenFile|Feature::OpenStream; } bool open(std::istream& in); bool open(const std::string& filename); void close(); - inline size_t image2DCount() const { return _image ? 1 : 0; } - ImageData2D* image2D(size_t id); + inline unsigned int image2DCount() const { return _image ? 1 : 0; } + ImageData2D* image2D(unsigned int id); #pragma pack(1) /** @brief TGA file header */ diff --git a/src/Plugins/TgaImporter/TgaImporterPluginRegistration.cpp b/src/Plugins/TgaImporter/TgaImporterPluginRegistration.cpp index a408bef17..601ed8fd1 100644 --- a/src/Plugins/TgaImporter/TgaImporterPluginRegistration.cpp +++ b/src/Plugins/TgaImporter/TgaImporterPluginRegistration.cpp @@ -16,4 +16,4 @@ #include "TgaImporter.h" PLUGIN_REGISTER(TgaImporter, Magnum::Trade::TgaImporter::TgaImporter, - "cz.mosra.magnum.Trade.AbstractImporter/0.1") + "cz.mosra.magnum.Trade.AbstractImporter/0.2") From e887c1a140e93d92466e92017f1b3284f3df23b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 23 Jun 2012 04:06:55 +0200 Subject: [PATCH 036/112] Renamed helper headers to have lowercase first letter. --- src/Plugins/TgaImporter/CMakeLists.txt | 2 +- ...PluginRegistration.cpp => pluginRegistrationTgaImporter.cpp} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/Plugins/TgaImporter/{TgaImporterPluginRegistration.cpp => pluginRegistrationTgaImporter.cpp} (100%) diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt index 601cba762..e0ccbebd4 100644 --- a/src/Plugins/TgaImporter/CMakeLists.txt +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -1,7 +1,7 @@ add_library(TgaImporterObjects OBJECT TgaImporter.cpp) set_target_properties(TgaImporterObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) -corrade_add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf $ TgaImporterPluginRegistration.cpp) +corrade_add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf $ pluginRegistrationTgaImporter.cpp) target_link_libraries(TgaImporter ${MAGNUM_LIBRARY}) if(BUILD_TESTS) diff --git a/src/Plugins/TgaImporter/TgaImporterPluginRegistration.cpp b/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp similarity index 100% rename from src/Plugins/TgaImporter/TgaImporterPluginRegistration.cpp rename to src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp From dc0895142ab59e1b0b8f89ae94f3aecc78797e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 23 Jun 2012 14:03:45 +0200 Subject: [PATCH 037/112] Ability to explicitly specify name for image from TgaImporter. --- src/Plugins/TgaImporter/TgaImporter.cpp | 8 ++++---- src/Plugins/TgaImporter/TgaImporter.h | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 7a9f70d5b..cfb3bc3bd 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -28,18 +28,18 @@ namespace Magnum { namespace Trade { namespace TgaImporter { static_assert(sizeof(TgaImporter::Header) == 18, "TgaImporter: header size is not 18 bytes"); #endif -bool TgaImporter::TgaImporter::open(const string& filename) { +bool TgaImporter::TgaImporter::open(const string& filename, const string& name) { ifstream in(filename.c_str()); if(!in.good()) { Error() << "TgaImporter: cannot open file" << filename; return false; } - bool status = open(in); + bool status = open(in, name); in.close(); return status; } -bool TgaImporter::open(istream& in) { +bool TgaImporter::open(istream& in, const string& name) { if(_image) close(); if(!in.good()) { Error() << "TgaImporter: cannot read input stream"; @@ -91,7 +91,7 @@ bool TgaImporter::open(istream& in) { Math::Vector2 dimensions(header.width, header.height); - _image = new ImageData2D(dimensions, components, buffer); + _image = new ImageData2D(name, dimensions, components, buffer); return true; } diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index daab490bc..8a61fb70d 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -46,8 +46,22 @@ class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { inline Features features() const { return Feature::OpenFile|Feature::OpenStream; } - bool open(std::istream& in); - bool open(const std::string& filename); + /** + * @brief Open input stream with specific image name + * + * @see open(std::istream&), ImageData2D::name() + */ + bool open(std::istream& in, const std::string& name); + inline bool open(std::istream& in) { return open(in, ""); } + + /** + * @brief Open file with specific image name + * + * @see open(const std::string&), ImageData2D::name() + */ + bool open(const std::string& filename, const std::string& name); + inline bool open(const std::string& filename) { return open(filename, ""); } + void close(); inline unsigned int image2DCount() const { return _image ? 1 : 0; } From 3cb611cbbfac715ee331f60c397cffad81464160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 23 Jun 2012 17:31:57 +0200 Subject: [PATCH 038/112] TgaImporter: quick ugly fix - don't delete the image data on closing. It causes problems in ColladaImporter, because it uses TgaImporter for opening the image, then takes ownership of the data and then destroys the importer. Need to think this thoroughly. --- src/Plugins/TgaImporter/TgaImporter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index cfb3bc3bd..97c96e756 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -96,7 +96,8 @@ bool TgaImporter::open(istream& in, const string& name) { } void TgaImporter::close() { - delete _image; + /** @todo fixme: delete it only if it wasn't retrieved by user */ + //delete _image; _image = nullptr; } From e75db8aede2b545812e503b646e0eed954d62b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 20 Jul 2012 21:47:42 +0200 Subject: [PATCH 039/112] Don't use C-style casts. --- src/Plugins/TgaImporter/TgaImporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 97c96e756..fe9f8fc86 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -81,7 +81,7 @@ bool TgaImporter::open(istream& in, const string& name) { components = AbstractImage::Components::BGRA; break; default: - Error() << "TgaImporter: unsupported bits-per-pixel:" << (int) header.bpp; + Error() << "TgaImporter: unsupported bits-per-pixel:" << int(header.bpp); return false; } From 6cd334d9c38e9bcebde37a739902199feef9061d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 20 Jul 2012 21:47:57 +0200 Subject: [PATCH 040/112] Anonymized unused function parameter. --- src/Plugins/TgaImporter/TgaImporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index fe9f8fc86..30ebfd24c 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -101,7 +101,7 @@ void TgaImporter::close() { _image = nullptr; } -ImageData2D* TgaImporter::image2D(unsigned int id) { +ImageData2D* TgaImporter::image2D(unsigned int) { return _image; } From 2aba9b98fa1f7d6a4a222646fb4f0877bdd509e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 3 Aug 2012 01:33:18 +0200 Subject: [PATCH 041/112] Got rid of Qt's QtTest in favor of Corrade's TestSuite. Also added check() function to AUR Git PKGBUILD. --- src/Plugins/TgaImporter/Test/CMakeLists.txt | 3 +- .../TgaImporter/Test/TgaImporterTest.cpp | 55 +++++++++++-------- .../TgaImporter/Test/TgaImporterTest.h | 8 +-- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/CMakeLists.txt b/src/Plugins/TgaImporter/Test/CMakeLists.txt index 04005d2cf..f53849abf 100644 --- a/src/Plugins/TgaImporter/Test/CMakeLists.txt +++ b/src/Plugins/TgaImporter/Test/CMakeLists.txt @@ -1,2 +1 @@ -corrade_add_test(TgaImporterTest TgaImporterTest.h TgaImporterTest.cpp) -target_link_libraries(TgaImporterTest TgaImporterTestLib) +corrade_add_test2(TgaImporterTest TgaImporterTest.cpp LIBRARIES TgaImporterTestLib) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index be277984d..7f084bacd 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -15,24 +15,31 @@ #include "TgaImporterTest.h" -#include - -#include "Utility/Debug.h" #include "../TgaImporter.h" using namespace std; -QTEST_APPLESS_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) +CORRADE_TEST_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { +TgaImporterTest::TgaImporterTest() { + addTests(&TgaImporterTest::openInexistent, + &TgaImporterTest::openShort, + &TgaImporterTest::paletted, + &TgaImporterTest::nonRgb, + &TgaImporterTest::bits16, + &TgaImporterTest::bits24, + &TgaImporterTest::bits32); +} + void TgaImporterTest::openInexistent() { ostringstream debug; Error::setOutput(&debug); TgaImporter importer; - QVERIFY(!importer.open("inexistent.file")); - QCOMPARE(debug.str().c_str(), "TgaImporter: cannot open file inexistent.file\n"); + CORRADE_VERIFY(!importer.open("inexistent.file")); + CORRADE_COMPARE(debug.str(), "TgaImporter: cannot open file inexistent.file\n"); } void TgaImporterTest::openShort() { @@ -43,8 +50,8 @@ void TgaImporterTest::openShort() { Error::setOutput(&debug); TgaImporter importer; - QVERIFY(!importer.open(in)); - QCOMPARE(debug.str().c_str(), "TgaImporter: the file is too short: 17 bytes\n"); + CORRADE_VERIFY(!importer.open(in)); + CORRADE_COMPARE(debug.str(), "TgaImporter: the file is too short: 17 bytes\n"); } void TgaImporterTest::paletted() { @@ -55,8 +62,8 @@ void TgaImporterTest::paletted() { Error::setOutput(&debug); TgaImporter importer; - QVERIFY(!importer.open(in)); - QCOMPARE(debug.str().c_str(), "TgaImporter: paletted files are not supported\n"); + CORRADE_VERIFY(!importer.open(in)); + CORRADE_COMPARE(debug.str(), "TgaImporter: paletted files are not supported\n"); } void TgaImporterTest::nonRgb() { @@ -67,8 +74,8 @@ void TgaImporterTest::nonRgb() { Error::setOutput(&debug); TgaImporter importer; - QVERIFY(!importer.open(in)); - QCOMPARE(debug.str().c_str(), "TgaImporter: non-RGB files are not supported\n"); + CORRADE_VERIFY(!importer.open(in)); + CORRADE_COMPARE(debug.str(), "TgaImporter: non-RGB files are not supported\n"); } void TgaImporterTest::bits16() { @@ -79,8 +86,8 @@ void TgaImporterTest::bits16() { Error::setOutput(&debug); TgaImporter importer; - QVERIFY(!importer.open(in)); - QCOMPARE(debug.str().c_str(), "TgaImporter: unsupported bits-per-pixel: 16\n"); + CORRADE_VERIFY(!importer.open(in)); + CORRADE_COMPARE(debug.str(), "TgaImporter: unsupported bits-per-pixel: 16\n"); } void TgaImporterTest::bits24() { @@ -91,12 +98,12 @@ void TgaImporterTest::bits24() { std::istringstream in(string(data, sizeof(data))); TgaImporter importer; - QVERIFY(importer.open(in)); + CORRADE_VERIFY(importer.open(in)); auto image = importer.image2D(0); - QVERIFY(image->components() == AbstractImage::Components::BGR); - QVERIFY(image->dimensions() == Math::Vector2(2, 3)); - QVERIFY(image->type() == TypeTraits::imageType()); - QVERIFY(string(static_cast(image->data())) == string(data + 18, 2*3*3)); + CORRADE_VERIFY(image->components() == AbstractImage::Components::BGR); + 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)); } void TgaImporterTest::bits32() { @@ -107,12 +114,12 @@ void TgaImporterTest::bits32() { std::istringstream in(string(data, sizeof(data))); TgaImporter importer; - QVERIFY(importer.open(in)); + CORRADE_VERIFY(importer.open(in)); auto image = importer.image2D(0); - QVERIFY(image->components() == AbstractImage::Components::BGRA); - QVERIFY(image->dimensions() == Math::Vector2(2, 3)); - QVERIFY(image->type() == TypeTraits::imageType()); - QVERIFY(string(static_cast(image->data()), 2*3*3) == string(data + 18, 2*3*3)); + CORRADE_VERIFY(image->components() == AbstractImage::Components::BGRA); + 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)); } }}}} diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.h b/src/Plugins/TgaImporter/Test/TgaImporterTest.h index e4d0f1fac..2f105ac30 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.h +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.h @@ -15,14 +15,14 @@ GNU Lesser General Public License version 3 for more details. */ -#include +#include namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { -class TgaImporterTest: public QObject { - Q_OBJECT +class TgaImporterTest: public Corrade::TestSuite::Tester { + public: + TgaImporterTest(); - private slots: void openInexistent(); void openShort(); void paletted(); From 21ef62201de3219e4e4424bbe2e79a261902896d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 3 Aug 2012 18:53:11 +0200 Subject: [PATCH 042/112] Treat Corrade includes as real, not internal dependency. --- src/Plugins/TgaImporter/TgaImporter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 30ebfd24c..1b8bae143 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -15,7 +15,8 @@ #include "TgaImporter.h" -#include "Utility/Endianness.h" +#include + #include "Math/Vector2.h" #include "Trade/ImageData.h" From 68ea16ea99e283ff9a98b8c1c6e52eb4da521508 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 3 Aug 2012 18:54:27 +0200 Subject: [PATCH 043/112] TgaImporter: ported to work also with OpenGL ES. OpenGL ES doesn't have BGR and BGRA, swizzling pixel values to make it RGB and RGBA there. --- .../TgaImporter/Test/TgaImporterTest.cpp | 26 +++++++++++++++++-- src/Plugins/TgaImporter/TgaImporter.cpp | 22 ++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) 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; } From f58ccfa1f7115f39df0f84cc06016dcfad10dc0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 17 Sep 2012 03:17:06 +0200 Subject: [PATCH 044/112] Adapted to (old) Magnum changes. --- src/Plugins/TgaImporter/Test/TgaImporterTest.cpp | 5 +++++ src/Plugins/TgaImporter/TgaImporter.cpp | 6 +++--- src/Plugins/TgaImporter/TgaImporter.h | 10 +++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 67806a31b..26e7a9809 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -15,9 +15,14 @@ #include "TgaImporterTest.h" +#include +#include +#include + #include "../TgaImporter.h" using namespace std; +using namespace Corrade::Utility; CORRADE_TEST_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 0364ec621..c2551f4f4 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -19,7 +19,7 @@ #include #include "Math/Vector2.h" -#include "Math/Swizzle.h" +#include #include "Trade/ImageData.h" using namespace std; @@ -106,11 +106,11 @@ bool TgaImporter::open(istream& in, const string& name) { 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); }); + [](Math::Vector3 pixel) { return 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); }); + [](Math::Vector4 pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); }); } #endif diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 8a61fb70d..27904108c 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -71,9 +71,9 @@ class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { /** @brief TGA file header */ /** @todoc Enable @c INLINE_SIMPLE_STRUCTS again when unclosed <component> in tagfile is fixed*/ struct TGAIMPORTER_LOCAL Header { - GLbyte identsize; /**< @brief Size of ID field that follows header (0) */ - GLbyte colorMapType; /**< @brief 0 = None, 1 = paletted */ - GLbyte imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ + char identsize; /**< @brief Size of ID field that follows header (0) */ + char colorMapType; /**< @brief 0 = None, 1 = paletted */ + char imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ unsigned short colorMapStart; /**< @brief First color map entry */ unsigned short colorMapLength; /**< @brief Number of colors */ unsigned char colorMapBpp; /**< @brief Bits per palette entry */ @@ -81,8 +81,8 @@ class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { unsigned short beginY; /**< @brief %Image y origin */ unsigned short width; /**< @brief %Image width */ unsigned short height; /**< @brief %Image height */ - GLbyte bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ - GLbyte descriptor; /**< @brief %Image descriptor */ + char bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ + char descriptor; /**< @brief %Image descriptor */ }; #pragma pack(8) From 92e250b6001a700ad95287046eb155c248545c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Oct 2012 20:08:20 +0200 Subject: [PATCH 045/112] Adapted to Magnum changes. --- .../TgaImporter/Test/TgaImporterTest.cpp | 4 +-- src/Plugins/TgaImporter/TgaImporter.cpp | 2 +- src/Plugins/TgaImporter/TgaImporter.h | 28 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 26e7a9809..6d7574d7b 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -117,7 +117,7 @@ void TgaImporterTest::bits24() { #else CORRADE_VERIFY(image->components() == AbstractImage::Components::RGB); #endif - CORRADE_COMPARE(image->dimensions(), Math::Vector2(2, 3)); + CORRADE_COMPARE(image->size(), Math::Vector2(2, 3)); CORRADE_VERIFY(image->type() == TypeTraits::imageType()); CORRADE_COMPARE(string(static_cast(image->data()), 2*3*3), string(pixels, 2*3*3)); } @@ -144,7 +144,7 @@ void TgaImporterTest::bits32() { #else CORRADE_VERIFY(image->components() == AbstractImage::Components::RGBA); #endif - CORRADE_COMPARE(image->dimensions(), Math::Vector2(2, 3)); + CORRADE_COMPARE(image->size(), Math::Vector2(2, 3)); CORRADE_VERIFY(image->type() == TypeTraits::imageType()); 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 c2551f4f4..593c774a1 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -124,7 +124,7 @@ void TgaImporter::close() { _image = nullptr; } -ImageData2D* TgaImporter::image2D(unsigned int) { +ImageData2D* TgaImporter::image2D(std::uint32_t) { return _image; } diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 27904108c..121de819d 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -64,25 +64,25 @@ class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { void close(); - inline unsigned int image2DCount() const { return _image ? 1 : 0; } - ImageData2D* image2D(unsigned int id); + inline std::uint32_t image2DCount() const { return _image ? 1 : 0; } + ImageData2D* image2D(std::uint32_t id); #pragma pack(1) /** @brief TGA file header */ /** @todoc Enable @c INLINE_SIMPLE_STRUCTS again when unclosed <component> in tagfile is fixed*/ struct TGAIMPORTER_LOCAL Header { - char identsize; /**< @brief Size of ID field that follows header (0) */ - char colorMapType; /**< @brief 0 = None, 1 = paletted */ - char imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ - unsigned short colorMapStart; /**< @brief First color map entry */ - unsigned short colorMapLength; /**< @brief Number of colors */ - unsigned char colorMapBpp; /**< @brief Bits per palette entry */ - unsigned short beginX; /**< @brief %Image x origin */ - unsigned short beginY; /**< @brief %Image y origin */ - unsigned short width; /**< @brief %Image width */ - unsigned short height; /**< @brief %Image height */ - char bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ - char descriptor; /**< @brief %Image descriptor */ + std::uint8_t identsize; /**< @brief Size of ID field that follows header (0) */ + std::uint8_t colorMapType; /**< @brief 0 = None, 1 = paletted */ + std::uint8_t imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ + std::uint16_t colorMapStart; /**< @brief First color map entry */ + std::uint16_t colorMapLength; /**< @brief Number of colors */ + std::uint8_t colorMapBpp; /**< @brief Bits per palette entry */ + std::uint16_t beginX; /**< @brief %Image x origin */ + std::uint16_t beginY; /**< @brief %Image y origin */ + std::uint16_t width; /**< @brief %Image width */ + std::uint16_t height; /**< @brief %Image height */ + std::uint8_t bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ + std::uint8_t descriptor; /**< @brief %Image descriptor */ }; #pragma pack(8) From 050eb89d47dd47765c383a4462fef387d3b5855f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Dec 2012 20:52:47 +0100 Subject: [PATCH 046/112] Adapted to Corrade changes. --- src/Plugins/TgaImporter/Test/CMakeLists.txt | 2 +- src/Plugins/TgaImporter/Test/TgaImporterTest.h | 2 +- src/Plugins/TgaImporter/TgaImporter.cpp | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/CMakeLists.txt b/src/Plugins/TgaImporter/Test/CMakeLists.txt index f53849abf..40adc197a 100644 --- a/src/Plugins/TgaImporter/Test/CMakeLists.txt +++ b/src/Plugins/TgaImporter/Test/CMakeLists.txt @@ -1 +1 @@ -corrade_add_test2(TgaImporterTest TgaImporterTest.cpp LIBRARIES TgaImporterTestLib) +corrade_add_test(TgaImporterTest TgaImporterTest.cpp LIBRARIES TgaImporterTestLib) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.h b/src/Plugins/TgaImporter/Test/TgaImporterTest.h index 2f105ac30..8835dbbbf 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.h +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.h @@ -19,7 +19,7 @@ namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { -class TgaImporterTest: public Corrade::TestSuite::Tester { +class TgaImporterTest: public Corrade::TestSuite::Tester { public: TgaImporterTest(); diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 593c774a1..d03a59d19 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -15,6 +15,7 @@ #include "TgaImporter.h" +#include #include #include From 884db80152dd8b37230d79610bb0d50e64891672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 7 Dec 2012 23:24:43 +0100 Subject: [PATCH 047/112] No `using namespace std` anywhere. Also added missing std:: prefix to remaining cases of std::size_t, std::[u]int[0-9]+_t, std::sin() etc., std::exit(). --- .../TgaImporter/Test/TgaImporterTest.cpp | 27 +++++++++---------- src/Plugins/TgaImporter/TgaImporter.cpp | 18 ++++++------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 6d7574d7b..4f595a236 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -21,7 +21,6 @@ #include "../TgaImporter.h" -using namespace std; using namespace Corrade::Utility; CORRADE_TEST_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) @@ -39,7 +38,7 @@ TgaImporterTest::TgaImporterTest() { } void TgaImporterTest::openInexistent() { - ostringstream debug; + std::ostringstream debug; Error::setOutput(&debug); TgaImporter importer; @@ -49,9 +48,9 @@ void TgaImporterTest::openInexistent() { void TgaImporterTest::openShort() { const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - istringstream in(string(data, sizeof(data))); + std::istringstream in(std::string(data, sizeof(data))); - ostringstream debug; + std::ostringstream debug; Error::setOutput(&debug); TgaImporter importer; @@ -61,9 +60,9 @@ void TgaImporterTest::openShort() { void TgaImporterTest::paletted() { const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - istringstream in(string(data, sizeof(data))); + std::istringstream in(std::string(data, sizeof(data))); - ostringstream debug; + std::ostringstream debug; Error::setOutput(&debug); TgaImporter importer; @@ -73,9 +72,9 @@ void TgaImporterTest::paletted() { void TgaImporterTest::nonRgb() { const char data[] = { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - istringstream in(string(data, sizeof(data))); + std::istringstream in(std::string(data, sizeof(data))); - ostringstream debug; + std::ostringstream debug; Error::setOutput(&debug); TgaImporter importer; @@ -85,9 +84,9 @@ void TgaImporterTest::nonRgb() { void TgaImporterTest::bits16() { const char data[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 }; - istringstream in(string(data, sizeof(data))); + std::istringstream in(std::string(data, sizeof(data))); - ostringstream debug; + std::ostringstream debug; Error::setOutput(&debug); TgaImporter importer; @@ -107,7 +106,7 @@ void TgaImporterTest::bits24() { 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))); + std::istringstream in(std::string(data, sizeof(data))); TgaImporter importer; CORRADE_VERIFY(importer.open(in)); @@ -119,7 +118,7 @@ void TgaImporterTest::bits24() { #endif CORRADE_COMPARE(image->size(), Math::Vector2(2, 3)); CORRADE_VERIFY(image->type() == TypeTraits::imageType()); - CORRADE_COMPARE(string(static_cast(image->data()), 2*3*3), string(pixels, 2*3*3)); + CORRADE_COMPARE(std::string(static_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); } void TgaImporterTest::bits32() { @@ -134,7 +133,7 @@ void TgaImporterTest::bits32() { 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))); + std::istringstream in(std::string(data, sizeof(data))); TgaImporter importer; CORRADE_VERIFY(importer.open(in)); @@ -146,7 +145,7 @@ void TgaImporterTest::bits32() { #endif CORRADE_COMPARE(image->size(), Math::Vector2(2, 3)); CORRADE_VERIFY(image->type() == TypeTraits::imageType()); - CORRADE_COMPARE(string(static_cast(image->data()), 2*3*3), string(pixels, 2*3*3)); + CORRADE_COMPARE(std::string(static_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); } }}}} diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index d03a59d19..ec3c5bbb0 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -22,8 +22,6 @@ #include "Math/Vector2.h" #include #include "Trade/ImageData.h" - -using namespace std; using namespace Corrade::Utility; namespace Magnum { namespace Trade { namespace TgaImporter { @@ -32,8 +30,8 @@ namespace Magnum { namespace Trade { namespace TgaImporter { static_assert(sizeof(TgaImporter::Header) == 18, "TgaImporter: header size is not 18 bytes"); #endif -bool TgaImporter::TgaImporter::open(const string& filename, const string& name) { - ifstream in(filename.c_str()); +bool TgaImporter::TgaImporter::open(const std::string& filename, const std::string& name) { + std::ifstream in(filename.c_str()); if(!in.good()) { Error() << "TgaImporter: cannot open file" << filename; return false; @@ -43,7 +41,7 @@ bool TgaImporter::TgaImporter::open(const string& filename, const string& name) return status; } -bool TgaImporter::open(istream& in, const string& name) { +bool TgaImporter::open(std::istream& in, const std::string& name) { if(_image) close(); if(!in.good()) { Error() << "TgaImporter: cannot read input stream"; @@ -51,10 +49,10 @@ bool TgaImporter::open(istream& in, const string& name) { } /* Check if the file is long enough */ - in.seekg(0, istream::end); - streampos filesize = in.tellg(); - in.seekg(0, istream::beg); - if(filesize < streampos(sizeof(Header))) { + in.seekg(0, std::istream::end); + std::streampos filesize = in.tellg(); + in.seekg(0, std::istream::beg); + if(filesize < std::streampos(sizeof(Header))) { Error() << "TgaImporter: the file is too short:" << filesize << "bytes"; return false; } @@ -97,7 +95,7 @@ bool TgaImporter::open(istream& in, const string& name) { return false; } - size_t size = header.width*header.height*header.bpp/8; + std::size_t size = header.width*header.height*header.bpp/8; GLubyte* buffer = new GLubyte[size]; in.read(reinterpret_cast(buffer), size); From 40b1b1ea2b5a000903c98fb10c6b8c2d0f2d72c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 18 Jan 2013 17:28:26 +0100 Subject: [PATCH 048/112] Adapted to Magnum changes. --- .../TgaImporter/Test/TgaImporterTest.cpp | 13 ++++++------ src/Plugins/TgaImporter/TgaImporter.cpp | 20 +++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 4f595a236..8a6527fc1 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -15,6 +15,7 @@ #include "TgaImporterTest.h" +#include #include #include #include @@ -112,12 +113,12 @@ void TgaImporterTest::bits24() { CORRADE_VERIFY(importer.open(in)); auto image = importer.image2D(0); #ifndef MAGNUM_TARGET_GLES - CORRADE_VERIFY(image->components() == AbstractImage::Components::BGR); + CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::BGR); #else - CORRADE_VERIFY(image->components() == AbstractImage::Components::RGB); + CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::RGB); #endif CORRADE_COMPARE(image->size(), Math::Vector2(2, 3)); - CORRADE_VERIFY(image->type() == TypeTraits::imageType()); + CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); CORRADE_COMPARE(std::string(static_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); } @@ -139,12 +140,12 @@ void TgaImporterTest::bits32() { CORRADE_VERIFY(importer.open(in)); auto image = importer.image2D(0); #ifndef MAGNUM_TARGET_GLES - CORRADE_VERIFY(image->components() == AbstractImage::Components::BGRA); + CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::BGRA); #else - CORRADE_VERIFY(image->components() == AbstractImage::Components::RGBA); + CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::RGBA); #endif CORRADE_COMPARE(image->size(), Math::Vector2(2, 3)); - CORRADE_VERIFY(image->type() == TypeTraits::imageType()); + CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); CORRADE_COMPARE(std::string(static_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); } diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index ec3c5bbb0..23f3121a8 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -74,35 +74,35 @@ bool TgaImporter::open(std::istream& in, const std::string& name) { return false; } - AbstractImage::Components components; + ImageData2D::Format format; switch(header.bpp) { case 24: #ifndef MAGNUM_TARGET_GLES - components = AbstractImage::Components::BGR; + format = ImageData2D::Format::BGR; #else - components = AbstractImage::Components::RGB; + format = ImageData2D::Format::RGB; #endif break; case 32: #ifndef MAGNUM_TARGET_GLES - components = AbstractImage::Components::BGRA; + format = ImageData2D::Format::BGRA; #else - components = AbstractImage::Components::RGBA; + format = ImageData2D::Format::RGBA; #endif break; default: - Error() << "TgaImporter: unsupported bits-per-pixel:" << int(header.bpp); + Error() << "TgaImporter: unsupported bits-per-pixel:" << header.bpp; return false; } std::size_t size = header.width*header.height*header.bpp/8; - GLubyte* buffer = new GLubyte[size]; - in.read(reinterpret_cast(buffer), size); + char* buffer = new char[size]; + in.read(buffer, size); Math::Vector2 dimensions(header.width, header.height); #ifdef MAGNUM_TARGET_GLES - if(components == AbstractImage::Components::RGB) { + if(format == AbstractImage::Components::RGB) { Math::Vector3* data = reinterpret_cast*>(buffer); std::transform(data, data + dimensions.product(), data, [](Math::Vector3 pixel) { return swizzle<'b', 'g', 'r'>(pixel); }); @@ -113,7 +113,7 @@ bool TgaImporter::open(std::istream& in, const std::string& name) { } #endif - _image = new ImageData2D(name, dimensions, components, buffer); + _image = new ImageData2D(name, dimensions, format, ImageData2D::Type::UnsignedByte, buffer); return true; } From 220ac9e1ca40c9a7d5af104cfaa110397d3e12d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 19 Jan 2013 22:00:29 +0100 Subject: [PATCH 049/112] Removed header files from tests. Following decisions made in Magnum itself. --- .../TgaImporter/Test/TgaImporterTest.cpp | 21 ++++++++--- .../TgaImporter/Test/TgaImporterTest.h | 37 ------------------- 2 files changed, 16 insertions(+), 42 deletions(-) delete mode 100644 src/Plugins/TgaImporter/Test/TgaImporterTest.h diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 8a6527fc1..97a308bdf 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -13,10 +13,8 @@ GNU Lesser General Public License version 3 for more details. */ -#include "TgaImporterTest.h" - #include -#include +#include #include #include @@ -24,10 +22,21 @@ using namespace Corrade::Utility; -CORRADE_TEST_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) - namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { +class TgaImporterTest: public Corrade::TestSuite::Tester { + public: + TgaImporterTest(); + + void openInexistent(); + void openShort(); + void paletted(); + void nonRgb(); + void bits16(); + void bits24(); + void bits32(); +}; + TgaImporterTest::TgaImporterTest() { addTests(&TgaImporterTest::openInexistent, &TgaImporterTest::openShort, @@ -150,3 +159,5 @@ void TgaImporterTest::bits32() { } }}}} + +CORRADE_TEST_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.h b/src/Plugins/TgaImporter/Test/TgaImporterTest.h deleted file mode 100644 index 8835dbbbf..000000000 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef Magnum_Trade_TgaImporter_Test_TgaImporterTest_h -#define Magnum_Trade_TgaImporter_Test_TgaImporterTest_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include - -namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { - -class TgaImporterTest: public Corrade::TestSuite::Tester { - public: - TgaImporterTest(); - - void openInexistent(); - void openShort(); - void paletted(); - void nonRgb(); - void bits16(); - void bits24(); - void bits32(); -}; - -}}}} - -#endif From cd00422e4f66ddcaa50b1b84219eab556ada3edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 21 Jan 2013 16:23:52 +0100 Subject: [PATCH 050/112] TgaImporter: adapted to Magnum changes. Not storing image name inside ImageData greatly simplifies the implementation. Also using `override` keyword where possible. --- src/Plugins/TgaImporter/TgaImporter.cpp | 8 ++++---- src/Plugins/TgaImporter/TgaImporter.h | 26 ++++++------------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 23f3121a8..ea4362729 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -30,18 +30,18 @@ namespace Magnum { namespace Trade { namespace TgaImporter { static_assert(sizeof(TgaImporter::Header) == 18, "TgaImporter: header size is not 18 bytes"); #endif -bool TgaImporter::TgaImporter::open(const std::string& filename, const std::string& name) { +bool TgaImporter::TgaImporter::open(const std::string& filename) { std::ifstream in(filename.c_str()); if(!in.good()) { Error() << "TgaImporter: cannot open file" << filename; return false; } - bool status = open(in, name); + bool status = open(in); in.close(); return status; } -bool TgaImporter::open(std::istream& in, const std::string& name) { +bool TgaImporter::open(std::istream& in) { if(_image) close(); if(!in.good()) { Error() << "TgaImporter: cannot read input stream"; @@ -113,7 +113,7 @@ bool TgaImporter::open(std::istream& in, const std::string& name) { } #endif - _image = new ImageData2D(name, dimensions, format, ImageData2D::Type::UnsignedByte, buffer); + _image = new ImageData2D(dimensions, format, ImageData2D::Type::UnsignedByte, buffer); return true; } diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 121de819d..110773650 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -44,28 +44,14 @@ class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager = 0, const std::string& plugin = ""): AbstractImporter(manager, plugin), _image(nullptr) {} inline virtual ~TgaImporter() { close(); } - inline Features features() const { return Feature::OpenFile|Feature::OpenStream; } + inline Features features() const override { return Feature::OpenFile|Feature::OpenStream; } - /** - * @brief Open input stream with specific image name - * - * @see open(std::istream&), ImageData2D::name() - */ - bool open(std::istream& in, const std::string& name); - inline bool open(std::istream& in) { return open(in, ""); } + bool open(std::istream& in) override; + bool open(const std::string& filename) override; + void close() override; - /** - * @brief Open file with specific image name - * - * @see open(const std::string&), ImageData2D::name() - */ - bool open(const std::string& filename, const std::string& name); - inline bool open(const std::string& filename) { return open(filename, ""); } - - void close(); - - inline std::uint32_t image2DCount() const { return _image ? 1 : 0; } - ImageData2D* image2D(std::uint32_t id); + std::uint32_t image2DCount() const override { return _image ? 1 : 0; } + ImageData2D* image2D(std::uint32_t id) override; #pragma pack(1) /** @brief TGA file header */ From 4c8cf7c8fa0c676e21d04b37c188afbcd5441ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 23 Feb 2013 16:29:07 +0100 Subject: [PATCH 051/112] Include cleanup. --- src/Plugins/TgaImporter/Test/TgaImporterTest.cpp | 2 -- src/Plugins/TgaImporter/TgaImporter.cpp | 12 ++++++------ src/Plugins/TgaImporter/TgaImporter.h | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 97a308bdf..6d24dd1cb 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -20,8 +20,6 @@ #include "../TgaImporter.h" -using namespace Corrade::Utility; - namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { class TgaImporterTest: public Corrade::TestSuite::Tester { diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index ea4362729..ef47b0ab8 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -18,11 +18,11 @@ #include #include #include - -#include "Math/Vector2.h" +#include #include -#include "Trade/ImageData.h" -using namespace Corrade::Utility; +#include + +using Corrade::Utility::Endianness; namespace Magnum { namespace Trade { namespace TgaImporter { @@ -61,8 +61,8 @@ bool TgaImporter::open(std::istream& in) { in.read(reinterpret_cast(&header), sizeof(Header)); /* Convert to machine endian */ - header.width = Endianness::littleEndian(header.width); - header.height = Endianness::littleEndian(header.height); + header.width = Endianness::littleEndian(header.width); + header.height = Endianness::littleEndian(header.height); if(header.colorMapType != 0) { Error() << "TgaImporter: paletted files are not supported"; diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 110773650..6d7c81c14 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -19,7 +19,7 @@ * @brief Class Magnum::Trade::TgaImporter::TgaImporter */ -#include "Trade/AbstractImporter.h" +#include #ifndef DOXYGEN_GENERATING_OUTPUT #ifdef _WIN32 From dc6b8a52eb7f07c6779d11132dbb342cd65ebf25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 28 Feb 2013 10:45:28 +0100 Subject: [PATCH 052/112] Adapted to Magnum changes (own type aliases). --- src/Plugins/TgaImporter/TgaImporter.cpp | 2 +- src/Plugins/TgaImporter/TgaImporter.h | 28 ++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index ef47b0ab8..e7b826adb 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -123,7 +123,7 @@ void TgaImporter::close() { _image = nullptr; } -ImageData2D* TgaImporter::image2D(std::uint32_t) { +ImageData2D* TgaImporter::image2D(UnsignedInt) { return _image; } diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 6d7c81c14..e4f1dff53 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -50,25 +50,25 @@ class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { bool open(const std::string& filename) override; void close() override; - std::uint32_t image2DCount() const override { return _image ? 1 : 0; } - ImageData2D* image2D(std::uint32_t id) override; + UnsignedInt image2DCount() const override { return _image ? 1 : 0; } + ImageData2D* image2D(UnsignedInt id) override; #pragma pack(1) /** @brief TGA file header */ /** @todoc Enable @c INLINE_SIMPLE_STRUCTS again when unclosed <component> in tagfile is fixed*/ struct TGAIMPORTER_LOCAL Header { - std::uint8_t identsize; /**< @brief Size of ID field that follows header (0) */ - std::uint8_t colorMapType; /**< @brief 0 = None, 1 = paletted */ - std::uint8_t imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ - std::uint16_t colorMapStart; /**< @brief First color map entry */ - std::uint16_t colorMapLength; /**< @brief Number of colors */ - std::uint8_t colorMapBpp; /**< @brief Bits per palette entry */ - std::uint16_t beginX; /**< @brief %Image x origin */ - std::uint16_t beginY; /**< @brief %Image y origin */ - std::uint16_t width; /**< @brief %Image width */ - std::uint16_t height; /**< @brief %Image height */ - std::uint8_t bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ - std::uint8_t descriptor; /**< @brief %Image descriptor */ + UnsignedByte identsize; /**< @brief Size of ID field that follows header (0) */ + UnsignedByte colorMapType; /**< @brief 0 = None, 1 = paletted */ + UnsignedByte imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ + UnsignedShort colorMapStart; /**< @brief First color map entry */ + UnsignedShort colorMapLength; /**< @brief Number of colors */ + UnsignedByte colorMapBpp; /**< @brief Bits per palette entry */ + UnsignedShort beginX; /**< @brief %Image x origin */ + UnsignedShort beginY; /**< @brief %Image y origin */ + UnsignedShort width; /**< @brief %Image width */ + UnsignedShort height; /**< @brief %Image height */ + UnsignedByte bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ + UnsignedByte descriptor; /**< @brief %Image descriptor */ }; #pragma pack(8) From af18c8d65d748b32825d228c66c784ed00cab61d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 8 Mar 2013 23:28:46 +0100 Subject: [PATCH 053/112] Adapted to Corrade and Magnum changes. --- src/Plugins/TgaImporter/Test/TgaImporterTest.cpp | 14 +++++++------- src/Plugins/TgaImporter/TgaImporter.h | 8 ++++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 6d24dd1cb..79a2421d0 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -36,13 +36,13 @@ class TgaImporterTest: public Corrade::TestSuite::Tester { }; TgaImporterTest::TgaImporterTest() { - addTests(&TgaImporterTest::openInexistent, - &TgaImporterTest::openShort, - &TgaImporterTest::paletted, - &TgaImporterTest::nonRgb, - &TgaImporterTest::bits16, - &TgaImporterTest::bits24, - &TgaImporterTest::bits32); + addTests({&TgaImporterTest::openInexistent, + &TgaImporterTest::openShort, + &TgaImporterTest::paletted, + &TgaImporterTest::nonRgb, + &TgaImporterTest::bits16, + &TgaImporterTest::bits24, + &TgaImporterTest::bits32}); } void TgaImporterTest::openInexistent() { diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index e4f1dff53..71d852f41 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -40,8 +40,12 @@ namespace Magnum { namespace Trade { namespace TgaImporter { /** @brief TGA importer plugin */ class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { public: - /** @copydoc AbstractImporter::AbstractImporter() */ - TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager = 0, const std::string& plugin = ""): AbstractImporter(manager, plugin), _image(nullptr) {} + /** @brief Default constructor */ + inline explicit TgaImporter(): _image(nullptr) {} + + /** @brief Plugin manager constructor */ + inline explicit TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractImporter(manager, std::move(plugin)), _image(nullptr) {} + inline virtual ~TgaImporter() { close(); } inline Features features() const override { return Feature::OpenFile|Feature::OpenStream; } From 193c03759af146c7b727ced149504cc5c5858c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 9 Mar 2013 14:32:06 +0100 Subject: [PATCH 054/112] Thorough CMakeLists cleanup. * Explicitly installing header files instead of recursive glob (some header are internal, thus no need to install them). * Calling enable_testing() only in project root. * Using MAGNUM_LIBRARIES instead of specifying all dependencies explicitly. * Using CORRADE_CXX_FLAGS instead of our own (heavily outdated) set. * Removed FindMagnumPlugins.cmake, the module does essentially nothing. * Various reorganization and cleanup. --- src/Plugins/TgaImporter/CMakeLists.txt | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt index e0ccbebd4..cc3cef88c 100644 --- a/src/Plugins/TgaImporter/CMakeLists.txt +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -1,16 +1,22 @@ -add_library(TgaImporterObjects OBJECT TgaImporter.cpp) +set(TgaImporter_SRCS + TgaImporter.cpp) + +set(TgaImporter_HEADERS + TgaImporter.h) + +add_library(TgaImporterObjects OBJECT ${TgaImporter_SRCS}) set_target_properties(TgaImporterObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) -corrade_add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf $ pluginRegistrationTgaImporter.cpp) -target_link_libraries(TgaImporter ${MAGNUM_LIBRARY}) +corrade_add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} + TgaImporter.conf + $ + pluginRegistrationTgaImporter.cpp) +target_link_libraries(TgaImporter ${MAGNUM_LIBRARIES}) + +install(FILES ${TgaImporter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/TgaImporter) if(BUILD_TESTS) add_library(TgaImporterTestLib $) - target_link_libraries(TgaImporterTestLib ${MAGNUM_LIBRARY} ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) - enable_testing() + target_link_libraries(TgaImporterTestLib ${MAGNUM_LIBRARIES}) add_subdirectory(Test) endif() - -if(WIN32) - target_link_libraries(TgaImporter ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY}) -endif() From 1f5247ab523f25b05c53fcc55eabf9eab4eb1dbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 11 Mar 2013 17:36:41 +0100 Subject: [PATCH 055/112] Relicensing to MIT/Expat license, part 2: headers. --- src/Plugins/TgaImporter/TgaImporter.h | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 71d852f41..b8437b14c 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -1,18 +1,27 @@ #ifndef Magnum_Trade_TgaImporter_TgaImporter_h #define Magnum_Trade_TgaImporter_TgaImporter_h /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ /** @file From 29fd52b3e66e112445692cbaa0202c0f6da44f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 11 Mar 2013 17:37:40 +0100 Subject: [PATCH 056/112] Relicensing to MIT/Expat license, part 3: source files. License header was not added to COLLADA test files (because it should be then also added to TGA test files, which is impossible). --- .../TgaImporter/Test/TgaImporterTest.cpp | 29 ++++++++++++------- src/Plugins/TgaImporter/TgaImporter.cpp | 29 ++++++++++++------- .../pluginRegistrationTgaImporter.cpp | 27 +++++++++++------ 3 files changed, 56 insertions(+), 29 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 79a2421d0..c2289b3ab 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index e7b826adb..912203c9d 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "TgaImporter.h" diff --git a/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp b/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp index 601ed8fd1..8627be4e4 100644 --- a/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp +++ b/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp @@ -1,16 +1,25 @@ /* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - This file is part of Magnum. - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. */ #include "TgaImporter.h" From be0d089678e1bab0025d1832d8f49616881f5f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 11 Mar 2013 17:40:37 +0100 Subject: [PATCH 057/112] Relicensing to MIT/Expat license, part 4: CMake and documentation files. --- src/Plugins/TgaImporter/CMakeLists.txt | 24 +++++++++++++++++++++ src/Plugins/TgaImporter/Test/CMakeLists.txt | 24 +++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt index cc3cef88c..b882e51bd 100644 --- a/src/Plugins/TgaImporter/CMakeLists.txt +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -1,3 +1,27 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + set(TgaImporter_SRCS TgaImporter.cpp) diff --git a/src/Plugins/TgaImporter/Test/CMakeLists.txt b/src/Plugins/TgaImporter/Test/CMakeLists.txt index 40adc197a..5834c045e 100644 --- a/src/Plugins/TgaImporter/Test/CMakeLists.txt +++ b/src/Plugins/TgaImporter/Test/CMakeLists.txt @@ -1 +1,25 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + corrade_add_test(TgaImporterTest TgaImporterTest.cpp LIBRARIES TgaImporterTestLib) From f40b112f8fea586f00085bdb68739f0c57c4e641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2013 10:59:10 +0100 Subject: [PATCH 058/112] TgaImporter: prefix macros with `MAGNUM_`. --- src/Plugins/TgaImporter/TgaImporter.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index b8437b14c..a1109bbc1 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -33,21 +33,21 @@ #ifndef DOXYGEN_GENERATING_OUTPUT #ifdef _WIN32 #ifdef TgaImporter_EXPORTS - #define TGAIMPORTER_EXPORT __declspec(dllexport) + #define MAGNUM_TGAIMPORTER_EXPORT __declspec(dllexport) #else - #define TGAIMPORTER_EXPORT __declspec(dllimport) + #define MAGNUM_TGAIMPORTER_EXPORT __declspec(dllimport) #endif - #define TGAIMPORTER_LOCAL + #define MAGNUM_TGAIMPORTER_LOCAL #else - #define TGAIMPORTER_EXPORT __attribute__ ((visibility ("default"))) - #define TGAIMPORTER_LOCAL __attribute__ ((visibility ("hidden"))) + #define MAGNUM_TGAIMPORTER_EXPORT __attribute__ ((visibility ("default"))) + #define MAGNUM_TGAIMPORTER_LOCAL __attribute__ ((visibility ("hidden"))) #endif #endif namespace Magnum { namespace Trade { namespace TgaImporter { /** @brief TGA importer plugin */ -class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { +class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { public: /** @brief Default constructor */ inline explicit TgaImporter(): _image(nullptr) {} @@ -69,7 +69,7 @@ class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { #pragma pack(1) /** @brief TGA file header */ /** @todoc Enable @c INLINE_SIMPLE_STRUCTS again when unclosed <component> in tagfile is fixed*/ - struct TGAIMPORTER_LOCAL Header { + struct MAGNUM_TGAIMPORTER_LOCAL Header { UnsignedByte identsize; /**< @brief Size of ID field that follows header (0) */ UnsignedByte colorMapType; /**< @brief 0 = None, 1 = paletted */ UnsignedByte imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ From e8c3838065102fe9423769a5b18c3a72a1332b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2013 12:32:49 +0100 Subject: [PATCH 059/112] TgaImporter: deinlined functions. --- src/Plugins/TgaImporter/TgaImporter.cpp | 14 ++++++++++++++ src/Plugins/TgaImporter/TgaImporter.h | 12 +++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 912203c9d..37f456847 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -39,6 +39,16 @@ namespace Magnum { namespace Trade { namespace TgaImporter { static_assert(sizeof(TgaImporter::Header) == 18, "TgaImporter: header size is not 18 bytes"); #endif +TgaImporter::TgaImporter(): _image(nullptr) {} + +TgaImporter::TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractImporter(manager, std::move(plugin)), _image(nullptr) {} + +TgaImporter::~TgaImporter() { close(); } + +TgaImporter::Features TgaImporter::features() const { + return Feature::OpenFile|Feature::OpenStream; +} + bool TgaImporter::TgaImporter::open(const std::string& filename) { std::ifstream in(filename.c_str()); if(!in.good()) { @@ -132,6 +142,10 @@ void TgaImporter::close() { _image = nullptr; } +UnsignedInt TgaImporter::TgaImporter::image2DCount() const { + return _image ? 1 : 0; +} + ImageData2D* TgaImporter::image2D(UnsignedInt) { return _image; } diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index a1109bbc1..d66cc35bf 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -50,20 +50,18 @@ namespace Magnum { namespace Trade { namespace TgaImporter { class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { public: /** @brief Default constructor */ - inline explicit TgaImporter(): _image(nullptr) {} + explicit TgaImporter(); /** @brief Plugin manager constructor */ - inline explicit TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractImporter(manager, std::move(plugin)), _image(nullptr) {} + explicit TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin); - inline virtual ~TgaImporter() { close(); } - - inline Features features() const override { return Feature::OpenFile|Feature::OpenStream; } + virtual ~TgaImporter(); + Features features() const override; bool open(std::istream& in) override; bool open(const std::string& filename) override; void close() override; - - UnsignedInt image2DCount() const override { return _image ? 1 : 0; } + UnsignedInt image2DCount() const override; ImageData2D* image2D(UnsignedInt id) override; #pragma pack(1) From 0927138ff153c75f274bf3ae9489bfc3cb959d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2013 14:25:25 +0100 Subject: [PATCH 060/112] Adapted to Magnum changes. --- .../TgaImporter/Test/TgaImporterTest.cpp | 20 ++++++--------- src/Plugins/TgaImporter/TgaImporter.cpp | 25 +++++++++---------- src/Plugins/TgaImporter/TgaImporter.h | 7 ++++-- .../pluginRegistrationTgaImporter.cpp | 2 +- 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index c2289b3ab..d11bccebd 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -59,55 +59,51 @@ void TgaImporterTest::openInexistent() { Error::setOutput(&debug); TgaImporter importer; - CORRADE_VERIFY(!importer.open("inexistent.file")); + CORRADE_VERIFY(!importer.openFile("inexistent.file")); CORRADE_COMPARE(debug.str(), "TgaImporter: cannot open file inexistent.file\n"); } void TgaImporterTest::openShort() { const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - std::istringstream in(std::string(data, sizeof(data))); std::ostringstream debug; Error::setOutput(&debug); TgaImporter importer; - CORRADE_VERIFY(!importer.open(in)); + CORRADE_VERIFY(!importer.openData(data)); CORRADE_COMPARE(debug.str(), "TgaImporter: the file is too short: 17 bytes\n"); } void TgaImporterTest::paletted() { const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - std::istringstream in(std::string(data, sizeof(data))); std::ostringstream debug; Error::setOutput(&debug); TgaImporter importer; - CORRADE_VERIFY(!importer.open(in)); + CORRADE_VERIFY(!importer.openData(data)); CORRADE_COMPARE(debug.str(), "TgaImporter: paletted files are not supported\n"); } void TgaImporterTest::nonRgb() { const char data[] = { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - std::istringstream in(std::string(data, sizeof(data))); std::ostringstream debug; Error::setOutput(&debug); TgaImporter importer; - CORRADE_VERIFY(!importer.open(in)); + CORRADE_VERIFY(!importer.openData(data)); CORRADE_COMPARE(debug.str(), "TgaImporter: non-RGB files are not supported\n"); } void TgaImporterTest::bits16() { const char data[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 }; - std::istringstream in(std::string(data, sizeof(data))); std::ostringstream debug; Error::setOutput(&debug); TgaImporter importer; - CORRADE_VERIFY(!importer.open(in)); + CORRADE_VERIFY(!importer.openData(data)); CORRADE_COMPARE(debug.str(), "TgaImporter: unsupported bits-per-pixel: 16\n"); } @@ -123,10 +119,9 @@ void TgaImporterTest::bits24() { 3, 2, 1, 4, 3, 2, 5, 4, 3, 6, 5, 4, 7, 6, 5, 8, 7, 6 }; #endif - std::istringstream in(std::string(data, sizeof(data))); TgaImporter importer; - CORRADE_VERIFY(importer.open(in)); + CORRADE_VERIFY(importer.openData(data)); auto image = importer.image2D(0); #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::BGR); @@ -150,10 +145,9 @@ void TgaImporterTest::bits32() { 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(std::string(data, sizeof(data))); TgaImporter importer; - CORRADE_VERIFY(importer.open(in)); + CORRADE_VERIFY(importer.openData(data)); auto image = importer.image2D(0); #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::BGRA); diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 37f456847..c9697e51a 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -25,6 +25,7 @@ #include "TgaImporter.h" #include +#include #include #include #include @@ -46,26 +47,24 @@ TgaImporter::TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager, TgaImporter::~TgaImporter() { close(); } TgaImporter::Features TgaImporter::features() const { - return Feature::OpenFile|Feature::OpenStream; + return Feature::OpenData|Feature::OpenFile; } -bool TgaImporter::TgaImporter::open(const std::string& filename) { +bool TgaImporter::TgaImporter::openData(const void* const data, const std::size_t size) { + std::istringstream in(std::string(reinterpret_cast(data), size)); + return open(in); +} + +bool TgaImporter::TgaImporter::openFile(const std::string& filename) { std::ifstream in(filename.c_str()); - if(!in.good()) { - Error() << "TgaImporter: cannot open file" << filename; - return false; - } - bool status = open(in); - in.close(); - return status; + if(in.good()) return open(in); + + Error() << "TgaImporter: cannot open file" << filename; + return false; } bool TgaImporter::open(std::istream& in) { if(_image) close(); - if(!in.good()) { - Error() << "TgaImporter: cannot read input stream"; - return false; - } /* Check if the file is long enough */ in.seekg(0, std::istream::end); diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index d66cc35bf..3a4a4fc45 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -58,8 +58,9 @@ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { virtual ~TgaImporter(); Features features() const override; - bool open(std::istream& in) override; - bool open(const std::string& filename) override; + bool openData(const void* const data, const std::size_t size) override; + using AbstractImporter::openData; + bool openFile(const std::string& filename) override; void close() override; UnsignedInt image2DCount() const override; ImageData2D* image2D(UnsignedInt id) override; @@ -84,6 +85,8 @@ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { #pragma pack(8) private: + bool MAGNUM_TGAIMPORTER_LOCAL open(std::istream& in); + ImageData2D* _image; }; diff --git a/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp b/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp index 8627be4e4..f09436993 100644 --- a/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp +++ b/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp @@ -25,4 +25,4 @@ #include "TgaImporter.h" PLUGIN_REGISTER(TgaImporter, Magnum::Trade::TgaImporter::TgaImporter, - "cz.mosra.magnum.Trade.AbstractImporter/0.2") + "cz.mosra.magnum.Trade.AbstractImporter/0.2.1") From 4a657b77d2421b3f0bd094b7bb7e852af56575d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2013 15:09:56 +0100 Subject: [PATCH 061/112] TgaImporter: parsing the image on call to image2D(). Solves the problem about image deletion, the image is imported again on every request and the user is responsible for its deletion. Now also asserting that the file is opened and that the image ID is zero. --- .../TgaImporter/Test/TgaImporterTest.cpp | 42 +++++++----- src/Plugins/TgaImporter/TgaImporter.cpp | 66 +++++++++---------- src/Plugins/TgaImporter/TgaImporter.h | 2 +- 3 files changed, 58 insertions(+), 52 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index d11bccebd..ec7da8321 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -64,50 +64,51 @@ void TgaImporterTest::openInexistent() { } void TgaImporterTest::openShort() { + TgaImporter importer; const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + CORRADE_VERIFY(importer.openData(data)); std::ostringstream debug; Error::setOutput(&debug); - - TgaImporter importer; - CORRADE_VERIFY(!importer.openData(data)); + CORRADE_VERIFY(!importer.image2D(0)); CORRADE_COMPARE(debug.str(), "TgaImporter: the file is too short: 17 bytes\n"); } void TgaImporterTest::paletted() { + TgaImporter importer; const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + CORRADE_VERIFY(importer.openData(data)); std::ostringstream debug; Error::setOutput(&debug); - - TgaImporter importer; - CORRADE_VERIFY(!importer.openData(data)); + CORRADE_VERIFY(!importer.image2D(0)); CORRADE_COMPARE(debug.str(), "TgaImporter: paletted files are not supported\n"); } void TgaImporterTest::nonRgb() { + TgaImporter importer; const char data[] = { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + CORRADE_VERIFY(importer.openData(data)); std::ostringstream debug; Error::setOutput(&debug); - - TgaImporter importer; - CORRADE_VERIFY(!importer.openData(data)); + CORRADE_VERIFY(!importer.image2D(0)); CORRADE_COMPARE(debug.str(), "TgaImporter: non-RGB files are not supported\n"); } void TgaImporterTest::bits16() { + TgaImporter importer; const char data[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 }; + CORRADE_VERIFY(importer.openData(data)); std::ostringstream debug; Error::setOutput(&debug); - - TgaImporter importer; - CORRADE_VERIFY(!importer.openData(data)); + CORRADE_VERIFY(!importer.image2D(0)); CORRADE_COMPARE(debug.str(), "TgaImporter: unsupported bits-per-pixel: 16\n"); } void TgaImporterTest::bits24() { + TgaImporter importer; const char data[] = { 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 @@ -119,10 +120,10 @@ void TgaImporterTest::bits24() { 3, 2, 1, 4, 3, 2, 5, 4, 3, 6, 5, 4, 7, 6, 5, 8, 7, 6 }; #endif - - TgaImporter importer; CORRADE_VERIFY(importer.openData(data)); - auto image = importer.image2D(0); + + Trade::ImageData2D* image = importer.image2D(0); + CORRADE_VERIFY(image); #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::BGR); #else @@ -131,9 +132,12 @@ void TgaImporterTest::bits24() { CORRADE_COMPARE(image->size(), Math::Vector2(2, 3)); CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); CORRADE_COMPARE(std::string(static_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); + + delete image; } void TgaImporterTest::bits32() { + TgaImporter importer; const char data[] = { 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 @@ -145,10 +149,10 @@ void TgaImporterTest::bits32() { 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 - - TgaImporter importer; CORRADE_VERIFY(importer.openData(data)); - auto image = importer.image2D(0); + + Trade::ImageData2D* image = importer.image2D(0); + CORRADE_VERIFY(image); #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::BGRA); #else @@ -157,6 +161,8 @@ void TgaImporterTest::bits32() { CORRADE_COMPARE(image->size(), Math::Vector2(2, 3)); CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); CORRADE_COMPARE(std::string(static_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); + + delete image; } }}}} diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index c9697e51a..bb1f97c59 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -40,9 +40,9 @@ namespace Magnum { namespace Trade { namespace TgaImporter { static_assert(sizeof(TgaImporter::Header) == 18, "TgaImporter: header size is not 18 bytes"); #endif -TgaImporter::TgaImporter(): _image(nullptr) {} +TgaImporter::TgaImporter(): in(nullptr) {} -TgaImporter::TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractImporter(manager, std::move(plugin)), _image(nullptr) {} +TgaImporter::TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractImporter(manager, std::move(plugin)), in(nullptr) {} TgaImporter::~TgaImporter() { close(); } @@ -51,32 +51,47 @@ TgaImporter::Features TgaImporter::features() const { } bool TgaImporter::TgaImporter::openData(const void* const data, const std::size_t size) { - std::istringstream in(std::string(reinterpret_cast(data), size)); - return open(in); + close(); + + in = new std::istringstream(std::string(reinterpret_cast(data), size)); + return true; } bool TgaImporter::TgaImporter::openFile(const std::string& filename) { - std::ifstream in(filename.c_str()); - if(in.good()) return open(in); + close(); + + in = new std::ifstream(filename.c_str()); + if(in->good()) return true; Error() << "TgaImporter: cannot open file" << filename; + close(); return false; } -bool TgaImporter::open(std::istream& in) { - if(_image) close(); +void TgaImporter::close() { + delete in; + in = nullptr; +} + +UnsignedInt TgaImporter::TgaImporter::image2DCount() const { + return in ? 1 : 0; +} + +ImageData2D* TgaImporter::image2D(UnsignedInt id) { + CORRADE_ASSERT(in, "Trade::TgaImporter::TgaImporter::image2D(): no file opened", nullptr); + CORRADE_ASSERT(id == 0, "Trade::TgaImporter::TgaImporter::image2D(): wrong image ID", nullptr); /* Check if the file is long enough */ - in.seekg(0, std::istream::end); - std::streampos filesize = in.tellg(); - in.seekg(0, std::istream::beg); + in->seekg(0, std::istream::end); + std::streampos filesize = in->tellg(); + in->seekg(0, std::istream::beg); if(filesize < std::streampos(sizeof(Header))) { Error() << "TgaImporter: the file is too short:" << filesize << "bytes"; - return false; + return nullptr; } Header header; - in.read(reinterpret_cast(&header), sizeof(Header)); + in->read(reinterpret_cast(&header), sizeof(Header)); /* Convert to machine endian */ header.width = Endianness::littleEndian(header.width); @@ -84,12 +99,12 @@ bool TgaImporter::open(std::istream& in) { if(header.colorMapType != 0) { Error() << "TgaImporter: paletted files are not supported"; - return false; + return nullptr; } if(header.imageType != 2) { Error() << "TgaImporter: non-RGB files are not supported"; - return false; + return nullptr; } ImageData2D::Format format; @@ -110,12 +125,12 @@ bool TgaImporter::open(std::istream& in) { break; default: Error() << "TgaImporter: unsupported bits-per-pixel:" << header.bpp; - return false; + return nullptr; } std::size_t size = header.width*header.height*header.bpp/8; char* buffer = new char[size]; - in.read(buffer, size); + in->read(buffer, size); Math::Vector2 dimensions(header.width, header.height); @@ -131,22 +146,7 @@ bool TgaImporter::open(std::istream& in) { } #endif - _image = new ImageData2D(dimensions, format, ImageData2D::Type::UnsignedByte, buffer); - return true; -} - -void TgaImporter::close() { - /** @todo fixme: delete it only if it wasn't retrieved by user */ - //delete _image; - _image = nullptr; -} - -UnsignedInt TgaImporter::TgaImporter::image2DCount() const { - return _image ? 1 : 0; -} - -ImageData2D* TgaImporter::image2D(UnsignedInt) { - return _image; + return new ImageData2D(dimensions, format, ImageData2D::Type::UnsignedByte, buffer); } }}} diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 3a4a4fc45..9ca30db32 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -87,7 +87,7 @@ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { private: bool MAGNUM_TGAIMPORTER_LOCAL open(std::istream& in); - ImageData2D* _image; + std::istream* in; }; }}} From f8b8d932172a00fae0dbc07a322d66b495c33cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2013 16:01:34 +0100 Subject: [PATCH 062/112] TgaImporter: minor code cleanup, blind ES compilation fix. --- .../TgaImporter/Test/TgaImporterTest.cpp | 20 +++++++++++++------ src/Plugins/TgaImporter/TgaImporter.cpp | 14 ++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index ec7da8321..4a2ed2658 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -87,7 +87,7 @@ void TgaImporterTest::paletted() { void TgaImporterTest::nonRgb() { TgaImporter importer; - const char data[] = { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + const char data[] = { 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; CORRADE_VERIFY(importer.openData(data)); std::ostringstream debug; @@ -111,13 +111,17 @@ void TgaImporterTest::bits24() { TgaImporter importer; const char data[] = { 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 + 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 + 3, 2, 1, 4, 3, 2, + 5, 4, 3, 6, 5, 4, + 7, 6, 5, 8, 7, 6 }; #endif CORRADE_VERIFY(importer.openData(data)); @@ -129,7 +133,7 @@ void TgaImporterTest::bits24() { #else CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::RGB); #endif - CORRADE_COMPARE(image->size(), Math::Vector2(2, 3)); + CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); CORRADE_COMPARE(std::string(static_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); @@ -140,13 +144,17 @@ void TgaImporterTest::bits32() { TgaImporter importer; const char data[] = { 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 + 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 + 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)); diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index bb1f97c59..42ae4f7d4 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -132,17 +132,17 @@ ImageData2D* TgaImporter::image2D(UnsignedInt id) { char* buffer = new char[size]; in->read(buffer, size); - Math::Vector2 dimensions(header.width, header.height); + Vector2i dimensions(header.width, header.height); #ifdef MAGNUM_TARGET_GLES - if(format == AbstractImage::Components::RGB) { - Math::Vector3* data = reinterpret_cast*>(buffer); + if(format == ImageData2D::Format::RGB) { + auto data = reinterpret_cast*>(buffer); std::transform(data, data + dimensions.product(), data, - [](Math::Vector3 pixel) { return swizzle<'b', 'g', 'r'>(pixel); }); - } else /* RGBA */ { - Math::Vector4* data = reinterpret_cast*>(buffer); + [](Math::Vector3 pixel) { return swizzle<'b', 'g', 'r'>(pixel); }); + } else if(format == ImageData2D::Format::RGBA) { + auto data = reinterpret_cast*>(buffer); std::transform(data, data + dimensions.product(), data, - [](Math::Vector4 pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); }); + [](Math::Vector4 pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); }); } #endif From cceba125695598af36aa148b57b58c1a71dcac42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2013 16:11:37 +0100 Subject: [PATCH 063/112] TgaImporter: support for grayscale images, updated error messages. The messages now print fully qualified function name. --- .../TgaImporter/Test/TgaImporterTest.cpp | 71 ++++++++++++++----- src/Plugins/TgaImporter/TgaImporter.cpp | 64 ++++++++++------- src/Plugins/TgaImporter/TgaImporter.h | 6 +- 3 files changed, 97 insertions(+), 44 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 4a2ed2658..a5045c3b2 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -38,20 +38,28 @@ class TgaImporterTest: public Corrade::TestSuite::Tester { void openInexistent(); void openShort(); void paletted(); - void nonRgb(); - void bits16(); - void bits24(); - void bits32(); + void compressed(); + + void colorBits16(); + void colorBits24(); + void colorBits32(); + + void grayscaleBits8(); + void grayscaleBits16(); }; TgaImporterTest::TgaImporterTest() { addTests({&TgaImporterTest::openInexistent, &TgaImporterTest::openShort, &TgaImporterTest::paletted, - &TgaImporterTest::nonRgb, - &TgaImporterTest::bits16, - &TgaImporterTest::bits24, - &TgaImporterTest::bits32}); + &TgaImporterTest::compressed, + + &TgaImporterTest::colorBits16, + &TgaImporterTest::colorBits24, + &TgaImporterTest::colorBits32, + + &TgaImporterTest::grayscaleBits8, + &TgaImporterTest::grayscaleBits16}); } void TgaImporterTest::openInexistent() { @@ -60,7 +68,7 @@ void TgaImporterTest::openInexistent() { TgaImporter importer; CORRADE_VERIFY(!importer.openFile("inexistent.file")); - CORRADE_COMPARE(debug.str(), "TgaImporter: cannot open file inexistent.file\n"); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::openFile(): cannot open file inexistent.file\n"); } void TgaImporterTest::openShort() { @@ -71,7 +79,7 @@ void TgaImporterTest::openShort() { std::ostringstream debug; Error::setOutput(&debug); CORRADE_VERIFY(!importer.image2D(0)); - CORRADE_COMPARE(debug.str(), "TgaImporter: the file is too short: 17 bytes\n"); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): the file is too short: 17 bytes\n"); } void TgaImporterTest::paletted() { @@ -82,10 +90,10 @@ void TgaImporterTest::paletted() { std::ostringstream debug; Error::setOutput(&debug); CORRADE_VERIFY(!importer.image2D(0)); - CORRADE_COMPARE(debug.str(), "TgaImporter: paletted files are not supported\n"); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): paletted files are not supported\n"); } -void TgaImporterTest::nonRgb() { +void TgaImporterTest::compressed() { TgaImporter importer; const char data[] = { 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; CORRADE_VERIFY(importer.openData(data)); @@ -93,10 +101,10 @@ void TgaImporterTest::nonRgb() { std::ostringstream debug; Error::setOutput(&debug); CORRADE_VERIFY(!importer.image2D(0)); - CORRADE_COMPARE(debug.str(), "TgaImporter: non-RGB files are not supported\n"); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): compressed files are not supported\n"); } -void TgaImporterTest::bits16() { +void TgaImporterTest::colorBits16() { TgaImporter importer; const char data[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 }; CORRADE_VERIFY(importer.openData(data)); @@ -104,10 +112,10 @@ void TgaImporterTest::bits16() { std::ostringstream debug; Error::setOutput(&debug); CORRADE_VERIFY(!importer.image2D(0)); - CORRADE_COMPARE(debug.str(), "TgaImporter: unsupported bits-per-pixel: 16\n"); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): unsupported color bits-per-pixel: 16\n"); } -void TgaImporterTest::bits24() { +void TgaImporterTest::colorBits24() { TgaImporter importer; const char data[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0, @@ -140,7 +148,7 @@ void TgaImporterTest::bits24() { delete image; } -void TgaImporterTest::bits32() { +void TgaImporterTest::colorBits32() { TgaImporter importer; const char data[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 32, 0, @@ -173,6 +181,35 @@ void TgaImporterTest::bits32() { delete image; } +void TgaImporterTest::grayscaleBits8() { + TgaImporter importer; + const char data[] = { + 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 8, 0, + 1, 2, + 3, 4, + 5, 6 + }; + CORRADE_VERIFY(importer.openData(data)); + + Trade::ImageData2D* image = importer.image2D(0); + CORRADE_VERIFY(image); + CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::Red); + CORRADE_COMPARE(image->size(), Vector2i(2, 3)); + CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); + CORRADE_COMPARE(std::string(static_cast(image->data()), 2*3), std::string(data + 18, 2*3)); +} + +void TgaImporterTest::grayscaleBits16() { + TgaImporter importer; + const char data[] = { 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 }; + CORRADE_VERIFY(importer.openData(data)); + + std::ostringstream debug; + Error::setOutput(&debug); + CORRADE_VERIFY(!importer.image2D(0)); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): unsupported grayscale bits-per-pixel: 16\n"); +} + }}}} CORRADE_TEST_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 42ae4f7d4..c45192895 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -63,7 +63,7 @@ bool TgaImporter::TgaImporter::openFile(const std::string& filename) { in = new std::ifstream(filename.c_str()); if(in->good()) return true; - Error() << "TgaImporter: cannot open file" << filename; + Error() << "Trade::TgaImporter::TgaImporter::openFile(): cannot open file" << filename; close(); return false; } @@ -86,7 +86,7 @@ ImageData2D* TgaImporter::image2D(UnsignedInt id) { std::streampos filesize = in->tellg(); in->seekg(0, std::istream::beg); if(filesize < std::streampos(sizeof(Header))) { - Error() << "TgaImporter: the file is too short:" << filesize << "bytes"; + Error() << "Trade::TgaImporter::TgaImporter::image2D(): the file is too short:" << filesize << "bytes"; return nullptr; } @@ -97,35 +97,47 @@ ImageData2D* TgaImporter::image2D(UnsignedInt id) { header.width = Endianness::littleEndian(header.width); header.height = Endianness::littleEndian(header.height); + /* Image format */ + ImageData2D::Format format; if(header.colorMapType != 0) { - Error() << "TgaImporter: paletted files are not supported"; - return nullptr; - } - - if(header.imageType != 2) { - Error() << "TgaImporter: non-RGB files are not supported"; + Error() << "Trade::TgaImporter::TgaImporter::image2D(): paletted files are not supported"; return nullptr; } - ImageData2D::Format format; - switch(header.bpp) { - case 24: - #ifndef MAGNUM_TARGET_GLES - format = ImageData2D::Format::BGR; - #else - format = ImageData2D::Format::RGB; - #endif - break; - case 32: - #ifndef MAGNUM_TARGET_GLES - format = ImageData2D::Format::BGRA; - #else - format = ImageData2D::Format::RGBA; - #endif - break; - default: - Error() << "TgaImporter: unsupported bits-per-pixel:" << header.bpp; + /* Color */ + if(header.imageType == 2) { + switch(header.bpp) { + case 24: + #ifndef MAGNUM_TARGET_GLES + format = ImageData2D::Format::BGR; + #else + format = ImageData2D::Format::RGB; + #endif + break; + case 32: + #ifndef MAGNUM_TARGET_GLES + format = ImageData2D::Format::BGRA; + #else + format = ImageData2D::Format::RGBA; + #endif + break; + default: + Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported color bits-per-pixel:" << header.bpp; + return nullptr; + } + + /* Grayscale */ + } else if(header.imageType == 3) { + format = ImageData2D::Format::Red; + if(header.bpp != 8) { + Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp; return nullptr; + } + + /* Compressed files */ + } else { + Error() << "Trade::TgaImporter::TgaImporter::image2D(): compressed files are not supported"; + return nullptr; } std::size_t size = header.width*header.height*header.bpp/8; diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 9ca30db32..80f057d9f 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -46,7 +46,11 @@ namespace Magnum { namespace Trade { namespace TgaImporter { -/** @brief TGA importer plugin */ +/** +@brief TGA image importer + +Supports uncompressed BGR, BGRA or grayscale images with 8 bits per channel. +*/ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { public: /** @brief Default constructor */ From b71310f6d0efea35cab724c41cb6f8958119da8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2013 17:40:32 +0100 Subject: [PATCH 064/112] TgaImporter: moved TGA header structure to separate file. Will be used elsewhere. --- src/Plugins/TgaImporter/CMakeLists.txt | 1 + src/Plugins/TgaImporter/TgaHeader.h | 58 +++++++++++++++++++++++++ src/Plugins/TgaImporter/TgaImporter.cpp | 12 +++-- src/Plugins/TgaImporter/TgaImporter.h | 19 -------- 4 files changed, 64 insertions(+), 26 deletions(-) create mode 100644 src/Plugins/TgaImporter/TgaHeader.h diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt index b882e51bd..ad379ce7d 100644 --- a/src/Plugins/TgaImporter/CMakeLists.txt +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -26,6 +26,7 @@ set(TgaImporter_SRCS TgaImporter.cpp) set(TgaImporter_HEADERS + TgaHeader.h TgaImporter.h) add_library(TgaImporterObjects OBJECT ${TgaImporter_SRCS}) diff --git a/src/Plugins/TgaImporter/TgaHeader.h b/src/Plugins/TgaImporter/TgaHeader.h new file mode 100644 index 000000000..d8cde1f17 --- /dev/null +++ b/src/Plugins/TgaImporter/TgaHeader.h @@ -0,0 +1,58 @@ +#ifndef Magnum_Trade_TgaImporter_TgaHeader_h +#define Magnum_Trade_TgaImporter_TgaHeader_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Struct Magnum::Trade::TgaImporter::TgaHeader + */ + +#include + +namespace Magnum { namespace Trade { namespace TgaImporter { + +#pragma pack(1) +/** @brief TGA file header */ +/** @todoc Enable @c INLINE_SIMPLE_STRUCTS again when unclosed <component> in tagfile is fixed*/ +struct TgaHeader { + UnsignedByte identsize; /**< @brief Size of ID field that follows header (0) */ + UnsignedByte colorMapType; /**< @brief 0 = None, 1 = paletted */ + UnsignedByte imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ + UnsignedShort colorMapStart; /**< @brief First color map entry */ + UnsignedShort colorMapLength; /**< @brief Number of colors */ + UnsignedByte colorMapBpp; /**< @brief Bits per palette entry */ + UnsignedShort beginX; /**< @brief %Image x origin */ + UnsignedShort beginY; /**< @brief %Image y origin */ + UnsignedShort width; /**< @brief %Image width */ + UnsignedShort height; /**< @brief %Image height */ + UnsignedByte bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ + UnsignedByte descriptor; /**< @brief %Image descriptor */ +}; +#pragma pack(8) + +static_assert(sizeof(TgaHeader) == 18, "TgaHeader size is not 18 bytes"); + +}}} + +#endif diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index c45192895..9c39c04ca 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -32,14 +32,12 @@ #include #include +#include "TgaHeader.h" + using Corrade::Utility::Endianness; namespace Magnum { namespace Trade { namespace TgaImporter { -#ifndef DOXYGEN_GENERATING_OUTPUT -static_assert(sizeof(TgaImporter::Header) == 18, "TgaImporter: header size is not 18 bytes"); -#endif - TgaImporter::TgaImporter(): in(nullptr) {} TgaImporter::TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractImporter(manager, std::move(plugin)), in(nullptr) {} @@ -85,13 +83,13 @@ ImageData2D* TgaImporter::image2D(UnsignedInt id) { in->seekg(0, std::istream::end); std::streampos filesize = in->tellg(); in->seekg(0, std::istream::beg); - if(filesize < std::streampos(sizeof(Header))) { + if(filesize < std::streampos(sizeof(TgaHeader))) { Error() << "Trade::TgaImporter::TgaImporter::image2D(): the file is too short:" << filesize << "bytes"; return nullptr; } - Header header; - in->read(reinterpret_cast(&header), sizeof(Header)); + TgaHeader header; + in->read(reinterpret_cast(&header), sizeof(TgaHeader)); /* Convert to machine endian */ header.width = Endianness::littleEndian(header.width); diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 80f057d9f..9fc8925bf 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -69,25 +69,6 @@ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { UnsignedInt image2DCount() const override; ImageData2D* image2D(UnsignedInt id) override; - #pragma pack(1) - /** @brief TGA file header */ - /** @todoc Enable @c INLINE_SIMPLE_STRUCTS again when unclosed <component> in tagfile is fixed*/ - struct MAGNUM_TGAIMPORTER_LOCAL Header { - UnsignedByte identsize; /**< @brief Size of ID field that follows header (0) */ - UnsignedByte colorMapType; /**< @brief 0 = None, 1 = paletted */ - UnsignedByte imageType; /**< @brief 0 = none, 1 = indexed, 2 = rgb, 3 = grey, +8=rle */ - UnsignedShort colorMapStart; /**< @brief First color map entry */ - UnsignedShort colorMapLength; /**< @brief Number of colors */ - UnsignedByte colorMapBpp; /**< @brief Bits per palette entry */ - UnsignedShort beginX; /**< @brief %Image x origin */ - UnsignedShort beginY; /**< @brief %Image y origin */ - UnsignedShort width; /**< @brief %Image width */ - UnsignedShort height; /**< @brief %Image height */ - UnsignedByte bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ - UnsignedByte descriptor; /**< @brief %Image descriptor */ - }; - #pragma pack(8) - private: bool MAGNUM_TGAIMPORTER_LOCAL open(std::istream& in); From ca9ed0150b6967fe5ba6be2550a7d3ca7ee3f543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2013 17:46:06 +0100 Subject: [PATCH 065/112] Adapted to Magnum changes. --- src/Plugins/TgaImporter/Test/TgaImporterTest.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index a5045c3b2..1305d4cd2 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -143,7 +143,7 @@ void TgaImporterTest::colorBits24() { #endif CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); - CORRADE_COMPARE(std::string(static_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); + CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); delete image; } @@ -176,7 +176,7 @@ void TgaImporterTest::colorBits32() { #endif CORRADE_COMPARE(image->size(), Math::Vector2(2, 3)); CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); - CORRADE_COMPARE(std::string(static_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); + CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); delete image; } @@ -196,7 +196,7 @@ void TgaImporterTest::grayscaleBits8() { CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::Red); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); - CORRADE_COMPARE(std::string(static_cast(image->data()), 2*3), std::string(data + 18, 2*3)); + CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3), std::string(data + 18, 2*3)); } void TgaImporterTest::grayscaleBits16() { From 9f2ea8aa15fe8b852e2856d9e4bd87c5ff315a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2013 17:46:30 +0100 Subject: [PATCH 066/112] TgaImporter: test also file opening. --- src/Plugins/TgaImporter/Test/CMakeLists.txt | 5 +++ .../TgaImporter/Test/TgaImporterTest.cpp | 32 ++++++++++++++++-- .../TgaImporter/Test/configure.h.cmake | 25 ++++++++++++++ src/Plugins/TgaImporter/Test/file.tga | Bin 0 -> 24 bytes 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 src/Plugins/TgaImporter/Test/configure.h.cmake create mode 100644 src/Plugins/TgaImporter/Test/file.tga diff --git a/src/Plugins/TgaImporter/Test/CMakeLists.txt b/src/Plugins/TgaImporter/Test/CMakeLists.txt index 5834c045e..3e825ad47 100644 --- a/src/Plugins/TgaImporter/Test/CMakeLists.txt +++ b/src/Plugins/TgaImporter/Test/CMakeLists.txt @@ -22,4 +22,9 @@ # DEALINGS IN THE SOFTWARE. # +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/configure.h) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + corrade_add_test(TgaImporterTest TgaImporterTest.cpp LIBRARIES TgaImporterTestLib) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 1305d4cd2..f0ac0d188 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -24,10 +24,14 @@ #include #include -#include +#include #include -#include "../TgaImporter.h" +#include "TgaImporter/TgaImporter.h" + +#include "configure.h" + +using Corrade::Utility::Directory; namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { @@ -46,6 +50,8 @@ class TgaImporterTest: public Corrade::TestSuite::Tester { void grayscaleBits8(); void grayscaleBits16(); + + void file(); }; TgaImporterTest::TgaImporterTest() { @@ -59,7 +65,9 @@ TgaImporterTest::TgaImporterTest() { &TgaImporterTest::colorBits32, &TgaImporterTest::grayscaleBits8, - &TgaImporterTest::grayscaleBits16}); + &TgaImporterTest::grayscaleBits16, + + &TgaImporterTest::file}); } void TgaImporterTest::openInexistent() { @@ -210,6 +218,24 @@ void TgaImporterTest::grayscaleBits16() { CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): unsupported grayscale bits-per-pixel: 16\n"); } +void TgaImporterTest::file() { + TgaImporter importer; + const char data[] = { + 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 8, 0, + 1, 2, + 3, 4, + 5, 6 + }; + CORRADE_VERIFY(importer.openFile(Directory::join(TGAIMPORTER_TEST_DIR, "file.tga"))); + + Trade::ImageData2D* image = importer.image2D(0); + CORRADE_VERIFY(image); + CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::Red); + CORRADE_COMPARE(image->size(), Vector2i(2, 3)); + CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); + CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3), std::string(data + 18, 2*3)); +} + }}}} CORRADE_TEST_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) diff --git a/src/Plugins/TgaImporter/Test/configure.h.cmake b/src/Plugins/TgaImporter/Test/configure.h.cmake new file mode 100644 index 000000000..e507e8ed7 --- /dev/null +++ b/src/Plugins/TgaImporter/Test/configure.h.cmake @@ -0,0 +1,25 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#define TGAIMPORTER_TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}" diff --git a/src/Plugins/TgaImporter/Test/file.tga b/src/Plugins/TgaImporter/Test/file.tga new file mode 100644 index 0000000000000000000000000000000000000000..711486718a0f3ccfad7e39ebfaae81823912afae GIT binary patch literal 24 XcmZQzU}k^;CLo)Gfsu)sg_R8e0SEvl literal 0 HcmV?d00001 From 3544b17fdf1135d550cecf7dbfcef43ccee56c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 29 Mar 2013 17:47:11 +0100 Subject: [PATCH 067/112] New plugin TgaImageConverter. --- src/Plugins/TgaImageConverter/CMakeLists.txt | 46 +++++++ .../TgaImageConverter/Test/CMakeLists.txt | 30 ++++ .../Test/TgaImageConverterTest.cpp | 129 ++++++++++++++++++ .../TgaImageConverter/Test/configure.h.cmake | 25 ++++ .../TgaImageConverter/TgaImageConverter.conf | 0 .../TgaImageConverter/TgaImageConverter.cpp | 94 +++++++++++++ .../TgaImageConverter/TgaImageConverter.h | 57 ++++++++ .../pluginRegistrationTgaImageConverter.cpp | 28 ++++ 8 files changed, 409 insertions(+) create mode 100644 src/Plugins/TgaImageConverter/CMakeLists.txt create mode 100644 src/Plugins/TgaImageConverter/Test/CMakeLists.txt create mode 100644 src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp create mode 100644 src/Plugins/TgaImageConverter/Test/configure.h.cmake create mode 100644 src/Plugins/TgaImageConverter/TgaImageConverter.conf create mode 100644 src/Plugins/TgaImageConverter/TgaImageConverter.cpp create mode 100644 src/Plugins/TgaImageConverter/TgaImageConverter.h create mode 100644 src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp diff --git a/src/Plugins/TgaImageConverter/CMakeLists.txt b/src/Plugins/TgaImageConverter/CMakeLists.txt new file mode 100644 index 000000000..62dd12d87 --- /dev/null +++ b/src/Plugins/TgaImageConverter/CMakeLists.txt @@ -0,0 +1,46 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +set(TgaImageConverter_SRCS + TgaImageConverter.cpp) + +set(TgaImageConverter_HEADERS + TgaImageConverter.h) + +add_library(TgaImageConverterObjects OBJECT ${TgaImageConverter_SRCS}) +set_target_properties(TgaImageConverterObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) + +corrade_add_plugin(TgaImageConverter ${MAGNUM_PLUGINS_IMAGECONVERTER_INSTALL_DIR} + TgaImageConverter.conf + $ + pluginRegistrationTgaImageConverter.cpp) +target_link_libraries(TgaImageConverter ${MAGNUM_LIBRARIES}) + +install(FILES ${TgaImageConverter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/TgaImageConverter) + +if(BUILD_TESTS) + add_library(TgaImageConverterTestLib $) + target_link_libraries(TgaImageConverterTestLib ${MAGNUM_LIBRARIES}) + add_subdirectory(Test) +endif() diff --git a/src/Plugins/TgaImageConverter/Test/CMakeLists.txt b/src/Plugins/TgaImageConverter/Test/CMakeLists.txt new file mode 100644 index 000000000..f1c56f698 --- /dev/null +++ b/src/Plugins/TgaImageConverter/Test/CMakeLists.txt @@ -0,0 +1,30 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/configure.h) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +corrade_add_test(TgaImageConverterTest TgaImageConverterTest.cpp LIBRARIES TgaImageConverterTestLib TgaImporterTestLib) diff --git a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp new file mode 100644 index 000000000..5d448e0b6 --- /dev/null +++ b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -0,0 +1,129 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "configure.h" + +using Corrade::Utility::Directory; + +namespace Magnum { namespace Trade { namespace TgaImageConverter { namespace Test { + +class TgaImageConverterTest: public Corrade::TestSuite::Tester { + public: + explicit TgaImageConverterTest(); + + void wrongFormat(); + void wrongType(); + + void data(); + void file(); +}; + +namespace { + const Image2D original({2, 3}, Image2D::Format::BGR, Image2D::Type::UnsignedByte, new char[18] { + 1, 2, 3, 2, 3, 4, + 3, 4, 5, 4, 5, 6, + 5, 6, 7, 6, 7, 8 + }); +} + +TgaImageConverterTest::TgaImageConverterTest() { + addTests({&TgaImageConverterTest::wrongFormat, + &TgaImageConverterTest::wrongType, + + &TgaImageConverterTest::data, + &TgaImageConverterTest::file}); +} + +void TgaImageConverterTest::wrongFormat() { + Image2D image({}, Image2D::Format::RG, Image2D::Type::UnsignedByte, nullptr); + + std::ostringstream out; + Error::setOutput(&out); + + const unsigned char* data; + std::tie(data, std::ignore) = TgaImageConverter().convertToData(&image); + CORRADE_VERIFY(!data); + CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format AbstractImage::Format::RG\n"); +} + +void TgaImageConverterTest::wrongType() { + Image2D image({}, Image2D::Format::Red, Image2D::Type::Float, nullptr); + + std::ostringstream out; + Error::setOutput(&out); + + const unsigned char* data; + std::tie(data, std::ignore) = TgaImageConverter().convertToData(&image); + CORRADE_VERIFY(!data); + CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type AbstractImage::Type::Float\n"); +} + +void TgaImageConverterTest::data() { + const unsigned char* data; + std::size_t size; + std::tie(data, size) = TgaImageConverter().convertToData(&original); + + TgaImporter::TgaImporter importer; + CORRADE_VERIFY(importer.openData(data, size)); + Trade::ImageData2D* converted = importer.image2D(0); + CORRADE_VERIFY(converted); + + CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); + CORRADE_COMPARE(converted->format(), Trade::ImageData2D::Format::BGR); + CORRADE_COMPARE(converted->type(), Trade::ImageData2D::Type::UnsignedByte); + CORRADE_COMPARE(std::string(reinterpret_cast(converted->data()), 2*3*3), + std::string(reinterpret_cast(original.data()), 2*3*3)); +} + +void TgaImageConverterTest::file() { + const std::string filename = Directory::join(TGAIMAGECONVERTER_TEST_DIR, "file.tga"); + Directory::rm(filename); + CORRADE_VERIFY(TgaImageConverter().convertToFile(&original, filename)); + + TgaImporter::TgaImporter importer; + CORRADE_VERIFY(importer.openFile(filename)); + Trade::ImageData2D* converted = importer.image2D(0); + CORRADE_VERIFY(converted); + + CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); + CORRADE_COMPARE(converted->format(), Trade::ImageData2D::Format::BGR); + CORRADE_COMPARE(converted->type(), Trade::ImageData2D::Type::UnsignedByte); + CORRADE_COMPARE(std::string(reinterpret_cast(converted->data()), 2*3*3), + std::string(reinterpret_cast(original.data()), 2*3*3)); + + Directory::rm(filename); +} + +}}}} + +CORRADE_TEST_MAIN(Magnum::Trade::TgaImageConverter::Test::TgaImageConverterTest) diff --git a/src/Plugins/TgaImageConverter/Test/configure.h.cmake b/src/Plugins/TgaImageConverter/Test/configure.h.cmake new file mode 100644 index 000000000..98c60f430 --- /dev/null +++ b/src/Plugins/TgaImageConverter/Test/configure.h.cmake @@ -0,0 +1,25 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#define TGAIMAGECONVERTER_TEST_DIR "${CMAKE_CURRENT_BINARY_DIR}" diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.conf b/src/Plugins/TgaImageConverter/TgaImageConverter.conf new file mode 100644 index 000000000..e69de29bb diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp new file mode 100644 index 000000000..3ba43c062 --- /dev/null +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp @@ -0,0 +1,94 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "TgaImageConverter.h" + +#include +#include +#include + +#include "TgaImporter/TgaHeader.h" + +namespace Magnum { namespace Trade { namespace TgaImageConverter { + +TgaImageConverter::TgaImageConverter() = default; + +TgaImageConverter::TgaImageConverter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractImageConverter(manager, std::move(plugin)) {} + +TgaImageConverter::Features TgaImageConverter::features() const { + return Feature::ConvertToData|Feature::ConvertToFile; +} + +std::pair TgaImageConverter::convertToData(const Image2D* const image) const { + if(image->format() != AbstractImage::Format::BGR && + image->format() != AbstractImage::Format::BGRA && + image->format() != AbstractImage::Format::Red) { + Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format" << image->format(); + return {nullptr, 0}; + } + + if(image->type() != AbstractImage::Type::UnsignedByte) { + Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type" << image->type(); + return {nullptr, 0}; + } + + /* Initialize data buffer */ + const UnsignedByte pixelSize = Image2D::pixelSize(image->format(), image->type()); + const std::size_t size = sizeof(TgaImporter::TgaHeader) + pixelSize*image->size().product(); + unsigned char* data = new unsigned char[size](); + + /* Fill header */ + auto header = reinterpret_cast(data); + header->imageType = image->format() == AbstractImage::Format::Red ? 3 : 2; + header->bpp = pixelSize*8; + header->width = image->size().x(); + header->height = image->size().y(); + + /* Fill data */ + std::copy(image->data(), image->data()+pixelSize*image->size().product(), data+sizeof(TgaImporter::TgaHeader)); + + return {data, size}; +} + +bool TgaImageConverter::convertToFile(const Image2D* const image, const std::string& filename) const { + /* Convert the image */ + const unsigned char* data; + std::size_t size; + std::tie(data, size) = convertToData(image); + if(!data) return false; + + /* Open file */ + std::ofstream out(filename.c_str()); + if(!out.good()) { + delete[] data; + return false; + } + + /* Write contents */ + out.write(reinterpret_cast(data), size); + delete[] data; + return true; +} + +}}} diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.h b/src/Plugins/TgaImageConverter/TgaImageConverter.h new file mode 100644 index 000000000..31bf183be --- /dev/null +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.h @@ -0,0 +1,57 @@ +#ifndef Magnum_Trade_TgaImageConverter_TgaImageConverter_h +#define Magnum_Trade_TgaImageConverter_TgaImageConverter_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Class Magnum::Trade::TgaImageConverter::TgaImageConverter + */ + +#include + +namespace Magnum { namespace Trade { namespace TgaImageConverter { + +/** +@brief TGA image converter + +Supports images with format @ref AbstractImage::Format "AbstractImage::Format::BGR", +@ref AbstractImage::Format "AbstractImage::Format::BGRA" or @ref AbstractImage::Format "AbstractImage::Format::Red" +and type @ref AbstractImage::Type "AbstractImage::Type::UnsignedByte". +*/ +class TgaImageConverter: public AbstractImageConverter { + public: + /** @brief Default constructor */ + explicit TgaImageConverter(); + + /** @brief Plugin manager constructor */ + explicit TgaImageConverter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin); + + Features features() const override; + std::pair convertToData(const Image2D* const image) const override; + bool convertToFile(const Image2D* const image, const std::string& filename) const override; +}; + +}}} + +#endif diff --git a/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp b/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp new file mode 100644 index 000000000..dd4b0082c --- /dev/null +++ b/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp @@ -0,0 +1,28 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "TgaImageConverter.h" + +PLUGIN_REGISTER(TgaImageConverter, Magnum::Trade::TgaImageConverter::TgaImageConverter, + "cz.mosra.magnum.Trade.AbstractImageConverter/0.1") From 089ec23c7715f43515f8cf6d76c35c97abf5544e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 20 May 2013 13:53:12 +0200 Subject: [PATCH 068/112] Adapted to Magnum changes. Shorter lines, yay! --- .../Test/TgaImageConverterTest.cpp | 19 +++++++-------- .../TgaImageConverter/TgaImageConverter.cpp | 13 ++++++----- .../TgaImageConverter/TgaImageConverter.h | 6 ++--- .../TgaImporter/Test/TgaImporterTest.cpp | 23 ++++++++++--------- src/Plugins/TgaImporter/TgaImporter.cpp | 15 ++++++------ 5 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index 5d448e0b6..dd67a14e0 100644 --- a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -49,7 +50,7 @@ class TgaImageConverterTest: public Corrade::TestSuite::Tester { }; namespace { - const Image2D original({2, 3}, Image2D::Format::BGR, Image2D::Type::UnsignedByte, new char[18] { + const Image2D original({2, 3}, ImageFormat::BGR, ImageType::UnsignedByte, new char[18] { 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8 @@ -65,7 +66,7 @@ TgaImageConverterTest::TgaImageConverterTest() { } void TgaImageConverterTest::wrongFormat() { - Image2D image({}, Image2D::Format::RG, Image2D::Type::UnsignedByte, nullptr); + Image2D image({}, ImageFormat::RG, ImageType::UnsignedByte, nullptr); std::ostringstream out; Error::setOutput(&out); @@ -73,11 +74,11 @@ void TgaImageConverterTest::wrongFormat() { const unsigned char* data; std::tie(data, std::ignore) = TgaImageConverter().convertToData(&image); CORRADE_VERIFY(!data); - CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format AbstractImage::Format::RG\n"); + CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format ImageFormat::RG\n"); } void TgaImageConverterTest::wrongType() { - Image2D image({}, Image2D::Format::Red, Image2D::Type::Float, nullptr); + Image2D image({}, ImageFormat::Red, ImageType::Float, nullptr); std::ostringstream out; Error::setOutput(&out); @@ -85,7 +86,7 @@ void TgaImageConverterTest::wrongType() { const unsigned char* data; std::tie(data, std::ignore) = TgaImageConverter().convertToData(&image); CORRADE_VERIFY(!data); - CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type AbstractImage::Type::Float\n"); + CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type ImageType::Float\n"); } void TgaImageConverterTest::data() { @@ -99,8 +100,8 @@ void TgaImageConverterTest::data() { CORRADE_VERIFY(converted); CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); - CORRADE_COMPARE(converted->format(), Trade::ImageData2D::Format::BGR); - CORRADE_COMPARE(converted->type(), Trade::ImageData2D::Type::UnsignedByte); + CORRADE_COMPARE(converted->format(), ImageFormat::BGR); + CORRADE_COMPARE(converted->type(), ImageType::UnsignedByte); CORRADE_COMPARE(std::string(reinterpret_cast(converted->data()), 2*3*3), std::string(reinterpret_cast(original.data()), 2*3*3)); } @@ -116,8 +117,8 @@ void TgaImageConverterTest::file() { CORRADE_VERIFY(converted); CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); - CORRADE_COMPARE(converted->format(), Trade::ImageData2D::Format::BGR); - CORRADE_COMPARE(converted->type(), Trade::ImageData2D::Type::UnsignedByte); + CORRADE_COMPARE(converted->format(), ImageFormat::BGR); + CORRADE_COMPARE(converted->type(), ImageType::UnsignedByte); CORRADE_COMPARE(std::string(reinterpret_cast(converted->data()), 2*3*3), std::string(reinterpret_cast(original.data()), 2*3*3)); diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp index 3ba43c062..b5b22116e 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "TgaImporter/TgaHeader.h" @@ -41,26 +42,26 @@ TgaImageConverter::Features TgaImageConverter::features() const { } std::pair TgaImageConverter::convertToData(const Image2D* const image) const { - if(image->format() != AbstractImage::Format::BGR && - image->format() != AbstractImage::Format::BGRA && - image->format() != AbstractImage::Format::Red) { + if(image->format() != ImageFormat::BGR && + image->format() != ImageFormat::BGRA && + image->format() != ImageFormat::Red) { Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format" << image->format(); return {nullptr, 0}; } - if(image->type() != AbstractImage::Type::UnsignedByte) { + if(image->type() != ImageType::UnsignedByte) { Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type" << image->type(); return {nullptr, 0}; } /* Initialize data buffer */ - const UnsignedByte pixelSize = Image2D::pixelSize(image->format(), image->type()); + const UnsignedByte pixelSize = image->pixelSize(); const std::size_t size = sizeof(TgaImporter::TgaHeader) + pixelSize*image->size().product(); unsigned char* data = new unsigned char[size](); /* Fill header */ auto header = reinterpret_cast(data); - header->imageType = image->format() == AbstractImage::Format::Red ? 3 : 2; + header->imageType = image->format() == ImageFormat::Red ? 3 : 2; header->bpp = pixelSize*8; header->width = image->size().x(); header->height = image->size().y(); diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.h b/src/Plugins/TgaImageConverter/TgaImageConverter.h index 31bf183be..7148b7f1a 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.h +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.h @@ -35,9 +35,9 @@ namespace Magnum { namespace Trade { namespace TgaImageConverter { /** @brief TGA image converter -Supports images with format @ref AbstractImage::Format "AbstractImage::Format::BGR", -@ref AbstractImage::Format "AbstractImage::Format::BGRA" or @ref AbstractImage::Format "AbstractImage::Format::Red" -and type @ref AbstractImage::Type "AbstractImage::Type::UnsignedByte". +Supports images with format @ref ImageFormat "ImageFormat::BGR", +@ref ImageFormat "ImageFormat::BGRA" or @ref ImageFormat "ImageFormat::Red" and +type @ref ImageType "ImageType::UnsignedByte". */ class TgaImageConverter: public AbstractImageConverter { public: diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index f0ac0d188..908969de6 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "TgaImporter/TgaImporter.h" @@ -145,12 +146,12 @@ void TgaImporterTest::colorBits24() { Trade::ImageData2D* image = importer.image2D(0); CORRADE_VERIFY(image); #ifndef MAGNUM_TARGET_GLES - CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::BGR); + CORRADE_COMPARE(image->format(), ImageFormat::BGR); #else - CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::RGB); + CORRADE_COMPARE(image->format(), ImageFormat::RGB); #endif CORRADE_COMPARE(image->size(), Vector2i(2, 3)); - CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); + CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); delete image; @@ -178,12 +179,12 @@ void TgaImporterTest::colorBits32() { Trade::ImageData2D* image = importer.image2D(0); CORRADE_VERIFY(image); #ifndef MAGNUM_TARGET_GLES - CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::BGRA); + CORRADE_COMPARE(image->format(), ImageFormat::BGRA); #else - CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::RGBA); + CORRADE_COMPARE(image->format(), ImageFormat::RGBA); #endif - CORRADE_COMPARE(image->size(), Math::Vector2(2, 3)); - CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); + CORRADE_COMPARE(image->size(), Vector2i(2, 3)); + CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3*3), std::string(pixels, 2*3*3)); delete image; @@ -201,9 +202,9 @@ void TgaImporterTest::grayscaleBits8() { Trade::ImageData2D* image = importer.image2D(0); CORRADE_VERIFY(image); - CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::Red); + CORRADE_COMPARE(image->format(), ImageFormat::Red); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); - CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); + CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3), std::string(data + 18, 2*3)); } @@ -230,9 +231,9 @@ void TgaImporterTest::file() { Trade::ImageData2D* image = importer.image2D(0); CORRADE_VERIFY(image); - CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::Red); + CORRADE_COMPARE(image->format(), ImageFormat::Red); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); - CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); + CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3), std::string(data + 18, 2*3)); } diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 9c39c04ca..6b8c9f8a0 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -96,7 +97,7 @@ ImageData2D* TgaImporter::image2D(UnsignedInt id) { header.height = Endianness::littleEndian(header.height); /* Image format */ - ImageData2D::Format format; + ImageFormat format; if(header.colorMapType != 0) { Error() << "Trade::TgaImporter::TgaImporter::image2D(): paletted files are not supported"; return nullptr; @@ -107,16 +108,16 @@ ImageData2D* TgaImporter::image2D(UnsignedInt id) { switch(header.bpp) { case 24: #ifndef MAGNUM_TARGET_GLES - format = ImageData2D::Format::BGR; + format = ImageFormat::BGR; #else - format = ImageData2D::Format::RGB; + format = ImageFormat::RGB; #endif break; case 32: #ifndef MAGNUM_TARGET_GLES - format = ImageData2D::Format::BGRA; + format = ImageFormat::BGRA; #else - format = ImageData2D::Format::RGBA; + format = ImageFormat::RGBA; #endif break; default: @@ -126,7 +127,7 @@ ImageData2D* TgaImporter::image2D(UnsignedInt id) { /* Grayscale */ } else if(header.imageType == 3) { - format = ImageData2D::Format::Red; + format = ImageFormat::Red; if(header.bpp != 8) { Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp; return nullptr; @@ -156,7 +157,7 @@ ImageData2D* TgaImporter::image2D(UnsignedInt id) { } #endif - return new ImageData2D(dimensions, format, ImageData2D::Type::UnsignedByte, buffer); + return new ImageData2D(dimensions, format, ImageType::UnsignedByte, buffer); } }}} From 5d1fcd26d3cd193b2ef35646a19821ca2c3bf8e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 24 May 2013 21:44:28 +0200 Subject: [PATCH 069/112] Adapted to Corrade and Magnum changes. More shorter lines (sometimes even longer lines). --- .../TgaImageConverter/Test/TgaImageConverterTest.cpp | 10 ++++------ src/Plugins/TgaImageConverter/TgaImageConverter.cpp | 2 +- src/Plugins/TgaImageConverter/TgaImageConverter.h | 2 +- src/Plugins/TgaImporter/Test/TgaImporterTest.cpp | 6 ++---- src/Plugins/TgaImporter/TgaImporter.cpp | 12 +++++------- src/Plugins/TgaImporter/TgaImporter.h | 2 +- 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index dd67a14e0..94810167e 100644 --- a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -34,11 +34,9 @@ #include "configure.h" -using Corrade::Utility::Directory; - namespace Magnum { namespace Trade { namespace TgaImageConverter { namespace Test { -class TgaImageConverterTest: public Corrade::TestSuite::Tester { +class TgaImageConverterTest: public TestSuite::Tester { public: explicit TgaImageConverterTest(); @@ -107,8 +105,8 @@ void TgaImageConverterTest::data() { } void TgaImageConverterTest::file() { - const std::string filename = Directory::join(TGAIMAGECONVERTER_TEST_DIR, "file.tga"); - Directory::rm(filename); + const std::string filename = Utility::Directory::join(TGAIMAGECONVERTER_TEST_DIR, "file.tga"); + Utility::Directory::rm(filename); CORRADE_VERIFY(TgaImageConverter().convertToFile(&original, filename)); TgaImporter::TgaImporter importer; @@ -122,7 +120,7 @@ void TgaImageConverterTest::file() { CORRADE_COMPARE(std::string(reinterpret_cast(converted->data()), 2*3*3), std::string(reinterpret_cast(original.data()), 2*3*3)); - Directory::rm(filename); + Utility::Directory::rm(filename); } }}}} diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp index b5b22116e..71434f290 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp @@ -35,7 +35,7 @@ namespace Magnum { namespace Trade { namespace TgaImageConverter { TgaImageConverter::TgaImageConverter() = default; -TgaImageConverter::TgaImageConverter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractImageConverter(manager, std::move(plugin)) {} +TgaImageConverter::TgaImageConverter(PluginManager::AbstractManager* manager, std::string plugin): AbstractImageConverter(manager, std::move(plugin)) {} TgaImageConverter::Features TgaImageConverter::features() const { return Feature::ConvertToData|Feature::ConvertToFile; diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.h b/src/Plugins/TgaImageConverter/TgaImageConverter.h index 7148b7f1a..174e98f0a 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.h +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.h @@ -45,7 +45,7 @@ class TgaImageConverter: public AbstractImageConverter { explicit TgaImageConverter(); /** @brief Plugin manager constructor */ - explicit TgaImageConverter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin); + explicit TgaImageConverter(PluginManager::AbstractManager* manager, std::string plugin); Features features() const override; std::pair convertToData(const Image2D* const image) const override; diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 908969de6..adbb5bcab 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -32,11 +32,9 @@ #include "configure.h" -using Corrade::Utility::Directory; - namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { -class TgaImporterTest: public Corrade::TestSuite::Tester { +class TgaImporterTest: public TestSuite::Tester { public: TgaImporterTest(); @@ -227,7 +225,7 @@ void TgaImporterTest::file() { 3, 4, 5, 6 }; - CORRADE_VERIFY(importer.openFile(Directory::join(TGAIMPORTER_TEST_DIR, "file.tga"))); + CORRADE_VERIFY(importer.openFile(Utility::Directory::join(TGAIMPORTER_TEST_DIR, "file.tga"))); Trade::ImageData2D* image = importer.image2D(0); CORRADE_VERIFY(image); diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 6b8c9f8a0..96a915d43 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -35,13 +35,11 @@ #include "TgaHeader.h" -using Corrade::Utility::Endianness; - namespace Magnum { namespace Trade { namespace TgaImporter { TgaImporter::TgaImporter(): in(nullptr) {} -TgaImporter::TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin): AbstractImporter(manager, std::move(plugin)), in(nullptr) {} +TgaImporter::TgaImporter(PluginManager::AbstractManager* manager, std::string plugin): AbstractImporter(manager, std::move(plugin)), in(nullptr) {} TgaImporter::~TgaImporter() { close(); } @@ -93,8 +91,8 @@ ImageData2D* TgaImporter::image2D(UnsignedInt id) { in->read(reinterpret_cast(&header), sizeof(TgaHeader)); /* Convert to machine endian */ - header.width = Endianness::littleEndian(header.width); - header.height = Endianness::littleEndian(header.height); + header.width = Utility::Endianness::littleEndian(header.width); + header.height = Utility::Endianness::littleEndian(header.height); /* Image format */ ImageFormat format; @@ -146,11 +144,11 @@ ImageData2D* TgaImporter::image2D(UnsignedInt id) { Vector2i dimensions(header.width, header.height); #ifdef MAGNUM_TARGET_GLES - if(format == ImageData2D::Format::RGB) { + if(format == ImageFormat::RGB) { auto data = reinterpret_cast*>(buffer); std::transform(data, data + dimensions.product(), data, [](Math::Vector3 pixel) { return swizzle<'b', 'g', 'r'>(pixel); }); - } else if(format == ImageData2D::Format::RGBA) { + } else if(format == ImageFormat::RGBA) { auto data = reinterpret_cast*>(buffer); std::transform(data, data + dimensions.product(), data, [](Math::Vector4 pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); }); diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 9fc8925bf..b1b8b7e3b 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -57,7 +57,7 @@ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { explicit TgaImporter(); /** @brief Plugin manager constructor */ - explicit TgaImporter(Corrade::PluginManager::AbstractPluginManager* manager, std::string plugin); + explicit TgaImporter(PluginManager::AbstractManager* manager, std::string plugin); virtual ~TgaImporter(); From b701dbb655466de1626ef3095de42c99bb7e2c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 31 May 2013 17:07:34 +0200 Subject: [PATCH 070/112] Adapted to Corrade changes. --- .../TgaImageConverter/pluginRegistrationTgaImageConverter.cpp | 4 ++-- src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp b/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp index dd4b0082c..c254a4520 100644 --- a/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp @@ -24,5 +24,5 @@ #include "TgaImageConverter.h" -PLUGIN_REGISTER(TgaImageConverter, Magnum::Trade::TgaImageConverter::TgaImageConverter, - "cz.mosra.magnum.Trade.AbstractImageConverter/0.1") +CORRADE_PLUGIN_REGISTER(TgaImageConverter, Magnum::Trade::TgaImageConverter::TgaImageConverter, + "cz.mosra.magnum.Trade.AbstractImageConverter/0.1") diff --git a/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp b/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp index f09436993..15fddbf01 100644 --- a/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp +++ b/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp @@ -24,5 +24,5 @@ #include "TgaImporter.h" -PLUGIN_REGISTER(TgaImporter, Magnum::Trade::TgaImporter::TgaImporter, - "cz.mosra.magnum.Trade.AbstractImporter/0.2.1") +CORRADE_PLUGIN_REGISTER(TgaImporter, Magnum::Trade::TgaImporter::TgaImporter, + "cz.mosra.magnum.Trade.AbstractImporter/0.2.1") From d17248959e01ff30de39141b401696242f63ba00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Jun 2013 15:32:29 +0200 Subject: [PATCH 071/112] TgaImporter: more verbose error when image type is not supported. --- src/Plugins/TgaImporter/Test/TgaImporterTest.cpp | 2 +- src/Plugins/TgaImporter/TgaImporter.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index adbb5bcab..7b4e089a9 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -108,7 +108,7 @@ void TgaImporterTest::compressed() { std::ostringstream debug; Error::setOutput(&debug); CORRADE_VERIFY(!importer.image2D(0)); - CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): compressed files are not supported\n"); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): unsupported (compressed?) image type: 9\n"); } void TgaImporterTest::colorBits16() { diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 96a915d43..50dd750a7 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -133,7 +133,7 @@ ImageData2D* TgaImporter::image2D(UnsignedInt id) { /* Compressed files */ } else { - Error() << "Trade::TgaImporter::TgaImporter::image2D(): compressed files are not supported"; + Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported (compressed?) image type:" << header.imageType; return nullptr; } From e8fe82ac28d312e42fea1e273af3eb6018876f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Jun 2013 15:32:54 +0200 Subject: [PATCH 072/112] TgaImporter: don't include these headers if not really needed. --- src/Plugins/TgaImporter/TgaImporter.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 50dd750a7..b5bda5f66 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -26,13 +26,16 @@ #include #include -#include #include #include #include -#include #include +#ifdef MAGNUM_TARGET_GLES +#include +#include +#endif + #include "TgaHeader.h" namespace Magnum { namespace Trade { namespace TgaImporter { From 51075b91c5ae22343d6d427d2f03868557a4c105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Jun 2013 15:36:34 +0200 Subject: [PATCH 073/112] TgaImageConverter: ported to OpenGL ES. --- .../Test/TgaImageConverterTest.cpp | 15 ++++++++++- .../TgaImageConverter/TgaImageConverter.cpp | 26 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index 94810167e..f1dd896f4 100644 --- a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -48,7 +48,12 @@ class TgaImageConverterTest: public TestSuite::Tester { }; namespace { - const Image2D original({2, 3}, ImageFormat::BGR, ImageType::UnsignedByte, new char[18] { + #ifndef MAGNUM_TARGET_GLES + const Image2D original({2, 3}, ImageFormat::BGR, ImageType::UnsignedByte, new char[18] + #else + const Image2D original({2, 3}, ImageFormat::RGB, ImageType::UnsignedByte, new char[18] + #endif + { 1, 2, 3, 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8 @@ -98,7 +103,11 @@ void TgaImageConverterTest::data() { CORRADE_VERIFY(converted); CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); + #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(converted->format(), ImageFormat::BGR); + #else + CORRADE_COMPARE(converted->format(), ImageFormat::RGB); + #endif CORRADE_COMPARE(converted->type(), ImageType::UnsignedByte); CORRADE_COMPARE(std::string(reinterpret_cast(converted->data()), 2*3*3), std::string(reinterpret_cast(original.data()), 2*3*3)); @@ -115,7 +124,11 @@ void TgaImageConverterTest::file() { CORRADE_VERIFY(converted); CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); + #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(converted->format(), ImageFormat::BGR); + #else + CORRADE_COMPARE(converted->format(), ImageFormat::RGB); + #endif CORRADE_COMPARE(converted->type(), ImageType::UnsignedByte); CORRADE_COMPARE(std::string(reinterpret_cast(converted->data()), 2*3*3), std::string(reinterpret_cast(original.data()), 2*3*3)); diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp index 71434f290..ed2bd87ad 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp @@ -29,6 +29,11 @@ #include #include +#ifdef MAGNUM_TARGET_GLES +#include +#include +#endif + #include "TgaImporter/TgaHeader.h" namespace Magnum { namespace Trade { namespace TgaImageConverter { @@ -42,9 +47,16 @@ TgaImageConverter::Features TgaImageConverter::features() const { } std::pair TgaImageConverter::convertToData(const Image2D* const image) const { + #ifndef MAGNUM_TARGET_GLES if(image->format() != ImageFormat::BGR && image->format() != ImageFormat::BGRA && - image->format() != ImageFormat::Red) { + image->format() != ImageFormat::Red) + #else + if(image->format() != ImageFormat::RGB && + image->format() != ImageFormat::RGBA && + image->format() != ImageFormat::Red) + #endif + { Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format" << image->format(); return {nullptr, 0}; } @@ -69,6 +81,18 @@ std::pair TgaImageConverter::convertToData(co /* Fill data */ std::copy(image->data(), image->data()+pixelSize*image->size().product(), data+sizeof(TgaImporter::TgaHeader)); + #ifdef MAGNUM_TARGET_GLES + if(image->format() == ImageFormat::RGB) { + auto pixels = reinterpret_cast*>(data+sizeof(TgaImporter::TgaHeader)); + std::transform(pixels, pixels + image->size().product(), pixels, + [](Math::Vector3 pixel) { return swizzle<'b', 'g', 'r'>(pixel); }); + } else if(image->format() == ImageFormat::RGBA) { + auto pixels = reinterpret_cast*>(data+sizeof(TgaImporter::TgaHeader)); + std::transform(pixels, pixels + image->size().product(), pixels, + [](Math::Vector4 pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); }); + } + #endif + return {data, size}; } From 8f08ae4baa82e2613c725b59a01988d074e3a7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Jun 2013 15:36:49 +0200 Subject: [PATCH 074/112] TgaImageConverter: don't forget about endianness. --- src/Plugins/TgaImageConverter/TgaImageConverter.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp index ed2bd87ad..7f5ae0cb4 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -75,8 +76,8 @@ std::pair TgaImageConverter::convertToData(co auto header = reinterpret_cast(data); header->imageType = image->format() == ImageFormat::Red ? 3 : 2; header->bpp = pixelSize*8; - header->width = image->size().x(); - header->height = image->size().y(); + header->width = Utility::Endianness::littleEndian(image->size().x()); + header->height = Utility::Endianness::littleEndian(image->size().y()); /* Fill data */ std::copy(image->data(), image->data()+pixelSize*image->size().product(), data+sizeof(TgaImporter::TgaHeader)); From 0ca94912444ce893f85862cb2af5187cbf66a361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 12 Jun 2013 15:38:30 +0200 Subject: [PATCH 075/112] TgaImporter: removed unneeded #include. --- src/Plugins/TgaImporter/TgaImporter.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index b5bda5f66..8d8e4b0e5 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include From 4d69b63fb671598a99c9a1f1c29f67369d1ac1a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 21 Jun 2013 18:43:01 +0200 Subject: [PATCH 076/112] Adapted to Magnum changes. Removed redundant checks, hidden implementation to class privates. --- .../Test/TgaImageConverterTest.cpp | 40 +++-------------- .../TgaImageConverter/TgaImageConverter.cpp | 44 +++++-------------- .../TgaImageConverter/TgaImageConverter.h | 6 +-- .../pluginRegistrationTgaImageConverter.cpp | 2 +- .../TgaImporter/Test/TgaImporterTest.cpp | 29 ++++++------ src/Plugins/TgaImporter/TgaImporter.cpp | 30 +++++-------- src/Plugins/TgaImporter/TgaImporter.h | 16 +++---- .../pluginRegistrationTgaImporter.cpp | 2 +- 8 files changed, 55 insertions(+), 114 deletions(-) diff --git a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index f1dd896f4..34f716cef 100644 --- a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -44,7 +45,6 @@ class TgaImageConverterTest: public TestSuite::Tester { void wrongType(); void data(); - void file(); }; namespace { @@ -64,8 +64,7 @@ TgaImageConverterTest::TgaImageConverterTest() { addTests({&TgaImageConverterTest::wrongFormat, &TgaImageConverterTest::wrongType, - &TgaImageConverterTest::data, - &TgaImageConverterTest::file}); + &TgaImageConverterTest::data}); } void TgaImageConverterTest::wrongFormat() { @@ -74,8 +73,7 @@ void TgaImageConverterTest::wrongFormat() { std::ostringstream out; Error::setOutput(&out); - const unsigned char* data; - std::tie(data, std::ignore) = TgaImageConverter().convertToData(&image); + const auto data = TgaImageConverter().exportToData(&image); CORRADE_VERIFY(!data); CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format ImageFormat::RG\n"); } @@ -86,19 +84,16 @@ void TgaImageConverterTest::wrongType() { std::ostringstream out; Error::setOutput(&out); - const unsigned char* data; - std::tie(data, std::ignore) = TgaImageConverter().convertToData(&image); + const auto data = TgaImageConverter().exportToData(&image); CORRADE_VERIFY(!data); CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type ImageType::Float\n"); } void TgaImageConverterTest::data() { - const unsigned char* data; - std::size_t size; - std::tie(data, size) = TgaImageConverter().convertToData(&original); + const auto data = TgaImageConverter().exportToData(&original); TgaImporter::TgaImporter importer; - CORRADE_VERIFY(importer.openData(data, size)); + CORRADE_VERIFY(importer.openData(data)); Trade::ImageData2D* converted = importer.image2D(0); CORRADE_VERIFY(converted); @@ -113,29 +108,6 @@ void TgaImageConverterTest::data() { std::string(reinterpret_cast(original.data()), 2*3*3)); } -void TgaImageConverterTest::file() { - const std::string filename = Utility::Directory::join(TGAIMAGECONVERTER_TEST_DIR, "file.tga"); - Utility::Directory::rm(filename); - CORRADE_VERIFY(TgaImageConverter().convertToFile(&original, filename)); - - TgaImporter::TgaImporter importer; - CORRADE_VERIFY(importer.openFile(filename)); - Trade::ImageData2D* converted = importer.image2D(0); - CORRADE_VERIFY(converted); - - CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); - #ifndef MAGNUM_TARGET_GLES - CORRADE_COMPARE(converted->format(), ImageFormat::BGR); - #else - CORRADE_COMPARE(converted->format(), ImageFormat::RGB); - #endif - CORRADE_COMPARE(converted->type(), ImageType::UnsignedByte); - CORRADE_COMPARE(std::string(reinterpret_cast(converted->data()), 2*3*3), - std::string(reinterpret_cast(original.data()), 2*3*3)); - - Utility::Directory::rm(filename); -} - }}}} CORRADE_TEST_MAIN(Magnum::Trade::TgaImageConverter::Test::TgaImageConverterTest) diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp index 7f5ae0cb4..d10ebc3c7 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -43,11 +44,9 @@ TgaImageConverter::TgaImageConverter() = default; TgaImageConverter::TgaImageConverter(PluginManager::AbstractManager* manager, std::string plugin): AbstractImageConverter(manager, std::move(plugin)) {} -TgaImageConverter::Features TgaImageConverter::features() const { - return Feature::ConvertToData|Feature::ConvertToFile; -} +auto TgaImageConverter::doFeatures() const -> Features { return Feature::ConvertData; } -std::pair TgaImageConverter::convertToData(const Image2D* const image) const { +Containers::Array TgaImageConverter::doExportToData(const Image2D* const image) const { #ifndef MAGNUM_TARGET_GLES if(image->format() != ImageFormat::BGR && image->format() != ImageFormat::BGRA && @@ -59,62 +58,41 @@ std::pair TgaImageConverter::convertToData(co #endif { Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format" << image->format(); - return {nullptr, 0}; + return nullptr; } if(image->type() != ImageType::UnsignedByte) { Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type" << image->type(); - return {nullptr, 0}; + return nullptr; } /* Initialize data buffer */ const UnsignedByte pixelSize = image->pixelSize(); - const std::size_t size = sizeof(TgaImporter::TgaHeader) + pixelSize*image->size().product(); - unsigned char* data = new unsigned char[size](); + auto data = Containers::Array::zeroInitialized(sizeof(TgaImporter::TgaHeader) + pixelSize*image->size().product()); /* Fill header */ - auto header = reinterpret_cast(data); + auto header = reinterpret_cast(data.begin()); header->imageType = image->format() == ImageFormat::Red ? 3 : 2; header->bpp = pixelSize*8; header->width = Utility::Endianness::littleEndian(image->size().x()); header->height = Utility::Endianness::littleEndian(image->size().y()); /* Fill data */ - std::copy(image->data(), image->data()+pixelSize*image->size().product(), data+sizeof(TgaImporter::TgaHeader)); + std::copy(image->data(), image->data()+pixelSize*image->size().product(), data.begin()+sizeof(TgaImporter::TgaHeader)); #ifdef MAGNUM_TARGET_GLES if(image->format() == ImageFormat::RGB) { - auto pixels = reinterpret_cast*>(data+sizeof(TgaImporter::TgaHeader)); + auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaImporter::TgaHeader)); std::transform(pixels, pixels + image->size().product(), pixels, [](Math::Vector3 pixel) { return swizzle<'b', 'g', 'r'>(pixel); }); } else if(image->format() == ImageFormat::RGBA) { - auto pixels = reinterpret_cast*>(data+sizeof(TgaImporter::TgaHeader)); + auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaImporter::TgaHeader)); std::transform(pixels, pixels + image->size().product(), pixels, [](Math::Vector4 pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); }); } #endif - return {data, size}; -} - -bool TgaImageConverter::convertToFile(const Image2D* const image, const std::string& filename) const { - /* Convert the image */ - const unsigned char* data; - std::size_t size; - std::tie(data, size) = convertToData(image); - if(!data) return false; - - /* Open file */ - std::ofstream out(filename.c_str()); - if(!out.good()) { - delete[] data; - return false; - } - - /* Write contents */ - out.write(reinterpret_cast(data), size); - delete[] data; - return true; + return std::move(data); } }}} diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.h b/src/Plugins/TgaImageConverter/TgaImageConverter.h index 174e98f0a..0f2fa5fda 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.h +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.h @@ -47,9 +47,9 @@ class TgaImageConverter: public AbstractImageConverter { /** @brief Plugin manager constructor */ explicit TgaImageConverter(PluginManager::AbstractManager* manager, std::string plugin); - Features features() const override; - std::pair convertToData(const Image2D* const image) const override; - bool convertToFile(const Image2D* const image, const std::string& filename) const override; + private: + Features doFeatures() const override; + Containers::Array doExportToData(const Image2D* const image) const override; }; }}} diff --git a/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp b/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp index c254a4520..c736aa768 100644 --- a/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp @@ -25,4 +25,4 @@ #include "TgaImageConverter.h" CORRADE_PLUGIN_REGISTER(TgaImageConverter, Magnum::Trade::TgaImageConverter::TgaImageConverter, - "cz.mosra.magnum.Trade.AbstractImageConverter/0.1") + "cz.mosra.magnum.Trade.AbstractImageConverter/0.2") diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 7b4e089a9..3c236ab42 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -23,6 +23,7 @@ */ #include +#include #include #include #include @@ -80,7 +81,7 @@ void TgaImporterTest::openInexistent() { void TgaImporterTest::openShort() { TgaImporter importer; - const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + const unsigned char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; CORRADE_VERIFY(importer.openData(data)); std::ostringstream debug; @@ -91,7 +92,7 @@ void TgaImporterTest::openShort() { void TgaImporterTest::paletted() { TgaImporter importer; - const char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + const unsigned char data[] = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; CORRADE_VERIFY(importer.openData(data)); std::ostringstream debug; @@ -102,7 +103,7 @@ void TgaImporterTest::paletted() { void TgaImporterTest::compressed() { TgaImporter importer; - const char data[] = { 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + const unsigned char data[] = { 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; CORRADE_VERIFY(importer.openData(data)); std::ostringstream debug; @@ -113,7 +114,7 @@ void TgaImporterTest::compressed() { void TgaImporterTest::colorBits16() { TgaImporter importer; - const char data[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 }; + const unsigned char data[] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 }; CORRADE_VERIFY(importer.openData(data)); std::ostringstream debug; @@ -124,14 +125,14 @@ void TgaImporterTest::colorBits16() { void TgaImporterTest::colorBits24() { TgaImporter importer; - const char data[] = { + const unsigned char data[] = { 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; + const char* pixels = reinterpret_cast(data) + 18; #else const char pixels[] = { 3, 2, 1, 4, 3, 2, @@ -157,14 +158,14 @@ void TgaImporterTest::colorBits24() { void TgaImporterTest::colorBits32() { TgaImporter importer; - const char data[] = { + const unsigned char data[] = { 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; + const char* pixels = reinterpret_cast(data) + 18; #else const char pixels[] = { 3, 2, 1, 1, 4, 3, 2, 1, @@ -190,7 +191,7 @@ void TgaImporterTest::colorBits32() { void TgaImporterTest::grayscaleBits8() { TgaImporter importer; - const char data[] = { + const unsigned char data[] = { 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 8, 0, 1, 2, 3, 4, @@ -203,12 +204,13 @@ void TgaImporterTest::grayscaleBits8() { CORRADE_COMPARE(image->format(), ImageFormat::Red); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); - CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3), std::string(data + 18, 2*3)); + CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3), + std::string(reinterpret_cast(data) + 18, 2*3)); } void TgaImporterTest::grayscaleBits16() { TgaImporter importer; - const char data[] = { 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 }; + const unsigned char data[] = { 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0 }; CORRADE_VERIFY(importer.openData(data)); std::ostringstream debug; @@ -219,7 +221,7 @@ void TgaImporterTest::grayscaleBits16() { void TgaImporterTest::file() { TgaImporter importer; - const char data[] = { + const unsigned char data[] = { 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 8, 0, 1, 2, 3, 4, @@ -232,7 +234,8 @@ void TgaImporterTest::file() { CORRADE_COMPARE(image->format(), ImageFormat::Red); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); - CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3), std::string(data + 18, 2*3)); + CORRADE_COMPARE(std::string(reinterpret_cast(image->data()), 2*3), + std::string(reinterpret_cast(data) + 18, 2*3)); } }}}} diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 8d8e4b0e5..719548d8b 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -45,41 +46,30 @@ TgaImporter::TgaImporter(PluginManager::AbstractManager* manager, std::string pl TgaImporter::~TgaImporter() { close(); } -TgaImporter::Features TgaImporter::features() const { - return Feature::OpenData|Feature::OpenFile; -} +auto TgaImporter::doFeatures() const -> Features { return Feature::OpenData; } -bool TgaImporter::TgaImporter::openData(const void* const data, const std::size_t size) { - close(); +bool TgaImporter::doIsOpened() const { return in; } - in = new std::istringstream(std::string(reinterpret_cast(data), size)); - return true; +void TgaImporter::doOpenData(const Containers::ArrayReference data) { + in = new std::istringstream(std::string(reinterpret_cast(data.begin()), data.size())); } -bool TgaImporter::TgaImporter::openFile(const std::string& filename) { - close(); - +void TgaImporter::doOpenFile(const std::string& filename) { in = new std::ifstream(filename.c_str()); - if(in->good()) return true; + if(in->good()) return; Error() << "Trade::TgaImporter::TgaImporter::openFile(): cannot open file" << filename; close(); - return false; } -void TgaImporter::close() { +void TgaImporter::doClose() { delete in; in = nullptr; } -UnsignedInt TgaImporter::TgaImporter::image2DCount() const { - return in ? 1 : 0; -} - -ImageData2D* TgaImporter::image2D(UnsignedInt id) { - CORRADE_ASSERT(in, "Trade::TgaImporter::TgaImporter::image2D(): no file opened", nullptr); - CORRADE_ASSERT(id == 0, "Trade::TgaImporter::TgaImporter::image2D(): wrong image ID", nullptr); +UnsignedInt TgaImporter::doImage2DCount() const { return 1; } +ImageData2D* TgaImporter::doImage2D(UnsignedInt) { /* Check if the file is long enough */ in->seekg(0, std::istream::end); std::streampos filesize = in->tellg(); diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index b1b8b7e3b..3280b0879 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -61,16 +61,14 @@ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { virtual ~TgaImporter(); - Features features() const override; - bool openData(const void* const data, const std::size_t size) override; - using AbstractImporter::openData; - bool openFile(const std::string& filename) override; - void close() override; - UnsignedInt image2DCount() const override; - ImageData2D* image2D(UnsignedInt id) override; - private: - bool MAGNUM_TGAIMPORTER_LOCAL open(std::istream& in); + Features MAGNUM_TGAIMPORTER_LOCAL doFeatures() const override; + bool MAGNUM_TGAIMPORTER_LOCAL doIsOpened() const override; + void MAGNUM_TGAIMPORTER_LOCAL doOpenData(Containers::ArrayReference data) override; + void MAGNUM_TGAIMPORTER_LOCAL doOpenFile(const std::string& filename) override; + void MAGNUM_TGAIMPORTER_LOCAL doClose() override; + UnsignedInt MAGNUM_TGAIMPORTER_LOCAL doImage2DCount() const override; + ImageData2D MAGNUM_TGAIMPORTER_LOCAL * doImage2D(UnsignedInt id) override; std::istream* in; }; diff --git a/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp b/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp index 15fddbf01..2f5a1ccab 100644 --- a/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp +++ b/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp @@ -25,4 +25,4 @@ #include "TgaImporter.h" CORRADE_PLUGIN_REGISTER(TgaImporter, Magnum::Trade::TgaImporter::TgaImporter, - "cz.mosra.magnum.Trade.AbstractImporter/0.2.1") + "cz.mosra.magnum.Trade.AbstractImporter/0.3") From 90a4e4a709eacce3e21146bff14c1b945567c7d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 22 Jun 2013 19:47:04 +0200 Subject: [PATCH 077/112] TgaImporter: simplified visibility macros. --- src/Plugins/TgaImporter/TgaImporter.h | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 3280b0879..f787bf452 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -28,21 +28,15 @@ * @brief Class Magnum::Trade::TgaImporter::TgaImporter */ +#include #include -#ifndef DOXYGEN_GENERATING_OUTPUT -#ifdef _WIN32 - #ifdef TgaImporter_EXPORTS - #define MAGNUM_TGAIMPORTER_EXPORT __declspec(dllexport) - #else - #define MAGNUM_TGAIMPORTER_EXPORT __declspec(dllimport) - #endif - #define MAGNUM_TGAIMPORTER_LOCAL +#ifdef TgaImporter_EXPORTS + #define MAGNUM_TGAIMPORTER_EXPORT CORRADE_VISIBILITY_EXPORT #else - #define MAGNUM_TGAIMPORTER_EXPORT __attribute__ ((visibility ("default"))) - #define MAGNUM_TGAIMPORTER_LOCAL __attribute__ ((visibility ("hidden"))) -#endif + #define MAGNUM_TGAIMPORTER_EXPORT CORRADE_VISIBILITY_IMPORT #endif +#define MAGNUM_TGAIMPORTER_LOCAL CORRADE_VISIBILITY_LOCAL namespace Magnum { namespace Trade { namespace TgaImporter { From 978f9cc2502f9b40193769a5fb7beb2e93d6feeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 24 Jun 2013 20:16:42 +0200 Subject: [PATCH 078/112] TgaImageConverter: export symbols for use as other plugin dependency. --- src/Plugins/TgaImageConverter/TgaImageConverter.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.h b/src/Plugins/TgaImageConverter/TgaImageConverter.h index 0f2fa5fda..8de3fc032 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.h +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.h @@ -30,6 +30,13 @@ #include +#ifdef TgaImageConverter_EXPORTS + #define MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT CORRADE_VISIBILITY_EXPORT +#else + #define MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT CORRADE_VISIBILITY_IMPORT +#endif +#define MAGNUM_TRADE_TGAIMAGECONVERTER_LOCAL CORRADE_VISIBILITY_LOCAL + namespace Magnum { namespace Trade { namespace TgaImageConverter { /** @@ -39,7 +46,7 @@ Supports images with format @ref ImageFormat "ImageFormat::BGR", @ref ImageFormat "ImageFormat::BGRA" or @ref ImageFormat "ImageFormat::Red" and type @ref ImageType "ImageType::UnsignedByte". */ -class TgaImageConverter: public AbstractImageConverter { +class MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT TgaImageConverter: public AbstractImageConverter { public: /** @brief Default constructor */ explicit TgaImageConverter(); @@ -48,8 +55,8 @@ class TgaImageConverter: public AbstractImageConverter { explicit TgaImageConverter(PluginManager::AbstractManager* manager, std::string plugin); private: - Features doFeatures() const override; - Containers::Array doExportToData(const Image2D* const image) const override; + Features MAGNUM_TRADE_TGAIMAGECONVERTER_LOCAL doFeatures() const override; + Containers::Array MAGNUM_TRADE_TGAIMAGECONVERTER_LOCAL doExportToData(const Image2D* const image) const override; }; }}} From 6eeb01411082b89c07379c65576b63b74d7ea424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 2 Jul 2013 18:57:34 +0200 Subject: [PATCH 079/112] Removed superfluous namespaces. Not sure how to handle everything properly (e.g. namespaces and naming for implementation classes, tests...), will update coding style for plugins accordingly later. --- .../Test/TgaImageConverterTest.cpp | 8 ++++---- .../TgaImageConverter/TgaImageConverter.cpp | 14 +++++++------- src/Plugins/TgaImageConverter/TgaImageConverter.h | 10 +++++----- .../pluginRegistrationTgaImageConverter.cpp | 4 ++-- src/Plugins/TgaImporter/Test/TgaImporterTest.cpp | 6 +++--- src/Plugins/TgaImporter/TgaHeader.h | 10 +++++----- src/Plugins/TgaImporter/TgaImporter.cpp | 4 ++-- src/Plugins/TgaImporter/TgaImporter.h | 10 +++++----- .../TgaImporter/pluginRegistrationTgaImporter.cpp | 2 +- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index 34f716cef..a4d72ca39 100644 --- a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -35,7 +35,7 @@ #include "configure.h" -namespace Magnum { namespace Trade { namespace TgaImageConverter { namespace Test { +namespace Magnum { namespace Trade { namespace Test { class TgaImageConverterTest: public TestSuite::Tester { public: @@ -92,7 +92,7 @@ void TgaImageConverterTest::wrongType() { void TgaImageConverterTest::data() { const auto data = TgaImageConverter().exportToData(&original); - TgaImporter::TgaImporter importer; + TgaImporter importer; CORRADE_VERIFY(importer.openData(data)); Trade::ImageData2D* converted = importer.image2D(0); CORRADE_VERIFY(converted); @@ -108,6 +108,6 @@ void TgaImageConverterTest::data() { std::string(reinterpret_cast(original.data()), 2*3*3)); } -}}}} +}}} -CORRADE_TEST_MAIN(Magnum::Trade::TgaImageConverter::Test::TgaImageConverterTest) +CORRADE_TEST_MAIN(Magnum::Trade::Test::TgaImageConverterTest) diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp index d10ebc3c7..a779acc39 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp @@ -38,7 +38,7 @@ #include "TgaImporter/TgaHeader.h" -namespace Magnum { namespace Trade { namespace TgaImageConverter { +namespace Magnum { namespace Trade { TgaImageConverter::TgaImageConverter() = default; @@ -68,25 +68,25 @@ Containers::Array TgaImageConverter::doExportToData(const Image2D /* Initialize data buffer */ const UnsignedByte pixelSize = image->pixelSize(); - auto data = Containers::Array::zeroInitialized(sizeof(TgaImporter::TgaHeader) + pixelSize*image->size().product()); + auto data = Containers::Array::zeroInitialized(sizeof(TgaHeader) + pixelSize*image->size().product()); /* Fill header */ - auto header = reinterpret_cast(data.begin()); + auto header = reinterpret_cast(data.begin()); header->imageType = image->format() == ImageFormat::Red ? 3 : 2; header->bpp = pixelSize*8; header->width = Utility::Endianness::littleEndian(image->size().x()); header->height = Utility::Endianness::littleEndian(image->size().y()); /* Fill data */ - std::copy(image->data(), image->data()+pixelSize*image->size().product(), data.begin()+sizeof(TgaImporter::TgaHeader)); + std::copy(image->data(), image->data()+pixelSize*image->size().product(), data.begin()+sizeof(TgaHeader)); #ifdef MAGNUM_TARGET_GLES if(image->format() == ImageFormat::RGB) { - auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaImporter::TgaHeader)); + auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaHeader)); std::transform(pixels, pixels + image->size().product(), pixels, [](Math::Vector3 pixel) { return swizzle<'b', 'g', 'r'>(pixel); }); } else if(image->format() == ImageFormat::RGBA) { - auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaImporter::TgaHeader)); + auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaHeader)); std::transform(pixels, pixels + image->size().product(), pixels, [](Math::Vector4 pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); }); } @@ -95,4 +95,4 @@ Containers::Array TgaImageConverter::doExportToData(const Image2D return std::move(data); } -}}} +}} diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.h b/src/Plugins/TgaImageConverter/TgaImageConverter.h index 8de3fc032..9da2320df 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.h +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Trade_TgaImageConverter_TgaImageConverter_h -#define Magnum_Trade_TgaImageConverter_TgaImageConverter_h +#ifndef Magnum_Trade_TgaImageConverter_h +#define Magnum_Trade_TgaImageConverter_h /* This file is part of Magnum. @@ -25,7 +25,7 @@ */ /** @file - * @brief Class Magnum::Trade::TgaImageConverter::TgaImageConverter + * @brief Class Magnum::Trade::TgaImageConverter */ #include @@ -37,7 +37,7 @@ #endif #define MAGNUM_TRADE_TGAIMAGECONVERTER_LOCAL CORRADE_VISIBILITY_LOCAL -namespace Magnum { namespace Trade { namespace TgaImageConverter { +namespace Magnum { namespace Trade { /** @brief TGA image converter @@ -59,6 +59,6 @@ class MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT TgaImageConverter: public AbstractIm Containers::Array MAGNUM_TRADE_TGAIMAGECONVERTER_LOCAL doExportToData(const Image2D* const image) const override; }; -}}} +}} #endif diff --git a/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp b/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp index c736aa768..eed43e072 100644 --- a/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp @@ -22,7 +22,7 @@ DEALINGS IN THE SOFTWARE. */ -#include "TgaImageConverter.h" +#include "TgaImageConverter/TgaImageConverter.h" -CORRADE_PLUGIN_REGISTER(TgaImageConverter, Magnum::Trade::TgaImageConverter::TgaImageConverter, +CORRADE_PLUGIN_REGISTER(TgaImageConverter, Magnum::Trade::TgaImageConverter, "cz.mosra.magnum.Trade.AbstractImageConverter/0.2") diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index 3c236ab42..bb39fca3c 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -33,7 +33,7 @@ #include "configure.h" -namespace Magnum { namespace Trade { namespace TgaImporter { namespace Test { +namespace Magnum { namespace Trade { namespace Test { class TgaImporterTest: public TestSuite::Tester { public: @@ -238,6 +238,6 @@ void TgaImporterTest::file() { std::string(reinterpret_cast(data) + 18, 2*3)); } -}}}} +}}} -CORRADE_TEST_MAIN(Magnum::Trade::TgaImporter::Test::TgaImporterTest) +CORRADE_TEST_MAIN(Magnum::Trade::Test::TgaImporterTest) diff --git a/src/Plugins/TgaImporter/TgaHeader.h b/src/Plugins/TgaImporter/TgaHeader.h index d8cde1f17..875b30bbd 100644 --- a/src/Plugins/TgaImporter/TgaHeader.h +++ b/src/Plugins/TgaImporter/TgaHeader.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Trade_TgaImporter_TgaHeader_h -#define Magnum_Trade_TgaImporter_TgaHeader_h +#ifndef Magnum_Trade_TgaHeader_h +#define Magnum_Trade_TgaHeader_h /* This file is part of Magnum. @@ -25,12 +25,12 @@ */ /** @file - * @brief Struct Magnum::Trade::TgaImporter::TgaHeader + * @brief Struct Magnum::Trade::TgaHeader */ #include -namespace Magnum { namespace Trade { namespace TgaImporter { +namespace Magnum { namespace Trade { #pragma pack(1) /** @brief TGA file header */ @@ -53,6 +53,6 @@ struct TgaHeader { static_assert(sizeof(TgaHeader) == 18, "TgaHeader size is not 18 bytes"); -}}} +}} #endif diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 719548d8b..ef9a563a4 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -38,7 +38,7 @@ #include "TgaHeader.h" -namespace Magnum { namespace Trade { namespace TgaImporter { +namespace Magnum { namespace Trade { TgaImporter::TgaImporter(): in(nullptr) {} @@ -150,4 +150,4 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { return new ImageData2D(dimensions, format, ImageType::UnsignedByte, buffer); } -}}} +}} diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index f787bf452..55238e3f9 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Trade_TgaImporter_TgaImporter_h -#define Magnum_Trade_TgaImporter_TgaImporter_h +#ifndef Magnum_Trade_TgaImporter_h +#define Magnum_Trade_TgaImporter_h /* This file is part of Magnum. @@ -25,7 +25,7 @@ */ /** @file - * @brief Class Magnum::Trade::TgaImporter::TgaImporter + * @brief Class Magnum::Trade::TgaImporter */ #include @@ -38,7 +38,7 @@ #endif #define MAGNUM_TGAIMPORTER_LOCAL CORRADE_VISIBILITY_LOCAL -namespace Magnum { namespace Trade { namespace TgaImporter { +namespace Magnum { namespace Trade { /** @brief TGA image importer @@ -67,6 +67,6 @@ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { std::istream* in; }; -}}} +}} #endif diff --git a/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp b/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp index 2f5a1ccab..25a34e435 100644 --- a/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp +++ b/src/Plugins/TgaImporter/pluginRegistrationTgaImporter.cpp @@ -24,5 +24,5 @@ #include "TgaImporter.h" -CORRADE_PLUGIN_REGISTER(TgaImporter, Magnum::Trade::TgaImporter::TgaImporter, +CORRADE_PLUGIN_REGISTER(TgaImporter, Magnum::Trade::TgaImporter, "cz.mosra.magnum.Trade.AbstractImporter/0.3") From cb9a66bd8a654c03bb98b0e62ac1cc8fb088a99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 2 Jul 2013 18:59:48 +0200 Subject: [PATCH 080/112] Properly prefix visibility macros. --- src/Plugins/TgaImporter/TgaImporter.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 55238e3f9..3f3b5d80f 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -32,11 +32,11 @@ #include #ifdef TgaImporter_EXPORTS - #define MAGNUM_TGAIMPORTER_EXPORT CORRADE_VISIBILITY_EXPORT + #define MAGNUM_TRADE_TGAIMPORTER_EXPORT CORRADE_VISIBILITY_EXPORT #else - #define MAGNUM_TGAIMPORTER_EXPORT CORRADE_VISIBILITY_IMPORT + #define MAGNUM_TRADE_TGAIMPORTER_EXPORT CORRADE_VISIBILITY_IMPORT #endif -#define MAGNUM_TGAIMPORTER_LOCAL CORRADE_VISIBILITY_LOCAL +#define MAGNUM_TRADE_TGAIMPORTER_LOCAL CORRADE_VISIBILITY_LOCAL namespace Magnum { namespace Trade { @@ -45,7 +45,7 @@ namespace Magnum { namespace Trade { Supports uncompressed BGR, BGRA or grayscale images with 8 bits per channel. */ -class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { +class MAGNUM_TRADE_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { public: /** @brief Default constructor */ explicit TgaImporter(); @@ -56,13 +56,13 @@ class MAGNUM_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { virtual ~TgaImporter(); private: - Features MAGNUM_TGAIMPORTER_LOCAL doFeatures() const override; - bool MAGNUM_TGAIMPORTER_LOCAL doIsOpened() const override; - void MAGNUM_TGAIMPORTER_LOCAL doOpenData(Containers::ArrayReference data) override; - void MAGNUM_TGAIMPORTER_LOCAL doOpenFile(const std::string& filename) override; - void MAGNUM_TGAIMPORTER_LOCAL doClose() override; - UnsignedInt MAGNUM_TGAIMPORTER_LOCAL doImage2DCount() const override; - ImageData2D MAGNUM_TGAIMPORTER_LOCAL * doImage2D(UnsignedInt id) override; + Features MAGNUM_TRADE_TGAIMPORTER_LOCAL doFeatures() const override; + bool MAGNUM_TRADE_TGAIMPORTER_LOCAL doIsOpened() const override; + void MAGNUM_TRADE_TGAIMPORTER_LOCAL doOpenData(Containers::ArrayReference data) override; + void MAGNUM_TRADE_TGAIMPORTER_LOCAL doOpenFile(const std::string& filename) override; + void MAGNUM_TRADE_TGAIMPORTER_LOCAL doClose() override; + UnsignedInt MAGNUM_TRADE_TGAIMPORTER_LOCAL doImage2DCount() const override; + ImageData2D MAGNUM_TRADE_TGAIMPORTER_LOCAL * doImage2D(UnsignedInt id) override; std::istream* in; }; From c53cb1b004cce92c9ec27ca954103337b476be1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 2 Jul 2013 19:00:43 +0200 Subject: [PATCH 081/112] Adapted to Magnum changes. Image constructor parameter reordering. --- .../TgaImageConverter/Test/TgaImageConverterTest.cpp | 8 ++++---- src/Plugins/TgaImporter/TgaImporter.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index a4d72ca39..31bc57129 100644 --- a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -49,9 +49,9 @@ class TgaImageConverterTest: public TestSuite::Tester { namespace { #ifndef MAGNUM_TARGET_GLES - const Image2D original({2, 3}, ImageFormat::BGR, ImageType::UnsignedByte, new char[18] + const Image2D original(ImageFormat::BGR, ImageType::UnsignedByte, {2, 3}, new char[18] #else - const Image2D original({2, 3}, ImageFormat::RGB, ImageType::UnsignedByte, new char[18] + const Image2D original(ImageFormat::RGB, ImageType::UnsignedByte, {2, 3}, new char[18] #endif { 1, 2, 3, 2, 3, 4, @@ -68,7 +68,7 @@ TgaImageConverterTest::TgaImageConverterTest() { } void TgaImageConverterTest::wrongFormat() { - Image2D image({}, ImageFormat::RG, ImageType::UnsignedByte, nullptr); + Image2D image(ImageFormat::RG, ImageType::UnsignedByte, {}, nullptr); std::ostringstream out; Error::setOutput(&out); @@ -79,7 +79,7 @@ void TgaImageConverterTest::wrongFormat() { } void TgaImageConverterTest::wrongType() { - Image2D image({}, ImageFormat::Red, ImageType::Float, nullptr); + Image2D image(ImageFormat::Red, ImageType::Float, {}, nullptr); std::ostringstream out; Error::setOutput(&out); diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index ef9a563a4..f7cf489af 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -129,11 +129,11 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { return nullptr; } - std::size_t size = header.width*header.height*header.bpp/8; - char* buffer = new char[size]; - in->read(buffer, size); + const std::size_t dataSize = header.width*header.height*header.bpp/8; + char* const data = new char[dataSize]; + in->read(data, dataSize); - Vector2i dimensions(header.width, header.height); + Vector2i size(header.width, header.height); #ifdef MAGNUM_TARGET_GLES if(format == ImageFormat::RGB) { @@ -147,7 +147,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { } #endif - return new ImageData2D(dimensions, format, ImageType::UnsignedByte, buffer); + return new ImageData2D(format, ImageType::UnsignedByte, size, data); } }} From 96166663f1555d054fa65035782ae23242860248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 3 Jul 2013 02:03:03 +0200 Subject: [PATCH 082/112] Doxygen fixes. --- src/Plugins/TgaImageConverter/TgaImageConverter.h | 2 ++ src/Plugins/TgaImporter/TgaImporter.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.h b/src/Plugins/TgaImageConverter/TgaImageConverter.h index 9da2320df..472bfaa4a 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.h +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.h @@ -30,12 +30,14 @@ #include +#ifndef DOXYGEN_GENERATING_OUTPUT #ifdef TgaImageConverter_EXPORTS #define MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT CORRADE_VISIBILITY_EXPORT #else #define MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT CORRADE_VISIBILITY_IMPORT #endif #define MAGNUM_TRADE_TGAIMAGECONVERTER_LOCAL CORRADE_VISIBILITY_LOCAL +#endif namespace Magnum { namespace Trade { diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 3f3b5d80f..2bc6e9cbf 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -31,12 +31,14 @@ #include #include +#ifndef DOXYGEN_GENERATING_OUTPUT #ifdef TgaImporter_EXPORTS #define MAGNUM_TRADE_TGAIMPORTER_EXPORT CORRADE_VISIBILITY_EXPORT #else #define MAGNUM_TRADE_TGAIMPORTER_EXPORT CORRADE_VISIBILITY_IMPORT #endif #define MAGNUM_TRADE_TGAIMPORTER_LOCAL CORRADE_VISIBILITY_LOCAL +#endif namespace Magnum { namespace Trade { From a5e7c1997322a451b172a0c4825e66976504a3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 3 Jul 2013 02:13:51 +0200 Subject: [PATCH 083/112] MagnumFont: simple bitmap font. The fonts is simply a file with character and glyph parameters along with glyph cache image. There is also MagnumFontConverter, which allows to create the font from any currently opened font. Added tests for both, they both need active GL context due to GlyphCache instance. MagnumFont doesn't have test for creating glyph cache yet. --- src/Plugins/MagnumFont/CMakeLists.txt | 53 +++++ src/Plugins/MagnumFont/MagnumFont.conf | 1 + src/Plugins/MagnumFont/MagnumFont.cpp | 222 ++++++++++++++++++ src/Plugins/MagnumFont/MagnumFont.h | 130 ++++++++++ src/Plugins/MagnumFont/Test/CMakeLists.txt | 30 +++ .../MagnumFont/Test/MagnumFontTest.cpp | 105 +++++++++ src/Plugins/MagnumFont/Test/font.conf | 29 +++ src/Plugins/MagnumFont/Test/font.tga | Bin 0 -> 18 bytes .../Test/magnumFontTestConfigure.h.cmake | 25 ++ .../pluginRegistrationMagnumFont.cpp | 28 +++ .../MagnumFontConverter/CMakeLists.txt | 52 ++++ .../MagnumFontConverter.conf | 1 + .../MagnumFontConverter.cpp | 106 +++++++++ .../MagnumFontConverter/MagnumFontConverter.h | 56 +++++ .../MagnumFontConverter/Test/CMakeLists.txt | 37 +++ .../Test/MagnumFontConverterTest.cpp | 99 ++++++++ .../magnumFontConverterTestConfigure.h.cmake | 25 ++ .../pluginRegistrationMagnumFontConverter.cpp | 28 +++ 18 files changed, 1027 insertions(+) create mode 100644 src/Plugins/MagnumFont/CMakeLists.txt create mode 100644 src/Plugins/MagnumFont/MagnumFont.conf create mode 100644 src/Plugins/MagnumFont/MagnumFont.cpp create mode 100644 src/Plugins/MagnumFont/MagnumFont.h create mode 100644 src/Plugins/MagnumFont/Test/CMakeLists.txt create mode 100644 src/Plugins/MagnumFont/Test/MagnumFontTest.cpp create mode 100644 src/Plugins/MagnumFont/Test/font.conf create mode 100644 src/Plugins/MagnumFont/Test/font.tga create mode 100644 src/Plugins/MagnumFont/Test/magnumFontTestConfigure.h.cmake create mode 100644 src/Plugins/MagnumFont/pluginRegistrationMagnumFont.cpp create mode 100644 src/Plugins/MagnumFontConverter/CMakeLists.txt create mode 100644 src/Plugins/MagnumFontConverter/MagnumFontConverter.conf create mode 100644 src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp create mode 100644 src/Plugins/MagnumFontConverter/MagnumFontConverter.h create mode 100644 src/Plugins/MagnumFontConverter/Test/CMakeLists.txt create mode 100644 src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp create mode 100644 src/Plugins/MagnumFontConverter/Test/magnumFontConverterTestConfigure.h.cmake create mode 100644 src/Plugins/MagnumFontConverter/pluginRegistrationMagnumFontConverter.cpp diff --git a/src/Plugins/MagnumFont/CMakeLists.txt b/src/Plugins/MagnumFont/CMakeLists.txt new file mode 100644 index 000000000..dc9025bc1 --- /dev/null +++ b/src/Plugins/MagnumFont/CMakeLists.txt @@ -0,0 +1,53 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +find_package(Magnum REQUIRED Text) + +set(MagnumFont_SOURCES + MagnumFont.cpp) + +set(MagnumFont_HEADERS + MagnumFont.h) + +add_library(MagnumFontObjects OBJECT ${MagnumFont_SOURCES}) +set_target_properties(MagnumFontObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) + +corrade_add_plugin(MagnumFont ${MAGNUM_PLUGINS_FONT_INSTALL_DIR} + MagnumFont.conf + $ + pluginRegistrationMagnumFont.cpp) +target_link_libraries(MagnumFont + ${MAGNUM_LIBRARIES} + ${MAGNUM_TEXT_LIBRARIES}) + +install(FILES ${MagnumFont_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/MagnumFont) + +if(BUILD_GL_TESTS) + add_library(MagnumFontTestLib $) + target_link_libraries(MagnumFontTestLib + ${MAGNUM_LIBRARIES} + ${MAGNUM_TEXT_LIBRARIES} + TgaImporterTestLib) + add_subdirectory(Test) +endif() diff --git a/src/Plugins/MagnumFont/MagnumFont.conf b/src/Plugins/MagnumFont/MagnumFont.conf new file mode 100644 index 000000000..6aae56c10 --- /dev/null +++ b/src/Plugins/MagnumFont/MagnumFont.conf @@ -0,0 +1 @@ +depends=TgaImporter diff --git a/src/Plugins/MagnumFont/MagnumFont.cpp b/src/Plugins/MagnumFont/MagnumFont.cpp new file mode 100644 index 000000000..b526a4fc3 --- /dev/null +++ b/src/Plugins/MagnumFont/MagnumFont.cpp @@ -0,0 +1,222 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "MagnumFont.h" + +#include +#include +#include +#include +#include +#include + +#include "TgaImporter/TgaImporter.h" + +namespace Magnum { namespace Text { + +struct MagnumFont::Data { + Utility::Configuration conf; + Trade::ImageData2D image; + std::unordered_map glyphId; + std::vector glyphAdvance; +}; + +namespace { + class MagnumFontLayouter: public AbstractLayouter { + public: + explicit MagnumFontLayouter(const std::unordered_map& glyphId, const std::vector& glyphAdvance, const GlyphCache* cache, Float fontSize, Float textSize, const std::string& text); + + std::tuple renderGlyph(UnsignedInt i) override; + + private: + const std::vector& glyphAdvance; + const GlyphCache* const cache; + const Float fontSize, textSize; + std::vector glyphs; + }; +} + +MagnumFont::MagnumFont(): _opened(nullptr) {} + +MagnumFont::MagnumFont(PluginManager::AbstractManager* const manager, std::string plugin): AbstractFont(manager, std::move(plugin)), _opened(nullptr) {} + +auto MagnumFont::doFeatures() const -> Features { return Feature::OpenData|Feature::MultiFile|Feature::PreparedGlyphCache; } + +bool MagnumFont::doIsOpened() const { return _opened; } + +void MagnumFont::doOpenData(const std::vector>>& data, const Float) { + /* We need just the configuration file and image file */ + if(data.size() != 2) { + Error() << "Magnum::Text::MagnumFont::openData(): wanted two files, got" << data.size(); + return; + } + + /* Open the configuration file */ + std::istringstream in({reinterpret_cast(data[0].second.begin()), data[0].second.size()}); + Utility::Configuration conf(in, Utility::Configuration::Flag::SkipComments); + if(!conf.isValid() || conf.isEmpty()) { + Error() << "Magnum::Text::MagnumFont::openData(): cannot open file" << data[0].first << conf.isValid(); + return; + } + + /* Check that we have also the image file */ + if(conf.value("image") != data[1].first) { + Error() << "Magnum::Text::MagnumFont::openData(): expected file" + << conf.value("image") << "but got" << data[1].first; + return; + } + + /* Open and load image file */ + Trade::TgaImporter importer; + if(!importer.openData(data[1].second)) { + Error() << "Magnum::Text::MagnumFont::openData(): cannot open image file"; + return; + } + Trade::ImageData2D* image = importer.image2D(0); + if(!image) { + Error() << "Magnum::Text::MagnumFont::openData(): cannot load image file"; + return; + } + + openInternal(std::move(conf), std::move(*image)); + delete image; +} + +void MagnumFont::doOpenFile(const std::string& filename, Float) { + /* Open the configuration file */ + Utility::Configuration conf(filename, Utility::Configuration::Flag::ReadOnly|Utility::Configuration::Flag::SkipComments); + if(!conf.isValid() || conf.isEmpty()) { + Error() << "Magnum::Text::MagnumFont::openFile(): cannot open file" << filename << conf.isValid(); + return; + } + + /* Open and load image file */ + const std::string imageFilename = Utility::Directory::join(Utility::Directory::path(filename), conf.value("image")); + Trade::TgaImporter importer; + if(!importer.openFile(imageFilename)) { + Error() << "Magnum::Text::MagnumFont::openFile(): cannot open image file" << imageFilename; + return; + } + Trade::ImageData2D* image = importer.image2D(0); + if(!image) { + Error() << "Magnum::Text::MagnumFont::openFile(): cannot load image file"; + return; + } + + openInternal(std::move(conf), std::move(*image)); + delete image; +} + +void MagnumFont::openInternal(Utility::Configuration&& conf, Trade::ImageData2D&& image) { + /* Everything okay, save the data internally */ + _opened = new Data{std::move(conf), std::move(image), {}, {}}; + _size = _opened->conf.value("fontSize"); + + /* Set glyph advance array to proper size */ + _opened->glyphAdvance.resize(_opened->conf.groupCount("glyph")); + + /* Fill character->glyph map */ + const std::vector chars = _opened->conf.groups("char"); + for(const Utility::ConfigurationGroup* const c: chars) { + const UnsignedInt glyphId = c->value("glyph"); + CORRADE_INTERNAL_ASSERT(glyphId < _opened->glyphAdvance.size()); + _opened->glyphId.emplace(c->value("unicode"), glyphId); + _opened->glyphAdvance[glyphId] = c->value("advance"); + } +} + +void MagnumFont::doClose() { + delete _opened; + _opened = nullptr; +} + +UnsignedInt MagnumFont::doGlyphId(const char32_t character) { + auto it = _opened->glyphId.find(character); + return it != _opened->glyphId.end() ? it->second : 0; +} + +Vector2 MagnumFont::doGlyphAdvance(const UnsignedInt glyph) { + return glyph < _opened->glyphAdvance.size() ? _opened->glyphAdvance[glyph] : Vector2(); +} + +GlyphCache* MagnumFont::doCreateGlyphCache() { + /* Set cache image */ + auto cache = new Text::DistanceFieldGlyphCache( + _opened->conf.value("originalImageSize"), + _opened->image.size(), + _opened->conf.value("padding").min()); + cache->setDistanceFieldImage({}, _opened->image); + + /* Fill glyph map */ + const std::vector glyphs = _opened->conf.groups("glyph"); + for(std::size_t i = 0; i != glyphs.size(); ++i) + cache->insert(i, glyphs[i]->value("position"), glyphs[i]->value("rectangle")); + + return cache; +} + +AbstractLayouter* MagnumFont::doLayout(const GlyphCache* cache, Float size, const std::string& text) { + return new MagnumFontLayouter(_opened->glyphId, _opened->glyphAdvance, cache, this->size(), size, text); +} + +namespace { + +MagnumFontLayouter::MagnumFontLayouter(const std::unordered_map& glyphId, const std::vector& glyphAdvance, const GlyphCache* cache, Float fontSize, Float textSize, const std::string& text): glyphAdvance(glyphAdvance), cache(cache), fontSize(fontSize), textSize(textSize) { + /* Get glyph codes from characters */ + glyphs.reserve(text.size()); + for(std::size_t i = 0; i != text.size(); ) { + UnsignedInt codepoint; + std::tie(codepoint, i) = Utility::Unicode::nextChar(text, i); + const auto it = glyphId.find(codepoint); + glyphs.push_back(it == glyphId.end() ? 0 : it->second); + } + _glyphCount = glyphs.size(); +} + +std::tuple MagnumFontLayouter::renderGlyph(UnsignedInt i) { + /* Position of the texture in the resulting glyph, texture coordinates */ + Vector2i position; + Rectanglei rectangle; + std::tie(position, rectangle) = (*cache)[glyphs[i]]; + + const Rectangle texturePosition = Rectangle::fromSize(Vector2(position)/fontSize, + Vector2(rectangle.size())/fontSize); + const Rectangle textureCoordinates(Vector2(rectangle.bottomLeft())/cache->textureSize(), + Vector2(rectangle.topRight())/cache->textureSize()); + + /* Absolute quad position, composed from cursor position, glyph offset + and texture position, denormalized to requested text size */ + Rectangle quadPosition = Rectangle::fromSize( + Vector2(texturePosition.left(), texturePosition.bottom())*textSize, + texturePosition.size()*textSize); + + /* Advance for given glyph, denormalized to requested text size */ + const Vector2 advance = glyphAdvance[glyphs[i]]*textSize/fontSize; + + return std::make_tuple(quadPosition, textureCoordinates, advance); +} + +} + +}} diff --git a/src/Plugins/MagnumFont/MagnumFont.h b/src/Plugins/MagnumFont/MagnumFont.h new file mode 100644 index 000000000..065b8f1e6 --- /dev/null +++ b/src/Plugins/MagnumFont/MagnumFont.h @@ -0,0 +1,130 @@ +#ifndef Magnum_Text_MagnumFont_h +#define Magnum_Text_MagnumFont_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Class Magnum::Text::MagnumFont + */ + +#include +#include + +namespace Magnum { namespace Text { + +/** +@brief Simple bitmap font + +The font consists of two files, one text file containing character and glyph +info and one TGA file containing the glyphs in distance field format. The font +can be conveniently created from any other format using MagnumFontConverter. +The file syntax is as in following: + + # Font image filename + image=font.tga + + # Size of unscaled font image + originalImageSize=1536 1536 + + # Glyph padding + padding=9 + + # Font size + fontSize=128 + + # Character + [char] + + # UTF-32 codepoint ('a') + unicode=0061 + + # Glyph ID + glyph=1 + + # Advance to next character in pixels (i.e. on unscaled font image) + advance=45 0 + + # Another character + [char] + unicode=0062 + glyph=2 + advance=42 0 + + # ... + + # Glyph 0, a.k.a. "Not Found" glyph + [glyph] + + # Glyph texture position relative to baseline, in pixels + position=5 -1 + + # Glyph rectangle in font image, in pixels (left, bottom, right, top) + rectangle=0 0 42 25 + + # Glyph 1 + [glyph] + position=0 0 + rectangle=45 0 44 25 + + # ... + +@see Trade::TgaImporter +*/ +class MagnumFont: public AbstractFont { + public: + /** @brief Default constructor */ + explicit MagnumFont(); + + /** @brief Plugin manager constructor */ + explicit MagnumFont(PluginManager::AbstractManager* manager, std::string plugin); + + private: + class Data; + + Features doFeatures() const override; + + bool doIsOpened() const override; + + void doOpenData(const std::vector>>& data, Float) override; + + void doOpenFile(const std::string& filename, Float) override; + + void doClose() override; + + UnsignedInt doGlyphId(char32_t character) override; + + Vector2 doGlyphAdvance(UnsignedInt glyph) override; + + GlyphCache* doCreateGlyphCache() override; + + AbstractLayouter* doLayout(const GlyphCache* cache, Float size, const std::string& text) override; + + Data* _opened; + + void openInternal(Utility::Configuration&& conf, Trade::ImageData2D&& image); +}; + +}} + +#endif diff --git a/src/Plugins/MagnumFont/Test/CMakeLists.txt b/src/Plugins/MagnumFont/Test/CMakeLists.txt new file mode 100644 index 000000000..0cc473499 --- /dev/null +++ b/src/Plugins/MagnumFont/Test/CMakeLists.txt @@ -0,0 +1,30 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/magnumFontTestConfigure.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/magnumFontTestConfigure.h) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +corrade_add_test(MagnumFontTest MagnumFontTest.cpp LIBRARIES MagnumFontTestLib ${GL_TEST_LIBRARIES}) diff --git a/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp b/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp new file mode 100644 index 000000000..638abc890 --- /dev/null +++ b/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp @@ -0,0 +1,105 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include + +#include "MagnumFont/MagnumFont.h" + +#include "magnumFontTestConfigure.h" + +namespace Magnum { namespace Text { namespace Test { + +class MagnumFontTest: public Magnum::Test::AbstractOpenGLTester { + public: + explicit MagnumFontTest(); + + void properties(); + void layout(); + void createGlyphCache(); +}; + +MagnumFontTest::MagnumFontTest() { + addTests({&MagnumFontTest::properties, + &MagnumFontTest::layout, + &MagnumFontTest::createGlyphCache}); +} + +void MagnumFontTest::properties() { + MagnumFont font; + CORRADE_VERIFY(font.openFile(Utility::Directory::join(MAGNUMFONT_TEST_DIR, "font.conf"), 0.0f)); + CORRADE_COMPARE(font.size(), 16.0f); + CORRADE_COMPARE(font.glyphAdvance(font.glyphId(U'W')), Vector2(23.0f, 0.0f)); +} + +void MagnumFontTest::layout() { + MagnumFont font; + CORRADE_VERIFY(font.openFile(Utility::Directory::join(MAGNUMFONT_TEST_DIR, "font.conf"), 0.0f)); + + /* Fill the cache with some fake glyphs */ + GlyphCache cache(Vector2i(256)); + cache.insert(font.glyphId(U'W'), {25, 34}, {{0, 8}, {16, 128}}); + cache.insert(font.glyphId(U'e'), {25, 12}, {{16, 4}, {64, 32}}); + + AbstractLayouter* layouter = font.layout(&cache, 0.5f, "Wave"); + CORRADE_VERIFY(layouter); + CORRADE_COMPARE(layouter->glyphCount(), 4); + + Rectangle position; + Rectangle textureCoordinates; + Vector2 advance; + + /* 'W' */ + std::tie(position, textureCoordinates, advance) = layouter->renderGlyph(0); + CORRADE_COMPARE(position, Rectangle({0.78125f, 1.0625f}, {1.28125f, 4.8125f})); + CORRADE_COMPARE(textureCoordinates, Rectangle({0, 0.03125f}, {0.0625f, 0.5f})); + CORRADE_COMPARE(advance, Vector2(0.71875f, 0.0f)); + + /* 'a' (not in cache) */ + std::tie(position, textureCoordinates, advance) = layouter->renderGlyph(1); + CORRADE_COMPARE(position, Rectangle()); + CORRADE_COMPARE(textureCoordinates, Rectangle()); + CORRADE_COMPARE(advance, Vector2(0.34375f, 0.0f)); + + /* 'v' (not in cache) */ + std::tie(position, textureCoordinates, advance) = layouter->renderGlyph(2); + CORRADE_COMPARE(position, Rectangle()); + CORRADE_COMPARE(textureCoordinates, Rectangle()); + CORRADE_COMPARE(advance, Vector2(0.34375f, 0.0f)); + + /* 'e' */ + std::tie(position, textureCoordinates, advance) = layouter->renderGlyph(3); + CORRADE_COMPARE(position, Rectangle({0.78125f, 0.375f}, {2.28125f, 1.25f})); + CORRADE_COMPARE(textureCoordinates, Rectangle({0.0625f, 0.015625f}, {0.25f, 0.125f})); + CORRADE_COMPARE(advance, Vector2(0.375f, 0.0f)); +} + +void MagnumFontTest::createGlyphCache() { + /** @todo */ +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Text::Test::MagnumFontTest) diff --git a/src/Plugins/MagnumFont/Test/font.conf b/src/Plugins/MagnumFont/Test/font.conf new file mode 100644 index 000000000..0a771d745 --- /dev/null +++ b/src/Plugins/MagnumFont/Test/font.conf @@ -0,0 +1,29 @@ +image=font.tga +originalImageSize=1536 1536 +padding=24 24 +fontSize=16 +[char] +unicode=57 +advance=23 0 +glyph=2 +[char] +unicode=61 +advance=11 0 +glyph=0 +[char] +unicode=65 +advance=12 0 +glyph=1 +[char] +unicode=76 +advance=11 0 +glyph=0 +[glyph] +position=0 0 +rectangle=0 0 0 0 +[glyph] +position=1 -12 +rectangle=-8 -20 88 56 +[glyph] +position=1 10 +rectangle=-24 -16 40 152 diff --git a/src/Plugins/MagnumFont/Test/font.tga b/src/Plugins/MagnumFont/Test/font.tga new file mode 100644 index 0000000000000000000000000000000000000000..8389c0da6bd4912d61d9a5896ee2441c3f22600d GIT binary patch literal 18 OcmZQzU}iuD91H*eQUDA9 literal 0 HcmV?d00001 diff --git a/src/Plugins/MagnumFont/Test/magnumFontTestConfigure.h.cmake b/src/Plugins/MagnumFont/Test/magnumFontTestConfigure.h.cmake new file mode 100644 index 000000000..250b209d4 --- /dev/null +++ b/src/Plugins/MagnumFont/Test/magnumFontTestConfigure.h.cmake @@ -0,0 +1,25 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#define MAGNUMFONT_TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}" diff --git a/src/Plugins/MagnumFont/pluginRegistrationMagnumFont.cpp b/src/Plugins/MagnumFont/pluginRegistrationMagnumFont.cpp new file mode 100644 index 000000000..3250c4f96 --- /dev/null +++ b/src/Plugins/MagnumFont/pluginRegistrationMagnumFont.cpp @@ -0,0 +1,28 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "MagnumFont/MagnumFont.h" + +CORRADE_PLUGIN_REGISTER(MagnumFont, Magnum::Text::MagnumFont, + "cz.mosra.magnum.Text.AbstractFont/0.2") diff --git a/src/Plugins/MagnumFontConverter/CMakeLists.txt b/src/Plugins/MagnumFontConverter/CMakeLists.txt new file mode 100644 index 000000000..9cc254f97 --- /dev/null +++ b/src/Plugins/MagnumFontConverter/CMakeLists.txt @@ -0,0 +1,52 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +find_package(Magnum REQUIRED Text) + +set(MagnumFontConverter_SOURCES + MagnumFontConverter.cpp) + +set(MagnumFontConverter_HEADERS + MagnumFontConverter.h) + +add_library(MagnumFontConverterObjects OBJECT ${MagnumFontConverter_SOURCES}) +set_target_properties(MagnumFontConverterObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) + +corrade_add_plugin(MagnumFontConverter ${MAGNUM_PLUGINS_FONTCONVERTER_INSTALL_DIR} + MagnumFontConverter.conf + $ + pluginRegistrationMagnumFontConverter.cpp) +target_link_libraries(MagnumFontConverter + ${MAGNUM_LIBRARIES} + ${MAGNUM_TEXT_LIBRARIES}) + +install(FILES ${MagnumFontConverter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/MagnumFontConverter) + +if(BUILD_TESTS) + add_library(MagnumFontConverterTestLib $) + target_link_libraries(MagnumFontConverterTestLib + ${MAGNUM_LIBRARIES} + ${MAGNUM_TEXT_LIBRARIES}) + add_subdirectory(Test) +endif() diff --git a/src/Plugins/MagnumFontConverter/MagnumFontConverter.conf b/src/Plugins/MagnumFontConverter/MagnumFontConverter.conf new file mode 100644 index 000000000..977dc2119 --- /dev/null +++ b/src/Plugins/MagnumFontConverter/MagnumFontConverter.conf @@ -0,0 +1 @@ +depends=TgaImageConverter diff --git a/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp b/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp new file mode 100644 index 000000000..ab2d155ad --- /dev/null +++ b/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp @@ -0,0 +1,106 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "MagnumFontConverter.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Magnum { namespace Text { + +MagnumFontConverter::MagnumFontConverter() = default; + +MagnumFontConverter::MagnumFontConverter(PluginManager::AbstractManager* manager, std::string plugin): AbstractFontConverter(manager, std::move(plugin)) {} + +auto MagnumFontConverter::doFeatures() const -> Features { + return Feature::ExportFont|Feature::ConvertData|Feature::MultiFile; +} + +std::vector>> MagnumFontConverter::doExportFontToData(AbstractFont* font, GlyphCache* cache, const std::string& filename, const std::u32string& characters) const { + Utility::Configuration configuration; + + configuration.setValue("image", Utility::Directory::filename(filename) + ".tga"); + configuration.setValue("originalImageSize", cache->textureSize()); + configuration.setValue("padding", cache->padding()); + configuration.setValue("fontSize", font->size()); + + /* Compress glyph IDs so the glyphs are in consecutive array, glyph 0 + should stay at position 0 */ + std::unordered_map glyphIdMap; + glyphIdMap.reserve(cache->glyphCount()); + glyphIdMap.emplace(0, 0); + for(const std::pair>& glyph: *cache) + glyphIdMap.emplace(glyph.first, glyphIdMap.size()); + + /** @todo Save only glyphs contained in @p characters */ + + /* Inverse map from new glyph IDs to old ones */ + std::vector inverseGlyphIdMap(glyphIdMap.size()); + for(const std::pair& map: glyphIdMap) + inverseGlyphIdMap[map.second] = map.first; + + /* Save character properties, map glyph IDs to new ones */ + for(const char32_t c: characters) { + Utility::ConfigurationGroup* group = configuration.addGroup("char"); + const UnsignedInt glyphId = font->glyphId(c); + group->setValue("unicode", c); + group->setValue("advance", font->glyphAdvance(glyphId)); + + /* Map old glyph ID to new, if not found, map to glyph 0 */ + auto found = glyphIdMap.find(glyphId); + group->setValue("glyph", found == glyphIdMap.end() ? 0 : glyphIdMap.at(glyphId)); + } + + /* Save glyph properties in order which preserves their IDs */ + for(UnsignedInt oldGlyphId: inverseGlyphIdMap) { + std::pair glyph = (*cache)[oldGlyphId]; + Utility::ConfigurationGroup* group = configuration.addGroup("glyph"); + group->setValue("position", glyph.first); + group->setValue("rectangle", glyph.second); + } + + std::ostringstream confOut; + configuration.save(confOut); + std::string confStr = confOut.str(); + Containers::Array confData{confStr.size()}; + std::copy(confStr.begin(), confStr.end(), confData.begin()); + + /* Save cache image */ + Image2D image(ImageFormat::Red, ImageType::UnsignedByte); + cache->texture()->image(0, image); + auto tgaData = Trade::TgaImageConverter().exportToData(&image); + + std::vector>> out; + out.emplace_back(filename + ".conf", std::move(confData)); + out.emplace_back(filename + ".tga", std::move(tgaData)); + return std::move(out); +} + +}} diff --git a/src/Plugins/MagnumFontConverter/MagnumFontConverter.h b/src/Plugins/MagnumFontConverter/MagnumFontConverter.h new file mode 100644 index 000000000..a0e773397 --- /dev/null +++ b/src/Plugins/MagnumFontConverter/MagnumFontConverter.h @@ -0,0 +1,56 @@ +#ifndef Magnum_Text_MagnumFontConverter_h +#define Magnum_Text_MagnumFontConverter_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Class Magnum::Text::MagnumFontConverter + */ + +#include + +namespace Magnum { namespace Text { + +/** +@brief Converter to MagnumFont + +Expects filename prefix, creates two files, `prefix.conf` and `prefix.tga`. See +MagnumFont for more information about the font. +*/ +class MagnumFontConverter: public Text::AbstractFontConverter { + public: + /** @brief Default constructor */ + explicit MagnumFontConverter(); + + /** @brief Plugin manager constructor */ + explicit MagnumFontConverter(PluginManager::AbstractManager* manager, std::string plugin); + + private: + Features doFeatures() const override; + std::vector>> doExportFontToData(AbstractFont* font, GlyphCache* cache, const std::string& filename, const std::u32string& characters) const override; +}; + +}} + +#endif diff --git a/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt b/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt new file mode 100644 index 000000000..7a41395ad --- /dev/null +++ b/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt @@ -0,0 +1,37 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/magnumFontConverterTestConfigure.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/magnumFontConverterTestConfigure.h) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../FreeTypeFont/Test/ + ${CMAKE_CURRENT_BINARY_DIR}/../../MagnumFont/Test/ + ${CMAKE_CURRENT_BINARY_DIR}) + +corrade_add_test(MagnumFontConverterTest MagnumFontConverterTest.cpp LIBRARIES + MagnumFontConverterTestLib + FreeTypeFontTestLib + TgaImageConverterTestLib + TgaImporterTestLib + ${GL_TEST_LIBRARIES}) diff --git a/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp b/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp new file mode 100644 index 000000000..a57311e09 --- /dev/null +++ b/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp @@ -0,0 +1,99 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "FreeTypeFont/FreeTypeFont.h" +#include "MagnumFontConverter/MagnumFontConverter.h" +#include "TgaImporter/TgaImporter.h" + +#include "freeTypeFontTestConfigure.h" +#include "magnumFontTestConfigure.h" +#include "magnumFontConverterTestConfigure.h" + +namespace Magnum { namespace Text { namespace Test { + +class MagnumFontConverterTest: public Magnum::Test::AbstractOpenGLTester { + public: + explicit MagnumFontConverterTest(); + + ~MagnumFontConverterTest(); + + void exportFont(); +}; + +MagnumFontConverterTest::MagnumFontConverterTest() { + addTests({&MagnumFontConverterTest::exportFont}); + + FreeTypeFont::initialize(); +} + +MagnumFontConverterTest::~MagnumFontConverterTest() { + FreeTypeFont::finalize(); +} + +void MagnumFontConverterTest::exportFont() { + /* Remove previously created files */ + Utility::Directory::rm(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.conf")); + Utility::Directory::rm(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.tga")); + + /* Open font */ + FreeTypeFont font; + CORRADE_VERIFY(font.openFile(Utility::Directory::join(FREETYPEFONT_TEST_DIR, "Oxygen.ttf"), 16.0f)); + + /* Create fake cache */ + MAGNUM_ASSERT_EXTENSION_SUPPORTED(Extensions::GL::ARB::texture_rg); + GlyphCache cache(TextureFormat::R8, Vector2i(1536), Vector2i(256), Vector2i(24)); + cache.insert(font.glyphId(U'W'), {25, 34}, {{0, 8}, {16, 128}}); + cache.insert(font.glyphId(U'e'), {25, 12}, {{16, 4}, {64, 32}}); + + /* Convert the file */ + MagnumFontConverter converter; + converter.exportFontToFile(&font, &cache, Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font"), "Wave"); + + /* Verify font parameters */ + /** @todo This might behave differently elsewhere due to unspecified order of glyphs in cache */ + CORRADE_COMPARE_AS(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.conf"), + Utility::Directory::join(MAGNUMFONT_TEST_DIR, "font.conf"), + TestSuite::Compare::File); + + /* Verify font image, no need to test image contents, as the image is garbage anyway */ + Trade::TgaImporter importer; + CORRADE_VERIFY(importer.openFile(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.tga"))); + Trade::ImageData2D* image = importer.image2D(0); + CORRADE_COMPARE(image->size(), Vector2i(256)); + CORRADE_COMPARE(image->format(), ImageFormat::Red); + CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Text::Test::MagnumFontConverterTest) diff --git a/src/Plugins/MagnumFontConverter/Test/magnumFontConverterTestConfigure.h.cmake b/src/Plugins/MagnumFontConverter/Test/magnumFontConverterTestConfigure.h.cmake new file mode 100644 index 000000000..befd1c45b --- /dev/null +++ b/src/Plugins/MagnumFontConverter/Test/magnumFontConverterTestConfigure.h.cmake @@ -0,0 +1,25 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#define MAGNUMFONTCONVERTER_TEST_WRITE_DIR "${CMAKE_CURRENT_BINARY_DIR}" diff --git a/src/Plugins/MagnumFontConverter/pluginRegistrationMagnumFontConverter.cpp b/src/Plugins/MagnumFontConverter/pluginRegistrationMagnumFontConverter.cpp new file mode 100644 index 000000000..a0bbc18ce --- /dev/null +++ b/src/Plugins/MagnumFontConverter/pluginRegistrationMagnumFontConverter.cpp @@ -0,0 +1,28 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "MagnumFontConverter/MagnumFontConverter.h" + +CORRADE_PLUGIN_REGISTER(MagnumFontConverter, Magnum::Text::MagnumFontConverter, + "cz.mosra.magnum.Text.AbstractFontConverter/0.1") From d3937556b5d23782b03aa4b0991561d9b1682b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 3 Jul 2013 21:31:19 +0200 Subject: [PATCH 084/112] Ability to build the plugins either as dynamic or static. --- src/Plugins/MagnumFont/CMakeLists.txt | 2 +- src/Plugins/MagnumFontConverter/CMakeLists.txt | 2 +- src/Plugins/TgaImageConverter/CMakeLists.txt | 2 +- src/Plugins/TgaImporter/CMakeLists.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugins/MagnumFont/CMakeLists.txt b/src/Plugins/MagnumFont/CMakeLists.txt index dc9025bc1..40509699e 100644 --- a/src/Plugins/MagnumFont/CMakeLists.txt +++ b/src/Plugins/MagnumFont/CMakeLists.txt @@ -33,7 +33,7 @@ set(MagnumFont_HEADERS add_library(MagnumFontObjects OBJECT ${MagnumFont_SOURCES}) set_target_properties(MagnumFontObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) -corrade_add_plugin(MagnumFont ${MAGNUM_PLUGINS_FONT_INSTALL_DIR} +add_plugin(MagnumFont ${MAGNUM_PLUGINS_FONT_INSTALL_DIR} MagnumFont.conf $ pluginRegistrationMagnumFont.cpp) diff --git a/src/Plugins/MagnumFontConverter/CMakeLists.txt b/src/Plugins/MagnumFontConverter/CMakeLists.txt index 9cc254f97..849b8f705 100644 --- a/src/Plugins/MagnumFontConverter/CMakeLists.txt +++ b/src/Plugins/MagnumFontConverter/CMakeLists.txt @@ -33,7 +33,7 @@ set(MagnumFontConverter_HEADERS add_library(MagnumFontConverterObjects OBJECT ${MagnumFontConverter_SOURCES}) set_target_properties(MagnumFontConverterObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) -corrade_add_plugin(MagnumFontConverter ${MAGNUM_PLUGINS_FONTCONVERTER_INSTALL_DIR} +add_plugin(MagnumFontConverter ${MAGNUM_PLUGINS_FONTCONVERTER_INSTALL_DIR} MagnumFontConverter.conf $ pluginRegistrationMagnumFontConverter.cpp) diff --git a/src/Plugins/TgaImageConverter/CMakeLists.txt b/src/Plugins/TgaImageConverter/CMakeLists.txt index 62dd12d87..81195bbba 100644 --- a/src/Plugins/TgaImageConverter/CMakeLists.txt +++ b/src/Plugins/TgaImageConverter/CMakeLists.txt @@ -31,7 +31,7 @@ set(TgaImageConverter_HEADERS add_library(TgaImageConverterObjects OBJECT ${TgaImageConverter_SRCS}) set_target_properties(TgaImageConverterObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) -corrade_add_plugin(TgaImageConverter ${MAGNUM_PLUGINS_IMAGECONVERTER_INSTALL_DIR} +add_plugin(TgaImageConverter ${MAGNUM_PLUGINS_IMAGECONVERTER_INSTALL_DIR} TgaImageConverter.conf $ pluginRegistrationTgaImageConverter.cpp) diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt index ad379ce7d..ce8654b2e 100644 --- a/src/Plugins/TgaImporter/CMakeLists.txt +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -32,7 +32,7 @@ set(TgaImporter_HEADERS add_library(TgaImporterObjects OBJECT ${TgaImporter_SRCS}) set_target_properties(TgaImporterObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) -corrade_add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} +add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf $ pluginRegistrationTgaImporter.cpp) From 0012ec37f7027e3e6613ec375c71a2c56cbfee7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 3 Jul 2013 21:32:03 +0200 Subject: [PATCH 085/112] OpenGL ES build fix. --- src/Plugins/TgaImporter/TgaImporter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index f7cf489af..b60fec706 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -137,12 +137,12 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { #ifdef MAGNUM_TARGET_GLES if(format == ImageFormat::RGB) { - auto data = reinterpret_cast*>(buffer); - std::transform(data, data + dimensions.product(), data, + auto pixels = reinterpret_cast*>(data); + std::transform(pixels, pixels + size.product(), pixels, [](Math::Vector3 pixel) { return swizzle<'b', 'g', 'r'>(pixel); }); } else if(format == ImageFormat::RGBA) { - auto data = reinterpret_cast*>(buffer); - std::transform(data, data + dimensions.product(), data, + auto pixels = reinterpret_cast*>(data); + std::transform(pixels, pixels + size.product(), pixels, [](Math::Vector4 pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); }); } #endif From 0eb828f67e5ebb621825b78d52991209fb00a822 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 18:26:12 +0200 Subject: [PATCH 086/112] TgaImporter: return Luminance if EXT_texture_rg is not supported in ES. Also documented the behavior. --- src/Plugins/TgaImporter/TgaImporter.cpp | 7 +++++++ src/Plugins/TgaImporter/TgaImporter.h | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index b60fec706..12aeac28f 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -33,6 +33,8 @@ #ifdef MAGNUM_TARGET_GLES #include +#include +#include #include #endif @@ -117,7 +119,12 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { /* Grayscale */ } else if(header.imageType == 3) { + #ifdef MAGNUM_TARGET_GLES + format = Context::current() && Context::current()->isExtensionSupported() ? + ImageFormat::Red : ImageFormat::Luminance; + #else format = ImageFormat::Red; + #endif if(header.bpp != 8) { Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp; return nullptr; diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 2bc6e9cbf..84bb20040 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -46,6 +46,16 @@ namespace Magnum { namespace Trade { @brief TGA image importer Supports uncompressed BGR, BGRA or grayscale images with 8 bits per channel. + +The images are imported with @ref ImageType "ImageType::UnsignedByte" and +@ref ImageFormat "ImageFormat::BGR", @ref ImageFormat "ImageFormat::BGRA" or +@ref ImageFormat "ImageFormat::Red" respectively. Grayscale images require +extension @extension{ARB,texture_rg}. + +In OpenGL ES BGR and BGRA images are converted to @ref ImageFormat "ImageFormat::RGB" +and @ref ImageFormat "ImageFormat::RGBA". In OpenGL ES 2.0, if @es_extension{EXT,texture_rg} +is not supported, grayscale images use @ref ImageFormat "ImageFormat::Luminance" +instead of @ref ImageFormat "ImageFormat::Red". */ class MAGNUM_TRADE_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { public: From 9ebfc456b93f162493a3b5699a35aed58cb9e6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 5 Jul 2013 18:27:20 +0200 Subject: [PATCH 087/112] MagnumFont: no need to use DistanceFieldGlyphCache. We are providing already done font with parameters that GlyphCache can handle. Moreover in ES DistanceFieldGlyphCache might expect RGB input images because Luminance is not renderable in most cases, thus it wouldn't work with Luminance TGA input. --- src/Plugins/MagnumFont/MagnumFont.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugins/MagnumFont/MagnumFont.cpp b/src/Plugins/MagnumFont/MagnumFont.cpp index b526a4fc3..1880f1332 100644 --- a/src/Plugins/MagnumFont/MagnumFont.cpp +++ b/src/Plugins/MagnumFont/MagnumFont.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include "TgaImporter/TgaImporter.h" @@ -162,11 +162,11 @@ Vector2 MagnumFont::doGlyphAdvance(const UnsignedInt glyph) { GlyphCache* MagnumFont::doCreateGlyphCache() { /* Set cache image */ - auto cache = new Text::DistanceFieldGlyphCache( + auto cache = new Text::GlyphCache( _opened->conf.value("originalImageSize"), _opened->image.size(), - _opened->conf.value("padding").min()); - cache->setDistanceFieldImage({}, _opened->image); + _opened->conf.value("padding")); + cache->setImage({}, _opened->image); /* Fill glyph map */ const std::vector glyphs = _opened->conf.groups("glyph"); From c22740543fc2aa8be7f885b85011ea3733a5d83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 6 Jul 2013 00:25:38 +0200 Subject: [PATCH 088/112] MagnumFontConverter: avoid double padding around the glyphs. The glyphs were exported with the padding and when they were inserted back into the cache later, the padding was added again. --- src/Plugins/MagnumFont/Test/font.conf | 12 ++++++------ .../MagnumFontConverter/MagnumFontConverter.cpp | 9 ++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Plugins/MagnumFont/Test/font.conf b/src/Plugins/MagnumFont/Test/font.conf index 0a771d745..1b5553a04 100644 --- a/src/Plugins/MagnumFont/Test/font.conf +++ b/src/Plugins/MagnumFont/Test/font.conf @@ -19,11 +19,11 @@ unicode=76 advance=11 0 glyph=0 [glyph] -position=0 0 -rectangle=0 0 0 0 +position=24 24 +rectangle=24 24 -24 -24 [glyph] -position=1 -12 -rectangle=-8 -20 88 56 +position=25 12 +rectangle=16 4 64 32 [glyph] -position=1 10 -rectangle=-24 -16 40 152 +position=25 34 +rectangle=0 8 16 128 diff --git a/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp b/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp index ab2d155ad..2c10c006e 100644 --- a/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp +++ b/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp @@ -78,12 +78,15 @@ std::vector>> MagnumFont group->setValue("glyph", found == glyphIdMap.end() ? 0 : glyphIdMap.at(glyphId)); } - /* Save glyph properties in order which preserves their IDs */ + /* Save glyph properties in order which preserves their IDs, remove padding + from the values so they aren't added twice when using the font later */ + /** @todo Some better way to handle this padding stuff */ for(UnsignedInt oldGlyphId: inverseGlyphIdMap) { std::pair glyph = (*cache)[oldGlyphId]; Utility::ConfigurationGroup* group = configuration.addGroup("glyph"); - group->setValue("position", glyph.first); - group->setValue("rectangle", glyph.second); + group->setValue("position", glyph.first+cache->padding()); + group->setValue("rectangle", Rectanglei(glyph.second.bottomLeft()+cache->padding(), + glyph.second.topRight()-cache->padding())); } std::ostringstream confOut; From 6807cd2b3941f92f2f60494ce60c807ac03da09d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Jul 2013 21:29:09 +0200 Subject: [PATCH 089/112] Adapted to Magnum changes. --- .../MagnumFontConverter.cpp | 2 +- .../Test/TgaImageConverterTest.cpp | 10 ++--- .../TgaImageConverter/TgaImageConverter.cpp | 38 +++++++++---------- .../TgaImageConverter/TgaImageConverter.h | 2 +- .../pluginRegistrationTgaImageConverter.cpp | 2 +- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp b/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp index 2c10c006e..99dfb0b96 100644 --- a/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp +++ b/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp @@ -98,7 +98,7 @@ std::vector>> MagnumFont /* Save cache image */ Image2D image(ImageFormat::Red, ImageType::UnsignedByte); cache->texture()->image(0, image); - auto tgaData = Trade::TgaImageConverter().exportToData(&image); + auto tgaData = Trade::TgaImageConverter().exportToData(image); std::vector>> out; out.emplace_back(filename + ".conf", std::move(confData)); diff --git a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index 31bc57129..16cb5562b 100644 --- a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -68,29 +68,29 @@ TgaImageConverterTest::TgaImageConverterTest() { } void TgaImageConverterTest::wrongFormat() { - Image2D image(ImageFormat::RG, ImageType::UnsignedByte, {}, nullptr); + ImageReference2D image(ImageFormat::RG, ImageType::UnsignedByte, {}, nullptr); std::ostringstream out; Error::setOutput(&out); - const auto data = TgaImageConverter().exportToData(&image); + const auto data = TgaImageConverter().exportToData(image); CORRADE_VERIFY(!data); CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format ImageFormat::RG\n"); } void TgaImageConverterTest::wrongType() { - Image2D image(ImageFormat::Red, ImageType::Float, {}, nullptr); + ImageReference2D image(ImageFormat::Red, ImageType::Float, {}, nullptr); std::ostringstream out; Error::setOutput(&out); - const auto data = TgaImageConverter().exportToData(&image); + const auto data = TgaImageConverter().exportToData(image); CORRADE_VERIFY(!data); CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type ImageType::Float\n"); } void TgaImageConverterTest::data() { - const auto data = TgaImageConverter().exportToData(&original); + const auto data = TgaImageConverter().exportToData(original); TgaImporter importer; CORRADE_VERIFY(importer.openData(data)); diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp index a779acc39..ed236a02f 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp @@ -46,48 +46,48 @@ TgaImageConverter::TgaImageConverter(PluginManager::AbstractManager* manager, st auto TgaImageConverter::doFeatures() const -> Features { return Feature::ConvertData; } -Containers::Array TgaImageConverter::doExportToData(const Image2D* const image) const { +Containers::Array TgaImageConverter::doExportToData(const ImageReference2D& image) const { #ifndef MAGNUM_TARGET_GLES - if(image->format() != ImageFormat::BGR && - image->format() != ImageFormat::BGRA && - image->format() != ImageFormat::Red) + if(image.format() != ImageFormat::BGR && + image.format() != ImageFormat::BGRA && + image.format() != ImageFormat::Red) #else - if(image->format() != ImageFormat::RGB && - image->format() != ImageFormat::RGBA && - image->format() != ImageFormat::Red) + if(image.format() != ImageFormat::RGB && + image.format() != ImageFormat::RGBA && + image.format() != ImageFormat::Red) #endif { - Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format" << image->format(); + Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format" << image.format(); return nullptr; } - if(image->type() != ImageType::UnsignedByte) { - Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type" << image->type(); + if(image.type() != ImageType::UnsignedByte) { + Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type" << image.type(); return nullptr; } /* Initialize data buffer */ - const UnsignedByte pixelSize = image->pixelSize(); - auto data = Containers::Array::zeroInitialized(sizeof(TgaHeader) + pixelSize*image->size().product()); + const UnsignedByte pixelSize = image.pixelSize(); + auto data = Containers::Array::zeroInitialized(sizeof(TgaHeader) + pixelSize*image.size().product()); /* Fill header */ auto header = reinterpret_cast(data.begin()); - header->imageType = image->format() == ImageFormat::Red ? 3 : 2; + header->imageType = image.format() == ImageFormat::Red ? 3 : 2; header->bpp = pixelSize*8; - header->width = Utility::Endianness::littleEndian(image->size().x()); - header->height = Utility::Endianness::littleEndian(image->size().y()); + header->width = Utility::Endianness::littleEndian(image.size().x()); + header->height = Utility::Endianness::littleEndian(image.size().y()); /* Fill data */ - std::copy(image->data(), image->data()+pixelSize*image->size().product(), data.begin()+sizeof(TgaHeader)); + std::copy(image.data(), image.data()+pixelSize*image.size().product(), data.begin()+sizeof(TgaHeader)); #ifdef MAGNUM_TARGET_GLES if(image->format() == ImageFormat::RGB) { auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaHeader)); - std::transform(pixels, pixels + image->size().product(), pixels, + std::transform(pixels, pixels + image.size().product(), pixels, [](Math::Vector3 pixel) { return swizzle<'b', 'g', 'r'>(pixel); }); - } else if(image->format() == ImageFormat::RGBA) { + } else if(image.format() == ImageFormat::RGBA) { auto pixels = reinterpret_cast*>(data.begin()+sizeof(TgaHeader)); - std::transform(pixels, pixels + image->size().product(), pixels, + std::transform(pixels, pixels + image.size().product(), pixels, [](Math::Vector4 pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); }); } #endif diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.h b/src/Plugins/TgaImageConverter/TgaImageConverter.h index 472bfaa4a..07c983b01 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.h +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.h @@ -58,7 +58,7 @@ class MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT TgaImageConverter: public AbstractIm private: Features MAGNUM_TRADE_TGAIMAGECONVERTER_LOCAL doFeatures() const override; - Containers::Array MAGNUM_TRADE_TGAIMAGECONVERTER_LOCAL doExportToData(const Image2D* const image) const override; + Containers::Array MAGNUM_TRADE_TGAIMAGECONVERTER_LOCAL doExportToData(const ImageReference2D& image) const override; }; }} diff --git a/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp b/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp index eed43e072..fe5767e82 100644 --- a/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/pluginRegistrationTgaImageConverter.cpp @@ -25,4 +25,4 @@ #include "TgaImageConverter/TgaImageConverter.h" CORRADE_PLUGIN_REGISTER(TgaImageConverter, Magnum::Trade::TgaImageConverter, - "cz.mosra.magnum.Trade.AbstractImageConverter/0.2") + "cz.mosra.magnum.Trade.AbstractImageConverter/0.2.1") From 4725aa6687308e41ed1ffd1e26fb097109bd1cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Jul 2013 21:30:12 +0200 Subject: [PATCH 090/112] MagnumFont: store glyph advance with glyphs, not characters. Allows to store glyph advance also for notfound glyph, which is exactly what we want for unknown characters. Also added version information to allow further extensions. --- src/Plugins/MagnumFont/MagnumFont.cpp | 22 ++++++++++++++++--- .../MagnumFont/Test/MagnumFontTest.cpp | 8 +++---- src/Plugins/MagnumFont/Test/font.conf | 8 +++---- .../MagnumFontConverter.cpp | 5 +++-- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/Plugins/MagnumFont/MagnumFont.cpp b/src/Plugins/MagnumFont/MagnumFont.cpp index 1880f1332..4c1448f57 100644 --- a/src/Plugins/MagnumFont/MagnumFont.cpp +++ b/src/Plugins/MagnumFont/MagnumFont.cpp @@ -80,6 +80,13 @@ void MagnumFont::doOpenData(const std::vector("version") != 1) { + Error() << "Magnum::Text::MagnumFont::openData(): unsupported file version, expected 1 but got" + << conf.value("version"); + return; + } + /* Check that we have also the image file */ if(conf.value("image") != data[1].first) { Error() << "Magnum::Text::MagnumFont::openData(): expected file" @@ -111,6 +118,13 @@ void MagnumFont::doOpenFile(const std::string& filename, Float) { return; } + /* Check version */ + if(conf.value("version") != 1) { + Error() << "Magnum::Text::MagnumFont::openFile(): unsupported file version, expected 1 but got" + << conf.value("version"); + return; + } + /* Open and load image file */ const std::string imageFilename = Utility::Directory::join(Utility::Directory::path(filename), conf.value("image")); Trade::TgaImporter importer; @@ -133,8 +147,11 @@ void MagnumFont::openInternal(Utility::Configuration&& conf, Trade::ImageData2D& _opened = new Data{std::move(conf), std::move(image), {}, {}}; _size = _opened->conf.value("fontSize"); - /* Set glyph advance array to proper size */ - _opened->glyphAdvance.resize(_opened->conf.groupCount("glyph")); + /* Glyph advances */ + const std::vector glyphs = _opened->conf.groups("glyph"); + _opened->glyphAdvance.reserve(glyphs.size()); + for(const Utility::ConfigurationGroup* const g: glyphs) + _opened->glyphAdvance.push_back(g->value("advance")); /* Fill character->glyph map */ const std::vector chars = _opened->conf.groups("char"); @@ -142,7 +159,6 @@ void MagnumFont::openInternal(Utility::Configuration&& conf, Trade::ImageData2D& const UnsignedInt glyphId = c->value("glyph"); CORRADE_INTERNAL_ASSERT(glyphId < _opened->glyphAdvance.size()); _opened->glyphId.emplace(c->value("unicode"), glyphId); - _opened->glyphAdvance[glyphId] = c->value("advance"); } } diff --git a/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp b/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp index 638abc890..d31dbd4b7 100644 --- a/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp +++ b/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp @@ -77,17 +77,17 @@ void MagnumFontTest::layout() { CORRADE_COMPARE(textureCoordinates, Rectangle({0, 0.03125f}, {0.0625f, 0.5f})); CORRADE_COMPARE(advance, Vector2(0.71875f, 0.0f)); - /* 'a' (not in cache) */ + /* 'a' (not found) */ std::tie(position, textureCoordinates, advance) = layouter->renderGlyph(1); CORRADE_COMPARE(position, Rectangle()); CORRADE_COMPARE(textureCoordinates, Rectangle()); - CORRADE_COMPARE(advance, Vector2(0.34375f, 0.0f)); + CORRADE_COMPARE(advance, Vector2(0.25f, 0.0f)); - /* 'v' (not in cache) */ + /* 'v' (not found) */ std::tie(position, textureCoordinates, advance) = layouter->renderGlyph(2); CORRADE_COMPARE(position, Rectangle()); CORRADE_COMPARE(textureCoordinates, Rectangle()); - CORRADE_COMPARE(advance, Vector2(0.34375f, 0.0f)); + CORRADE_COMPARE(advance, Vector2(0.25f, 0.0f)); /* 'e' */ std::tie(position, textureCoordinates, advance) = layouter->renderGlyph(3); diff --git a/src/Plugins/MagnumFont/Test/font.conf b/src/Plugins/MagnumFont/Test/font.conf index 1b5553a04..4c2a3baea 100644 --- a/src/Plugins/MagnumFont/Test/font.conf +++ b/src/Plugins/MagnumFont/Test/font.conf @@ -1,29 +1,29 @@ +version=1 image=font.tga originalImageSize=1536 1536 padding=24 24 fontSize=16 [char] unicode=57 -advance=23 0 glyph=2 [char] unicode=61 -advance=11 0 glyph=0 [char] unicode=65 -advance=12 0 glyph=1 [char] unicode=76 -advance=11 0 glyph=0 [glyph] +advance=8 0 position=24 24 rectangle=24 24 -24 -24 [glyph] +advance=12 0 position=25 12 rectangle=16 4 64 32 [glyph] +advance=23 0 position=25 34 rectangle=0 8 16 128 diff --git a/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp b/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp index 99dfb0b96..7b5282bd4 100644 --- a/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp +++ b/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp @@ -46,6 +46,7 @@ auto MagnumFontConverter::doFeatures() const -> Features { std::vector>> MagnumFontConverter::doExportFontToData(AbstractFont* font, GlyphCache* cache, const std::string& filename, const std::u32string& characters) const { Utility::Configuration configuration; + configuration.setValue("version", 1); configuration.setValue("image", Utility::Directory::filename(filename) + ".tga"); configuration.setValue("originalImageSize", cache->textureSize()); configuration.setValue("padding", cache->padding()); @@ -66,12 +67,11 @@ std::vector>> MagnumFont for(const std::pair& map: glyphIdMap) inverseGlyphIdMap[map.second] = map.first; - /* Save character properties, map glyph IDs to new ones */ + /* Character->glyph map, map glyph IDs to new ones */ for(const char32_t c: characters) { Utility::ConfigurationGroup* group = configuration.addGroup("char"); const UnsignedInt glyphId = font->glyphId(c); group->setValue("unicode", c); - group->setValue("advance", font->glyphAdvance(glyphId)); /* Map old glyph ID to new, if not found, map to glyph 0 */ auto found = glyphIdMap.find(glyphId); @@ -84,6 +84,7 @@ std::vector>> MagnumFont for(UnsignedInt oldGlyphId: inverseGlyphIdMap) { std::pair glyph = (*cache)[oldGlyphId]; Utility::ConfigurationGroup* group = configuration.addGroup("glyph"); + group->setValue("advance", font->glyphAdvance(oldGlyphId)); group->setValue("position", glyph.first+cache->padding()); group->setValue("rectangle", Rectanglei(glyph.second.bottomLeft()+cache->padding(), glyph.second.topRight()-cache->padding())); From b003e53f00818d12847050136f6a840cf4d51e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 23 Jul 2013 12:56:00 +0200 Subject: [PATCH 091/112] Wrap CMAKE_SHARED_LIBRARY_CXX_FLAGS in quotes. The variable is empty on some platforms (Windows), would cause issues. --- src/Plugins/MagnumFont/CMakeLists.txt | 2 +- src/Plugins/MagnumFontConverter/CMakeLists.txt | 2 +- src/Plugins/TgaImageConverter/CMakeLists.txt | 2 +- src/Plugins/TgaImporter/CMakeLists.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugins/MagnumFont/CMakeLists.txt b/src/Plugins/MagnumFont/CMakeLists.txt index 40509699e..82c4061e9 100644 --- a/src/Plugins/MagnumFont/CMakeLists.txt +++ b/src/Plugins/MagnumFont/CMakeLists.txt @@ -31,7 +31,7 @@ set(MagnumFont_HEADERS MagnumFont.h) add_library(MagnumFontObjects OBJECT ${MagnumFont_SOURCES}) -set_target_properties(MagnumFontObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) +set_target_properties(MagnumFontObjects PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") add_plugin(MagnumFont ${MAGNUM_PLUGINS_FONT_INSTALL_DIR} MagnumFont.conf diff --git a/src/Plugins/MagnumFontConverter/CMakeLists.txt b/src/Plugins/MagnumFontConverter/CMakeLists.txt index 849b8f705..9e023e56e 100644 --- a/src/Plugins/MagnumFontConverter/CMakeLists.txt +++ b/src/Plugins/MagnumFontConverter/CMakeLists.txt @@ -31,7 +31,7 @@ set(MagnumFontConverter_HEADERS MagnumFontConverter.h) add_library(MagnumFontConverterObjects OBJECT ${MagnumFontConverter_SOURCES}) -set_target_properties(MagnumFontConverterObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) +set_target_properties(MagnumFontConverterObjects PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") add_plugin(MagnumFontConverter ${MAGNUM_PLUGINS_FONTCONVERTER_INSTALL_DIR} MagnumFontConverter.conf diff --git a/src/Plugins/TgaImageConverter/CMakeLists.txt b/src/Plugins/TgaImageConverter/CMakeLists.txt index 81195bbba..67cee27c2 100644 --- a/src/Plugins/TgaImageConverter/CMakeLists.txt +++ b/src/Plugins/TgaImageConverter/CMakeLists.txt @@ -29,7 +29,7 @@ set(TgaImageConverter_HEADERS TgaImageConverter.h) add_library(TgaImageConverterObjects OBJECT ${TgaImageConverter_SRCS}) -set_target_properties(TgaImageConverterObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) +set_target_properties(TgaImageConverterObjects PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") add_plugin(TgaImageConverter ${MAGNUM_PLUGINS_IMAGECONVERTER_INSTALL_DIR} TgaImageConverter.conf diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt index ce8654b2e..cd4c034ea 100644 --- a/src/Plugins/TgaImporter/CMakeLists.txt +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -30,7 +30,7 @@ set(TgaImporter_HEADERS TgaImporter.h) add_library(TgaImporterObjects OBJECT ${TgaImporter_SRCS}) -set_target_properties(TgaImporterObjects PROPERTIES COMPILE_FLAGS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}) +set_target_properties(TgaImporterObjects PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf From 1e5f4d68def905a2347f1d4c6353f41bf818f631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 23 Jul 2013 13:49:16 +0200 Subject: [PATCH 092/112] Fixed visibility macros for plugins used as dependencies. The symbols weren't exported on mingw32, causing linker errors. --- src/Plugins/TgaImageConverter/CMakeLists.txt | 2 +- src/Plugins/TgaImageConverter/TgaImageConverter.h | 2 +- src/Plugins/TgaImporter/CMakeLists.txt | 2 +- src/Plugins/TgaImporter/TgaImporter.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugins/TgaImageConverter/CMakeLists.txt b/src/Plugins/TgaImageConverter/CMakeLists.txt index 67cee27c2..b28911348 100644 --- a/src/Plugins/TgaImageConverter/CMakeLists.txt +++ b/src/Plugins/TgaImageConverter/CMakeLists.txt @@ -29,7 +29,7 @@ set(TgaImageConverter_HEADERS TgaImageConverter.h) add_library(TgaImageConverterObjects OBJECT ${TgaImageConverter_SRCS}) -set_target_properties(TgaImageConverterObjects PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") +set_target_properties(TgaImageConverterObjects PROPERTIES COMPILE_FLAGS "-DTgaImageConverterObjects_EXPORTS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") add_plugin(TgaImageConverter ${MAGNUM_PLUGINS_IMAGECONVERTER_INSTALL_DIR} TgaImageConverter.conf diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.h b/src/Plugins/TgaImageConverter/TgaImageConverter.h index 07c983b01..e8ca3a3db 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.h +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.h @@ -31,7 +31,7 @@ #include #ifndef DOXYGEN_GENERATING_OUTPUT -#ifdef TgaImageConverter_EXPORTS +#if defined(TgaImageConverter_EXPORTS) || defined(TgaImageConverterObjects_EXPORTS) #define MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT CORRADE_VISIBILITY_EXPORT #else #define MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT CORRADE_VISIBILITY_IMPORT diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt index cd4c034ea..7bdcff1d8 100644 --- a/src/Plugins/TgaImporter/CMakeLists.txt +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -30,7 +30,7 @@ set(TgaImporter_HEADERS TgaImporter.h) add_library(TgaImporterObjects OBJECT ${TgaImporter_SRCS}) -set_target_properties(TgaImporterObjects PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") +set_target_properties(TgaImporterObjects PROPERTIES COMPILE_FLAGS "-DTgaImporterObjects_EXPORTS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") add_plugin(TgaImporter ${MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR} TgaImporter.conf diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 84bb20040..bf0c35894 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -32,7 +32,7 @@ #include #ifndef DOXYGEN_GENERATING_OUTPUT -#ifdef TgaImporter_EXPORTS +#if defined(TgaImporter_EXPORTS) || defined(TgaImporterObjects_EXPORTS) #define MAGNUM_TRADE_TGAIMPORTER_EXPORT CORRADE_VISIBILITY_EXPORT #else #define MAGNUM_TRADE_TGAIMPORTER_EXPORT CORRADE_VISIBILITY_IMPORT From d442cb964e216b61870ddac86af45e094c8c41a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 23 Jul 2013 13:52:07 +0200 Subject: [PATCH 093/112] Explicitly specify library types for *TestLib targets. Use static libraries for plugins which aren't used as dependencies (as they don't export any symbols anyway), use shared libraries for plugins used as dependencies (as they already export the symbols and static libraries cause linker errors on mingw32). --- src/Plugins/MagnumFont/CMakeLists.txt | 2 +- src/Plugins/MagnumFontConverter/CMakeLists.txt | 2 +- src/Plugins/TgaImageConverter/CMakeLists.txt | 2 +- src/Plugins/TgaImporter/CMakeLists.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugins/MagnumFont/CMakeLists.txt b/src/Plugins/MagnumFont/CMakeLists.txt index 82c4061e9..23c3d855b 100644 --- a/src/Plugins/MagnumFont/CMakeLists.txt +++ b/src/Plugins/MagnumFont/CMakeLists.txt @@ -44,7 +44,7 @@ target_link_libraries(MagnumFont install(FILES ${MagnumFont_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/MagnumFont) if(BUILD_GL_TESTS) - add_library(MagnumFontTestLib $) + add_library(MagnumFontTestLib STATIC $) target_link_libraries(MagnumFontTestLib ${MAGNUM_LIBRARIES} ${MAGNUM_TEXT_LIBRARIES} diff --git a/src/Plugins/MagnumFontConverter/CMakeLists.txt b/src/Plugins/MagnumFontConverter/CMakeLists.txt index 9e023e56e..12804b7e5 100644 --- a/src/Plugins/MagnumFontConverter/CMakeLists.txt +++ b/src/Plugins/MagnumFontConverter/CMakeLists.txt @@ -44,7 +44,7 @@ target_link_libraries(MagnumFontConverter install(FILES ${MagnumFontConverter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/MagnumFontConverter) if(BUILD_TESTS) - add_library(MagnumFontConverterTestLib $) + add_library(MagnumFontConverterTestLib STATIC $) target_link_libraries(MagnumFontConverterTestLib ${MAGNUM_LIBRARIES} ${MAGNUM_TEXT_LIBRARIES}) diff --git a/src/Plugins/TgaImageConverter/CMakeLists.txt b/src/Plugins/TgaImageConverter/CMakeLists.txt index b28911348..f72e90679 100644 --- a/src/Plugins/TgaImageConverter/CMakeLists.txt +++ b/src/Plugins/TgaImageConverter/CMakeLists.txt @@ -40,7 +40,7 @@ target_link_libraries(TgaImageConverter ${MAGNUM_LIBRARIES}) install(FILES ${TgaImageConverter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/TgaImageConverter) if(BUILD_TESTS) - add_library(TgaImageConverterTestLib $) + add_library(TgaImageConverterTestLib SHARED $) target_link_libraries(TgaImageConverterTestLib ${MAGNUM_LIBRARIES}) add_subdirectory(Test) endif() diff --git a/src/Plugins/TgaImporter/CMakeLists.txt b/src/Plugins/TgaImporter/CMakeLists.txt index 7bdcff1d8..90b63a1ea 100644 --- a/src/Plugins/TgaImporter/CMakeLists.txt +++ b/src/Plugins/TgaImporter/CMakeLists.txt @@ -41,7 +41,7 @@ target_link_libraries(TgaImporter ${MAGNUM_LIBRARIES}) install(FILES ${TgaImporter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/TgaImporter) if(BUILD_TESTS) - add_library(TgaImporterTestLib $) + add_library(TgaImporterTestLib SHARED $) target_link_libraries(TgaImporterTestLib ${MAGNUM_LIBRARIES}) add_subdirectory(Test) endif() From 533be4db3ddd35911a4597461ce5b2792b48f928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 23 Jul 2013 13:54:32 +0200 Subject: [PATCH 094/112] MagnumFontConverter: the test needs OpenGL. --- src/Plugins/MagnumFontConverter/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/MagnumFontConverter/CMakeLists.txt b/src/Plugins/MagnumFontConverter/CMakeLists.txt index 12804b7e5..696a5728c 100644 --- a/src/Plugins/MagnumFontConverter/CMakeLists.txt +++ b/src/Plugins/MagnumFontConverter/CMakeLists.txt @@ -43,7 +43,7 @@ target_link_libraries(MagnumFontConverter install(FILES ${MagnumFontConverter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/MagnumFontConverter) -if(BUILD_TESTS) +if(BUILD_GL_TESTS) add_library(MagnumFontConverterTestLib STATIC $) target_link_libraries(MagnumFontConverterTestLib ${MAGNUM_LIBRARIES} From 82ffeaae01ba809ab1dd13d4d4055a12a1763505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 23 Jul 2013 14:03:35 +0200 Subject: [PATCH 095/112] Link plugin dependencies to libraries, not test executables. The test executables shouldn't need it at all. --- src/Plugins/MagnumFontConverter/CMakeLists.txt | 3 ++- src/Plugins/MagnumFontConverter/Test/CMakeLists.txt | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugins/MagnumFontConverter/CMakeLists.txt b/src/Plugins/MagnumFontConverter/CMakeLists.txt index 696a5728c..9c8694b62 100644 --- a/src/Plugins/MagnumFontConverter/CMakeLists.txt +++ b/src/Plugins/MagnumFontConverter/CMakeLists.txt @@ -47,6 +47,7 @@ if(BUILD_GL_TESTS) add_library(MagnumFontConverterTestLib STATIC $) target_link_libraries(MagnumFontConverterTestLib ${MAGNUM_LIBRARIES} - ${MAGNUM_TEXT_LIBRARIES}) + ${MAGNUM_TEXT_LIBRARIES} + TgaImageConverterTestLib) add_subdirectory(Test) endif() diff --git a/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt b/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt index 7a41395ad..a6b28e93e 100644 --- a/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt +++ b/src/Plugins/MagnumFontConverter/Test/CMakeLists.txt @@ -32,6 +32,5 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/../../FreeTypeFont/Test/ corrade_add_test(MagnumFontConverterTest MagnumFontConverterTest.cpp LIBRARIES MagnumFontConverterTestLib FreeTypeFontTestLib - TgaImageConverterTestLib TgaImporterTestLib ${GL_TEST_LIBRARIES}) From f7f380064c237eab267d98a446d5f2613c02e3ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 23 Jul 2013 14:04:44 +0200 Subject: [PATCH 096/112] Link plugins to their dependencies on Windows. Fixes linker issues, not present anywhere else. --- src/Plugins/MagnumFont/CMakeLists.txt | 5 +++++ src/Plugins/MagnumFontConverter/CMakeLists.txt | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/Plugins/MagnumFont/CMakeLists.txt b/src/Plugins/MagnumFont/CMakeLists.txt index 23c3d855b..11d09f8e5 100644 --- a/src/Plugins/MagnumFont/CMakeLists.txt +++ b/src/Plugins/MagnumFont/CMakeLists.txt @@ -41,6 +41,10 @@ target_link_libraries(MagnumFont ${MAGNUM_LIBRARIES} ${MAGNUM_TEXT_LIBRARIES}) +if(WIN32) + target_link_libraries(MagnumFont TgaImporter) +endif() + install(FILES ${MagnumFont_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/MagnumFont) if(BUILD_GL_TESTS) @@ -49,5 +53,6 @@ if(BUILD_GL_TESTS) ${MAGNUM_LIBRARIES} ${MAGNUM_TEXT_LIBRARIES} TgaImporterTestLib) + add_subdirectory(Test) endif() diff --git a/src/Plugins/MagnumFontConverter/CMakeLists.txt b/src/Plugins/MagnumFontConverter/CMakeLists.txt index 9c8694b62..71efa0c47 100644 --- a/src/Plugins/MagnumFontConverter/CMakeLists.txt +++ b/src/Plugins/MagnumFontConverter/CMakeLists.txt @@ -41,6 +41,10 @@ target_link_libraries(MagnumFontConverter ${MAGNUM_LIBRARIES} ${MAGNUM_TEXT_LIBRARIES}) +if(WIN32) + target_link_libraries(MagnumFontConverter TgaImageConverter) +endif() + install(FILES ${MagnumFontConverter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/MagnumFontConverter) if(BUILD_GL_TESTS) From e55b4b80c69599e8baf1ecd81d4688452fae67dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 23 Jul 2013 14:24:28 +0200 Subject: [PATCH 097/112] Cleaned up and unified error and assertion messages. --- src/Plugins/MagnumFont/MagnumFont.cpp | 20 +++++++++---------- .../TgaImageConverter/TgaImageConverter.cpp | 4 ++-- src/Plugins/TgaImporter/TgaImporter.cpp | 12 +++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Plugins/MagnumFont/MagnumFont.cpp b/src/Plugins/MagnumFont/MagnumFont.cpp index 4c1448f57..82111786d 100644 --- a/src/Plugins/MagnumFont/MagnumFont.cpp +++ b/src/Plugins/MagnumFont/MagnumFont.cpp @@ -68,7 +68,7 @@ bool MagnumFont::doIsOpened() const { return _opened; } void MagnumFont::doOpenData(const std::vector>>& data, const Float) { /* We need just the configuration file and image file */ if(data.size() != 2) { - Error() << "Magnum::Text::MagnumFont::openData(): wanted two files, got" << data.size(); + Error() << "Text::MagnumFont::openData(): wanted two files, got" << data.size(); return; } @@ -76,20 +76,20 @@ void MagnumFont::doOpenData(const std::vector(data[0].second.begin()), data[0].second.size()}); Utility::Configuration conf(in, Utility::Configuration::Flag::SkipComments); if(!conf.isValid() || conf.isEmpty()) { - Error() << "Magnum::Text::MagnumFont::openData(): cannot open file" << data[0].first << conf.isValid(); + Error() << "Text::MagnumFont::openData(): cannot open file" << data[0].first << conf.isValid(); return; } /* Check version */ if(conf.value("version") != 1) { - Error() << "Magnum::Text::MagnumFont::openData(): unsupported file version, expected 1 but got" + Error() << "Text::MagnumFont::openData(): unsupported file version, expected 1 but got" << conf.value("version"); return; } /* Check that we have also the image file */ if(conf.value("image") != data[1].first) { - Error() << "Magnum::Text::MagnumFont::openData(): expected file" + Error() << "Text::MagnumFont::openData(): expected file" << conf.value("image") << "but got" << data[1].first; return; } @@ -97,12 +97,12 @@ void MagnumFont::doOpenData(const std::vector("version") != 1) { - Error() << "Magnum::Text::MagnumFont::openFile(): unsupported file version, expected 1 but got" + Error() << "Text::MagnumFont::openFile(): unsupported file version, expected 1 but got" << conf.value("version"); return; } @@ -129,12 +129,12 @@ void MagnumFont::doOpenFile(const std::string& filename, Float) { const std::string imageFilename = Utility::Directory::join(Utility::Directory::path(filename), conf.value("image")); Trade::TgaImporter importer; if(!importer.openFile(imageFilename)) { - Error() << "Magnum::Text::MagnumFont::openFile(): cannot open image file" << imageFilename; + Error() << "Text::MagnumFont::openFile(): cannot open image file" << imageFilename; return; } Trade::ImageData2D* image = importer.image2D(0); if(!image) { - Error() << "Magnum::Text::MagnumFont::openFile(): cannot load image file"; + Error() << "Text::MagnumFont::openFile(): cannot load image file"; return; } diff --git a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp index ed236a02f..1e259fdc0 100644 --- a/src/Plugins/TgaImageConverter/TgaImageConverter.cpp +++ b/src/Plugins/TgaImageConverter/TgaImageConverter.cpp @@ -57,12 +57,12 @@ Containers::Array TgaImageConverter::doExportToData(const ImageRe image.format() != ImageFormat::Red) #endif { - Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format" << image.format(); + Error() << "Trade::TgaImageConverter::convertToData(): unsupported image format" << image.format(); return nullptr; } if(image.type() != ImageType::UnsignedByte) { - Error() << "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type" << image.type(); + Error() << "Trade::TgaImageConverter::convertToData(): unsupported image type" << image.type(); return nullptr; } diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 12aeac28f..4838767ea 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -60,7 +60,7 @@ void TgaImporter::doOpenFile(const std::string& filename) { in = new std::ifstream(filename.c_str()); if(in->good()) return; - Error() << "Trade::TgaImporter::TgaImporter::openFile(): cannot open file" << filename; + Error() << "Trade::TgaImporter::openFile(): cannot open file" << filename; close(); } @@ -77,7 +77,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { std::streampos filesize = in->tellg(); in->seekg(0, std::istream::beg); if(filesize < std::streampos(sizeof(TgaHeader))) { - Error() << "Trade::TgaImporter::TgaImporter::image2D(): the file is too short:" << filesize << "bytes"; + Error() << "Trade::TgaImporter::image2D(): the file is too short:" << filesize << "bytes"; return nullptr; } @@ -91,7 +91,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { /* Image format */ ImageFormat format; if(header.colorMapType != 0) { - Error() << "Trade::TgaImporter::TgaImporter::image2D(): paletted files are not supported"; + Error() << "Trade::TgaImporter::image2D(): paletted files are not supported"; return nullptr; } @@ -113,7 +113,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { #endif break; default: - Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported color bits-per-pixel:" << header.bpp; + Error() << "Trade::TgaImporter::image2D(): unsupported color bits-per-pixel:" << header.bpp; return nullptr; } @@ -126,13 +126,13 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { format = ImageFormat::Red; #endif if(header.bpp != 8) { - Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp; + Error() << "Trade::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp; return nullptr; } /* Compressed files */ } else { - Error() << "Trade::TgaImporter::TgaImporter::image2D(): unsupported (compressed?) image type:" << header.imageType; + Error() << "Trade::TgaImporter::image2D(): unsupported (compressed?) image type:" << header.imageType; return nullptr; } From e60306d3d77137bb57684818ae70a91d19cba4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 23 Jul 2013 14:27:03 +0200 Subject: [PATCH 098/112] MagnumFont: don't forget to close on destruction. --- src/Plugins/MagnumFont/MagnumFont.cpp | 2 ++ src/Plugins/MagnumFont/MagnumFont.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Plugins/MagnumFont/MagnumFont.cpp b/src/Plugins/MagnumFont/MagnumFont.cpp index 82111786d..79a6c5193 100644 --- a/src/Plugins/MagnumFont/MagnumFont.cpp +++ b/src/Plugins/MagnumFont/MagnumFont.cpp @@ -61,6 +61,8 @@ MagnumFont::MagnumFont(): _opened(nullptr) {} MagnumFont::MagnumFont(PluginManager::AbstractManager* const manager, std::string plugin): AbstractFont(manager, std::move(plugin)), _opened(nullptr) {} +MagnumFont::~MagnumFont() { close(); } + auto MagnumFont::doFeatures() const -> Features { return Feature::OpenData|Feature::MultiFile|Feature::PreparedGlyphCache; } bool MagnumFont::doIsOpened() const { return _opened; } diff --git a/src/Plugins/MagnumFont/MagnumFont.h b/src/Plugins/MagnumFont/MagnumFont.h index 065b8f1e6..1e772e778 100644 --- a/src/Plugins/MagnumFont/MagnumFont.h +++ b/src/Plugins/MagnumFont/MagnumFont.h @@ -99,6 +99,8 @@ class MagnumFont: public AbstractFont { /** @brief Plugin manager constructor */ explicit MagnumFont(PluginManager::AbstractManager* manager, std::string plugin); + ~MagnumFont(); + private: class Data; From c5685d5f304bf7f0bd03685ceedff751be5243f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 23 Jul 2013 14:27:33 +0200 Subject: [PATCH 099/112] No need to make destructors as virtual. The parent ones are marked already. --- src/Plugins/TgaImporter/TgaImporter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index bf0c35894..0f3c8a67d 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -65,7 +65,7 @@ class MAGNUM_TRADE_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { /** @brief Plugin manager constructor */ explicit TgaImporter(PluginManager::AbstractManager* manager, std::string plugin); - virtual ~TgaImporter(); + ~TgaImporter(); private: Features MAGNUM_TRADE_TGAIMPORTER_LOCAL doFeatures() const override; From 2835f6cc130f9692627e5f29936c44ce81218772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 23 Jul 2013 19:45:17 +0200 Subject: [PATCH 100/112] Properly update tests after message cleanup. Followup to 03e81361c979c2f92ed646c2bef1cd615bfe9ba9. I should test before pushing. --- .../TgaImageConverter/Test/TgaImageConverterTest.cpp | 4 ++-- src/Plugins/TgaImporter/Test/TgaImporterTest.cpp | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index 16cb5562b..e8ee0b5fb 100644 --- a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -75,7 +75,7 @@ void TgaImageConverterTest::wrongFormat() { const auto data = TgaImageConverter().exportToData(image); CORRADE_VERIFY(!data); - CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image format ImageFormat::RG\n"); + CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::convertToData(): unsupported image format ImageFormat::RG\n"); } void TgaImageConverterTest::wrongType() { @@ -86,7 +86,7 @@ void TgaImageConverterTest::wrongType() { const auto data = TgaImageConverter().exportToData(image); CORRADE_VERIFY(!data); - CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::TgaImageConverter::convertToData(): unsupported image type ImageType::Float\n"); + CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::convertToData(): unsupported image type ImageType::Float\n"); } void TgaImageConverterTest::data() { diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index bb39fca3c..fb9738344 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -76,7 +76,7 @@ void TgaImporterTest::openInexistent() { TgaImporter importer; CORRADE_VERIFY(!importer.openFile("inexistent.file")); - CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::openFile(): cannot open file inexistent.file\n"); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::openFile(): cannot open file inexistent.file\n"); } void TgaImporterTest::openShort() { @@ -87,7 +87,7 @@ void TgaImporterTest::openShort() { std::ostringstream debug; Error::setOutput(&debug); CORRADE_VERIFY(!importer.image2D(0)); - CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): the file is too short: 17 bytes\n"); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::image2D(): the file is too short: 17 bytes\n"); } void TgaImporterTest::paletted() { @@ -98,7 +98,7 @@ void TgaImporterTest::paletted() { std::ostringstream debug; Error::setOutput(&debug); CORRADE_VERIFY(!importer.image2D(0)); - CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): paletted files are not supported\n"); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::image2D(): paletted files are not supported\n"); } void TgaImporterTest::compressed() { @@ -109,7 +109,7 @@ void TgaImporterTest::compressed() { std::ostringstream debug; Error::setOutput(&debug); CORRADE_VERIFY(!importer.image2D(0)); - CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): unsupported (compressed?) image type: 9\n"); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::image2D(): unsupported (compressed?) image type: 9\n"); } void TgaImporterTest::colorBits16() { @@ -120,7 +120,7 @@ void TgaImporterTest::colorBits16() { std::ostringstream debug; Error::setOutput(&debug); CORRADE_VERIFY(!importer.image2D(0)); - CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): unsupported color bits-per-pixel: 16\n"); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::image2D(): unsupported color bits-per-pixel: 16\n"); } void TgaImporterTest::colorBits24() { @@ -216,7 +216,7 @@ void TgaImporterTest::grayscaleBits16() { std::ostringstream debug; Error::setOutput(&debug); CORRADE_VERIFY(!importer.image2D(0)); - CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::TgaImporter::image2D(): unsupported grayscale bits-per-pixel: 16\n"); + CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::image2D(): unsupported grayscale bits-per-pixel: 16\n"); } void TgaImporterTest::file() { From 5b0d0fe943b8fb8b97b72ed4997111bce0b46319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 1 Aug 2013 18:54:15 +0200 Subject: [PATCH 101/112] Adapted to "pointer chasing" Magnum changes. --- src/Plugins/MagnumFont/MagnumFont.cpp | 14 +++++----- src/Plugins/MagnumFont/MagnumFont.h | 2 +- .../MagnumFont/Test/MagnumFontTest.cpp | 2 +- .../MagnumFontConverter.cpp | 26 +++++++++---------- .../MagnumFontConverter/MagnumFontConverter.h | 2 +- .../Test/MagnumFontConverterTest.cpp | 2 +- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Plugins/MagnumFont/MagnumFont.cpp b/src/Plugins/MagnumFont/MagnumFont.cpp index 79a6c5193..8481144e5 100644 --- a/src/Plugins/MagnumFont/MagnumFont.cpp +++ b/src/Plugins/MagnumFont/MagnumFont.cpp @@ -45,13 +45,13 @@ struct MagnumFont::Data { namespace { class MagnumFontLayouter: public AbstractLayouter { public: - explicit MagnumFontLayouter(const std::unordered_map& glyphId, const std::vector& glyphAdvance, const GlyphCache* cache, Float fontSize, Float textSize, const std::string& text); + explicit MagnumFontLayouter(const std::unordered_map& glyphId, const std::vector& glyphAdvance, const GlyphCache& cache, Float fontSize, Float textSize, const std::string& text); std::tuple renderGlyph(UnsignedInt i) override; private: const std::vector& glyphAdvance; - const GlyphCache* const cache; + const GlyphCache& cache; const Float fontSize, textSize; std::vector glyphs; }; @@ -194,13 +194,13 @@ GlyphCache* MagnumFont::doCreateGlyphCache() { return cache; } -AbstractLayouter* MagnumFont::doLayout(const GlyphCache* cache, Float size, const std::string& text) { +AbstractLayouter* MagnumFont::doLayout(const GlyphCache& cache, Float size, const std::string& text) { return new MagnumFontLayouter(_opened->glyphId, _opened->glyphAdvance, cache, this->size(), size, text); } namespace { -MagnumFontLayouter::MagnumFontLayouter(const std::unordered_map& glyphId, const std::vector& glyphAdvance, const GlyphCache* cache, Float fontSize, Float textSize, const std::string& text): glyphAdvance(glyphAdvance), cache(cache), fontSize(fontSize), textSize(textSize) { +MagnumFontLayouter::MagnumFontLayouter(const std::unordered_map& glyphId, const std::vector& glyphAdvance, const GlyphCache& cache, Float fontSize, Float textSize, const std::string& text): glyphAdvance(glyphAdvance), cache(cache), fontSize(fontSize), textSize(textSize) { /* Get glyph codes from characters */ glyphs.reserve(text.size()); for(std::size_t i = 0; i != text.size(); ) { @@ -216,12 +216,12 @@ std::tuple MagnumFontLayouter::renderGlyph(Unsign /* Position of the texture in the resulting glyph, texture coordinates */ Vector2i position; Rectanglei rectangle; - std::tie(position, rectangle) = (*cache)[glyphs[i]]; + std::tie(position, rectangle) = cache[glyphs[i]]; const Rectangle texturePosition = Rectangle::fromSize(Vector2(position)/fontSize, Vector2(rectangle.size())/fontSize); - const Rectangle textureCoordinates(Vector2(rectangle.bottomLeft())/cache->textureSize(), - Vector2(rectangle.topRight())/cache->textureSize()); + const Rectangle textureCoordinates(Vector2(rectangle.bottomLeft())/cache.textureSize(), + Vector2(rectangle.topRight())/cache.textureSize()); /* Absolute quad position, composed from cursor position, glyph offset and texture position, denormalized to requested text size */ diff --git a/src/Plugins/MagnumFont/MagnumFont.h b/src/Plugins/MagnumFont/MagnumFont.h index 1e772e778..760eef1f7 100644 --- a/src/Plugins/MagnumFont/MagnumFont.h +++ b/src/Plugins/MagnumFont/MagnumFont.h @@ -120,7 +120,7 @@ class MagnumFont: public AbstractFont { GlyphCache* doCreateGlyphCache() override; - AbstractLayouter* doLayout(const GlyphCache* cache, Float size, const std::string& text) override; + AbstractLayouter* doLayout(const GlyphCache& cache, Float size, const std::string& text) override; Data* _opened; diff --git a/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp b/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp index d31dbd4b7..35b130f8e 100644 --- a/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp +++ b/src/Plugins/MagnumFont/Test/MagnumFontTest.cpp @@ -63,7 +63,7 @@ void MagnumFontTest::layout() { cache.insert(font.glyphId(U'W'), {25, 34}, {{0, 8}, {16, 128}}); cache.insert(font.glyphId(U'e'), {25, 12}, {{16, 4}, {64, 32}}); - AbstractLayouter* layouter = font.layout(&cache, 0.5f, "Wave"); + AbstractLayouter* layouter = font.layout(cache, 0.5f, "Wave"); CORRADE_VERIFY(layouter); CORRADE_COMPARE(layouter->glyphCount(), 4); diff --git a/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp b/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp index 7b5282bd4..364f4745d 100644 --- a/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp +++ b/src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp @@ -43,21 +43,21 @@ auto MagnumFontConverter::doFeatures() const -> Features { return Feature::ExportFont|Feature::ConvertData|Feature::MultiFile; } -std::vector>> MagnumFontConverter::doExportFontToData(AbstractFont* font, GlyphCache* cache, const std::string& filename, const std::u32string& characters) const { +std::vector>> MagnumFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const { Utility::Configuration configuration; configuration.setValue("version", 1); configuration.setValue("image", Utility::Directory::filename(filename) + ".tga"); - configuration.setValue("originalImageSize", cache->textureSize()); - configuration.setValue("padding", cache->padding()); - configuration.setValue("fontSize", font->size()); + configuration.setValue("originalImageSize", cache.textureSize()); + configuration.setValue("padding", cache.padding()); + configuration.setValue("fontSize", font.size()); /* Compress glyph IDs so the glyphs are in consecutive array, glyph 0 should stay at position 0 */ std::unordered_map glyphIdMap; - glyphIdMap.reserve(cache->glyphCount()); + glyphIdMap.reserve(cache.glyphCount()); glyphIdMap.emplace(0, 0); - for(const std::pair>& glyph: *cache) + for(const std::pair>& glyph: cache) glyphIdMap.emplace(glyph.first, glyphIdMap.size()); /** @todo Save only glyphs contained in @p characters */ @@ -70,7 +70,7 @@ std::vector>> MagnumFont /* Character->glyph map, map glyph IDs to new ones */ for(const char32_t c: characters) { Utility::ConfigurationGroup* group = configuration.addGroup("char"); - const UnsignedInt glyphId = font->glyphId(c); + const UnsignedInt glyphId = font.glyphId(c); group->setValue("unicode", c); /* Map old glyph ID to new, if not found, map to glyph 0 */ @@ -82,12 +82,12 @@ std::vector>> MagnumFont from the values so they aren't added twice when using the font later */ /** @todo Some better way to handle this padding stuff */ for(UnsignedInt oldGlyphId: inverseGlyphIdMap) { - std::pair glyph = (*cache)[oldGlyphId]; + std::pair glyph = cache[oldGlyphId]; Utility::ConfigurationGroup* group = configuration.addGroup("glyph"); - group->setValue("advance", font->glyphAdvance(oldGlyphId)); - group->setValue("position", glyph.first+cache->padding()); - group->setValue("rectangle", Rectanglei(glyph.second.bottomLeft()+cache->padding(), - glyph.second.topRight()-cache->padding())); + group->setValue("advance", font.glyphAdvance(oldGlyphId)); + group->setValue("position", glyph.first+cache.padding()); + group->setValue("rectangle", Rectanglei(glyph.second.bottomLeft()+cache.padding(), + glyph.second.topRight()-cache.padding())); } std::ostringstream confOut; @@ -98,7 +98,7 @@ std::vector>> MagnumFont /* Save cache image */ Image2D image(ImageFormat::Red, ImageType::UnsignedByte); - cache->texture()->image(0, image); + cache.texture().image(0, image); auto tgaData = Trade::TgaImageConverter().exportToData(image); std::vector>> out; diff --git a/src/Plugins/MagnumFontConverter/MagnumFontConverter.h b/src/Plugins/MagnumFontConverter/MagnumFontConverter.h index a0e773397..7b1be2ad2 100644 --- a/src/Plugins/MagnumFontConverter/MagnumFontConverter.h +++ b/src/Plugins/MagnumFontConverter/MagnumFontConverter.h @@ -48,7 +48,7 @@ class MagnumFontConverter: public Text::AbstractFontConverter { private: Features doFeatures() const override; - std::vector>> doExportFontToData(AbstractFont* font, GlyphCache* cache, const std::string& filename, const std::u32string& characters) const override; + std::vector>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const override; }; }} diff --git a/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp b/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp index a57311e09..2ef161a5a 100644 --- a/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp +++ b/src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp @@ -77,7 +77,7 @@ void MagnumFontConverterTest::exportFont() { /* Convert the file */ MagnumFontConverter converter; - converter.exportFontToFile(&font, &cache, Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font"), "Wave"); + converter.exportFontToFile(font, cache, Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font"), "Wave"); /* Verify font parameters */ /** @todo This might behave differently elsewhere due to unspecified order of glyphs in cache */ From 8ca25de2ecee4cc95612ec1cf32a736bf188ea7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 12 Aug 2013 14:15:18 +0200 Subject: [PATCH 102/112] TgaImporter: minor cleanup. Reset back to default packing (it's 8, but this looks better like default). --- src/Plugins/TgaImporter/TgaHeader.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaHeader.h b/src/Plugins/TgaImporter/TgaHeader.h index 875b30bbd..def766d8e 100644 --- a/src/Plugins/TgaImporter/TgaHeader.h +++ b/src/Plugins/TgaImporter/TgaHeader.h @@ -28,7 +28,7 @@ * @brief Struct Magnum::Trade::TgaHeader */ -#include +#include namespace Magnum { namespace Trade { @@ -49,7 +49,7 @@ struct TgaHeader { UnsignedByte bpp; /**< @brief Bits per pixel (8, 16, 24, 32) */ UnsignedByte descriptor; /**< @brief %Image descriptor */ }; -#pragma pack(8) +#pragma pack() static_assert(sizeof(TgaHeader) == 18, "TgaHeader size is not 18 bytes"); From d972bd40de781e6166c5f712763d03f57d0cd3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 12 Aug 2013 14:20:49 +0200 Subject: [PATCH 103/112] New plugin WavAudioImporter. --- src/Plugins/WavAudioImporter/CMakeLists.txt | 51 +++++++ .../WavAudioImporter/Test/CMakeLists.txt | 30 ++++ .../WavAudioImporter/Test/WavImporterTest.cpp | 123 +++++++++++++++++ .../WavAudioImporter/Test/configure.h.cmake | 25 ++++ src/Plugins/WavAudioImporter/Test/mono16.wav | Bin 0 -> 48 bytes src/Plugins/WavAudioImporter/Test/stereo8.wav | Bin 0 -> 48 bytes .../Test/unsupportedChannelCount.wav | Bin 0 -> 44 bytes .../Test/unsupportedFormat.wav | Bin 0 -> 44 bytes .../WavAudioImporter/Test/wrongSignature.wav | Bin 0 -> 44 bytes .../WavAudioImporter/WavAudioImporter.conf | 0 src/Plugins/WavAudioImporter/WavHeader.h | 60 ++++++++ src/Plugins/WavAudioImporter/WavImporter.cpp | 130 ++++++++++++++++++ src/Plugins/WavAudioImporter/WavImporter.h | 72 ++++++++++ .../pluginRegistrationWavAudioImporter.cpp | 28 ++++ 14 files changed, 519 insertions(+) create mode 100644 src/Plugins/WavAudioImporter/CMakeLists.txt create mode 100644 src/Plugins/WavAudioImporter/Test/CMakeLists.txt create mode 100644 src/Plugins/WavAudioImporter/Test/WavImporterTest.cpp create mode 100644 src/Plugins/WavAudioImporter/Test/configure.h.cmake create mode 100644 src/Plugins/WavAudioImporter/Test/mono16.wav create mode 100644 src/Plugins/WavAudioImporter/Test/stereo8.wav create mode 100644 src/Plugins/WavAudioImporter/Test/unsupportedChannelCount.wav create mode 100644 src/Plugins/WavAudioImporter/Test/unsupportedFormat.wav create mode 100644 src/Plugins/WavAudioImporter/Test/wrongSignature.wav create mode 100644 src/Plugins/WavAudioImporter/WavAudioImporter.conf create mode 100644 src/Plugins/WavAudioImporter/WavHeader.h create mode 100644 src/Plugins/WavAudioImporter/WavImporter.cpp create mode 100644 src/Plugins/WavAudioImporter/WavImporter.h create mode 100644 src/Plugins/WavAudioImporter/pluginRegistrationWavAudioImporter.cpp diff --git a/src/Plugins/WavAudioImporter/CMakeLists.txt b/src/Plugins/WavAudioImporter/CMakeLists.txt new file mode 100644 index 000000000..0d2e69d3d --- /dev/null +++ b/src/Plugins/WavAudioImporter/CMakeLists.txt @@ -0,0 +1,51 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +find_package(Magnum REQUIRED Audio) + +include_directories(${MAGNUM_AUDIO_INCLUDE_DIRS}) + +set(WavAudioImporter_SRCS + WavImporter.cpp) + +set(WavAudioImporter_HEADERS + WavHeader.h + WavImporter.h) + +add_library(WavAudioImporterObjects OBJECT ${WavAudioImporter_SRCS}) +set_target_properties(WavAudioImporterObjects PROPERTIES COMPILE_FLAGS "-DWavAudioImporterObjects_EXPORTS ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}") + +add_plugin(WavAudioImporter ${MAGNUM_PLUGINS_AUDIOIMPORTER_INSTALL_DIR} + WavAudioImporter.conf + $ + pluginRegistrationWavAudioImporter.cpp) +target_link_libraries(WavAudioImporter ${MAGNUM_AUDIO_LIBRARIES}) + +install(FILES ${WavAudioImporter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/WavAudioImporter) + +if(BUILD_TESTS) + add_library(WavAudioImporterTestLib STATIC $) + target_link_libraries(WavAudioImporterTestLib ${MAGNUM_LIBRARIES} ${MAGNUM_AUDIO_LIBRARIES}) + add_subdirectory(Test) +endif() diff --git a/src/Plugins/WavAudioImporter/Test/CMakeLists.txt b/src/Plugins/WavAudioImporter/Test/CMakeLists.txt new file mode 100644 index 000000000..fda7c7e61 --- /dev/null +++ b/src/Plugins/WavAudioImporter/Test/CMakeLists.txt @@ -0,0 +1,30 @@ +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake + ${CMAKE_CURRENT_BINARY_DIR}/configure.h) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +corrade_add_test(WavAudioImporterTest WavImporterTest.cpp LIBRARIES WavAudioImporterTestLib) diff --git a/src/Plugins/WavAudioImporter/Test/WavImporterTest.cpp b/src/Plugins/WavAudioImporter/Test/WavImporterTest.cpp new file mode 100644 index 000000000..1a9593379 --- /dev/null +++ b/src/Plugins/WavAudioImporter/Test/WavImporterTest.cpp @@ -0,0 +1,123 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include +#include +#include +#include + +#include "WavAudioImporter/WavImporter.h" + +#include "configure.h" + +namespace Magnum { namespace Audio { namespace Test { + +class WavImporterTest: public TestSuite::Tester { + public: + explicit WavImporterTest(); + + void wrongSize(); + void wrongSignature(); + void unsupportedFormat(); + void unsupportedChannelCount(); + void mono16(); + void stereo8(); +}; + +WavImporterTest::WavImporterTest() { + addTests({&WavImporterTest::wrongSize, + &WavImporterTest::wrongSignature, + &WavImporterTest::unsupportedFormat, + &WavImporterTest::unsupportedChannelCount, + &WavImporterTest::mono16, + &WavImporterTest::stereo8}); +} + +void WavImporterTest::wrongSize() { + std::ostringstream out; + Error::setOutput(&out); + + WavImporter importer; + CORRADE_VERIFY(!importer.openData(Containers::Array(43))); + CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): the file is too short: 43 bytes\n"); +} + +void WavImporterTest::wrongSignature() { + std::ostringstream out; + Error::setOutput(&out); + + WavImporter importer; + CORRADE_VERIFY(!importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "wrongSignature.wav"))); + CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): the file signature is invalid\n"); +} + +void WavImporterTest::unsupportedFormat() { + std::ostringstream out; + Error::setOutput(&out); + + WavImporter importer; + CORRADE_VERIFY(!importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "unsupportedFormat.wav"))); + CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): unsupported audio format 2\n"); +} + +void WavImporterTest::unsupportedChannelCount() { + std::ostringstream out; + Error::setOutput(&out); + + WavImporter importer; + CORRADE_VERIFY(!importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "unsupportedChannelCount.wav"))); + CORRADE_COMPARE(out.str(), "Audio::WavImporter::openData(): unsupported channel count 6 with 8 bits per sample\n"); +} + +void WavImporterTest::mono16() { + WavImporter importer; + CORRADE_VERIFY(importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "mono16.wav"))); + + CORRADE_COMPARE(importer.format(), Buffer::Format::Mono16); + CORRADE_COMPARE(importer.frequency(), 44000); + Containers::Array data = importer.data(); + CORRADE_COMPARE(data.size(), 4); + CORRADE_COMPARE(data[0], 0x1d); + CORRADE_COMPARE(data[1], 0x10); + CORRADE_COMPARE(data[2], 0x71); + CORRADE_COMPARE(data[3], 0xC5); +} + +void WavImporterTest::stereo8() { + WavImporter importer; + CORRADE_VERIFY(importer.openFile(Utility::Directory::join(WAVAUDIOIMPORTER_TEST_DIR, "stereo8.wav"))); + + CORRADE_COMPARE(importer.format(), Buffer::Format::Stereo8); + CORRADE_COMPARE(importer.frequency(), 96000); + Containers::Array data = importer.data(); + CORRADE_COMPARE(data.size(), 4); + CORRADE_COMPARE(data[0], 0xde); + CORRADE_COMPARE(data[1], 0xfe); + CORRADE_COMPARE(data[2], 0xca); + CORRADE_COMPARE(data[3], 0x7e); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Audio::Test::WavImporterTest) diff --git a/src/Plugins/WavAudioImporter/Test/configure.h.cmake b/src/Plugins/WavAudioImporter/Test/configure.h.cmake new file mode 100644 index 000000000..d5a41dac3 --- /dev/null +++ b/src/Plugins/WavAudioImporter/Test/configure.h.cmake @@ -0,0 +1,25 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#define WAVAUDIOIMPORTER_TEST_DIR "${CMAKE_CURRENT_SOURCE_DIR}" diff --git a/src/Plugins/WavAudioImporter/Test/mono16.wav b/src/Plugins/WavAudioImporter/Test/mono16.wav new file mode 100644 index 0000000000000000000000000000000000000000..30d8982744daa86afc5009ca1053259d3bffd861 GIT binary patch literal 48 zcmWIYbaT^SU|tzyk_Z%L0077a2uc6| literal 0 HcmV?d00001 diff --git a/src/Plugins/WavAudioImporter/Test/wrongSignature.wav b/src/Plugins/WavAudioImporter/Test/wrongSignature.wav new file mode 100644 index 0000000000000000000000000000000000000000..e50f1cd12bf059d9f2d175f08a654d4d74218c40 GIT binary patch literal 44 fcmWIYbaP_>0>>~ + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Struct Magnum::Audio::WavHeader + */ + +#include + +namespace Magnum { namespace Audio { + +#pragma pack(1) +/** @brief WAV file header */ +struct WavHeader { + char chunkId[4]; /**< @brief `RIFF` characters */ + UnsignedInt chunkSize; /**< @brief Size of the rest of the file */ + char format[4]; /**< @brief `WAVE` characters */ + + char subChunk1Id[4]; /**< @brief `fmt ` characters */ + UnsignedInt subChunk1Size; /**< @brief 16 for PCM */ + UnsignedShort audioFormat; /**< @brief 1 = PCM */ + UnsignedShort numChannels; /**< @brief 1 = Mono, 2 = Stereo */ + UnsignedInt sampleRate; /**< @brief Sample rate in Hz */ + UnsignedInt byteRate; /**< @brief Bytes per second */ + UnsignedShort blockAlign; /**< @brief Bytes per sample (all channels) */ + UnsignedShort bitsPerSample; /**< @brief Bits per sample (one channel) */ + + char subChunk2Id[4]; /**< @brief `data` characters */ + UnsignedInt subChunk2Size; /**< @brief Size of the following data */ +}; +#pragma pack() + +static_assert(sizeof(WavHeader) == 44, "WavHeader size is not 44 bytes"); + +}} + +#endif diff --git a/src/Plugins/WavAudioImporter/WavImporter.cpp b/src/Plugins/WavAudioImporter/WavImporter.cpp new file mode 100644 index 000000000..db93e0885 --- /dev/null +++ b/src/Plugins/WavAudioImporter/WavImporter.cpp @@ -0,0 +1,130 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "WavImporter.h" + +#include +#include +#include + +#include "WavHeader.h" + +namespace Magnum { namespace Audio { + +WavImporter::WavImporter() = default; + +WavImporter::WavImporter(PluginManager::AbstractManager* manager, std::string plugin): AbstractImporter(manager, std::move(plugin)) {} + +WavImporter::~WavImporter() { close(); } + +auto WavImporter::doFeatures() const -> Features { return Feature::OpenData; } + +bool WavImporter::doIsOpened() const { return _data; } + +void WavImporter::doOpenData(Containers::ArrayReference data) { + /* Check file size */ + if(data.size() < sizeof(WavHeader)) { + Error() << "Audio::WavImporter::openData(): the file is too short:" << data.size() << "bytes"; + return; + } + + /* Get header contents and fix endianness */ + WavHeader header(*reinterpret_cast(data.begin())); + Utility::Endianness::littleEndianInPlace(header.chunkSize, + header.subChunk1Size, header.audioFormat, header.numChannels, + header.sampleRate, header.byteRate, header.blockAlign, + header.bitsPerSample, header.subChunk2Size); + + /* Check file signature */ + if(std::strncmp(header.chunkId, "RIFF", 4) != 0 || + std::strncmp(header.format, "WAVE", 4) != 0 || + std::strncmp(header.subChunk1Id, "fmt ", 4) != 0 || + std::strncmp(header.subChunk2Id, "data", 4) != 0) { + Error() << "Audio::WavImporter::openData(): the file signature is invalid"; + return; + } + + /* Check file size */ + if(header.chunkSize + 8 != data.size()) { + Error() << "Audio::WavImporter::openData(): the file has improper size, expected" + << header.chunkSize + 8 << "but got" << data.size(); + return; + } + + /* Check PCM format */ + if(header.audioFormat != 1) { + Error() << "Audio::WavImporter::openData(): unsupported audio format" << header.audioFormat; + return; + } + + /* Verify more things */ + if(header.subChunk1Size != 16 || + header.subChunk2Size + 44 != data.size() || + header.blockAlign != header.numChannels*header.bitsPerSample/8 || + header.byteRate != header.sampleRate*header.blockAlign) { + Error() << "Audio::WavImporter::openData(): the file is corrupted"; + return; + } + + /* Decide about format */ + if(header.numChannels == 1 && header.bitsPerSample == 8) + _format = Buffer::Format::Mono8; + else if(header.numChannels == 1 && header.bitsPerSample == 16) + _format = Buffer::Format::Mono16; + else if(header.numChannels == 2 && header.bitsPerSample == 8) + _format = Buffer::Format::Stereo8; + else if(header.numChannels == 2 && header.bitsPerSample == 16) + _format = Buffer::Format::Stereo16; + else { + Error() << "Audio::WavImporter::openData(): unsupported channel count" + << header.numChannels << "with" << header.bitsPerSample + << "bits per sample"; + return; + } + + /* Save frequency */ + _frequency = header.sampleRate; + + /** @todo Convert the data from little endian too */ + CORRADE_INTERNAL_ASSERT(!Utility::Endianness::isBigEndian()); + + /* Copy the data */ + _data = Containers::Array(header.subChunk2Size); + std::copy(data.begin()+sizeof(WavHeader), data.end(), _data.begin()); + return; +} + +void WavImporter::doClose() { _data = nullptr; } + +Buffer::Format WavImporter::doFormat() const { return _format; } + +UnsignedInt WavImporter::doFrequency() const { return _frequency; } + +Containers::Array WavImporter::doData() { + Containers::Array copy(_data.size()); + std::copy(_data.begin(), _data.end(), copy.begin()); + return copy; +} + +}} diff --git a/src/Plugins/WavAudioImporter/WavImporter.h b/src/Plugins/WavAudioImporter/WavImporter.h new file mode 100644 index 000000000..c780d964f --- /dev/null +++ b/src/Plugins/WavAudioImporter/WavImporter.h @@ -0,0 +1,72 @@ +#ifndef Magnum_Audio_WavImporter_h +#define Magnum_Audio_WavImporter_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +/** @file + * @brief Class Magnum::Audio::WavImporter + */ + +#include +#include +#include