core/vil/vil_new.h
Go to the documentation of this file.
00001 // This is core/vil/vil_new.h
00002 #ifndef vil_new_h_
00003 #define vil_new_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Make a new image.
00010 //
00011 // If it's very big, it might make a disk image, with a temporary name in which
00012 // case "prototype" will be consulted about issues such as file format etc.  If
00013 // you want more control over the exact disk format, use one of the routines
00014 // with more than 4 arguments.
00015 //
00016 // \author awf@robots.ox.ac.uk
00017 // \date 26 Feb 00
00018 //
00019 // \verbatim
00020 //  Modifications
00021 //   16 Feb 2000 AWF - Initial version.
00022 //   25 Sep 2002 Ian Scott - convert to vil.
00023 //   30 Mar 2007 Peter Vanroose- Removed deprecated vil_new_image_view_j_i_plane
00024 // \endverbatim
00025 
00026 #include <vil/vil_fwd.h>
00027 #include <vil/vil_image_resource.h>
00028 #include <vil/vil_blocked_image_resource.h>
00029 #include <vil/vil_pyramid_image_resource.h>
00030 #include <vil/vil_image_view.h>
00031 #include <vxl_config.h>
00032 
00033 //: Make a new image of given format.
00034 // If the format is not scalar, the number of planes must be 1. When you create
00035 // a multi-component image in this way, the vil_image_resource API will treat
00036 // it as a scalar pixel image with multiple planes. (This doesn't affect the
00037 // underlying data storage.)
00038 // \relatesalso vil_image_resource
00039 vil_image_resource_sptr vil_new_image_resource(unsigned ni, unsigned nj, unsigned nplanes,
00040                                                vil_pixel_format format);
00041 
00042 //: Make a new image of given format with interleaved planes.
00043 // The format must be scalar.
00044 // \relatesalso vil_image_resource
00045 vil_image_resource_sptr vil_new_image_resource_interleaved(unsigned ni, unsigned nj,
00046                                                            unsigned nplanes,
00047                                                            vil_pixel_format format);
00048 
00049 //: Make a new image resource that is a wrapper on an existing view's data.
00050 // \note The output will be a shallow copy of the input, so changing the pixel values
00051 // of one may change the pixel value of the other. Thanks to the magic of smart pointers,
00052 // the output will remain valid even if you destroy the input. When you wrap
00053 // a multi-component image in this way, the vil_image_resource API will treat
00054 // it as a scalar pixel image with multiple planes. (This doesn't affect the
00055 // underlying data storage.)
00056 // \relatesalso vil_image_resource
00057 vil_image_resource_sptr vil_new_image_resource_of_view(vil_image_view_base const& view);
00058 
00059 
00060 //: Make a new image, similar format to the prototype.
00061 // \relatesalso vil_image_resource
00062 vil_image_resource_sptr vil_new_image_resource(unsigned ni, unsigned nj,
00063                                                vil_image_resource_sptr const& prototype);
00064 
00065 //: Make a new image.
00066 // \relatesalso vil_image_resource
00067 vil_image_resource_sptr vil_new_image_resource(vil_stream* os,
00068                                                unsigned ni, unsigned nj,
00069                                                unsigned nplanes,
00070                                                vil_pixel_format format,
00071                                                char const* file_format = 0);
00072 
00073 //: Make a new image.
00074 // \relatesalso vil_image_resource
00075 vil_image_resource_sptr vil_new_image_resource(char const* filename,
00076                                                unsigned ni, unsigned nj,
00077                                                unsigned nplanes,
00078                                                vil_pixel_format format,
00079                                                char const* file_format = 0);
00080 
00081 //: Make a new vil_image_resource, writing to file "filename", size ni x nj, copying pixel format etc from "prototype".
00082 // \relatesalso vil_image_resource
00083 vil_image_resource_sptr vil_new_image_resource(char const* filename,
00084                                                unsigned ni, unsigned nj,
00085                                                unsigned nplanes,
00086                                                vil_image_resource_sptr const &prototype,
00087                                                char const* format = 0);
00088 
00089 //: Make a new vil_image_resource, writing to stream "os", size ni x nj, copying pixel format etc from "prototype".
00090 // \relatesalso vil_image_resource
00091 vil_image_resource_sptr vil_new_image_resource(vil_stream* os,
00092                                                unsigned ni, unsigned nj,
00093                                                unsigned nplanes,
00094                                                vil_image_resource_sptr const& prototype,
00095                                                char const* file_format = 0);
00096 //: Make a new blocked resource file
00097 vil_blocked_image_resource_sptr
00098 vil_new_blocked_image_resource(vil_stream* os, unsigned ni, unsigned nj,
00099                                unsigned nplanes, vil_pixel_format format,
00100                                unsigned size_block_i, unsigned size_block_j,
00101                                char const* file_format = 0);
00102 
00103 //: Make a new blocked resource file
00104 vil_blocked_image_resource_sptr
00105 vil_new_blocked_image_resource(char const* filename, unsigned ni, unsigned nj,
00106                                unsigned nplanes, vil_pixel_format format,
00107                                unsigned size_block_i, unsigned size_block_j,
00108                                char const* file_format = 0);
00109 
00110 //: create a blocked interface around any image resource
00111 // For zero size blocks, appropriate default blocking is created
00112 vil_blocked_image_resource_sptr
00113 vil_new_blocked_image_facade(const vil_image_resource_sptr& src,
00114                              const unsigned size_block_i=0,
00115                              const unsigned size_block_j=0);
00116 //: Make a new cached resource
00117 vil_blocked_image_resource_sptr
00118 vil_new_cached_image_resource(const vil_blocked_image_resource_sptr& bir,
00119                               const unsigned cache_size = 100);
00120 
00121 
00122 //: Make a new pyramid image resource for writing.
00123 //  Any number of pyramid layers can be inserted and with any scale.
00124 //  Image resources that duplicate existing scales are not inserted.
00125 vil_pyramid_image_resource_sptr
00126 vil_new_pyramid_image_resource(char const* file_or_directory,
00127                                char const* file_format);
00128 
00129 //: Construct a pyramid image resource from a base image.
00130 //  All levels are stored in the same resource file. Each level has the same
00131 //  scale ratio (0.5) to the preceding level. Level 0 is the original
00132 //  base image. The resource is returned open for reading.
00133 //  The temporary directory is for storing intermediate image
00134 //  resources during the construction of the pyramid. Files are
00135 //  be removed from the directory after completion.  If temp_dir is 0
00136 //  then the intermediate resources are created in memory.
00137 vil_pyramid_image_resource_sptr
00138 vil_new_pyramid_image_from_base(char const* filename,
00139                                 vil_image_resource_sptr const& base_image,
00140                                 unsigned nlevels,
00141                                 char const* file_format,
00142                                 char const* temp_dir);
00143 
00144 //: Construct a new pyramid image resource from a base image
00145 //  The result is a directory containing separate images for each
00146 //  pyramid level. Each level has the same scale ratio (0.5) to the
00147 //  preceding level and is created using level_file_format.
00148 //  Level 0 is the original base image. If copy_base is false, then Level 0
00149 //  is already present in the directory and is used without modification.
00150 //  Each pyramid file in the directory is
00151 //   named filename + "level_index", e.g. R0, R1, ... Rn.
00152 vil_pyramid_image_resource_sptr
00153 vil_new_pyramid_image_list_from_base(char const* directory,
00154                                      vil_image_resource_sptr const& base_image,
00155                                      unsigned nlevels,
00156                                      bool copy_base,
00157                                      char const* level_file_format,
00158                                      char const* filename);
00159 
00160 #if 0 // deprecated
00161 //: Create a new image view whose plane step is 1.
00162 //  Pixel data type is the type of the last (dummy) argument.
00163 //  i_step will be nplanes, j_step will be nplanes x ni.
00164 //  \relatesalso vil_image_view
00165 // \deprecated in favour of vil_image_view constructor
00166 template <class T>
00167 vil_image_view<T> vil_new_image_view_j_i_plane(unsigned ni, unsigned nj, unsigned nplanes, T /*dummy*/)
00168 {
00169   VXL_DEPRECATED("vil_new_image_view_j_i_plane");
00170   vil_pixel_format fmt = vil_pixel_format_of(T());
00171   vil_memory_chunk_sptr chunk = new vil_memory_chunk(ni*nj*nplanes*sizeof(T),
00172                                                      vil_pixel_format_component_format(fmt));
00173   return vil_image_view<T>(chunk, reinterpret_cast<T*>(chunk->data()), ni, nj, nplanes, nplanes, nplanes*ni, 1);
00174 }
00175 #endif // 0
00176 
00177 //: Create a new image view whose j_step is 1.
00178 //  Pixel data type is the type of the last (dummy) argument.
00179 //  i_step will be nj, planestep will be ni x nj.
00180 //  \relatesalso vil_image_view
00181 template <class T>
00182 vil_image_view<T> vil_new_image_view_plane_i_j(unsigned ni, unsigned nj, unsigned nplanes, T /*dummy*/)
00183 {
00184   vil_pixel_format fmt = vil_pixel_format_of(T());
00185   vil_memory_chunk_sptr chunk = new vil_memory_chunk(ni*nj*nplanes*sizeof(T),
00186                                                      vil_pixel_format_component_format(fmt));
00187   return vil_image_view<T>(chunk, reinterpret_cast<T*>(chunk->data()), ni, nj, nplanes, nj, 1, nj*ni);
00188 }
00189 
00190 //: Create a new image view whose plane step is 1 and whose j_step is nplanes.
00191 //  Pixel data type is the type of the last (dummy) argument.
00192 //  i_step will be nplanes x nj.
00193 //  \relatesalso vil_image_view
00194 template <class T>
00195 vil_image_view<T> vil_new_image_view_i_j_plane(unsigned ni, unsigned nj, unsigned nplanes, T /*dummy*/)
00196 {
00197   vil_pixel_format fmt = vil_pixel_format_of(T());
00198   vil_memory_chunk_sptr chunk = new vil_memory_chunk(ni*nj*nplanes*sizeof(T),
00199                                                      vil_pixel_format_component_format(fmt));
00200   return vil_image_view<T>(chunk, reinterpret_cast<T*>(chunk->data()), ni, nj, nplanes, nplanes*nj, nplanes, 1);
00201 }
00202 
00203 //: Create a shallow copy of an image and wrap it in a vil_image_view_base_sptr
00204 // \note vil_image_view_base_sptr almost certainly doesn't behave as
00205 // you would expect, and this function should really only be used by experts.
00206 // \relatesalso vil_image_view
00207 vil_image_view_base_sptr vil_new_image_view_base_sptr(const vil_image_view_base&);
00208 
00209 
00210 #if defined(VCL_WIN32) && VXL_USE_WIN_WCHAR_T
00211 //: Make a new image.
00212 // \relatesalso vil_image_resource
00213 vil_image_resource_sptr vil_new_image_resource(vil_stream* os,
00214                                                unsigned ni, unsigned nj,
00215                                                unsigned nplanes,
00216                                                vil_pixel_format format,
00217                                                wchar_t const* file_format = 0);
00218 //: Make a new image.
00219 // \relatesalso vil_image_resource
00220 vil_image_resource_sptr vil_new_image_resource(wchar_t const* filename,
00221                                                unsigned ni, unsigned nj,
00222                                                unsigned nplanes,
00223                                                vil_pixel_format format,
00224                                                wchar_t const* file_format = 0);
00225 
00226 //: Make a new vil_image_resource, writing to file "filename", size ni x nj, copying pixel format etc from "prototype".
00227 // \relatesalso vil_image_resource
00228 vil_image_resource_sptr vil_new_image_resource(wchar_t const* filename,
00229                                                unsigned ni, unsigned nj,
00230                                                unsigned nplanes,
00231                                                vil_image_resource_sptr const &prototype,
00232                                                wchar_t const* format = 0);
00233 
00234 #endif //defined(VCL_WIN32) && VXL_USE_WIN_WCHAR_T
00235 
00236 
00237 #endif // vil_new_h_