core/vil/vil_file_format.h
Go to the documentation of this file.
00001 // This is core/vil/vil_file_format.h
00002 #ifndef vil_file_format_h_
00003 #define vil_file_format_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Base class for image formats
00010 // \author awf
00011 
00012 #include <vil/vil_fwd.h> // for vil_stream
00013 #include <vil/vil_image_resource.h>
00014 #include <vil/vil_blocked_image_resource.h>
00015 #include <vil/vil_pyramid_image_resource.h>
00016 //: Base class for image formats.
00017 //  There is one derived class for each handled file format in the
00018 // directory file_formats. E.g. vil/file_formats/vil_pnm.h etc
00019 class vil_file_format
00020 {
00021  public:
00022   virtual ~vil_file_format();
00023 
00024   //: Return a character string which uniquely identifies this format.
00025   //E.g. "pnm", "jpeg", etc.
00026   virtual char const* tag() const = 0;
00027 
00028   //: Attempt to make a generic_image which will read from vil_stream vs.
00029   // Reads enough of vs to determine if it's this format, and if not, returns 0.
00030   // If it is, returns a subclass of vil_image_resource on which get_section may
00031   // be applied.
00032   virtual vil_image_resource_sptr make_input_image(vil_stream* vs) = 0;
00033 
00034   //: Read a pyramid resource from a list of image files in a directory
00035   //  ... or from an image file_format that supports multiple images per file.
00036   virtual vil_pyramid_image_resource_sptr
00037     make_input_pyramid_image(char const* /*directory_or_file*/)
00038     {return 0;}
00039 
00040   //: Construct a pyramid image resource from a base image.
00041   //  All levels are stored in the same resource file. Each level has the same
00042   //  scale ratio (0.5) to the preceding level. Level 0 is the original
00043   //  base image. The resource is returned open for reading.
00044   //  The temporary directory is for storing intermediate image
00045   //  resources during the construction of the pyramid. Files are
00046   //  be removed from the directory after completion.  If temp_dir is 0
00047   //  then the intermediate resources are created in memory.
00048   virtual vil_pyramid_image_resource_sptr
00049     make_pyramid_image_from_base(char const* /*filename*/,
00050                                  vil_image_resource_sptr const& /*base_image*/,
00051                                  unsigned /*nlevels*/,
00052                                  char const* /*temp_dir*/)
00053     {return 0;}
00054 
00055   //: Make a "generic_image" on which put_section may be applied.
00056   // The stream vs is assumed to be open for writing, as an image header may be
00057   // written to it immediately.
00058   // The width/height etc are explicitly specified, so that file_format implementors
00059   // know what they need to do...
00060   virtual vil_image_resource_sptr make_output_image(vil_stream* /*vs*/,
00061                                                     unsigned /*nx*/,
00062                                                     unsigned /*ny*/,
00063                                                     unsigned /*nplanes*/,
00064                                                     enum vil_pixel_format) = 0;
00065   //: Construct a blocked output image resource
00066   // Returns a null resource unless the format supports blocking
00067   virtual vil_blocked_image_resource_sptr
00068     make_blocked_output_image(vil_stream* /*vs*/,
00069                               unsigned /*nx*/,
00070                               unsigned /*ny*/,
00071                               unsigned /*nplanes*/,
00072                               unsigned /*size_block_i*/,
00073                               unsigned /* size_block_j*/,
00074                               enum vil_pixel_format)
00075     {return 0;}
00076 
00077   virtual vil_pyramid_image_resource_sptr
00078     make_pyramid_output_image(char const* /*file*/)
00079     {return 0;}
00080 
00081  public:
00082   static vil_file_format** all();
00083   static void add_file_format(vil_file_format* ff);
00084 };
00085 
00086 #endif // vil_file_format_h_