core/vil/vil_flip.h
Go to the documentation of this file.
00001 // This is core/vil/vil_flip.h
00002 #ifndef vil_flip_h_
00003 #define vil_flip_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Ian Scott.
00010 
00011 #include <vil/vil_image_resource.h>
00012 #include <vil/vil_image_view.h>
00013 
00014 
00015 //: Create a reflected view in which i -> ni-1-i.
00016 //  i.e. vil_flip_lr(view)(i,j,p) = view(ni-1-i,j,p)
00017 //  O(1).
00018 // \relatesalso vil_image_view
00019 template<class T>
00020 inline vil_image_view<T> vil_flip_lr(const vil_image_view<T>& v)
00021 {
00022   return vil_image_view<T>(v.memory_chunk(),
00023                            v.top_left_ptr()+(v.ni()-1)*v.istep(),
00024                            v.ni(),v.nj(),v.nplanes(),
00025                            -v.istep(),v.jstep(),v.planestep());
00026 }
00027 
00028 //: Create a reflected view in which y -> nj-1-j.
00029 //  i.e. vil_flip_ud(view)(i,j,p) = view(i,nj-1-j,p)
00030 //  O(1).
00031 // \relatesalso vil_image_view
00032 template<class T>
00033 inline vil_image_view<T> vil_flip_ud(const vil_image_view<T>& v)
00034 {
00035   return vil_image_view<T>(v.memory_chunk(),
00036                            v.top_left_ptr()+(v.nj()-1)*v.jstep(),
00037                            v.ni(),v.nj(),v.nplanes(),
00038                            v.istep(),-v.jstep(),v.planestep());
00039 }
00040 
00041 
00042 //: Flip an image resource left to right.
00043 // \relatesalso vil_image_resource
00044 vil_image_resource_sptr vil_flip_lr(const vil_image_resource_sptr &src);
00045 
00046 
00047 //: A generic_image adaptor that behaves like a flipped left to right version of its input
00048 class vil_flip_lr_image_resource : public vil_image_resource
00049 {
00050   vil_flip_lr_image_resource(vil_image_resource_sptr const&);
00051   friend vil_image_resource_sptr vil_flip_lr(const vil_image_resource_sptr &src);
00052  public:
00053 
00054   virtual unsigned nplanes() const { return src_->nplanes(); }
00055   virtual unsigned ni() const { return src_->ni(); }
00056   virtual unsigned nj() const { return src_->nj(); }
00057 
00058   virtual enum vil_pixel_format pixel_format() const { return src_->pixel_format(); }
00059 
00060 
00061   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00062                                                  unsigned j0, unsigned nj) const;
00063 
00064   virtual vil_image_view_base_sptr get_view(unsigned i0, unsigned ni,
00065                                             unsigned j0, unsigned nj) const;
00066 
00067 
00068   //: Put the data in this view back into the image source.
00069   virtual bool put_view(const vil_image_view_base& im, unsigned i0,
00070                         unsigned j0);
00071 
00072   //: Extra property information
00073   virtual bool get_property(char const* tag, void* property_value = 0) const {
00074     return src_->get_property(tag, property_value); }
00075 
00076 
00077  protected:
00078   //: Reference to underlying image source
00079   vil_image_resource_sptr src_;
00080 };
00081 
00082 
00083 //: Flip an image resource left to right.
00084 // \relatesalso vil_image_resource
00085 vil_image_resource_sptr vil_flip_ud(const vil_image_resource_sptr &src);
00086 
00087 
00088 //: A generic_image adaptor that behaves like a flipped left to right version of its input
00089 class vil_flip_ud_image_resource : public vil_image_resource
00090 {
00091   vil_flip_ud_image_resource(vil_image_resource_sptr const&);
00092   friend vil_image_resource_sptr vil_flip_ud(const vil_image_resource_sptr &src);
00093  public:
00094 
00095   virtual unsigned nplanes() const { return src_->nplanes(); }
00096   virtual unsigned ni() const { return src_->ni(); }
00097   virtual unsigned nj() const { return src_->nj(); }
00098 
00099   virtual enum vil_pixel_format pixel_format() const { return src_->pixel_format(); }
00100 
00101 
00102   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00103                                                  unsigned j0, unsigned nj) const;
00104 
00105   virtual vil_image_view_base_sptr get_view(unsigned i0, unsigned ni,
00106                                             unsigned j0, unsigned nj) const;
00107 
00108 
00109   //: Put the data in this view back into the image source.
00110   virtual bool put_view(const vil_image_view_base& im, unsigned i0,
00111                         unsigned j0);
00112 
00113   //: Extra property information
00114   virtual bool get_property(char const* tag, void* property_value = 0) const {
00115     return src_->get_property(tag, property_value); }
00116 
00117  protected:
00118   //: Reference to underlying image source
00119   vil_image_resource_sptr src_;
00120 };
00121 
00122 #endif // vil_flip_h_