void TgaImporterTest::colorBits32() { TgaImporter importer; 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 = reinterpret_cast<const char*>(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 CORRADE_VERIFY(importer.openData(data)); std::optional<Trade::ImageData2D> image = importer.image2D(0); CORRADE_VERIFY(image); #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(image->format(), ImageFormat::BGRA); #else CORRADE_COMPARE(image->format(), ImageFormat::RGBA); #endif CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), ImageType::UnsignedByte); CORRADE_COMPARE(std::string(reinterpret_cast<const char*>(image->data()), 2*3*3), std::string(pixels, 2*3*3)); }
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); CORRADE_VERIFY(!importer.image2D(0)); CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::image2D(): paletted files are not supported\n"); }
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); CORRADE_VERIFY(!importer.image2D(0)); CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::image2D(): the file is too short: 17 bytes\n"); }
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::image2D(): unsupported grayscale bits-per-pixel: 16\n"); }
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)); std::ostringstream debug; Error::setOutput(&debug); CORRADE_VERIFY(!importer.image2D(0)); CORRADE_COMPARE(debug.str(), "Trade::TgaImporter::image2D(): unsupported (compressed?) image type: 9\n"); }
void TgaImageConverterTest::rgba() { const auto data = TgaImageConverter().exportToData(OriginalRGBA); TgaImporter importer; CORRADE_VERIFY(importer.openData(data)); std::optional<Trade::ImageData2D> converted = importer.image2D(0); CORRADE_VERIFY(converted); CORRADE_COMPARE(converted->storage().alignment(), 4); CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); CORRADE_COMPARE(converted->format(), PixelFormat::RGBA); CORRADE_COMPARE(converted->type(), PixelType::UnsignedByte); CORRADE_COMPARE_AS(converted->data(), Containers::ArrayView<const char> {OriginalDataRGBA}, TestSuite::Compare::Container); }
void TgaImageConverterTest::data() { const auto data = TgaImageConverter().exportToData(original); TgaImporter importer; CORRADE_VERIFY(importer.openData(data)); std::optional<Trade::ImageData2D> converted = importer.image2D(0); CORRADE_VERIFY(converted); CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(converted->format(), ColorFormat::BGR); #else CORRADE_COMPARE(converted->format(), ColorFormat::RGB); #endif CORRADE_COMPARE(converted->type(), ColorType::UnsignedByte); CORRADE_COMPARE((std::string{converted->data(), 2*3*3}), (std::string{original.data(), 2*3*3})); }
void TgaImporterTest::file() { TgaImporter importer; 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, 5, 6 }; CORRADE_VERIFY(importer.openFile(Utility::Directory::join(TGAIMPORTER_TEST_DIR, "file.tga"))); std::optional<Trade::ImageData2D> image = importer.image2D(0); CORRADE_VERIFY(image); 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<const char*>(image->data()), 2*3), std::string(reinterpret_cast<const char*>(data) + 18, 2*3)); }
void TgaImporterTest::grayscaleBits8() { TgaImporter importer; 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, 5, 6 }; CORRADE_VERIFY(importer.openData(data)); std::optional<Trade::ImageData2D> image = importer.image2D(0); CORRADE_VERIFY(image); 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<const char*>(image->data()), 2*3), std::string(reinterpret_cast<const char*>(data) + 18, 2*3)); }
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(Utility::Directory::join(TGAIMPORTER_TEST_DIR, "file.tga"))); std::optional<Trade::ImageData2D> image = importer.image2D(0); CORRADE_VERIFY(image); #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(image->format(), ColorFormat::Red); #else CORRADE_COMPARE(image->format(), ColorFormat::Luminance); #endif CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), ColorType::UnsignedByte); CORRADE_COMPARE((std::string{image->data(), 2*3}), (std::string{data + 18, 2*3})); }
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)); std::optional<Trade::ImageData2D> image = importer.image2D(0); CORRADE_VERIFY(image); #ifndef MAGNUM_TARGET_GLES2 CORRADE_COMPARE(image->format(), ColorFormat::Red); #else CORRADE_COMPARE(image->format(), ColorFormat::Luminance); #endif CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), ColorType::UnsignedByte); CORRADE_COMPARE((std::string{image->data(), 2*3}), (std::string{data + 18, 2*3})); }
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, 1, 2, 3, 1, 2, 3, 4, 1, 3, 4, 5, 1, 4, 5, 6, 1, 5, 6, 7, 1, 6, 7, 8, 1 }; 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 }; CORRADE_VERIFY(importer.openData(data)); std::optional<Trade::ImageData2D> image = importer.image2D(0); CORRADE_VERIFY(image); CORRADE_COMPARE(image->format(), ColorFormat::RGBA); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); CORRADE_COMPARE(image->type(), ColorType::UnsignedByte); CORRADE_COMPARE((std::string{image->data(), 2*3*3}), (std::string{pixels, 2*3*3})); }