00001 #include "vil3d_load.h" 00002 //: 00003 // \file 00004 // \brief Functions to read an image from a file 00005 // \author Ian Scott 00006 00007 #include <vil/vil_exception.h> 00008 #include <vil3d/vil3d_file_format.h> 00009 #include <vcl_sstream.h> 00010 00011 vil3d_image_resource_sptr vil3d_load_image_resource(char const* filename) 00012 { 00013 for (unsigned i=0;i<vil3d_file_format::n_formats();++i) 00014 { 00015 vil3d_image_resource_sptr im = 00016 vil3d_file_format::format(i).make_input_image(filename); 00017 if (im) return im; 00018 } 00019 vcl_ostringstream ss; 00020 for (unsigned i=0;i+1<vil3d_file_format::n_formats();++i) 00021 ss << vil3d_file_format::format(i).tag() << ' '; 00022 if (vil3d_file_format::n_formats() > 1) 00023 ss << "or "; 00024 if (vil3d_file_format::n_formats()) 00025 ss << vil3d_file_format::format(vil3d_file_format::n_formats()-1).tag(); 00026 vil_exception_warning(vil_exception_image_io("vil3d_load_image_resource", 00027 ss.str() , filename, "Unable to find a suitable image loader." ) ); 00028 return 0; 00029 } 00030 00031 00032 //: Convenience function for loading an image into an image view. 00033 vil3d_image_view_base_sptr vil3d_load(const char *file) 00034 { 00035 vil3d_image_resource_sptr data = vil3d_load_image_resource(file); 00036 if (!data) return 0; 00037 return data -> get_view(0, data->ni(), 0, data->nj(), 0, data->nk()); 00038 }