Commit beee293d authored by Davis King's avatar Davis King

Added a bunch of overloads for all the various save_*() and load_*() image

I/O options dlib supports.  Also added ones which can work directly with
a string file name.
parent 998c7b2f
...@@ -759,6 +759,34 @@ namespace dlib ...@@ -759,6 +759,34 @@ namespace dlib
} }
// ----------------------------------------------------------------------------------------
template <typename image_type>
void load_bmp (
image_type& image,
const std::string& file_name
)
{
std::ifstream fin(file_name.c_str(), std::ios::binary);
if (!fin)
throw image_save_error("Unable to open " + file_name + " for reading.");
load_bmp(image, fin);
}
// ----------------------------------------------------------------------------------------
template <typename image_type>
void load_dng (
image_type& image,
const std::string& file_name
)
{
std::ifstream fin(file_name.c_str(), std::ios::binary);
if (!fin)
throw image_save_error("Unable to open " + file_name + " for reading.");
load_dng(image, fin);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -37,7 +37,7 @@ namespace dlib ...@@ -37,7 +37,7 @@ namespace dlib
- #image[0][0] will be the upper left corner of the image - #image[0][0] will be the upper left corner of the image
- #image[image.nr()-1][image.nc()-1] will be the lower right - #image[image.nr()-1][image.nc()-1] will be the lower right
corner of the image corner of the image
- Performs any color space conversion necessairy to convert the - Performs any color space conversion necessary to convert the
BMP image data into the pixel type used by the given image BMP image data into the pixel type used by the given image
object. object.
throws throws
...@@ -50,6 +50,25 @@ namespace dlib ...@@ -50,6 +50,25 @@ namespace dlib
value for its type. value for its type.
!*/ !*/
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
void load_bmp (
image_type& image,
const std::string& file_name
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
ensures
- opens the file indicated by file_name with an input file stream named fin
and performs:
load_bmp(image,fin);
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
/*! /*!
...@@ -76,7 +95,7 @@ namespace dlib ...@@ -76,7 +95,7 @@ namespace dlib
- #image[0][0] will be the upper left corner of the image - #image[0][0] will be the upper left corner of the image
- #image[image.nr()-1][image.nc()-1] will be the lower right - #image[image.nr()-1][image.nc()-1] will be the lower right
corner of the image corner of the image
- Performs any color space conversion necessairy to convert the - Performs any color space conversion necessary to convert the
dng image data into the pixel type used by the given image dng image data into the pixel type used by the given image
object. object.
throws throws
...@@ -89,6 +108,25 @@ namespace dlib ...@@ -89,6 +108,25 @@ namespace dlib
value for its type. value for its type.
!*/ !*/
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
void load_dng (
image_type& image,
const std::string& file_name
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
ensures
- opens the file indicated by file_name with an input file stream named fin
and performs:
load_dng(image,fin);
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
...@@ -72,6 +72,22 @@ namespace dlib ...@@ -72,6 +72,22 @@ namespace dlib
unsigned long output_components_; unsigned long output_components_;
std::vector<unsigned char> data; std::vector<unsigned char> data;
}; };
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
void load_jpeg (
image_type& image,
const std::string& file_name
)
{
jpeg_loader(file_name).get_image(image);
}
// ----------------------------------------------------------------------------------------
} }
#ifdef NO_MAKEFILE #ifdef NO_MAKEFILE
......
...@@ -106,6 +106,26 @@ namespace dlib ...@@ -106,6 +106,26 @@ namespace dlib
!*/ !*/
}; };
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
void load_jpeg (
image_type& image,
const std::string& file_name
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
ensures
- performs: jpeg_loader(file_name).get_image(image);
!*/
// ----------------------------------------------------------------------------------------
} }
#endif // DLIB_JPEG_IMPORT_ABSTRACT #endif // DLIB_JPEG_IMPORT_ABSTRACT
......
...@@ -140,6 +140,22 @@ namespace dlib ...@@ -140,6 +140,22 @@ namespace dlib
int color_type_; int color_type_;
scoped_ptr<LibpngData> ld_; scoped_ptr<LibpngData> ld_;
}; };
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
void load_png (
image_type& image,
const std::string& file_name
)
{
png_loader(file_name).get_image(image);
}
// ----------------------------------------------------------------------------------------
} }
#ifdef NO_MAKEFILE #ifdef NO_MAKEFILE
......
...@@ -124,6 +124,26 @@ namespace dlib ...@@ -124,6 +124,26 @@ namespace dlib
!*/ !*/
}; };
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
void load_png (
image_type& image,
const std::string& file_name
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
ensures
- performs: png_loader(file_name).get_image(image);
!*/
// ----------------------------------------------------------------------------------------
} }
#endif // DLIB_PNG_IMPORT_ABSTRACT #endif // DLIB_PNG_IMPORT_ABSTRACT
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "image_saver_abstract.h" #include "image_saver_abstract.h"
#include <iostream> #include <iostream>
#include <fstream>
#include <sstream> #include <sstream>
#include "../algs.h" #include "../algs.h"
#include "../pixel.h" #include "../pixel.h"
...@@ -13,6 +14,7 @@ ...@@ -13,6 +14,7 @@
#include "../entropy_encoder_model.h" #include "../entropy_encoder_model.h"
#include "dng_shared.h" #include "dng_shared.h"
#include "../uintn.h" #include "../uintn.h"
#include "../dir_nav.h"
namespace dlib namespace dlib
{ {
...@@ -524,6 +526,33 @@ namespace dlib ...@@ -524,6 +526,33 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename image_type>
void save_dng (
const image_type& image,
const std::string& file_name
)
{
std::ofstream fout(file_name.c_str(), std::ios::binary);
if (!fout)
throw image_save_error("Unable to open " + file_name + " for writing.");
save_dng(image, fout);
}
// ----------------------------------------------------------------------------------------
template <typename image_type>
void save_bmp (
const image_type& image,
const std::string& file_name
)
{
std::ofstream fout(file_name.c_str(), std::ios::binary);
if (!fout)
throw image_save_error("Unable to open " + file_name + " for writing.");
save_bmp(image, fout);
}
// ----------------------------------------------------------------------------------------
} }
......
...@@ -43,6 +43,25 @@ namespace dlib ...@@ -43,6 +43,25 @@ namespace dlib
- std::bad_alloc - std::bad_alloc
!*/ !*/
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
void save_bmp (
const image_type& image,
const std::string& file_name
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
ensures
- opens the file indicated by file_name with an output file stream named fout
and performs:
save_bmp(image,fout);
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
/*! /*!
...@@ -75,6 +94,23 @@ namespace dlib ...@@ -75,6 +94,23 @@ namespace dlib
- std::bad_alloc - std::bad_alloc
!*/ !*/
// ----------------------------------------------------------------------------------------
template <typename image_type>
void save_dng (
const image_type& image,
const std::string& file_name
);
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
ensures
- opens the file indicated by file_name with an output file stream named fout
and performs:
save_dng(image,fout);
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
......
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