contrib/tbl/vepl/vepl_convert.txx
Go to the documentation of this file.
00001 // This is tbl/vepl/vepl_convert.txx
00002 #ifndef vepl_convert_txx_
00003 #define vepl_convert_txx_
00004 
00005 #include "vepl_convert.h"
00006 #include <vepl/accessors/vipl_accessors_vil_image_view_base.h>
00007 #include <vipl/vipl_convert.h>
00008 #include <vil/vil_image_view.h>
00009 #include <vil/vil_pixel_format.h>
00010 #include <vil/vil_new.h>
00011 #include <vxl_config.h> // for vxl_byte
00012 
00013 template <class D>
00014 vil_image_resource_sptr vepl_convert(vil_image_resource_sptr image, D /*dummy*/)
00015 {
00016   vil_image_resource_sptr img_out = vil_new_image_resource(image->ni(), image->nj(), image->nplanes(), image->pixel_format());
00017 
00018   // byte greyscale
00019   if (image->pixel_format() == VIL_PIXEL_FORMAT_BYTE) {
00020     vil_image_view<vxl_byte> in = image->get_view();
00021     vil_image_view<D> out = image->get_copy_view();
00022     vipl_convert<vil_image_view_base,vil_image_view_base,vxl_byte,D> op;
00023     op.put_in_data_ptr(&in);
00024     op.put_out_data_ptr(&out);
00025     op.filter();
00026     img_out->put_view(out);
00027   }
00028 
00029   // float
00030   else if (image->pixel_format() == VIL_PIXEL_FORMAT_FLOAT) {
00031     vil_image_view<float> in = image->get_view();
00032     vil_image_view<D > out(image->ni(),image->nj(),image->nplanes());
00033     vipl_convert<vil_image_view_base,vil_image_view_base,float,D> op;
00034     op.put_in_data_ptr(&in);
00035     op.put_out_data_ptr(&out);
00036     op.filter();
00037   }
00038 
00039   // double
00040   else if (image->pixel_format() == VIL_PIXEL_FORMAT_DOUBLE) {
00041     vil_image_view<double> in = image->get_view();
00042     vil_image_view<D > out(image->ni(),image->nj(),image->nplanes());
00043     vipl_convert<vil_image_view_base,vil_image_view_base,double,D> op;
00044     op.put_in_data_ptr(&in);
00045     op.put_out_data_ptr(&out);
00046     op.filter();
00047     img_out->put_view(out);
00048   }
00049 
00050   //
00051   else
00052     vcl_cerr << __FILE__ ": vepl_convert() not implemented for " << image << '\n';
00053 
00054   return img_out;
00055 }
00056 
00057 #endif // vepl_convert_txx_