vil_image_resource_plugin.cxx
Go to the documentation of this file.
1 // This is core/vil/vil_image_resource_plugin.cxx
2 //:
3 // \file
4 // \brief Interface for loading new image formats
5 // This class provides an interface for loading images in new formats
6 // \author Franck Bettinger
7 // \date Sun Mar 17 22:57:00 2002
8 
9 #include <vector>
11 #ifdef _MSC_VER
12 # include <vcl_msvc_warnings.h>
13 #endif
14 
15 //=======================================================================
16 
17 static std::vector<vil_image_resource_plugin*>
18  *vil_image_resource_plugins_list_ = nullptr;
19 
20 //=======================================================================
21 
24  const std::string & path, const std::string & filetype,
25  const std::string & colour)
26 {
27  if (vil_image_resource_plugins_list_==nullptr ||
28  is_a()!=std::string("vil_image_resource_plugin"))
29  {
30  return false;
31  }
32 
33  for (unsigned int i=0;i<vil_image_resource_plugins_list_->size();i++)
34  {
35  if (vil_image_resource_plugins_list_->operator[](i)->load_the_image(
36  image,path,filetype,colour))
37  {
38  return true;
39  }
40  }
41 
42  return false;
43 }
44 
45 //=======================================================================
46 
49 {
50  if (plugin==nullptr || plugin->is_a()==std::string("vil_image_resource_plugin"))
51  {
52  return;
53  }
54 
55  if (vil_image_resource_plugins_list_==nullptr)
56  {
57  vil_image_resource_plugins_list_ =
58  new std::vector<vil_image_resource_plugin*>();
59  }
60 
61  vil_image_resource_plugins_list_->push_back(plugin);
62 }
63 
64 //=======================================================================
65 
67 {
68  if (vil_image_resource_plugins_list_==nullptr) return;
69  auto n = (unsigned int)(vil_image_resource_plugins_list_->size());
70  for (unsigned int i=0;i<n;++i)
71  delete vil_image_resource_plugins_list_->operator[](i);
72  vil_image_resource_plugins_list_->resize(0);
73 
74  // Clean up the list itself
75  delete vil_image_resource_plugins_list_;
76  vil_image_resource_plugins_list_=nullptr;
77 }
78 
79 //=======================================================================
80 
81 bool vil_image_resource_plugin::can_be_loaded(const std::string& filename)
82 {
83  if (vil_image_resource_plugins_list_==nullptr ||
84  is_a()!=std::string("vil_image_resource_plugin"))
85  {
86  return false;
87  }
88 
89  for (unsigned int i=0;i<vil_image_resource_plugins_list_->size();i++)
90  {
91  if (vil_image_resource_plugins_list_->operator[](i)->can_be_loaded(
92  filename))
93  {
94  return true;
95  }
96  }
97  return false;
98 }
static void register_plugin(vil_image_resource_plugin *plugin)
Register a vil_image_resource_plugin to the list of plugins.
Interface for loading new image formats.
virtual bool can_be_loaded(const std::string &filename)
Check whether a filename is a potential candidate for loading and if it is available.
virtual std::string is_a() const
Name of the class.
virtual bool load_the_image(vil_image_view_base_sptr &image, const std::string &path)
Attempt to load image from named file.
static void delete_all_plugins()
Delete all registered plugins.
A base class for a plugin for vil images loading.