Commit bb5e847b authored by Davis King's avatar Davis King

Made image saving routines work on matrix objects in addition to array2d

objects.
parent 13b8c5f3
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "../dir_nav.h" #include "../dir_nav.h"
#include "../float_details.h" #include "../float_details.h"
#include "../vectorstream.h" #include "../vectorstream.h"
#include "../matrix/matrix_exp.h"
#include "../image_transforms/assign_image.h"
namespace dlib namespace dlib
{ {
...@@ -229,7 +231,7 @@ namespace dlib ...@@ -229,7 +231,7 @@ namespace dlib
template < template <
typename image_type typename image_type
> >
inline void save_bmp ( inline typename disable_if<is_matrix<image_type> >::type save_bmp (
const image_type& image, const image_type& image,
std::ostream& out std::ostream& out
) )
...@@ -237,6 +239,19 @@ namespace dlib ...@@ -237,6 +239,19 @@ namespace dlib
save_bmp_helper<image_type>::save_bmp(image,out); save_bmp_helper<image_type>::save_bmp(image,out);
} }
template <
typename EXP
>
inline void save_bmp (
const matrix_exp<EXP>& image,
std::ostream& out
)
{
array2d<typename EXP::type> temp;
assign_image(temp, image);
save_bmp_helper<array2d<typename EXP::type> >::save_bmp(temp,out);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
namespace dng_helpers_namespace namespace dng_helpers_namespace
...@@ -578,7 +593,7 @@ namespace dlib ...@@ -578,7 +593,7 @@ namespace dlib
template < template <
typename image_type typename image_type
> >
inline void save_dng ( inline typename disable_if<is_matrix<image_type> >::type save_dng (
const image_type& image, const image_type& image,
std::ostream& out std::ostream& out
) )
...@@ -587,6 +602,20 @@ namespace dlib ...@@ -587,6 +602,20 @@ namespace dlib
save_dng_helper<image_type>::save_dng(image,out); save_dng_helper<image_type>::save_dng(image,out);
} }
template <
typename EXP
>
inline void save_dng (
const matrix_exp<EXP>& image,
std::ostream& out
)
{
array2d<typename EXP::type> temp;
assign_image(temp, image);
using namespace dng_helpers_namespace;
save_dng_helper<array2d<typename EXP::type> >::save_dng(temp,out);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename image_type> template <typename image_type>
......
...@@ -29,7 +29,8 @@ namespace dlib ...@@ -29,7 +29,8 @@ namespace dlib
); );
/*! /*!
requires requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h - image_type == is an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix
- pixel_traits<typename image_type::type> is defined - pixel_traits<typename image_type::type> is defined
ensures ensures
- writes the image to the out stream in the Microsoft Windows BMP format. - writes the image to the out stream in the Microsoft Windows BMP format.
...@@ -57,7 +58,8 @@ namespace dlib ...@@ -57,7 +58,8 @@ namespace dlib
); );
/*! /*!
requires requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h - image_type == is an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix
- pixel_traits<typename image_type::type> is defined - pixel_traits<typename image_type::type> is defined
ensures ensures
- opens the file indicated by file_name with an output file stream named fout - opens the file indicated by file_name with an output file stream named fout
...@@ -83,7 +85,8 @@ namespace dlib ...@@ -83,7 +85,8 @@ namespace dlib
); );
/*! /*!
requires requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h - image_type == is an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix
- pixel_traits<typename image_type::type> is defined - pixel_traits<typename image_type::type> is defined
ensures ensures
- writes the image to the out stream in the dlib dng format. - writes the image to the out stream in the dlib dng format.
...@@ -111,7 +114,8 @@ namespace dlib ...@@ -111,7 +114,8 @@ namespace dlib
); );
/*! /*!
requires requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h - image_type == is an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix
- pixel_traits<typename image_type::type> is defined - pixel_traits<typename image_type::type> is defined
ensures ensures
- opens the file indicated by file_name with an output file stream named fout - opens the file indicated by file_name with an output file stream named fout
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "../pixel.h" #include "../pixel.h"
#include "../matrix/matrix_exp.h"
#include "../image_transforms/assign_image.h"
namespace dlib namespace dlib
{ {
...@@ -38,7 +40,7 @@ namespace dlib ...@@ -38,7 +40,7 @@ namespace dlib
template < template <
typename image_type typename image_type
> >
void save_png( typename disable_if<is_matrix<image_type> >::type save_png(
const image_type& img, const image_type& img,
const std::string& file_name const std::string& file_name
) )
...@@ -130,6 +132,24 @@ namespace dlib ...@@ -130,6 +132,24 @@ namespace dlib
#endif #endif
} }
// ----------------------------------------------------------------------------------------
template <
typename EXP
>
void save_png(
const matrix_exp<EXP>& img,
const std::string& file_name
)
{
array2d<typename EXP::type> temp;
assign_image(temp, img);
save_png(temp, file_name);
}
// ----------------------------------------------------------------------------------------
} }
#ifdef NO_MAKEFILE #ifdef NO_MAKEFILE
......
...@@ -19,7 +19,8 @@ namespace dlib ...@@ -19,7 +19,8 @@ namespace dlib
); );
/*! /*!
requires requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h - image_type == is an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix
- pixel_traits<typename image_type::type> is defined - pixel_traits<typename image_type::type> is defined
- image.size() != 0 - image.size() != 0
ensures ensures
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment