core/vil/vil_memory_image.h
Go to the documentation of this file.
00001 // This is core/vil/vil_memory_image.h
00002 #ifndef vil_memory_image_h_
00003 #define vil_memory_image_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Ian Scott
00010 // \verbatim
00011 //  Modifications
00012 //   Peter Vanroose - 21 Aug.2003 - support added for _RGB_, _RGBA_ and _COMPLEX_ pixel_formats
00013 // \endverbatim
00014 
00015 #include <vil/vil_image_resource.h>
00016 #include <vil/vil_image_view_base.h>
00017 #include <vil/vil_property.h>
00018 #include <vcl_cstring.h>
00019 
00020 //: Generic image implementation for PNM files
00021 // You can't create one of these yourself - use vil_new_image_resource() instead.
00022 class vil_memory_image : public vil_image_resource
00023 {
00024   //: Management of the memory image is devolved to an internal image_view.
00025   vil_image_view_base* view_;
00026 
00027   //: Create an empty memory image.
00028   vil_memory_image();
00029 
00030   //: Create an in-memory image of given size and pixel type.
00031   // If not interleaved, pixel type must be scalar or nplanes must be 1.
00032   // If n_interleaved_planes is not 1, pixel type must be scalar,
00033   // and n_planes must be 1.
00034   vil_memory_image(unsigned ni,
00035                    unsigned nj,
00036                    unsigned nplanes,
00037                    vil_pixel_format format,
00038                    unsigned n_interleaved_planes = 1);
00039 
00040   //: Create a wrapper around the given image_view
00041   vil_memory_image(vil_image_view_base const &);
00042 
00043 
00044   friend vil_image_resource_sptr vil_new_image_resource(
00045     unsigned ni, unsigned nj, unsigned nplanes,
00046     vil_pixel_format format);
00047 
00048   friend vil_image_resource_sptr vil_new_image_resource_interleaved(
00049     unsigned ni, unsigned nj, unsigned nplanes,
00050     vil_pixel_format format);
00051 
00052   friend vil_image_resource_sptr vil_new_image_resource_of_view(
00053     vil_image_view_base const & view);
00054 
00055  public:
00056 
00057   ~vil_memory_image() {delete view_;}
00058 
00059   //: Dimensions:  planes x width x height x components
00060   virtual unsigned nplanes() const { return view_->nplanes(); }
00061   virtual unsigned ni() const { return view_->ni(); }
00062   virtual unsigned nj() const { return view_->nj(); }
00063 
00064   virtual enum vil_pixel_format pixel_format() const { return view_->pixel_format(); }
00065 
00066   //: Create a read/write view of a copy of this data.
00067   // \return 0 if unable to get view of correct size.
00068   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00069                                                  unsigned j0, unsigned nj) const;
00070 
00071   //: Create a view of this data.
00072   // \return 0 if unable to get view of correct size.
00073   virtual vil_image_view_base_sptr get_view(unsigned i0, unsigned ni,
00074                                             unsigned j0, unsigned nj) const;
00075 
00076   //: Put the data in this view back into the image source.
00077   virtual bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0);
00078 
00079   //: Declare that this is an in-memory image which is not read-only
00080   bool get_property(char const * tag, void * prop = 0) const
00081   {
00082     if (0==vcl_strcmp(tag, vil_property_memory))
00083       return prop ? (*static_cast<bool*>(prop)) = true : true;
00084 
00085     return false;
00086   }
00087 };
00088 
00089 #endif // vil_memory_image_h_