From dc0895142ab59e1b0b8f89ae94f3aecc78797e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sat, 23 Jun 2012 14:03:45 +0200 Subject: [PATCH] Ability to explicitly specify name for image from TgaImporter. --- src/Plugins/TgaImporter/TgaImporter.cpp | 8 ++++---- src/Plugins/TgaImporter/TgaImporter.h | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Plugins/TgaImporter/TgaImporter.cpp b/src/Plugins/TgaImporter/TgaImporter.cpp index 7a9f70d5b..cfb3bc3bd 100644 --- a/src/Plugins/TgaImporter/TgaImporter.cpp +++ b/src/Plugins/TgaImporter/TgaImporter.cpp @@ -28,18 +28,18 @@ namespace Magnum { namespace Trade { namespace TgaImporter { static_assert(sizeof(TgaImporter::Header) == 18, "TgaImporter: header size is not 18 bytes"); #endif -bool TgaImporter::TgaImporter::open(const string& filename) { +bool TgaImporter::TgaImporter::open(const string& filename, const string& name) { ifstream in(filename.c_str()); if(!in.good()) { Error() << "TgaImporter: cannot open file" << filename; return false; } - bool status = open(in); + bool status = open(in, name); in.close(); return status; } -bool TgaImporter::open(istream& in) { +bool TgaImporter::open(istream& in, const string& name) { if(_image) close(); if(!in.good()) { Error() << "TgaImporter: cannot read input stream"; @@ -91,7 +91,7 @@ bool TgaImporter::open(istream& in) { Math::Vector2 dimensions(header.width, header.height); - _image = new ImageData2D(dimensions, components, buffer); + _image = new ImageData2D(name, dimensions, components, buffer); return true; } diff --git a/src/Plugins/TgaImporter/TgaImporter.h b/src/Plugins/TgaImporter/TgaImporter.h index daab490bc..8a61fb70d 100644 --- a/src/Plugins/TgaImporter/TgaImporter.h +++ b/src/Plugins/TgaImporter/TgaImporter.h @@ -46,8 +46,22 @@ class TGAIMPORTER_EXPORT TgaImporter: public AbstractImporter { inline Features features() const { return Feature::OpenFile|Feature::OpenStream; } - bool open(std::istream& in); - bool open(const std::string& filename); + /** + * @brief Open input stream with specific image name + * + * @see open(std::istream&), ImageData2D::name() + */ + bool open(std::istream& in, const std::string& name); + inline bool open(std::istream& in) { return open(in, ""); } + + /** + * @brief Open file with specific image name + * + * @see open(const std::string&), ImageData2D::name() + */ + bool open(const std::string& filename, const std::string& name); + inline bool open(const std::string& filename) { return open(filename, ""); } + void close(); inline unsigned int image2DCount() const { return _image ? 1 : 0; }