Browse Source

Merge branch 'master' into compatibility

Conflicts:
	src/Plugins/TgaImporter/TgaImporter.cpp
Vladimír Vondruš 13 years ago
parent
commit
b101f5801c
  1. 10
      src/Plugins/MagnumFont/MagnumFont.cpp
  2. 12
      src/Plugins/MagnumFont/MagnumFont.h
  3. 11
      src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp
  4. 18
      src/Plugins/MagnumFontConverter/MagnumFontConverter.h
  5. 9
      src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp
  6. 22
      src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp
  7. 22
      src/Plugins/TgaImageConverter/TgaImageConverter.cpp
  8. 13
      src/Plugins/TgaImageConverter/TgaImageConverter.h
  9. 34
      src/Plugins/TgaImporter/Test/TgaImporterTest.cpp
  10. 34
      src/Plugins/TgaImporter/TgaImporter.cpp
  11. 23
      src/Plugins/TgaImporter/TgaImporter.h
  12. 2
      src/Plugins/WavAudioImporter/CMakeLists.txt
  13. 9
      src/Plugins/WavAudioImporter/WavImporter.h

10
src/Plugins/MagnumFont/MagnumFont.cpp

@ -106,14 +106,13 @@ void MagnumFont::doOpenData(const std::vector<std::pair<std::string, Containers:
Error() << "Text::MagnumFont::openData(): cannot open image file"; Error() << "Text::MagnumFont::openData(): cannot open image file";
return; return;
} }
Trade::ImageData2D* image = importer.image2D(0); std::optional<Trade::ImageData2D> image = importer.image2D(0);
if(!image) { if(!image) {
Error() << "Text::MagnumFont::openData(): cannot load image file"; Error() << "Text::MagnumFont::openData(): cannot load image file";
return; return;
} }
openInternal(std::move(conf), std::move(*image)); openInternal(std::move(conf), std::move(*image));
delete image;
} }
void MagnumFont::doOpenFile(const std::string& filename, Float) { void MagnumFont::doOpenFile(const std::string& filename, Float) {
@ -138,14 +137,13 @@ void MagnumFont::doOpenFile(const std::string& filename, Float) {
Error() << "Text::MagnumFont::openFile(): cannot open image file" << imageFilename; Error() << "Text::MagnumFont::openFile(): cannot open image file" << imageFilename;
return; return;
} }
Trade::ImageData2D* image = importer.image2D(0); std::optional<Trade::ImageData2D> image = importer.image2D(0);
if(!image) { if(!image) {
Error() << "Text::MagnumFont::openFile(): cannot load image file"; Error() << "Text::MagnumFont::openFile(): cannot load image file";
return; return;
} }
openInternal(std::move(conf), std::move(*image)); openInternal(std::move(conf), std::move(*image));
delete image;
} }
void MagnumFont::openInternal(Utility::Configuration&& conf, Trade::ImageData2D&& image) { void MagnumFont::openInternal(Utility::Configuration&& conf, Trade::ImageData2D&& image) {
@ -229,8 +227,8 @@ std::tuple<Rectangle, Rectangle, Vector2> MagnumFontLayouter::renderGlyph(Unsign
const Rectangle texturePosition = Rectangle::fromSize(Vector2(position)/fontSize, const Rectangle texturePosition = Rectangle::fromSize(Vector2(position)/fontSize,
Vector2(rectangle.size())/fontSize); Vector2(rectangle.size())/fontSize);
const Rectangle textureCoordinates(Vector2(rectangle.bottomLeft())/cache.textureSize(), const Rectangle textureCoordinates(Vector2(rectangle.bottomLeft())/Vector2(cache.textureSize()),
Vector2(rectangle.topRight())/cache.textureSize()); Vector2(rectangle.topRight())/Vector2(cache.textureSize()));
/* Absolute quad position, composed from cursor position, glyph offset /* Absolute quad position, composed from cursor position, glyph offset
and texture position, denormalized to requested text size */ and texture position, denormalized to requested text size */

12
src/Plugins/MagnumFont/MagnumFont.h

@ -34,7 +34,15 @@
namespace Magnum { namespace Text { namespace Magnum { namespace Text {
/** /**
@brief Simple bitmap font @brief Simple bitmap font plugin
This plugin depends on @ref Trade::TgaImporter "TgaImporter" plugin and is
built if `WITH_MAGNUMFONT` is enabled in CMake. To use dynamic plugin, you need
to load `%MagnumFont` plugin from `fonts/` subdirectory of your plugin dir. To
use static plugin or use this as a dependency of another plugin, you need to
request `%MagnumFont` component in CMake and link to
`${MAGNUMPLUGINS_MAGNUMFONT_LIBRARIES}`. See @ref building-plugins and
@ref cmake-plugins for more information.
The font consists of two files, one text file containing character and glyph 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 info and one TGA file containing the glyphs in distance field format. The font
@ -102,7 +110,7 @@ class MagnumFont: public AbstractFont {
~MagnumFont(); ~MagnumFont();
private: private:
class Data; struct Data;
Features doFeatures() const override; Features doFeatures() const override;

11
src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp

@ -27,8 +27,8 @@
#include <sstream> #include <sstream>
#include <Containers/Array.h> #include <Containers/Array.h>
#include <Utility/Directory.h> #include <Utility/Directory.h>
#include <ColorFormat.h>
#include <Image.h> #include <Image.h>
#include <ImageFormat.h>
#include <Text/GlyphCache.h> #include <Text/GlyphCache.h>
#include <Text/AbstractFont.h> #include <Text/AbstractFont.h>
#include <TgaImageConverter/TgaImageConverter.h> #include <TgaImageConverter/TgaImageConverter.h>
@ -43,7 +43,12 @@ auto MagnumFontConverter::doFeatures() const -> Features {
return Feature::ExportFont|Feature::ConvertData|Feature::MultiFile; return Feature::ExportFont|Feature::ConvertData|Feature::MultiFile;
} }
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const { #ifndef _WIN32
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const
#else
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector<char32_t>& characters) const
#endif
{
Utility::Configuration configuration; Utility::Configuration configuration;
configuration.setValue("version", 1); configuration.setValue("version", 1);
@ -97,7 +102,7 @@ std::vector<std::pair<std::string, Containers::Array<unsigned char>>> MagnumFont
std::copy(confStr.begin(), confStr.end(), confData.begin()); std::copy(confStr.begin(), confStr.end(), confData.begin());
/* Save cache image */ /* Save cache image */
Image2D image(ImageFormat::Red, ImageType::UnsignedByte); Image2D image(ColorFormat::Red, ColorType::UnsignedByte);
cache.texture().image(0, image); cache.texture().image(0, image);
auto tgaData = Trade::TgaImageConverter().exportToData(image); auto tgaData = Trade::TgaImageConverter().exportToData(image);

18
src/Plugins/MagnumFontConverter/MagnumFontConverter.h

@ -33,10 +33,20 @@
namespace Magnum { namespace Text { namespace Magnum { namespace Text {
/** /**
@brief Converter to MagnumFont @brief MagnumFont converter plugin
Expects filename prefix, creates two files, `prefix.conf` and `prefix.tga`. See Expects filename prefix, creates two files, `prefix.conf` and `prefix.tga`. See
MagnumFont for more information about the font. @ref MagnumFont for more information about the font.
This plugin is available only on desktop OpenGL, as it uses @ref Texture::image()
to read back the generated data. It depends on
@ref Trade::TgaImageConverter "TgaImageConverter" plugin and is built if
`WITH_MAGNUMFONTCONVERTER` is enabled in CMake. To use dynamic plugin, you need
to load `%MagnumFontConverter` plugin from `fontconverters/` subdirectory of
your plugin dir. To use static plugin or use this as a dependency of another
plugin, you need to request `%MagnumFontConverter` component in CMake and link
to `${MAGNUMPLUGINS_MAGNUMFONTCONVERTER_LIBRARIES}`. See @ref building-plugins
and @ref cmake-plugins for more information.
*/ */
class MagnumFontConverter: public Text::AbstractFontConverter { class MagnumFontConverter: public Text::AbstractFontConverter {
public: public:
@ -48,7 +58,11 @@ class MagnumFontConverter: public Text::AbstractFontConverter {
private: private:
Features doFeatures() const override; Features doFeatures() const override;
#ifndef _WIN32
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const override; std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const override;
#else
std::vector<std::pair<std::string, Containers::Array<unsigned char>>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector<char32_t>& characters) const override;
#endif
}; };
}} }}

9
src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp

@ -24,8 +24,8 @@
#include <Utility/Directory.h> #include <Utility/Directory.h>
#include <TestSuite/Compare/File.h> #include <TestSuite/Compare/File.h>
#include <ColorFormat.h>
#include <Extensions.h> #include <Extensions.h>
#include <ImageFormat.h>
#include <TextureFormat.h> #include <TextureFormat.h>
#include <Test/AbstractOpenGLTester.h> #include <Test/AbstractOpenGLTester.h>
#include <Text/GlyphCache.h> #include <Text/GlyphCache.h>
@ -88,10 +88,11 @@ void MagnumFontConverterTest::exportFont() {
/* Verify font image, no need to test image contents, as the image is garbage anyway */ /* Verify font image, no need to test image contents, as the image is garbage anyway */
Trade::TgaImporter importer; Trade::TgaImporter importer;
CORRADE_VERIFY(importer.openFile(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.tga"))); CORRADE_VERIFY(importer.openFile(Utility::Directory::join(MAGNUMFONTCONVERTER_TEST_WRITE_DIR, "font.tga")));
Trade::ImageData2D* image = importer.image2D(0); std::optional<Trade::ImageData2D> image = importer.image2D(0);
CORRADE_VERIFY(image);
CORRADE_COMPARE(image->size(), Vector2i(256)); CORRADE_COMPARE(image->size(), Vector2i(256));
CORRADE_COMPARE(image->format(), ImageFormat::Red); CORRADE_COMPARE(image->format(), ColorFormat::Red);
CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); CORRADE_COMPARE(image->type(), ColorType::UnsignedByte);
} }
}}} }}}

22
src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp

@ -27,8 +27,8 @@
#include <Containers/Array.h> #include <Containers/Array.h>
#include <TestSuite/Tester.h> #include <TestSuite/Tester.h>
#include <Utility/Directory.h> #include <Utility/Directory.h>
#include <ColorFormat.h>
#include <Image.h> #include <Image.h>
#include <ImageFormat.h>
#include <Trade/ImageData.h> #include <Trade/ImageData.h>
#include <TgaImageConverter/TgaImageConverter.h> #include <TgaImageConverter/TgaImageConverter.h>
#include <TgaImporter/TgaImporter.h> #include <TgaImporter/TgaImporter.h>
@ -49,9 +49,9 @@ class TgaImageConverterTest: public TestSuite::Tester {
namespace { namespace {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
const Image2D original(ImageFormat::BGR, ImageType::UnsignedByte, {2, 3}, new char[18] const Image2D original(ColorFormat::BGR, ColorType::UnsignedByte, {2, 3}, new char[18]
#else #else
const Image2D original(ImageFormat::RGB, ImageType::UnsignedByte, {2, 3}, new char[18] const Image2D original(ColorFormat::RGB, ColorType::UnsignedByte, {2, 3}, new char[18]
#endif #endif
{ {
1, 2, 3, 2, 3, 4, 1, 2, 3, 2, 3, 4,
@ -68,25 +68,25 @@ TgaImageConverterTest::TgaImageConverterTest() {
} }
void TgaImageConverterTest::wrongFormat() { void TgaImageConverterTest::wrongFormat() {
ImageReference2D image(ImageFormat::RG, ImageType::UnsignedByte, {}, nullptr); ImageReference2D image(ColorFormat::RG, ColorType::UnsignedByte, {}, nullptr);
std::ostringstream out; std::ostringstream out;
Error::setOutput(&out); Error::setOutput(&out);
const auto data = TgaImageConverter().exportToData(image); const auto data = TgaImageConverter().exportToData(image);
CORRADE_VERIFY(!data); CORRADE_VERIFY(!data);
CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::convertToData(): unsupported image format ImageFormat::RG\n"); CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::convertToData(): unsupported image format ColorFormat::RG\n");
} }
void TgaImageConverterTest::wrongType() { void TgaImageConverterTest::wrongType() {
ImageReference2D image(ImageFormat::Red, ImageType::Float, {}, nullptr); ImageReference2D image(ColorFormat::Red, ColorType::Float, {}, nullptr);
std::ostringstream out; std::ostringstream out;
Error::setOutput(&out); Error::setOutput(&out);
const auto data = TgaImageConverter().exportToData(image); const auto data = TgaImageConverter().exportToData(image);
CORRADE_VERIFY(!data); CORRADE_VERIFY(!data);
CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::convertToData(): unsupported image type ImageType::Float\n"); CORRADE_COMPARE(out.str(), "Trade::TgaImageConverter::convertToData(): unsupported image type ColorType::Float\n");
} }
void TgaImageConverterTest::data() { void TgaImageConverterTest::data() {
@ -94,16 +94,16 @@ void TgaImageConverterTest::data() {
TgaImporter importer; TgaImporter importer;
CORRADE_VERIFY(importer.openData(data)); CORRADE_VERIFY(importer.openData(data));
Trade::ImageData2D* converted = importer.image2D(0); std::optional<Trade::ImageData2D> converted = importer.image2D(0);
CORRADE_VERIFY(converted); CORRADE_VERIFY(converted);
CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); CORRADE_COMPARE(converted->size(), Vector2i(2, 3));
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(converted->format(), ImageFormat::BGR); CORRADE_COMPARE(converted->format(), ColorFormat::BGR);
#else #else
CORRADE_COMPARE(converted->format(), ImageFormat::RGB); CORRADE_COMPARE(converted->format(), ColorFormat::RGB);
#endif #endif
CORRADE_COMPARE(converted->type(), ImageType::UnsignedByte); CORRADE_COMPARE(converted->type(), ColorType::UnsignedByte);
CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(converted->data()), 2*3*3), CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(converted->data()), 2*3*3),
std::string(reinterpret_cast<const char*>(original.data()), 2*3*3)); std::string(reinterpret_cast<const char*>(original.data()), 2*3*3));
} }

22
src/Plugins/TgaImageConverter/TgaImageConverter.cpp

@ -28,8 +28,8 @@
#include <tuple> #include <tuple>
#include <Containers/Array.h> #include <Containers/Array.h>
#include <Utility/Endianness.h> #include <Utility/Endianness.h>
#include <ColorFormat.h>
#include <Image.h> #include <Image.h>
#include <ImageFormat.h>
#ifdef MAGNUM_TARGET_GLES #ifdef MAGNUM_TARGET_GLES
#include <algorithm> #include <algorithm>
@ -48,20 +48,20 @@ auto TgaImageConverter::doFeatures() const -> Features { return Feature::Convert
Containers::Array<unsigned char> TgaImageConverter::doExportToData(const ImageReference2D& image) const { Containers::Array<unsigned char> TgaImageConverter::doExportToData(const ImageReference2D& image) const {
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
if(image.format() != ImageFormat::BGR && if(image.format() != ColorFormat::BGR &&
image.format() != ImageFormat::BGRA && image.format() != ColorFormat::BGRA &&
image.format() != ImageFormat::Red) image.format() != ColorFormat::Red)
#else #else
if(image.format() != ImageFormat::RGB && if(image.format() != ColorFormat::RGB &&
image.format() != ImageFormat::RGBA && image.format() != ColorFormat::RGBA &&
image.format() != ImageFormat::Red) image.format() != ColorFormat::Red)
#endif #endif
{ {
Error() << "Trade::TgaImageConverter::convertToData(): unsupported image format" << image.format(); Error() << "Trade::TgaImageConverter::convertToData(): unsupported image format" << image.format();
return nullptr; return nullptr;
} }
if(image.type() != ImageType::UnsignedByte) { if(image.type() != ColorType::UnsignedByte) {
Error() << "Trade::TgaImageConverter::convertToData(): unsupported image type" << image.type(); Error() << "Trade::TgaImageConverter::convertToData(): unsupported image type" << image.type();
return nullptr; return nullptr;
} }
@ -72,7 +72,7 @@ Containers::Array<unsigned char> TgaImageConverter::doExportToData(const ImageRe
/* Fill header */ /* Fill header */
auto header = reinterpret_cast<TgaHeader*>(data.begin()); auto header = reinterpret_cast<TgaHeader*>(data.begin());
header->imageType = image.format() == ImageFormat::Red ? 3 : 2; header->imageType = image.format() == ColorFormat::Red ? 3 : 2;
header->bpp = pixelSize*8; header->bpp = pixelSize*8;
header->width = Utility::Endianness::littleEndian(image.size().x()); header->width = Utility::Endianness::littleEndian(image.size().x());
header->height = Utility::Endianness::littleEndian(image.size().y()); header->height = Utility::Endianness::littleEndian(image.size().y());
@ -81,11 +81,11 @@ Containers::Array<unsigned char> TgaImageConverter::doExportToData(const ImageRe
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 #ifdef MAGNUM_TARGET_GLES
if(image->format() == ImageFormat::RGB) { if(image->format() == ColorFormat::RGB) {
auto pixels = reinterpret_cast<Math::Vector3<UnsignedByte>*>(data.begin()+sizeof(TgaHeader)); auto pixels = reinterpret_cast<Math::Vector3<UnsignedByte>*>(data.begin()+sizeof(TgaHeader));
std::transform(pixels, pixels + image.size().product(), pixels, std::transform(pixels, pixels + image.size().product(), pixels,
[](Math::Vector3<UnsignedByte> pixel) { return swizzle<'b', 'g', 'r'>(pixel); }); [](Math::Vector3<UnsignedByte> pixel) { return swizzle<'b', 'g', 'r'>(pixel); });
} else if(image.format() == ImageFormat::RGBA) { } else if(image.format() == ColorFormat::RGBA) {
auto pixels = reinterpret_cast<Math::Vector4<UnsignedByte>*>(data.begin()+sizeof(TgaHeader)); auto pixels = reinterpret_cast<Math::Vector4<UnsignedByte>*>(data.begin()+sizeof(TgaHeader));
std::transform(pixels, pixels + image.size().product(), pixels, std::transform(pixels, pixels + image.size().product(), pixels,
[](Math::Vector4<UnsignedByte> pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); }); [](Math::Vector4<UnsignedByte> pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); });

13
src/Plugins/TgaImageConverter/TgaImageConverter.h

@ -42,10 +42,17 @@
namespace Magnum { namespace Trade { namespace Magnum { namespace Trade {
/** /**
@brief TGA image converter @brief TGA image converter plugin
Supports images with format @ref ImageFormat::BGR, @ref ImageFormat::BGRA or Supports images with format @ref ColorFormat::BGR, @ref ColorFormat::BGRA or
@ref ImageFormat::Red and type @ref ImageType::UnsignedByte. @ref ColorFormat::Red and type @ref ColorType::UnsignedByte.
This plugin is built if `WITH_TGAIMAGECONVERTER` is enabled in CMake. To use
dynamic plugin, you need to load `%TgaImageConverter` plugin from
`imageconverters/` subdirectory of your plugin dir. To use static plugin or use
this as a dependency of another plugin, you need to request `%TgaImageConverter`
component in CMake and link to `${MAGNUMPLUGINS_TGAIMAGECONVERTER_LIBRARIES}`.
See @ref building-plugins and @ref cmake-plugins for more information.
*/ */
class MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT TgaImageConverter: public AbstractImageConverter { class MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT TgaImageConverter: public AbstractImageConverter {
public: public:

34
src/Plugins/TgaImporter/Test/TgaImporterTest.cpp

@ -26,7 +26,7 @@
#include <Containers/Array.h> #include <Containers/Array.h>
#include <TestSuite/Tester.h> #include <TestSuite/Tester.h>
#include <Utility/Directory.h> #include <Utility/Directory.h>
#include <ImageFormat.h> #include <ColorFormat.h>
#include <Trade/ImageData.h> #include <Trade/ImageData.h>
#include "TgaImporter/TgaImporter.h" #include "TgaImporter/TgaImporter.h"
@ -142,18 +142,16 @@ void TgaImporterTest::colorBits24() {
#endif #endif
CORRADE_VERIFY(importer.openData(data)); CORRADE_VERIFY(importer.openData(data));
Trade::ImageData2D* image = importer.image2D(0); std::optional<Trade::ImageData2D> image = importer.image2D(0);
CORRADE_VERIFY(image); CORRADE_VERIFY(image);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(image->format(), ImageFormat::BGR); CORRADE_COMPARE(image->format(), ColorFormat::BGR);
#else #else
CORRADE_COMPARE(image->format(), ImageFormat::RGB); CORRADE_COMPARE(image->format(), ColorFormat::RGB);
#endif #endif
CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->size(), Vector2i(2, 3));
CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); CORRADE_COMPARE(image->type(), ColorType::UnsignedByte);
CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3*3), std::string(pixels, 2*3*3)); CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3*3), std::string(pixels, 2*3*3));
delete image;
} }
void TgaImporterTest::colorBits32() { void TgaImporterTest::colorBits32() {
@ -175,18 +173,16 @@ void TgaImporterTest::colorBits32() {
#endif #endif
CORRADE_VERIFY(importer.openData(data)); CORRADE_VERIFY(importer.openData(data));
Trade::ImageData2D* image = importer.image2D(0); std::optional<Trade::ImageData2D> image = importer.image2D(0);
CORRADE_VERIFY(image); CORRADE_VERIFY(image);
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(image->format(), ImageFormat::BGRA); CORRADE_COMPARE(image->format(), ColorFormat::BGRA);
#else #else
CORRADE_COMPARE(image->format(), ImageFormat::RGBA); CORRADE_COMPARE(image->format(), ColorFormat::RGBA);
#endif #endif
CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->size(), Vector2i(2, 3));
CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); CORRADE_COMPARE(image->type(), ColorType::UnsignedByte);
CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3*3), std::string(pixels, 2*3*3)); CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3*3), std::string(pixels, 2*3*3));
delete image;
} }
void TgaImporterTest::grayscaleBits8() { void TgaImporterTest::grayscaleBits8() {
@ -199,11 +195,11 @@ void TgaImporterTest::grayscaleBits8() {
}; };
CORRADE_VERIFY(importer.openData(data)); CORRADE_VERIFY(importer.openData(data));
Trade::ImageData2D* image = importer.image2D(0); std::optional<Trade::ImageData2D> image = importer.image2D(0);
CORRADE_VERIFY(image); CORRADE_VERIFY(image);
CORRADE_COMPARE(image->format(), ImageFormat::Red); CORRADE_COMPARE(image->format(), ColorFormat::Red);
CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->size(), Vector2i(2, 3));
CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); CORRADE_COMPARE(image->type(), ColorType::UnsignedByte);
CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3), CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3),
std::string(reinterpret_cast<const char*>(data) + 18, 2*3)); std::string(reinterpret_cast<const char*>(data) + 18, 2*3));
} }
@ -229,11 +225,11 @@ void TgaImporterTest::file() {
}; };
CORRADE_VERIFY(importer.openFile(Utility::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); std::optional<Trade::ImageData2D> image = importer.image2D(0);
CORRADE_VERIFY(image); CORRADE_VERIFY(image);
CORRADE_COMPARE(image->format(), ImageFormat::Red); CORRADE_COMPARE(image->format(), ColorFormat::Red);
CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->size(), Vector2i(2, 3));
CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); CORRADE_COMPARE(image->type(), ColorType::UnsignedByte);
CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3), CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3),
std::string(reinterpret_cast<const char*>(data) + 18, 2*3)); std::string(reinterpret_cast<const char*>(data) + 18, 2*3));
} }

