00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008 #include "vil_load.h"
00009 #include <vcl_iostream.h>
00010 #include <vil/vil_open.h>
00011 #include <vil/vil_new.h>
00012 #include <vil/vil_file_format.h>
00013 #include <vil/vil_stream.h>
00014 #include <vil/vil_image_resource.h>
00015 #include <vil/vil_image_resource_plugin.h>
00016 #include <vil/vil_image_view.h>
00017
00018 vil_image_resource_sptr vil_load_image_resource_raw(vil_stream *is,
00019 bool verbose)
00020 {
00021 for (vil_file_format** p = vil_file_format::all(); *p; ++p) {
00022 #if 0
00023 vcl_cerr << __FILE__ " : trying \'" << (*p)->tag() << "\'\n";
00024 #endif
00025 is->seek(0);
00026 vil_image_resource_sptr im = (*p)->make_input_image(is);
00027 if (im)
00028 return im;
00029 }
00030
00031
00032 if (verbose) {
00033 vcl_cerr << __FILE__ ": Unable to load image;\ntried";
00034 for (vil_file_format** p = vil_file_format::all(); *p; ++p)
00035
00036
00037 vcl_cerr << " \'" << (*p)->tag() << "\'" << vcl_flush;
00038 vcl_cerr << vcl_endl;
00039 }
00040
00041 return 0;
00042 }
00043
00044 vil_image_resource_sptr vil_load_image_resource_raw(char const* filename,
00045 bool verbose)
00046 {
00047 vil_smart_ptr<vil_stream> is = vil_open(filename, "r");
00048 vil_image_resource_sptr isp = 0;
00049 if (is)
00050 isp = vil_load_image_resource_raw(is.as_pointer(), verbose);
00051 if (!isp && verbose)
00052 vcl_cerr << __FILE__ ": Failed to load [" << filename << "]\n";
00053 return isp;
00054 }
00055
00056 vil_image_resource_sptr vil_load_image_resource(char const* filename,
00057 bool verbose)
00058 {
00059 vil_image_resource_sptr im = vil_load_image_resource_plugin(filename);
00060 if (!im)
00061 im=vil_load_image_resource_raw(filename, verbose);
00062 if (!im && verbose)
00063 vcl_cerr << __FILE__ ": Failed to load [" << filename << "]\n";
00064 return im;
00065 }
00066
00067
00068 vil_image_resource_sptr vil_load_image_resource_plugin(char const* filename)
00069 {
00070 vil_image_resource_plugin im_resource_plugin;
00071 if (im_resource_plugin.can_be_loaded(filename))
00072 {
00073 vil_image_view_base* img=new vil_image_view<vxl_byte>(640,480,3);
00074 vil_image_resource_sptr im;
00075 vil_image_view_base_sptr im_view(img);
00076 if (im_resource_plugin.load_the_image(im_view,filename))
00077 {
00078 im=vil_new_image_resource(im_view->ni(),im_view->nj(),
00079 im_view->nplanes(),im_view->pixel_format());
00080 if (im->put_view((const vil_image_view_base&)*im_view,0,0))
00081 return im;
00082 }
00083 }
00084 return vil_image_resource_sptr(0);
00085 }
00086
00087 vil_pyramid_image_resource_sptr
00088 vil_load_pyramid_resource(char const* directory_or_file, bool verbose)
00089 {
00090 for (vil_file_format** p = vil_file_format::all(); *p; ++p) {
00091 #if 0
00092 vcl_cerr << __FILE__ " : trying \'" << (*p)->tag() << "\'\n";
00093
00094
00095 vcl_cerr << "make_input_pyramid_image(" << directory_or_file << ")\n";
00096 #endif
00097 vil_pyramid_image_resource_sptr pir =
00098 (*p)->make_input_pyramid_image(directory_or_file);
00099 if (pir)
00100 return pir;
00101 }
00102
00103 if (verbose) {
00104 vcl_cerr << __FILE__ ": Unable to load pyramid image;\ntried";
00105 for (vil_file_format** p = vil_file_format::all(); *p; ++p)
00106
00107
00108 vcl_cerr << " \'" << (*p)->tag() << "\'" << vcl_flush;
00109 vcl_cerr << vcl_endl;
00110 }
00111 return 0;
00112 }
00113
00114
00115 vil_image_view_base_sptr vil_load(const char *file, bool verbose)
00116 {
00117 vil_image_resource_sptr data = vil_load_image_resource(file, verbose);
00118 if (!data) return 0;
00119 return data -> get_view();
00120 }
00121
00122
00123 #if defined(VCL_WIN32) && VXL_USE_WIN_WCHAR_T
00124
00125
00126
00127
00128 vil_image_resource_sptr vil_load_image_resource_raw(wchar_t const* filename, bool verbose)
00129 {
00130 vil_smart_ptr<vil_stream> is = vil_open(filename, "r");
00131 vil_image_resource_sptr isp = 0;
00132 if (is)
00133 isp = vil_load_image_resource_raw(is.as_pointer(), verbose);
00134 if (!isp && verbose)
00135 std::wcerr << __FILE__ << L": Failed to load [" << filename << L"]\n";
00136 return isp;
00137 }
00138
00139 vil_image_resource_sptr vil_load_image_resource(wchar_t const* filename, bool verbose)
00140 {
00141
00142
00143
00144
00145 vil_image_resource_sptr im = vil_load_image_resource_raw(filename);
00146 return im;
00147 }
00148
00149
00150 vil_image_view_base_sptr vil_load(const wchar_t *file, bool verbose)
00151 {
00152 vil_image_resource_sptr data = vil_load_image_resource(file, verbose);
00153 if (!data) return 0;
00154 return data -> get_view();
00155 }
00156
00157 #endif //defined(VCL_WIN32) && VXL_USE_WIN_WCHAR_T