core/vil/file_formats/vil_ras.h
Go to the documentation of this file.
00001 // This is core/vil/file_formats/vil_ras.h
00002 #ifndef vil_ras_file_format_h_
00003 #define vil_ras_file_format_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Amitha Perera
00010 // \date 12 Apr 2002
00011 //
00012 // \verbatim
00013 // Modifications
00014 // 22 Apr 2003: Amitha Perera - converted to vil
00015 // 31 Dec 2005: J.L. Mundy - extended to read 16 bit images - didn't extend writing
00016 // \endverbatim
00017 // 
00018 #include <vil/vil_image_resource.h>
00019 #include <vil/vil_file_format.h>
00020 #include <vil/vil_stream.h>
00021 
00022 #include <vxl_config.h>
00023 
00024 class vil_image_view_base;
00025 
00026 
00027 //: Loader for Sun raster files
00028 class vil_ras_file_format : public vil_file_format
00029 {
00030  public:
00031   virtual char const* tag() const;
00032   virtual vil_image_resource_sptr make_input_image( vil_stream* vs );
00033   virtual vil_image_resource_sptr make_output_image(vil_stream* vs,
00034                                                     unsigned ni,
00035                                                     unsigned nj,
00036                                                     unsigned nplanes,
00037                                                     vil_pixel_format format);
00038 };
00039 
00040 //: Generic image implementation for Sun raster files
00041 class vil_ras_image : public vil_image_resource
00042 {
00043   vil_stream* vs_;
00044   vxl_uint_32 width_;
00045   vxl_uint_32 height_;
00046   unsigned components_;
00047   unsigned bits_per_component_; //< always 8
00048 
00049   vil_streampos start_of_data_;
00050 
00051   vxl_uint_32 depth_;
00052   vxl_uint_32 length_;
00053   vxl_uint_32 type_;
00054   vxl_uint_32 map_type_;
00055   vxl_uint_32 map_length_;
00056   vxl_uint_8* col_map_;
00057 
00058   vil_pixel_format format_;
00059 
00060   bool read_header();
00061   bool write_header();
00062 
00063   friend class vil_ras_file_format;
00064  public:
00065 
00066   vil_ras_image(vil_stream* is);
00067   vil_ras_image(vil_stream* is,
00068                 unsigned ni,
00069                 unsigned nj,
00070                 unsigned nplanes,
00071                 vil_pixel_format format );
00072   virtual ~vil_ras_image();
00073 
00074   // Inherit the documentation from vil_image_resource
00075 
00076   virtual unsigned nplanes() const;
00077   virtual unsigned ni() const;
00078   virtual unsigned nj() const;
00079 
00080   virtual vil_pixel_format pixel_format() const;
00081 
00082   //: Create a read/write view of a copy of this data.
00083   //
00084   // This function will always return a multi-plane, scalar-pixel, RGB
00085   // view of the data, even if the disk format is BGR. This follows
00086   // the principle of least surprise, since there is an implicit
00087   // assumption everywhere that 3-component colour image data is
00088   // stored RGB.
00089   //
00090   // \return 0 if unable to get view of correct size, or if resource is write-only.
00091   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00092                                                  unsigned j0, unsigned nj) const;
00093 
00094   virtual bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0);
00095 
00096   char const* file_format() const;
00097   bool get_property(char const *tag, void *prop = 0) const;
00098 };
00099 
00100 #endif // vil_ras_file_format_h_