core/vil/file_formats/vil_viff.h
Go to the documentation of this file.
00001 // This is core/vil/file_formats/vil_viff.h
00002 #ifndef vil_viff_file_format_h_
00003 #define vil_viff_file_format_h_
00004 //:
00005 // \file
00006 // \brief  Loader for Khoros 1.0 images
00007 // \author Peter Vanroose, ESAT, KULeuven.
00008 // \date 17 Feb 2000
00009 // VIFF is the "Visualization Image File Format" used by Khoros 1.0.
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //    3 Oct  2001 Peter Vanroose - Implemented get_property("top_row_first")
00014 //   21 Febr 2002 Maarten Vergauwen - Added access functions for [fi]spare[12]
00015 //    5 June 2003 Peter Vanroose - bug fix for 64-bit platforms: data is 32-bit
00016 //   14 June 2003 Peter Vanroose - ported from vil1
00017 // \endverbatim
00018 #include <vil/vil_stream.h>
00019 #include <vil/vil_file_format.h>
00020 #include <vil/vil_image_resource.h>
00021 #include "vil_viffheader.h"
00022 #include <vxl_config.h> // for vxl_uint_32
00023 
00024 //: Loader for VIFF files, i.e., 1-banded Khoros 1.0 images
00025 // This supports char, short, int, float and double pixel cell types.
00026 // Adapted from the version by Reinhard Koch, Nov. 19, 1996.
00027 class vil_viff_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 nplanes,
00034                                                     vil_pixel_format format);
00035 };
00036 
00037 //: Generic image implementation for VIFF (Khoros) files
00038 class vil_viff_image : public vil_image_resource
00039 {
00040   vil_stream* is_;
00041   unsigned int ni_;
00042   unsigned int nj_;
00043   unsigned int nplanes_;
00044 
00045   vil_streampos start_of_data_;
00046   enum vil_pixel_format format_;
00047 
00048   bool endian_consistent_;
00049   vil_viff_xvimage header_;
00050 
00051   bool read_header();
00052   bool write_header();
00053   bool check_endian();
00054 
00055   friend class vil_viff_file_format;
00056 
00057  public:
00058   vil_viff_image(vil_stream* is);
00059   vil_viff_image(vil_stream* is,
00060                  unsigned int ni, unsigned int nj, unsigned int nplanes,
00061                  vil_pixel_format format);
00062   ~vil_viff_image();
00063 
00064   //: Dimensions.  Planes x W x H
00065   virtual unsigned int ni() const { return ni_; }
00066   virtual unsigned int nj() const { return nj_; }
00067   virtual unsigned int nplanes() const { return nplanes_; }
00068 
00069   virtual enum vil_pixel_format pixel_format() const { return format_; }
00070 
00071   //: Return part of this as buffer
00072   virtual vil_image_view_base_sptr get_copy_view(unsigned int x0, unsigned int ni, unsigned int y0, unsigned int nj) const;
00073   //: Write buf into this at position (x0,y0)
00074   virtual bool put_view(vil_image_view_base const& buf, unsigned int x0, unsigned int y0);
00075 
00076   char const* file_format() const;
00077   bool get_property(char const *tag, void *prop = 0) const;
00078 
00079   //: User defined spare values in header
00080   vxl_uint_32 ispare1() const { return header_.ispare1;}
00081   vxl_uint_32 ispare2() const { return header_.ispare2;}
00082   float fspare1() const { return header_.fspare1;}
00083   float fspare2() const { return header_.fspare2;}
00084   void set_ispare1(vxl_uint_32 ispare1);
00085   void set_ispare2(vxl_uint_32 ispare2);
00086   void set_fspare1(float fspare1);
00087   void set_fspare2(float fspare2);
00088 };
00089 
00090 #endif // vil_viff_file_format_h_