Browse Source

TgaImporter: minor code cleanup, blind ES compilation fix.

pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
f8b8d93217
  1. 20
      src/Plugins/TgaImporter/Test/TgaImporterTest.cpp
  2. 14
      src/Plugins/TgaImporter/TgaImporter.cpp

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

@ -87,7 +87,7 @@ void TgaImporterTest::paletted() {
void TgaImporterTest::nonRgb() { void TgaImporterTest::nonRgb() {
TgaImporter importer; 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)); CORRADE_VERIFY(importer.openData(data));
std::ostringstream debug; std::ostringstream debug;
@ -111,13 +111,17 @@ void TgaImporterTest::bits24() {
TgaImporter importer; TgaImporter importer;
const char data[] = { const char data[] = {
0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 24, 0, 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 #ifndef MAGNUM_TARGET_GLES
const char* pixels = data + 18; const char* pixels = data + 18;
#else #else
const char pixels[] = { 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 #endif
CORRADE_VERIFY(importer.openData(data)); CORRADE_VERIFY(importer.openData(data));
@ -129,7 +133,7 @@ void TgaImporterTest::bits24() {
#else #else
CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::RGB); CORRADE_COMPARE(image->format(), Trade::ImageData2D::Format::RGB);
#endif #endif
CORRADE_COMPARE(image->size(), Math::Vector2<GLsizei>(2, 3)); CORRADE_COMPARE(image->size(), Vector2i(2, 3));
CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte); CORRADE_COMPARE(image->type(), Trade::ImageData2D::Type::UnsignedByte);
CORRADE_COMPARE(std::string(static_cast<const char*>(image->data()), 2*3*3), std::string(pixels, 2*3*3)); CORRADE_COMPARE(std::string(static_cast<const char*>(image->data()), 2*3*3), std::string(pixels, 2*3*3));
@ -140,13 +144,17 @@ void TgaImporterTest::bits32() {
TgaImporter importer; TgaImporter importer;
const char data[] = { const char data[] = {
0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 0, 32, 0, 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 #ifndef MAGNUM_TARGET_GLES
const char* pixels = data + 18; const char* pixels = data + 18;
#else #else
const char pixels[] = { 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 #endif
CORRADE_VERIFY(importer.openData(data)); CORRADE_VERIFY(importer.openData(data));

14
src/Plugins/TgaImporter/TgaImporter.cpp

@ -132,17 +132,17 @@ ImageData2D* TgaImporter::image2D(UnsignedInt id) {
char* buffer = new char[size]; char* buffer = new char[size];
in->read(buffer, size); in->read(buffer, size);
Math::Vector2<GLsizei> dimensions(header.width, header.height); Vector2i dimensions(header.width, header.height);
#ifdef MAGNUM_TARGET_GLES #ifdef MAGNUM_TARGET_GLES
if(format == AbstractImage::Components::RGB) { if(format == ImageData2D::Format::RGB) {
Math::Vector3<GLubyte>* data = reinterpret_cast<Math::Vector3<GLubyte>*>(buffer); auto data = reinterpret_cast<Math::Vector3<UnsignedByte>*>(buffer);
std::transform(data, data + dimensions.product(), data, std::transform(data, data + dimensions.product(), data,
[](Math::Vector3<GLubyte> pixel) { return swizzle<'b', 'g', 'r'>(pixel); }); [](Math::Vector3<UnsignedByte> pixel) { return swizzle<'b', 'g', 'r'>(pixel); });
} else /* RGBA */ { } else if(format == ImageData2D::Format::RGBA) {
Math::Vector4<GLubyte>* data = reinterpret_cast<Math::Vector4<GLubyte>*>(buffer); auto data = reinterpret_cast<Math::Vector4<UnsignedByte>*>(buffer);
std::transform(data, data + dimensions.product(), data, std::transform(data, data + dimensions.product(), data,
[](Math::Vector4<GLubyte> pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); }); [](Math::Vector4<UnsignedByte> pixel) { return swizzle<'b', 'g', 'r', 'a'>(pixel); });
} }
#endif #endif

Loading…
Cancel
Save