34
src/Plugins/TgaImporter/TgaImporter.cpp

@ -28,7 +28,7 @@
#include <sstream> #include <sstream>
#include <Utility/Endianness.h> #include <Utility/Endianness.h>
#include <Containers/Array.h> #include <Containers/Array.h>
#include <ImageFormat.h> #include <ColorFormat.h>
#include <Trade/ImageData.h> #include <Trade/ImageData.h>
#ifdef MAGNUM_TARGET_GLES #ifdef MAGNUM_TARGET_GLES
@ -81,14 +81,14 @@ void TgaImporter::doClose() {
UnsignedInt TgaImporter::doImage2DCount() const { return 1; } UnsignedInt TgaImporter::doImage2DCount() const { return 1; }
ImageData2D* TgaImporter::doImage2D(UnsignedInt) { std::optional<ImageData2D> TgaImporter::doImage2D(UnsignedInt) {
/* Check if the file is long enough */ /* Check if the file is long enough */
in->seekg(0, std::istream::end); in->seekg(0, std::istream::end);
std::streampos filesize = in->tellg(); std::streampos filesize = in->tellg();
in->seekg(0, std::istream::beg); in->seekg(0, std::istream::beg);
if(filesize < std::streampos(sizeof(TgaHeader))) { if(filesize < std::streampos(sizeof(TgaHeader))) {
Error() << "Trade::TgaImporter::image2D(): the file is too short:" << filesize << "bytes"; Error() << "Trade::TgaImporter::image2D(): the file is too short:" << filesize << "bytes";
return nullptr; return std::nullopt;
} }
TgaHeader header; TgaHeader header;
@ -99,10 +99,10 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) {
header.height = Utility::Endianness::littleEndian(header.height); header.height = Utility::Endianness::littleEndian(header.height);
/* Image format */ /* Image format */
ImageFormat format; ColorFormat format;
if(header.colorMapType != 0) { if(header.colorMapType != 0) {
Error() << "Trade::TgaImporter::image2D(): paletted files are not supported"; Error() << "Trade::TgaImporter::image2D(): paletted files are not supported";
return nullptr; return std::nullopt;
} }
/* Color */ /* Color */
@ -110,40 +110,40 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) {
switch(header.bpp) { switch(header.bpp) {
case 24: case 24:
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
format = ImageFormat::BGR; format = ColorFormat::BGR;
#else #else
format = ImageFormat::RGB; format = ColorFormat::RGB;
#endif #endif
break; break;
case 32: case 32:
#ifndef MAGNUM_TARGET_GLES #ifndef MAGNUM_TARGET_GLES
format = ImageFormat::BGRA; format = ColorFormat::BGRA;
#else #else
format = ImageFormat::RGBA; format = ColorFormat::RGBA;
#endif #endif
break; break;
default: default:
Error() << "Trade::TgaImporter::image2D(): unsupported color bits-per-pixel:" << header.bpp; Error() << "Trade::TgaImporter::image2D(): unsupported color bits-per-pixel:" << header.bpp;
return nullptr; return std::nullopt;
} }
/* Grayscale */ /* Grayscale */
} else if(header.imageType == 3) { } else if(header.imageType == 3) {
#ifdef MAGNUM_TARGET_GLES #ifdef MAGNUM_TARGET_GLES
format = Context::current() && Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_rg>() ? format = Context::current() && Context::current()->isExtensionSupported<Extensions::GL::EXT::texture_rg>() ?
ImageFormat::Red : ImageFormat::Luminance; ColorFormat::Red : ColorFormat::Luminance;
#else #else
format = ImageFormat::Red; format = ColorFormat::Red;
#endif #endif
if(header.bpp != 8) { if(header.bpp != 8) {
Error() << "Trade::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp; Error() << "Trade::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp;
return nullptr; return std::nullopt;
} }
/* Compressed files */ /* Compressed files */
} else { } else {
Error() << "Trade::TgaImporter::image2D(): unsupported (compressed?) image type:" << header.imageType; Error() << "Trade::TgaImporter::image2D(): unsupported (compressed?) image type:" << header.imageType;
return nullptr; return std::nullopt;
} }
const std::size_t dataSize = header.width*header.height*header.bpp/8; const std::size_t dataSize = header.width*header.height*header.bpp/8;
@ -153,16 +153,16 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) {
Vector2i size(header.width, header.height); Vector2i size(header.width, header.height);
#ifdef MAGNUM_TARGET_GLES #ifdef MAGNUM_TARGET_GLES
if(format == ImageFormat::RGB) { if(format == ColorFormat::RGB) {
auto pixels = reinterpret_cast<Math::Vector3<UnsignedByte>*>(data); auto pixels = reinterpret_cast<Math::Vector3<UnsignedByte>*>(data);
std::transform(pixels, pixels + size.product(), pixels, bgr); std::transform(pixels, pixels + size.product(), pixels, bgr);
} else if(format == ImageFormat::RGBA) { } else if(format == ColorFormat::RGBA) {
auto pixels = reinterpret_cast<Math::Vector4<UnsignedByte>*>(data); auto pixels = reinterpret_cast<Math::Vector4<UnsignedByte>*>(data);
std::transform(pixels, pixels + size.product(), pixels, bgra); std::transform(pixels, pixels + size.product(), pixels, bgra);
} }
#endif #endif
return new ImageData2D(format, ImageType::UnsignedByte, size, data); return ImageData2D(format, ColorType::UnsignedByte, size, data);
} }
}} }}

