* mln/io/magick/save.hh: Add save_options structure.
---
milena/ChangeLog | 6 ++
milena/mln/io/magick/save.hh | 141 ++++++++++++++++++++++++++++++++++-------
2 files changed, 123 insertions(+), 24 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 1e49435..775731e 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,11 @@
2013-04-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add save options to magick::save.
+
+ * mln/io/magick/save.hh: Add save_options structure.
+
+2013-04-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add a new routine to get image headers thanks to GraphicsMagick.
* mln/io/magick/get_header.hh,
diff --git a/milena/mln/io/magick/save.hh b/milena/mln/io/magick/save.hh
index d8ca8a1..8437462 100644
--- a/milena/mln/io/magick/save.hh
+++ b/milena/mln/io/magick/save.hh
@@ -58,29 +58,71 @@ namespace mln
namespace magick
{
- /*! \brief Save a Milena image into a file using Magick++.
- \overload
+ /*!
+ \brief Store specific save options to use with Magick++.
+ \ingroup iomagick
+ */
+ struct save_options
+ {
+ save_options();
+
+ /*! \brief Define the compression algorithm.
+
+ By default it is set to Magick::NoCompression.
+ */
+ Magick::CompressionType compression_type;
+
+ /*! \brief Define the image type in output (RGB, Bilevel,...).
+
+ By default it is set to Magick::OptimizeType which will
+ decide automatically the best type according to image
+ characteristics.
+ */
+ Magick::ImageType image_type;
+ };
+
- \param[in] ima The image to save.
- \param[in] filename The name of the output file.
+ /*!
+ \brief Save a Milena image into a file using Magick++.
+ \overload
- \ingroup iomagick
+ \param[in] ima The image to save.
+ \param[in] filename The name of the output file.
+
+ \ingroup iomagick
*/
template <typename I>
void
save(const Image<I>& ima, const std::string& filename);
- /*! \brief Save a Milena image into a file using Magick++.
- \param[in] ima The image to save.
+ /*!
+ \brief Save a Milena image into a file using Magick++.
+ \overload
+
+ \param[in] ima The image to save.
+ \param[in] options Save options.
+ \param[in] filename The name of the output file.
+
+ \ingroup iomagick
+ */
+ template <typename I>
+ void
+ save(const Image<I>& ima, const save_options& options,
+ const std::string& filename);
+
+ /*!
+ \brief Save a Milena image into a file using Magick++.
+ \overload
- \param[in] opacity_mask Mask used to set pixel opacity_mask in output
- image. Output format must support this feature to be taken
- into account.
+ \param[in] ima The image to save.
+ \param[in] opacity_mask Mask used to set pixel opacity_mask in output
+ image. Output format must support this feature to be taken
+ into account.
- \param[in] filename The name of the output file.
+ \param[in] filename The name of the output file.
- \ingroup iomagick
+ \ingroup iomagick
*/
template <typename I, typename J>
void
@@ -88,20 +130,39 @@ namespace mln
const std::string& filename);
- // FIXME: Unfinished?
-#if 0
- /** Save a Milena tiled image into a file using Magick++.
+ /*!
+ \brief Save a Milena image into a file using Magick++.
- \param[out] ima The image to save.
- \param[in] filename The name of the output file. */
- template <typename T>
+ \param[in] ima The image to save.
+ \param[in] opacity_mask Mask used to set pixel opacity_mask in output
+ image. Output format must support this feature to be taken
+ into account.
+ \param[in] options Save options.
+ \param[in] filename The name of the output file.
+
+ \ingroup iomagick
+ */
+ template <typename I, typename J>
void
- save(const Image< tiled2d<T> >& ima, const std::string&
filename);
-#endif
+ save(const Image<I>& ima, const Image<J>& opacity_mask,
+ const save_options& options, const std::string& filename);
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ inline
+ void set_options(Magick::Image& magick_ima,
+ const save_options& options)
+ {
+ magick_ima.compressType(options.compression_type);
+ magick_ima.type(options.image_type);
+ }
+
+ } // end of mln::io::magick::internal
+
namespace impl
{
@@ -468,10 +529,22 @@ namespace mln
} // end of namespace mln::io::magick::internal
+ // save_options
+ inline
+ save_options::save_options()
+ : compression_type(Magick::NoCompression),
+ image_type(Magick::OptimizeType)
+ {
+ }
+
+
+
+ // Facades
+
template <typename I, typename J>
void
save(const Image<I>& ima_, const Image<J>& opacity_mask_,
- const std::string& filename)
+ const save_options& options, const std::string& filename)
{
mln_trace("mln::io::magick::save");
@@ -524,21 +597,41 @@ namespace mln
internal::paste_data_dispatch(ima, magick_ima);
}
+ // Take options into account.
+ internal::set_options(magick_ima, options);
+
magick_ima.write(filename);
}
-
-
template <typename I>
inline
void
save(const Image<I>& ima, const std::string& filename)
{
mln_ch_value(I,bool) opacity_mask;
- save(ima, opacity_mask, filename);
+ save_options options;
+ save(ima, opacity_mask, options, filename);
+ }
+
+ template <typename I>
+ inline
+ void
+ save(const Image<I>& ima, const save_options& options,
+ const std::string& filename)
+ {
+ mln_ch_value(I,bool) opacity_mask;
+ save(ima, opacity_mask, options, filename);
}
+ template <typename I, typename J>
+ void
+ save(const Image<I>& ima, const Image<J>& opacity_mask,
+ const std::string& filename)
+ {
+ save_options options;
+ save(ima, opacity_mask, options, filename);
+ }
# endif // ! MLN_INCLUDE_ONLY
--
1.7.2.5