core/vil/file_formats/vil_iris.h
Go to the documentation of this file.
00001 // This is core/vil/file_formats/vil_iris.h
00002 #ifndef vil_iris_file_format_h_
00003 #define vil_iris_file_format_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Joris Schouteden, ESAT, KULeuven
00010 // \date 17 Feb 2000
00011 //
00012 // \verbatim
00013 //  Modifications
00014 //   17-Feb-2000 JS - Initial version, copied from IrisRGBImage.C
00015 //      Jul-2000 Peter Vanroose - bug fixed in write_header() by adding extra argument to constructor to pass imagename_ member
00016 //    3-Oct-2001 Peter Vanroose - Implemented get_property("top_row_first")
00017 //    5-Jun-2003 Peter Vanroose - bug fix in get_section & put_section: storage is planar, not RGB
00018 //   16-Jun-2003 Peter Vanroose - ported from vil1
00019 //   17-Jun-2003 Peter Vanroose - bug fix: data is big-endian; byte-swap added
00020 //\endverbatim
00021 
00022 #include <vil/vil_file_format.h>
00023 #include <vil/vil_image_resource.h>
00024 #include <vil/vil_stream.h>
00025 
00026 //: Loader for RGB files (sgi iris)
00027 class vil_iris_file_format : public vil_file_format
00028 {
00029  public:
00030   virtual char const* tag() const;
00031   virtual vil_image_resource_sptr make_input_image(vil_stream* vs);
00032   virtual vil_image_resource_sptr make_output_image(vil_stream* vs,
00033                                                     unsigned int ni, unsigned int nj, unsigned int planes,
00034                                                     vil_pixel_format format);
00035 };
00036 
00037 //: Generic image implementation for iris (SGI) RGB files
00038 class vil_iris_generic_image : public vil_image_resource
00039 {
00040   unsigned long *starttab_;
00041   unsigned long *lengthtab_;
00042 
00043   bool read_header();
00044   bool write_header();
00045 
00046   friend class vil_iris_file_format;
00047  public:
00048 
00049   vil_iris_generic_image(vil_stream* is, char const* imagename = "");
00050   vil_iris_generic_image(vil_stream* is,
00051                          unsigned int ni, unsigned int nj, unsigned int planes,
00052                          vil_pixel_format format);
00053   ~vil_iris_generic_image();
00054 
00055   //: Dimensions.  Planes x ni(width) x nj(height).
00056   virtual unsigned int ni() const { return ni_; }
00057   virtual unsigned int nj() const { return nj_; }
00058   virtual unsigned int nplanes() const { return nplanes_; }
00059 
00060   virtual enum vil_pixel_format pixel_format() const { return format_; }
00061 
00062   virtual vil_image_view_base_sptr get_copy_view( unsigned int x0, unsigned int ni, unsigned int y0, unsigned int nj) const;
00063   virtual bool put_view( vil_image_view_base const& buf, unsigned int x0, unsigned int y0);
00064 
00065   char const* file_format() const;
00066   bool get_property(char const *tag, void *prop = 0) const;
00067 
00068  protected:
00069   vil_stream* is_;
00070 
00071   int magic_;
00072 
00073   unsigned int ni_;
00074   unsigned int nj_;
00075   unsigned int nplanes_;
00076   enum vil_pixel_format format_;
00077 
00078   int pixmin_;
00079   int pixmax_;
00080   int storage_;
00081   int dimension_;
00082   int colormap_;
00083   char imagename_[81];
00084   vil_streampos start_of_data_;
00085 
00086   bool read_offset_tables();
00087 
00088   // Read a Run-Length encoded section
00089   vil_image_view_base_sptr get_section_rle( unsigned int x0, unsigned int ni, unsigned int y0, unsigned int nj) const;
00090 
00091   // Read a plain section
00092   vil_image_view_base_sptr get_section_verbatim( unsigned int x0, unsigned int ni, unsigned int y0, unsigned int nj) const;
00093 };
00094 
00095 #endif // vil_iris_file_format_h_