From c1c02dea5818be742981b309561cbc5930e3e693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 28 Jun 2021 19:08:57 +0200 Subject: [PATCH] Trade: make Abstract{Image,Scene}Converter::doConvertToFile() protected. This is already done for the AbstractImporter and the new AbstractShaderConverter, as there's a common use case of checking just the filename for input/output path or file type detection and then delegating to the common implementation working directly on data. --- doc/changelog.dox | 7 ++ src/Magnum/Trade/AbstractImageConverter.h | 136 ++++++++++++---------- src/Magnum/Trade/AbstractSceneConverter.h | 22 ++-- 3 files changed, 96 insertions(+), 69 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index f793a0160..9820f2f47 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -335,6 +335,13 @@ See also: @subsubsection changelog-latest-changes-trade Trade library +- @ref Trade::AbstractImageConverter::doConvertToFile() and + @ref Trade::AbstractSceneConverter::doConvertToFile() are now + @cpp protected @ce instead of @cpp private @ce to allow calling them from + plugin implementations and reuse the provided fallback to + @relativeref{Trade::AbstractImageConverter,doConvertToData()}, for example + when the implementation only neeeds to do a format detection based on file + extension - Recognizing TIFF file header magic in @ref Trade::AnyImageImporter "AnyImageImporter" - @ref Audio::AnyImporter "AnyAudioImporter", @relativeref{Trade,AnyImageImporter}, @relativeref{Trade,AnyImageConverter}, diff --git a/src/Magnum/Trade/AbstractImageConverter.h b/src/Magnum/Trade/AbstractImageConverter.h index e44adc466..0e4ad45a2 100644 --- a/src/Magnum/Trade/AbstractImageConverter.h +++ b/src/Magnum/Trade/AbstractImageConverter.h @@ -870,6 +870,82 @@ class MAGNUM_TRADE_EXPORT AbstractImageConverter: public PluginManager::Abstract */ bool convertToFile(const ImageData3D& image, Containers::StringView filename); + protected: + /** + * @brief Implementation for @ref convertToFile(const ImageView1D&, Containers::StringView) + * @m_since_latest + * + * If @ref ImageConverterFeature::Convert1DToData is supported, default + * implementation calls @ref doConvertToData(const ImageView1D&) and + * saves the result to given file. It is allowed to call this function + * from your @ref doConvertToFile() implementation, for example when + * you only need to do format detection based on file extension. + */ + virtual bool doConvertToFile(const ImageView1D& image, Containers::StringView filename); + + /** + * @brief Implementation for @ref convertToFile(const ImageView2D&, Containers::StringView) + * @m_since_latest + * + * If @ref ImageConverterFeature::Convert2DToData is supported, default + * implementation calls @ref doConvertToData(const ImageView2D&) and + * saves the result to given file. It is allowed to call this function + * from your @ref doConvertToFile() implementation, for example when + * you only need to do format detection based on file extension. + */ + virtual bool doConvertToFile(const ImageView2D& image, Containers::StringView filename); + + /** + * @brief Implementation for @ref convertToFile(const ImageView3D&, Containers::StringView) + * @m_since_latest + * + * If @ref ImageConverterFeature::Convert3DToData is supported, default + * implementation calls @ref doConvertToData(const ImageView3D&) and + * saves the result to given file. It is allowed to call this function + * from your @ref doConvertToFile() implementation, for example when + * you only need to do format detection based on file extension. + */ + virtual bool doConvertToFile(const ImageView3D& image, Containers::StringView filename); + + /** + * @brief Implementation for @ref convertToFile(const CompressedImageView1D&, Containers::StringView) + * @m_since_latest + * + * If @ref ImageConverterFeature::ConvertCompressed1DToData is + * supported, default implementation calls @ref doConvertToData(const CompressedImageView1D&) + * and saves the result to given file. It is allowed to call this + * function from your @ref doConvertToFile() implementation, for + * example when you only need to do format detection based on file + * extension. + */ + virtual bool doConvertToFile(const CompressedImageView1D& image, Containers::StringView filename); + + /** + * @brief Implementation for @ref convertToFile(const CompressedImageView2D&, Containers::StringView) + * @m_since_latest + * + * If @ref ImageConverterFeature::ConvertCompressed2DToData is + * supported, default implementation calls @ref doConvertToData(const CompressedImageView2D&) + * and saves the result to given file. It is allowed to call this + * function from your @ref doConvertToFile() implementation, for + * example when you only need to do format detection based on file + * extension. + */ + virtual bool doConvertToFile(const CompressedImageView2D& image, Containers::StringView filename); + + /** + * @brief Implementation for @ref convertToFile(const CompressedImageView3D&, Containers::StringView) + * @m_since_latest + * + * If @ref ImageConverterFeature::ConvertCompressed3DToData is + * supported, default implementation calls @ref doConvertToData(const CompressedImageView3D&) + * and saves the result to given file. It is allowed to call this + * function from your @ref doConvertToFile() implementation, for + * example when you only need to do format detection based on file + * extension. + */ + virtual bool doConvertToFile(const CompressedImageView3D& image, Containers::StringView filename); + private: /** @brief Implementation for @ref features() */ virtual ImageConverterFeatures doFeatures() const = 0; @@ -962,66 +1038,6 @@ class MAGNUM_TRADE_EXPORT AbstractImageConverter: public PluginManager::Abstract */ virtual Containers::Array doConvertToData(const CompressedImageView3D& image); - /** - * @brief Implementation for @ref convertToFile(const ImageView1D&, Containers::StringView) - * @m_since_latest - * - * If @ref ImageConverterFeature::Convert1DToData is supported, default - * implementation calls @ref doConvertToData(const ImageView1D&) and - * saves the result to given file. - */ - virtual bool doConvertToFile(const ImageView1D& image, Containers::StringView filename); - - /** - * @brief Implementation for @ref convertToFile(const ImageView2D&, Containers::StringView) - * @m_since_latest - * - * If @ref ImageConverterFeature::Convert2DToData is supported, default - * implementation calls @ref doConvertToData(const ImageView2D&) and - * saves the result to given file. - */ - virtual bool doConvertToFile(const ImageView2D& image, Containers::StringView filename); - - /** - * @brief Implementation for @ref convertToFile(const ImageView3D&, Containers::StringView) - * @m_since_latest - * - * If @ref ImageConverterFeature::Convert3DToData is supported, default - * implementation calls @ref doConvertToData(const ImageView3D&) and - * saves the result to given file. - */ - virtual bool doConvertToFile(const ImageView3D& image, Containers::StringView filename); - - /** - * @brief Implementation for @ref convertToFile(const CompressedImageView1D&, Containers::StringView) - * @m_since_latest - * - * If @ref ImageConverterFeature::ConvertCompressed1DToData is - * supported, default implementation calls @ref doConvertToData(const CompressedImageView1D&) - * and saves the result to given file. - */ - virtual bool doConvertToFile(const CompressedImageView1D& image, Containers::StringView filename); - - /** - * @brief Implementation for @ref convertToFile(const CompressedImageView2D&, Containers::StringView) - * @m_since_latest - * - * If @ref ImageConverterFeature::ConvertCompressed2DToData is - * supported, default implementation calls @ref doConvertToData(const CompressedImageView2D&) - * and saves the result to given file. - */ - virtual bool doConvertToFile(const CompressedImageView2D& image, Containers::StringView filename); - - /** - * @brief Implementation for @ref convertToFile(const CompressedImageView3D&, Containers::StringView) - * @m_since_latest - * - * If @ref ImageConverterFeature::ConvertCompressed3DToData is - * supported, default implementation calls @ref doConvertToData(const CompressedImageView3D&) - * and saves the result to given file. - */ - virtual bool doConvertToFile(const CompressedImageView3D& image, Containers::StringView filename); - ImageConverterFlags _flags; }; diff --git a/src/Magnum/Trade/AbstractSceneConverter.h b/src/Magnum/Trade/AbstractSceneConverter.h index b5587f4af..c1f13c7f7 100644 --- a/src/Magnum/Trade/AbstractSceneConverter.h +++ b/src/Magnum/Trade/AbstractSceneConverter.h @@ -318,6 +318,19 @@ class MAGNUM_TRADE_EXPORT AbstractSceneConverter: public PluginManager::Abstract CORRADE_DEPRECATED("use convertToFile(const MeshData&, Containers::StringView) instead") bool convertToFile(const std::string& filename, const MeshData& mesh); #endif + protected: + /** + * @brief Implementation for @ref convertToFile(const MeshData&, Containers::StringView) + * + * If @ref SceneConverterFeature::ConvertMeshToData is supported, + * default implementation calls @ref doConvertToData(const MeshData&) + * and saves the result to given file. It is allowed to call this + * function from your @ref doConvertToFile() implementation, for + * example when you only need to do format detection based on file + * extension. + */ + virtual bool doConvertToFile(const MeshData& mesh, Containers::StringView filename); + private: /** * @brief Implementation for @ref features() @@ -350,15 +363,6 @@ class MAGNUM_TRADE_EXPORT AbstractSceneConverter: public PluginManager::Abstract /** @brief Implementation for @ref convertToData(const MeshData&) */ virtual Containers::Array doConvertToData(const MeshData& mesh); - /** - * @brief Implementation for @ref convertToFile(const MeshData&, Containers::StringView) - * - * If @ref SceneConverterFeature::ConvertMeshToData is supported, - * default implementation calls @ref doConvertToData(const MeshData&) - * and saves the result to given file. - */ - virtual bool doConvertToFile(const MeshData& mesh, Containers::StringView filename); - SceneConverterFlags _flags; };