Commit d3a73bdb authored by Davis King's avatar Davis King

Added the load_image() function which just looks at a file's extension and

then calls the appropriate image loading function.
parent beee293d
......@@ -6,6 +6,7 @@
#include "image_loader/image_loader.h"
#include "image_loader/png_loader.h"
#include "image_loader/jpeg_loader.h"
#include "image_loader/load_image.h"
#include "image_saver/image_saver.h"
#include "image_saver/save_png.h"
......
// Copyright (C) 2011 Davis E. King (davis@dlib.net), Nils Labugt
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_LOAd_IMAGE_H__
#define DLIB_LOAd_IMAGE_H__
#include "load_image_abstract.h"
#include "../string.h"
#include "png_loader.h"
#include "jpeg_loader.h"
#include "image_loader.h"
namespace dlib
{
template <typename image_type>
void load_image (
image_type& image,
const std::string& file_name
)
{
const std::string extension = tolower(right_substr(file_name,"."));
if (extension == "bmp")
load_bmp(image, file_name);
#ifdef DLIB_PNG_SUPPORT
else if (extension == "png")
load_png(image, file_name);
#endif
#ifdef DLIB_JPEG_SUPPORT
else if (extension == "jpeg" || extension == "jpg")
load_jpeg(image, file_name);
#endif
else if (extension == "dng")
load_dng(image, file_name);
else
{
if (extension == "jpeg" || extension == "jpg")
throw image_load_error("DLIB_JPEG_SUPPORT not #defined: Unable to load image in file " + file_name);
else if (extension == "png")
throw image_load_error("DLIB_PNG_SUPPORT not #defined: Unable to load image in file " + file_name);
else
throw image_load_error("Unknown file extension: Unable to load image in file " + file_name);
}
}
}
#endif // DLIB_LOAd_IMAGE_H__
// Copyright (C) 2011 Davis E. King (davis@dlib.net), Nils Labugt
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_LOAd_IMAGE_ABSTRACT_
#ifdef DLIB_LOAd_IMAGE_ABSTRACT_
#include "load_image_abstract.h"
#include "../string.h"
namespace dlib
{
template <typename image_type>
void load_image (
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
- let EXT == the extension of the file given by file_name converted
to lower case (i.e. the part of the file after the '.')
- if (EXT == "png") then
- performs: load_png(image, file_name);
- else if (EXT == "jpg" || EXT == "jpeg") then
- performs: load_jpeg(image, file_name);
- else if (EXT == "bmp") then
- performs: load_bmp(image, file_name);
- else if (EXT == "dng") then
- performs: load_dng(image, file_name);
- else
- throws image_load_error
throws
- image_load_error
This exception is thrown if there is some error that prevents
us from loading the given image file.
!*/
}
#endif // DLIB_LOAd_IMAGE_ABSTRACT_
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