23
src/Plugins/TgaImporter/TgaImporter.h

@ -43,18 +43,25 @@
namespace Magnum { namespace Trade { namespace Magnum { namespace Trade {
/** /**
@brief TGA image importer @brief TGA importer plugin
Supports uncompressed BGR, BGRA or grayscale images with 8 bits per channel. Supports uncompressed BGR, BGRA or grayscale images with 8 bits per channel.
The images are imported with @ref ImageType::UnsignedByte and @ref ImageFormat::BGR, This plugin is built if `WITH_TGAIMPORTER` is enabled in CMake. To use dynamic
@ref ImageFormat::BGRA or @ref ImageFormat::Red, respectively. Grayscale images plugin, you need to load `%TgaImporter` plugin from `importers/` subdirectory
of your plugin dir. To use static plugin or use this as a dependency of another
plugin, you need to request `%TgaImporter` component in CMake and link to
`${MAGNUMPLUGINS_TGAIMPORTER_LIBRARIES}`. See @ref building-plugins and
@ref cmake-plugins for more information.
The images are imported with @ref ColorType::UnsignedByte and @ref ColorFormat::BGR,
@ref ColorFormat::BGRA or @ref ColorFormat::Red, respectively. Grayscale images
require extension @extension{ARB,texture_rg}. require extension @extension{ARB,texture_rg}.
In OpenGL ES BGR and BGRA images are converted to @ref ImageFormat::RGB In OpenGL ES BGR and BGRA images are converted to @ref ColorFormat::RGB
and @ref ImageFormat::RGBA. In OpenGL ES 2.0, if @es_extension{EXT,texture_rg} and @ref ColorFormat::RGBA. In OpenGL ES 2.0, if @es_extension{EXT,texture_rg}
is not supported, grayscale images use @ref ImageFormat::Luminance instead of is not supported, grayscale images use @ref ColorFormat::Luminance instead of
@ref ImageFormat::Red. @ref ColorFormat::Red.
*/ */
class MAGNUM_TRADE_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { class MAGNUM_TRADE_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter {
public: public:
@ -73,7 +80,7 @@ class MAGNUM_TRADE_TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter {
void MAGNUM_TRADE_TGAIMPORTER_LOCAL doOpenFile(const std::string& filename) override; void MAGNUM_TRADE_TGAIMPORTER_LOCAL doOpenFile(const std::string& filename) override;
void MAGNUM_TRADE_TGAIMPORTER_LOCAL doClose() override; void MAGNUM_TRADE_TGAIMPORTER_LOCAL doClose() override;
UnsignedInt MAGNUM_TRADE_TGAIMPORTER_LOCAL doImage2DCount() const override; UnsignedInt MAGNUM_TRADE_TGAIMPORTER_LOCAL doImage2DCount() const override;
ImageData2D MAGNUM_TRADE_TGAIMPORTER_LOCAL * doImage2D(UnsignedInt id) override; std::optional<ImageData2D> MAGNUM_TRADE_TGAIMPORTER_LOCAL doImage2D(UnsignedInt id) override;
std::istream* in; std::istream* in;
}; };

2
src/Plugins/WavAudioImporter/CMakeLists.txt

@ -40,7 +40,7 @@ add_plugin(WavAudioImporter ${MAGNUM_PLUGINS_AUDIOIMPORTER_INSTALL_DIR}
WavAudioImporter.conf WavAudioImporter.conf
$<TARGET_OBJECTS:WavAudioImporterObjects> $<TARGET_OBJECTS:WavAudioImporterObjects>
pluginRegistrationWavAudioImporter.cpp) pluginRegistrationWavAudioImporter.cpp)
target_link_libraries(WavAudioImporter ${MAGNUM_AUDIO_LIBRARIES}) target_link_libraries(WavAudioImporter ${MAGNUM_LIBRARIES} ${MAGNUM_AUDIO_LIBRARIES})
install(FILES ${WavAudioImporter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/WavAudioImporter) install(FILES ${WavAudioImporter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/WavAudioImporter)

9
src/Plugins/WavAudioImporter/WavImporter.h

@ -35,11 +35,18 @@
namespace Magnum { namespace Audio { namespace Magnum { namespace Audio {
/** /**
@brief WAV importer @brief WAV importer plugin
Supports mono and stereo PCM files with 8 or 16 bits per channel. The files are Supports mono and stereo PCM files with 8 or 16 bits per channel. The files are
imported with @ref Buffer::Format::Mono8, @ref Buffer::Format::Mono16, imported with @ref Buffer::Format::Mono8, @ref Buffer::Format::Mono16,
@ref Buffer::Format::Stereo8 or @ref Buffer::Format::Stereo16, respectively. @ref Buffer::Format::Stereo8 or @ref Buffer::Format::Stereo16, respectively.
This plugin is built if `WITH_WAVAUDIOIMPORTER` is enabled in CMake. To use
dynamic plugin, you need to load `%WavAudioImporter` plugin from `audioimporters/`
subdirectory of your plugin dir. To use static plugin or or use this as a
dependency of another plugin, you need to request `%WavAudioImporter` component
in CMake and link to `${MAGNUMPLUGINS_WAVAUDIOIMPORTER_LIBRARIES}`. See
@ref building-plugins and @ref cmake-plugins for more information.
*/ */
class WavImporter: public AbstractImporter { class WavImporter: public AbstractImporter {
public: public:

Loading…
Cancel
Save