core/vil/vil_flip.cxx
Go to the documentation of this file.
00001 // This is core/vil/vil_flip.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author Ian Scott.
00008 //
00009 // \verbatim
00010 //  Modifications
00011 //   23 Oct.2003 - Peter Vanroose - Added support for 64-bit int pixels
00012 // \endverbatim
00013 //
00014 //-----------------------------------------------------------------------------
00015 
00016 #include "vil_flip.h"
00017 
00018 vil_image_resource_sptr vil_flip_lr(const vil_image_resource_sptr &src)
00019 {
00020   return new vil_flip_lr_image_resource(src);
00021 }
00022 
00023 vil_flip_lr_image_resource::vil_flip_lr_image_resource(vil_image_resource_sptr const& src):
00024   src_(src)
00025 {
00026 }
00027 
00028 vil_image_view_base_sptr vil_flip_lr_image_resource::get_copy_view(unsigned i0, unsigned ni,
00029                                                                    unsigned j0, unsigned nj) const
00030 {
00031   if (i0 + ni > src_->ni()) return 0;
00032   vil_image_view_base_sptr vs = src_->get_copy_view(src_->ni()- i0-ni, ni, j0, nj);
00033   if (!vs) return 0;
00034 
00035   switch (vs->pixel_format())
00036   {
00037 #define macro( F, T ) \
00038   case F : \
00039     return new vil_image_view<T > (vil_flip_lr(static_cast<const vil_image_view<T >&>(*vs)));
00040 
00041     macro(VIL_PIXEL_FORMAT_BYTE, vxl_byte)
00042     macro(VIL_PIXEL_FORMAT_SBYTE, vxl_sbyte)
00043 #if VXL_HAS_INT_64
00044     macro(VIL_PIXEL_FORMAT_UINT_64, vxl_uint_64)
00045     macro(VIL_PIXEL_FORMAT_INT_64, vxl_int_64)
00046 #endif
00047     macro(VIL_PIXEL_FORMAT_UINT_32, vxl_uint_32)
00048     macro(VIL_PIXEL_FORMAT_INT_32, vxl_int_32)
00049     macro(VIL_PIXEL_FORMAT_UINT_16, vxl_uint_16)
00050     macro(VIL_PIXEL_FORMAT_INT_16, vxl_int_16)
00051     macro(VIL_PIXEL_FORMAT_FLOAT, float)
00052     macro(VIL_PIXEL_FORMAT_DOUBLE, double)
00053     macro(VIL_PIXEL_FORMAT_COMPLEX_FLOAT ,  vcl_complex<float>)
00054     macro(VIL_PIXEL_FORMAT_COMPLEX_DOUBLE , vcl_complex<double>)
00055 #undef macro
00056   default:
00057     return 0;
00058   }
00059 }
00060 
00061 vil_image_view_base_sptr vil_flip_lr_image_resource::get_view(unsigned i0, unsigned ni,
00062                                                               unsigned j0, unsigned nj) const
00063 {
00064   if (i0 + ni > src_->ni()) return 0;
00065   vil_image_view_base_sptr vs = src_->get_view(src_->ni()- i0-ni, ni, j0, nj);
00066   if (!vs) return 0;
00067 
00068   switch (vs->pixel_format())
00069   {
00070 #define macro( F, T ) \
00071   case F : \
00072     return new vil_image_view<T > (vil_flip_lr(static_cast<const vil_image_view<T >&>(*vs)));
00073 
00074     macro(VIL_PIXEL_FORMAT_BYTE, vxl_byte)
00075     macro(VIL_PIXEL_FORMAT_SBYTE, vxl_sbyte)
00076 #if VXL_HAS_INT_64
00077     macro(VIL_PIXEL_FORMAT_UINT_64, vxl_uint_64)
00078     macro(VIL_PIXEL_FORMAT_INT_64, vxl_int_64)
00079 #endif
00080     macro(VIL_PIXEL_FORMAT_UINT_32, vxl_uint_32)
00081     macro(VIL_PIXEL_FORMAT_INT_32, vxl_int_32)
00082     macro(VIL_PIXEL_FORMAT_UINT_16, vxl_uint_16)
00083     macro(VIL_PIXEL_FORMAT_INT_16, vxl_int_16)
00084     macro(VIL_PIXEL_FORMAT_FLOAT, float)
00085     macro(VIL_PIXEL_FORMAT_DOUBLE, double)
00086     macro(VIL_PIXEL_FORMAT_COMPLEX_FLOAT ,  vcl_complex<float>)
00087     macro(VIL_PIXEL_FORMAT_COMPLEX_DOUBLE , vcl_complex<double>)
00088 #undef macro
00089   default:
00090     return 0;
00091   }
00092 }
00093 
00094 //: Put the data in this view back into the image source.
00095 bool vil_flip_lr_image_resource::put_view(const vil_image_view_base& im, unsigned i0,
00096                                           unsigned j0)
00097 {
00098   if (i0 + im.ni() > src_->ni()) return false;
00099   switch (im.pixel_format())
00100   {
00101 #define macro( F, T ) \
00102   case F : \
00103     return src_->put_view(vil_flip_lr(static_cast<const vil_image_view<T >&>(im)), src_->ni()-i0-im.ni(), j0);
00104 
00105     macro(VIL_PIXEL_FORMAT_BYTE, vxl_byte)
00106     macro(VIL_PIXEL_FORMAT_SBYTE, vxl_sbyte)
00107 #if VXL_HAS_INT_64
00108     macro(VIL_PIXEL_FORMAT_UINT_64, vxl_uint_64)
00109     macro(VIL_PIXEL_FORMAT_INT_64, vxl_int_64)
00110 #endif
00111     macro(VIL_PIXEL_FORMAT_UINT_32, vxl_uint_32)
00112     macro(VIL_PIXEL_FORMAT_INT_32, vxl_int_32)
00113     macro(VIL_PIXEL_FORMAT_UINT_16, vxl_uint_16)
00114     macro(VIL_PIXEL_FORMAT_INT_16, vxl_int_16)
00115     macro(VIL_PIXEL_FORMAT_FLOAT, float)
00116     macro(VIL_PIXEL_FORMAT_DOUBLE, double)
00117     macro(VIL_PIXEL_FORMAT_COMPLEX_FLOAT ,  vcl_complex<float>)
00118     macro(VIL_PIXEL_FORMAT_COMPLEX_DOUBLE , vcl_complex<double>)
00119 #undef macro
00120   default:
00121     return false;
00122   }
00123 }
00124 
00125 vil_image_resource_sptr vil_flip_ud(const vil_image_resource_sptr &src)
00126 {
00127   return new vil_flip_ud_image_resource(src);
00128 }
00129 
00130 vil_flip_ud_image_resource::vil_flip_ud_image_resource(vil_image_resource_sptr const& src):
00131   src_(src)
00132 {
00133 }
00134 
00135 
00136 vil_image_view_base_sptr vil_flip_ud_image_resource::get_copy_view(unsigned i0, unsigned ni,
00137                                                                    unsigned j0, unsigned nj) const
00138 {
00139   if (j0 + nj > src_->nj()) return 0;
00140   vil_image_view_base_sptr vs = src_->get_copy_view(i0, ni, src_->nj()- j0-nj, nj);
00141   if (!vs) return 0;
00142 
00143   switch (vs->pixel_format())
00144   {
00145 #define macro( F, T ) \
00146   case F : \
00147     return new vil_image_view<T > (vil_flip_ud(static_cast<const vil_image_view<T >&>(*vs)));
00148 
00149     macro(VIL_PIXEL_FORMAT_BYTE, vxl_byte)
00150     macro(VIL_PIXEL_FORMAT_SBYTE, vxl_sbyte)
00151 #if VXL_HAS_INT_64
00152     macro(VIL_PIXEL_FORMAT_UINT_64, vxl_uint_64)
00153     macro(VIL_PIXEL_FORMAT_INT_64, vxl_int_64)
00154 #endif
00155     macro(VIL_PIXEL_FORMAT_UINT_32, vxl_uint_32)
00156     macro(VIL_PIXEL_FORMAT_INT_32, vxl_int_32)
00157     macro(VIL_PIXEL_FORMAT_UINT_16, vxl_uint_16)
00158     macro(VIL_PIXEL_FORMAT_INT_16, vxl_int_16)
00159     macro(VIL_PIXEL_FORMAT_FLOAT, float)
00160     macro(VIL_PIXEL_FORMAT_DOUBLE, double)
00161     macro(VIL_PIXEL_FORMAT_COMPLEX_FLOAT ,  vcl_complex<float>)
00162     macro(VIL_PIXEL_FORMAT_COMPLEX_DOUBLE , vcl_complex<double>)
00163 #undef macro
00164   default:
00165     return 0;
00166   }
00167 }
00168 
00169 vil_image_view_base_sptr vil_flip_ud_image_resource::get_view(unsigned i0, unsigned ni,
00170                                                               unsigned j0, unsigned nj) const
00171 {
00172   if (i0 + ni > src_->ni()) return 0;
00173   vil_image_view_base_sptr vs = src_->get_view(i0, ni, src_->nj()-j0-nj, nj);
00174   if (!vs) return 0;
00175 
00176   switch (vs->pixel_format())
00177   {
00178 #define macro( F, T ) \
00179   case F : \
00180     return new vil_image_view<T > (vil_flip_ud(static_cast<const vil_image_view<T >&>(*vs)));
00181 
00182     macro(VIL_PIXEL_FORMAT_BYTE, vxl_byte)
00183     macro(VIL_PIXEL_FORMAT_SBYTE, vxl_sbyte)
00184 #if VXL_HAS_INT_64
00185     macro(VIL_PIXEL_FORMAT_UINT_64, vxl_uint_64)
00186     macro(VIL_PIXEL_FORMAT_INT_64, vxl_int_64)
00187 #endif
00188     macro(VIL_PIXEL_FORMAT_UINT_32, vxl_uint_32)
00189     macro(VIL_PIXEL_FORMAT_INT_32, vxl_int_32)
00190     macro(VIL_PIXEL_FORMAT_UINT_16, vxl_uint_16)
00191     macro(VIL_PIXEL_FORMAT_INT_16, vxl_int_16)
00192     macro(VIL_PIXEL_FORMAT_FLOAT, float)
00193     macro(VIL_PIXEL_FORMAT_DOUBLE, double)
00194     macro(VIL_PIXEL_FORMAT_COMPLEX_FLOAT ,  vcl_complex<float>)
00195     macro(VIL_PIXEL_FORMAT_COMPLEX_DOUBLE , vcl_complex<double>)
00196 #undef macro
00197   default:
00198     return 0;
00199   }
00200 }
00201 
00202 //: Put the data in this view back into the image source.
00203 bool vil_flip_ud_image_resource::put_view(const vil_image_view_base& im, unsigned i0,
00204                                           unsigned j0)
00205 {
00206   if (i0 + im.ni() > src_->ni()) return false;
00207   switch (im.pixel_format())
00208   {
00209 #define macro( F, T ) \
00210   case F : \
00211     return src_->put_view(vil_flip_ud(static_cast<const vil_image_view<T >&>(im)), i0, src_->nj()-j0-im.nj()); \
00212 
00213     macro(VIL_PIXEL_FORMAT_BYTE, vxl_byte)
00214     macro(VIL_PIXEL_FORMAT_SBYTE, vxl_sbyte)
00215 #if VXL_HAS_INT_64
00216     macro(VIL_PIXEL_FORMAT_UINT_64, vxl_uint_64)
00217     macro(VIL_PIXEL_FORMAT_INT_64, vxl_int_64)
00218 #endif
00219     macro(VIL_PIXEL_FORMAT_UINT_32, vxl_uint_32)
00220     macro(VIL_PIXEL_FORMAT_INT_32, vxl_int_32)
00221     macro(VIL_PIXEL_FORMAT_UINT_16, vxl_uint_16)
00222     macro(VIL_PIXEL_FORMAT_INT_16, vxl_int_16)
00223     macro(VIL_PIXEL_FORMAT_FLOAT, float)
00224     macro(VIL_PIXEL_FORMAT_DOUBLE, double)
00225     macro(VIL_PIXEL_FORMAT_COMPLEX_FLOAT ,  vcl_complex<float>)
00226     macro(VIL_PIXEL_FORMAT_COMPLEX_DOUBLE , vcl_complex<double>)
00227 #undef macro
00228   default:
00229     return false;
00230   }
00231 }