Browse Source

Adapted to Magnum changes.

pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
b7e241f17a
  1. 4
      src/Plugins/MagnumFontConverter/MagnumFontConverter.cpp
  2. 6
      src/Plugins/MagnumFontConverter/Test/MagnumFontConverterTest.cpp
  3. 20
      src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp
  4. 22
      src/Plugins/TgaImageConverter/TgaImageConverter.cpp
  5. 4
      src/Plugins/TgaImageConverter/TgaImageConverter.h
  6. 22
      src/Plugins/TgaImporter/Test/TgaImporterTest.cpp
  7. 22
      src/Plugins/TgaImporter/TgaImporter.cpp
  8. 12
      src/Plugins/TgaImporter/TgaImporter.h

4
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>
@ -102,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);

6
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>
@ -91,8 +91,8 @@ void MagnumFontConverterTest::exportFont() {
std::optional<Trade::ImageData2D> image = importer.image2D(0); std::optional<Trade::ImageData2D> image = importer.image2D(0);
CORRADE_VERIFY(image); 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);
} }
}}} }}}

20
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() {
@ -99,11 +99,11 @@ void TgaImageConverterTest::data() {
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); });

4
src/Plugins/TgaImageConverter/TgaImageConverter.h

@ -44,8 +44,8 @@ namespace Magnum { namespace Trade {
/** /**
@brief TGA image converter @brief TGA image converter
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.
*/ */
class MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT TgaImageConverter: public AbstractImageConverter { class MAGNUM_TRADE_TGAIMAGECONVERTER_EXPORT TgaImageConverter: public AbstractImageConverter {
public: public:

22
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"
@ -145,12 +145,12 @@ void TgaImporterTest::colorBits24() {
std::optional<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));
} }
@ -176,12 +176,12 @@ void TgaImporterTest::colorBits32() {
std::optional<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));
} }
@ -197,9 +197,9 @@ void TgaImporterTest::grayscaleBits8() {
std::optional<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));
} }
@ -227,9 +227,9 @@ void TgaImporterTest::file() {
std::optional<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));
} }

22
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
@ -89,7 +89,7 @@ std::optional<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 std::nullopt; return std::nullopt;
@ -100,16 +100,16 @@ std::optional<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:
@ -121,9 +121,9 @@ std::optional<ImageData2D> TgaImporter::doImage2D(UnsignedInt) {
} 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;
@ -143,18 +143,18 @@ std::optional<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, std::transform(pixels, pixels + 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(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, std::transform(pixels, pixels + 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); });
} }
#endif #endif
return ImageData2D(format, ImageType::UnsignedByte, size, data); return ImageData2D(format, ColorType::UnsignedByte, size, data);
} }
}} }}

12
src/Plugins/TgaImporter/TgaImporter.h

@ -47,14 +47,14 @@ namespace Magnum { namespace Trade {
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, The images are imported with @ref ColorType::UnsignedByte and @ref ColorFormat::BGR,
@ref ImageFormat::BGRA or @ref ImageFormat::Red, respectively. Grayscale images @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:

Loading…
Cancel
Save