core/vil/vil_image_resource_plugin.h
Go to the documentation of this file.
00001 // This is core/vil/vil_image_resource_plugin.h
00002 #ifndef vil_image_resource_plugin_h_
00003 #define vil_image_resource_plugin_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Interface for loading new image formats
00010 //
00011 // This class provides an interface for loading images in new formats
00012 // \author      Franck Bettinger
00013 // \date        Sun Mar 17 22:57:00 2002
00014 
00015 #include <vcl_string.h>
00016 #include <vil/vil_image_view_base.h>
00017 #include <vil/vil_image_resource.h>
00018 
00019 //=======================================================================
00020 
00021 //: A base class for a plugin for vil images loading
00022 // This class provides an interface for loading images in new formats
00023 
00024 class vil_image_resource_plugin : public vil_image_resource
00025 {
00026  public:
00027 
00028   //: Default constructor
00029   vil_image_resource_plugin() : filetype_(""), colour_(""), width_(-1), height_(-1) {}
00030 
00031   //: Destructor
00032   virtual ~vil_image_resource_plugin() {}
00033 
00034   //: Name of the class
00035   virtual vcl_string is_a() const { return "vil_image_resource_plugin"; }
00036 
00037   virtual vil_pixel_format pixel_format() const { return VIL_PIXEL_FORMAT_UNKNOWN; }
00038 
00039   virtual unsigned ni() const { return 0; }
00040   virtual unsigned nj() const { return 0; }
00041   virtual unsigned nplanes() const { return 0; }
00042 
00043   virtual bool get_property(char const * /*tag*/, void * /*property_value*/=0) const { return false; }
00044   virtual vil_image_view_base_sptr get_copy_view(unsigned /*i0*/, unsigned /*ni*/, unsigned /*j0*/, unsigned /*nj*/) const
00045   { return vil_image_view_base_sptr(0); }
00046 
00047   virtual bool put_view(vil_image_view_base const& /*im*/, unsigned /*i0*/, unsigned /*j0*/) { return false; }
00048 
00049   //: Attempt to load image from named file.
00050   // \return  true if successful
00051   virtual bool load_the_image(vil_image_view_base_sptr& image, const vcl_string & path)
00052   { return load_the_image(image,path,filetype_,colour_); }
00053 
00054   //: Attempt to load image from named file.
00055   // \param filetype  String hinting at what image format is
00056   // \param colour    define whether to load images as colour or grey-scale.
00057   //        Options are '' (i.e. rely on image), 'Grey' or 'RGB'
00058   // \return  true if successful
00059   virtual bool load_the_image(vil_image_view_base_sptr& image,
00060                               const vcl_string & path,
00061                               const vcl_string & filetype,
00062                               const vcl_string & colour);
00063 
00064   //: Register a vil_image_resource_plugin to the list of plugins
00065   static void register_plugin(vil_image_resource_plugin* plugin);
00066 
00067   //: Delete all registered plugins
00068   static void delete_all_plugins();
00069 
00070   //: Set the desired image size
00071   virtual void set_size(int width, int height) { width_=width; height_=height; }
00072 
00073   //: Check whether a filename is a potential candidate for loading and if it is available.
00074   virtual bool can_be_loaded(const vcl_string& filename);
00075 
00076   //: Set the colour options
00077   void set_colour(const vcl_string& colour) { colour_=colour; }
00078 
00079   //: Set the filetype options
00080   void set_filetype(const vcl_string& filetype) { filetype_=filetype; }
00081 
00082  protected:
00083 
00084   //: file type
00085   vcl_string filetype_;
00086 
00087   //: colour
00088   vcl_string colour_;
00089 
00090   vil_pixel_format pixel_format_;
00091   unsigned int ni_;
00092   unsigned int nj_;
00093   unsigned int nplanes_;
00094   int width_;
00095   int height_;
00096 };
00097 
00098 #endif // vil_image_resource_plugin_h_