core/vil1/file_formats/vil1_mit.h

Go to the documentation of this file.
00001 // This is core/vil1/file_formats/vil1_mit.h
00002 #ifndef vil1_mit_file_format_h_
00003 #define vil1_mit_file_format_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Image in MIT format
00010 // \author  Alison Noble, Oxford University.
00011 //          Joris Schouteden, vil1 version
00012 //
00013 //   vil1_mit is a simple image format consisting of a header
00014 //   of 4 shorts (type,bits_per_pixel,width,height) and the raw data.
00015 //   The full specification defines a number of image/edge types (see header
00016 //   for details). Currently only 8-bit images can be read.
00017 //
00018 // \verbatim
00019 //  Modifications
00020 //     000218 JS  Initial version, header info from MITImage.C
00021 //  3 October 2001 Peter Vanroose - Implemented get_property("top_row_first")
00022 //\endverbatim
00023 
00024 #include <vil1/vil1_file_format.h>
00025 #include <vil1/vil1_image_impl.h>
00026 
00027 //: Loader for MIT files
00028 //
00029 // TYPES:
00030 // -# unsigned (grayscale)
00031 // -# rgb
00032 // -# hsb
00033 // -# cap
00034 // -# signed (grayscale?)
00035 // -# float
00036 // -# edge
00037 
00038 class vil1_mit_file_format : public vil1_file_format
00039 {
00040  public:
00041   virtual char const* tag() const;
00042   virtual vil1_image_impl* make_input_image(vil1_stream* vs);
00043   virtual vil1_image_impl* make_output_image(vil1_stream* vs, int planes,
00044                                              int width,
00045                                              int height,
00046                                              int components,
00047                                              int bits_per_component,
00048                                              vil1_component_format format);
00049 };
00050 
00051 //: Generic image implementation for MIT files
00052 class vil1_mit_generic_image : public vil1_image_impl
00053 {
00054   vil1_stream* is_;
00055   int magic_;
00056   int width_;
00057   int height_;
00058   int maxval_;
00059 
00060   int start_of_data_;
00061   int components_;
00062   int bits_per_component_;
00063 
00064   int type_;
00065   int bits_per_pixel_;
00066 
00067   bool read_header();
00068   bool write_header();
00069 
00070   friend class vil1_mit_file_format;
00071  public:
00072 
00073   vil1_mit_generic_image(vil1_stream* is);
00074   vil1_mit_generic_image(vil1_stream* is, int planes,
00075                          int width,
00076                          int height,
00077                          int components,
00078                          int bits_per_component,
00079                          vil1_component_format format);
00080   ~vil1_mit_generic_image();
00081 
00082   //: Dimensions.  Planes x W x H x Components
00083   virtual int planes() const { return 1; }
00084   virtual int width() const { return width_; }
00085   virtual int height() const { return height_; }
00086   virtual int components() const { return components_; }
00087 
00088   virtual int bits_per_component() const
00089   {
00090     return (type_ != 2) ? bits_per_pixel_ : bits_per_pixel_ / 3;
00091   }
00092 
00093   virtual int bytes_per_pixel() const
00094   {
00095     return bits_per_pixel_ / 8;
00096   }
00097 
00098   virtual enum vil1_component_format component_format() const
00099   {
00100     if (type_ == 1 || type_ == 2) return VIL1_COMPONENT_FORMAT_UNSIGNED_INT;
00101     else return VIL1_COMPONENT_FORMAT_IEEE_FLOAT;
00102   }
00103 
00104   //: Copy this to BUF,
00105   virtual bool get_section(void* buf, int x0, int y0, int width, int height) const;
00106   virtual bool put_section(void const* buf, int x0, int y0, int width, int height);
00107 
00108   //: Return the image interpreted as rgb bytes.
00109   //virtual bool get_section_rgb_byte(void* buf, int x0, int y0, int width, int height) const;
00110   //virtual bool get_section_float(void* buf, int x0, int y0, int width, int height) const;
00111   //virtual bool get_section_byte(void* buf, int x0, int y0, int width, int height) const;
00112 
00113   char const* file_format() const;
00114   bool get_property(char const *tag, void *prop = 0) const;
00115   vil1_image get_plane(unsigned int p) const;
00116 };
00117 
00118 #endif // vil1_mit_file_format_h_

Generated on Sat Nov 22 05:08:28 2008 for core/vil1 by  doxygen 1.5.1