diff --git a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp index e8ee0b5fb..c2d0c3490 100644 --- a/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp +++ b/src/Plugins/TgaImageConverter/Test/TgaImageConverterTest.cpp @@ -94,7 +94,7 @@ void TgaImageConverterTest::data() { TgaImporter importer; CORRADE_VERIFY(importer.openData(data)); - Trade::ImageData2D* converted = importer.image2D(0); + std::optional converted = importer.image2D(0); CORRADE_VERIFY(converted); CORRADE_COMPARE(converted->size(), Vector2i(2, 3)); diff --git a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp index fb9738344..f0e14d83c 100644 --- a/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp +++ b/src/Plugins/TgaImporter/Test/TgaImporterTest.cpp @@ -142,7 +142,7 @@ void TgaImporterTest::colorBits24() { #endif CORRADE_VERIFY(importer.openData(data)); - Trade::ImageData2D* image = importer.image2D(0); + std::optional image = importer.image2D(0); CORRADE_VERIFY(image); #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(image->format(), ImageFormat::BGR); @@ -152,8 +152,6 @@ void TgaImporterTest::colorBits24() { 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; } void TgaImporterTest::colorBits32() { @@ -175,7 +173,7 @@ void TgaImporterTest::colorBits32() { #endif CORRADE_VERIFY(importer.openData(data)); - Trade::ImageData2D* image = importer.image2D(0); + std::optional image = importer.image2D(0); CORRADE_VERIFY(image); #ifndef MAGNUM_TARGET_GLES CORRADE_COMPARE(image->format(), ImageFormat::BGRA); @@ -185,8 +183,6 @@ void TgaImporterTest::colorBits32() { 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; } void TgaImporterTest::grayscaleBits8() { @@ -199,7 +195,7 @@ void TgaImporterTest::grayscaleBits8() { }; CORRADE_VERIFY(importer.openData(data)); - Trade::ImageData2D* image = importer.image2D(0); + std::optional image = importer.image2D(0); CORRADE_VERIFY(image); CORRADE_COMPARE(image->format(), ImageFormat::Red); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); @@ -229,7 +225,7 @@ void TgaImporterTest::file() { }; CORRADE_VERIFY(importer.openFile(Utility::Directory::join(TGAIMPORTER_TEST_DIR, "file.tga"))); - Trade::ImageData2D* image = importer.image2D(0); + std::optional image = importer.image2D(0); CORRADE_VERIFY(image); CORRADE_COMPARE(image->format(), ImageFormat::Red); CORRADE_COMPARE(image->size(), Vector2i(2, 3)); diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 4838767ea..27a4fa30e 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -71,14 +71,14 @@ void TgaImporter::doClose() { UnsignedInt TgaImporter::doImage2DCount() const { return 1; } -ImageData2D* TgaImporter::doImage2D(UnsignedInt) { +std::optional TgaImporter::doImage2D(UnsignedInt) { /* Check if the file is long enough */ in->seekg(0, std::istream::end); std::streampos filesize = in->tellg(); in->seekg(0, std::istream::beg); if(filesize < std::streampos(sizeof(TgaHeader))) { Error() << "Trade::TgaImporter::image2D(): the file is too short:" << filesize << "bytes"; - return nullptr; + return std::nullopt; } TgaHeader header; @@ -92,7 +92,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { ImageFormat format; if(header.colorMapType != 0) { Error() << "Trade::TgaImporter::image2D(): paletted files are not supported"; - return nullptr; + return std::nullopt; } /* Color */ @@ -114,7 +114,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { break; default: Error() << "Trade::TgaImporter::image2D(): unsupported color bits-per-pixel:" << header.bpp; - return nullptr; + return std::nullopt; } /* Grayscale */ @@ -127,13 +127,13 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { #endif if(header.bpp != 8) { Error() << "Trade::TgaImporter::image2D(): unsupported grayscale bits-per-pixel:" << header.bpp; - return nullptr; + return std::nullopt; } /* Compressed files */ } else { 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; @@ -154,7 +154,7 @@ ImageData2D* TgaImporter::doImage2D(UnsignedInt) { } #endif - return new ImageData2D(format, ImageType::UnsignedByte, size, data); + return ImageData2D(format, ImageType::UnsignedByte, size, data); } }} diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index 0e08b168d..728c9ea69 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -73,7 +73,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 doClose() override; UnsignedInt MAGNUM_TRADE_TGAIMPORTER_LOCAL doImage2DCount() const override; - ImageData2D MAGNUM_TRADE_TGAIMPORTER_LOCAL * doImage2D(UnsignedInt id) override; + std::optional MAGNUM_TRADE_TGAIMPORTER_LOCAL doImage2D(UnsignedInt id) override; std::istream* in; };