core/vil/file_formats/vil_mit.h
Go to the documentation of this file.
00001 // This is core/vil/file_formats/vil_mit.h
00002 #ifndef vil_mit_file_format_h_
00003 #define vil_mit_file_format_h_
00004 //:
00005 // \file
00006 // \brief Image in MIT format
00007 // \author Alison Noble, Oxford University, TargetJr version
00008 //         Joris Schouteden, vil1 version
00009 //         Peter Vanroose,   vil version
00010 //
00011 //   vil_mit is a simple image format consisting of a header
00012 //   of 4 shorts (type,bits_per_pixel,width,height) and the raw data.
00013 //   The full specification defines a number of image/edge types (see header
00014 //   for details).
00015 //
00016 // \verbatim
00017 //  Modifications
00018 //   000218 JS      Initial version, header info from MITImage.C
00019 //   3 October 2001 Peter Vanroose - Implemented get_property("top_row_first")
00020 //   17 June 2003   Peter Vanroose - Converted from vil1, and implemented 16-bit
00021 // \endverbatim
00022 
00023 #include <vil/vil_file_format.h>
00024 #include <vil/vil_image_resource.h>
00025 
00026 //: Loader for MIT files
00027 //
00028 // TYPES:
00029 // -# unsigned (grayscale)
00030 // -# rgb
00031 // -# hsb
00032 // -# cap
00033 // -# signed (grayscale?)
00034 // -# float
00035 // -# edge
00036 
00037 class vil_mit_file_format : public vil_file_format
00038 {
00039  public:
00040   virtual char const* tag() const;
00041   virtual vil_image_resource_sptr make_input_image(vil_stream* vs);
00042   virtual vil_image_resource_sptr make_output_image(vil_stream* vs,
00043                                                     unsigned int ni, unsigned int nj, unsigned int nplanes,
00044                                                     vil_pixel_format format);
00045 };
00046 
00047 //: Generic image implementation for MIT files
00048 class vil_mit_image : public vil_image_resource
00049 {
00050   vil_stream* is_;
00051   unsigned int ni_;
00052   unsigned int nj_;
00053   unsigned int components_;
00054   unsigned int type_;
00055   enum vil_pixel_format format_;
00056 
00057   bool read_header();
00058   bool write_header();
00059 
00060   friend class vil_mit_file_format;
00061  public:
00062 
00063   vil_mit_image(vil_stream* is);
00064   vil_mit_image(vil_stream* is,
00065                 unsigned int ni, unsigned int nj, unsigned int nplanes,
00066                 vil_pixel_format format);
00067  ~vil_mit_image();
00068 
00069   //: Dimensions.  W x H x Components
00070   virtual unsigned int ni() const { return ni_; }
00071   virtual unsigned int nj() const { return nj_; }
00072   virtual unsigned int nplanes() const { return components_; }
00073 
00074   unsigned int bytes_per_pixel() const { return vil_pixel_format_sizeof_components(format_); }
00075 
00076   virtual enum vil_pixel_format pixel_format() const { return format_; }
00077 
00078   //: Return part of this as buffer
00079   virtual vil_image_view_base_sptr get_copy_view(unsigned int x0, unsigned int ni, unsigned int y0, unsigned int nj) const;
00080   //: Write buf into this at position (x0,y0)
00081   virtual bool put_view(vil_image_view_base const& buf, unsigned int x0, unsigned int y0);
00082 
00083   char const* file_format() const;
00084   bool get_property(char const *tag, void *prop = 0) const;
00085 };
00086 
00087 #endif // vil_mit_file_format_h_