core/vil/vil_image_resource_plugin.cxx
Go to the documentation of this file.
00001 // This is core/vil/vil_image_resource_plugin.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \brief Interface for loading new image formats
00008 // This class provides an interface for loading images in new formats
00009 // \author      Franck Bettinger
00010 // \date        Sun Mar 17 22:57:00 2002
00011 
00012 #include "vil_image_resource_plugin.h"
00013 #include <vcl_vector.h>
00014 
00015 //=======================================================================
00016 
00017 static vcl_vector<vil_image_resource_plugin*>
00018     *vil_image_resource_plugins_list_ = 0;
00019 
00020 //=======================================================================
00021 
00022 bool vil_image_resource_plugin::load_the_image (
00023     vil_image_view_base_sptr& image,
00024     const vcl_string & path, const vcl_string & filetype,
00025     const vcl_string & colour)
00026 {
00027   if (vil_image_resource_plugins_list_==0 ||
00028       is_a()!=vcl_string("vil_image_resource_plugin"))
00029   {
00030     return false;
00031   }
00032 
00033   for (unsigned int i=0;i<vil_image_resource_plugins_list_->size();i++)
00034   {
00035     if (vil_image_resource_plugins_list_->operator[](i)->load_the_image(
00036         image,path,filetype,colour))
00037     {
00038       return true;
00039     }
00040   }
00041 
00042   return false;
00043 }
00044 
00045 //=======================================================================
00046 
00047 void vil_image_resource_plugin::register_plugin(
00048     vil_image_resource_plugin* plugin)
00049 {
00050   if (plugin==0 || plugin->is_a()==vcl_string("vil_image_resource_plugin"))
00051   {
00052     return;
00053   }
00054 
00055   if (vil_image_resource_plugins_list_==0)
00056   {
00057     vil_image_resource_plugins_list_ =
00058       new vcl_vector<vil_image_resource_plugin*>();
00059   }
00060 
00061   vil_image_resource_plugins_list_->push_back(plugin);
00062 }
00063 
00064 //=======================================================================
00065 
00066 void vil_image_resource_plugin::delete_all_plugins()
00067 {
00068   if (vil_image_resource_plugins_list_==0) return;
00069   unsigned int n = (unsigned int)(vil_image_resource_plugins_list_->size());
00070   for (unsigned int i=0;i<n;++i)
00071     delete vil_image_resource_plugins_list_->operator[](i);
00072   vil_image_resource_plugins_list_->resize(0);
00073 
00074   // Clean up the list itself
00075   delete vil_image_resource_plugins_list_;
00076   vil_image_resource_plugins_list_=0;
00077 }
00078 
00079 //=======================================================================
00080 
00081 bool vil_image_resource_plugin::can_be_loaded(const vcl_string& filename)
00082 {
00083   if (vil_image_resource_plugins_list_==0 ||
00084       is_a()!=vcl_string("vil_image_resource_plugin"))
00085   {
00086     return false;
00087   }
00088 
00089   for (unsigned int i=0;i<vil_image_resource_plugins_list_->size();i++)
00090   {
00091     if (vil_image_resource_plugins_list_->operator[](i)->can_be_loaded(
00092         filename))
00093     {
00094       return true;
00095     }
00096   }
00097   return false;
00098 }