contrib/mul/vil3d/vil3d_new.cxx
Go to the documentation of this file.
00001 // This is mul/vil3d/vil3d_new.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author Ian Scott 4 Mar 2003
00008 
00009 #include "vil3d_new.h"
00010 
00011 #include <vcl_cstring.h>
00012 
00013 #include <vil3d/vil3d_file_format.h>
00014 #include <vil3d/vil3d_image_resource.h>
00015 #include <vil3d/vil3d_memory_image.h>
00016 #include <vil3d/vil3d_save.h>
00017 
00018 
00019 // The first two functions really should be upgraded to create an image in
00020 // a temporary file on disk if the sizes are large.
00021 
00022 //: Make a new image of given format.
00023 vil3d_image_resource_sptr vil3d_new_image_resource(unsigned ni, unsigned nj,
00024                                                    unsigned nk, unsigned nplanes,
00025                                                    vil_pixel_format format)
00026 {
00027   return new vil3d_memory_image(ni, nj, nk, nplanes, format);
00028 }
00029 
00030 
00031 vil3d_image_resource_sptr vil3d_new_image_resource(const char* name,
00032                                                    unsigned ni,
00033                                                    unsigned nj,
00034                                                    unsigned nk,
00035                                                    unsigned nplanes,
00036                                                    vil_pixel_format format,
00037                                                    char const* file_type)
00038 {
00039   if (!file_type) // avoid segfault in strcmp()
00040     file_type = vil3d_save_guess_file_format(name);
00041 
00042 
00043 
00044   vil3d_image_resource_sptr outimage = 0;
00045   for (unsigned i=0; i < vil3d_file_format::n_formats(); ++i)
00046   {
00047     const vil3d_file_format& fmt = vil3d_file_format::format(i);
00048     if (vcl_strcmp(fmt.tag(), file_type) == 0) {
00049       outimage = fmt.make_output_image(name, ni, nj, nk, nplanes, format);
00050       if (!outimage)
00051         vcl_cerr << "vil3d_new: Cannot new to type [" << file_type << "]\n";
00052       return outimage;
00053     }
00054   }
00055 
00056   vcl_cerr << "vil3d_new: Unknown file type [" << file_type << "]\n";
00057   vcl_cerr << "Known file types are: ";
00058   for (unsigned i=0; i < vil3d_file_format::n_formats(); ++i)
00059   {
00060     if (i) vcl_cerr << ',';
00061     vcl_cerr << vil3d_file_format::format(i).tag() ;
00062   }
00063   vcl_cerr << '.' << vcl_endl;
00064 
00065   return 0;
00066 }