mlpack
image_info_impl.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_DATA_IMAGE_INFO_IMPL_HPP
14 #define MLPACK_CORE_DATA_IMAGE_INFO_IMPL_HPP
15 
16 #ifdef HAS_STB // Compile this only if stb is present.
17 
18 // In case it hasn't been included yet.
19 #include "image_info.hpp"
20 
21 namespace mlpack {
22 namespace data {
23 
24 static const std::vector<std::string> loadFileTypes({"jpg", "png", "tga",
25  "bmp", "psd", "gif", "hdr", "pic", "pnm", "jpeg"});
26 
27 static const std::vector<std::string> saveFileTypes({"jpg", "png", "tga",
28  "bmp", "hdr"});
29 
30 inline bool ImageFormatSupported(const std::string& fileName, const bool save)
31 {
32  if (save)
33  {
34  // Iterate over all supported file types that can be saved.
35  for (auto extension : saveFileTypes)
36  {
37  if (extension == Extension(fileName))
38  return true;
39  }
40  }
41  else
42  {
43  // Iterate over all supported file types that can be loaded.
44  for (auto extension : loadFileTypes)
45  {
46  if (extension == Extension(fileName))
47  return true;
48  }
49  }
50 
51  return false;
52 }
53 
54 } // namespace data
55 } // namespace mlpack
56 
57 #endif // HAS_STB.
58 
59 namespace mlpack {
60 namespace data {
61 
62 inline ImageInfo::ImageInfo(const size_t width,
63  const size_t height,
64  const size_t channels,
65  const size_t quality) :
66  width(width),
67  height(height),
68  channels(channels),
69  quality(quality)
70 {
71  // Do nothing.
72 }
73 
74 } // namespace data
75 } // namespace mlpack
76 
77 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
bool ImageFormatSupported(const std::string &fileName, const bool save=false)
Checks if the given image filename is supported.
ImageInfo(const size_t width=0, const size_t height=0, const size_t channels=3, const size_t quality=90)
Instantiate the ImageInfo object with the given image width, height, number of channels and quality p...
Definition: image_info_impl.hpp:62