core/vil/file_formats/vil_png.h
Go to the documentation of this file.
00001 // This is core/vil/file_formats/vil_png.h
00002 #ifndef vil_png_file_format_h_
00003 #define vil_png_file_format_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author   awf@robots.ox.ac.uk
00010 // \date 17 Feb 00
00011 //
00012 //\verbatim
00013 //  Modifications
00014 //  3 October 2001 Peter Vanroose - Implemented get_property("top_row_first")
00015 // 13 November 2002 Ian Scott - Converted to vil
00016 //\endverbatim
00017 
00018 #include <vil/vil_file_format.h>
00019 #include <vil/vil_image_resource.h>
00020 
00021 struct vil_png_structures;
00022 
00023 //: Portable network graphics, http://www.cdrom.com/pub/png
00024 class vil_png_file_format : public vil_file_format
00025 {
00026  public:
00027   virtual char const* tag() const;
00028   virtual vil_image_resource_sptr make_input_image(vil_stream* vs);
00029   virtual vil_image_resource_sptr make_output_image(vil_stream* vs,
00030                                                     unsigned nx,
00031                                                     unsigned ny,
00032                                                     unsigned nplanes,
00033                                                     enum vil_pixel_format);
00034 };
00035 
00036 //: Generic image implementation for PNG files
00037 class vil_png_image : public vil_image_resource
00038 {
00039   vil_stream* vs_;
00040   int width_;
00041   int height_;
00042   int components_;
00043   int bits_per_component_;
00044   vil_pixel_format format_;
00045   int start_of_data_;
00046 
00047   bool read_header();
00048   bool write_header();
00049 
00050   friend class vil_png_file_format;
00051   vil_png_structures* p_;
00052  public:
00053 
00054   vil_png_image(vil_stream* is);
00055   vil_png_image(vil_stream* is, unsigned ni,
00056                 unsigned nj, unsigned nplanes,
00057                 vil_pixel_format format);
00058   ~vil_png_image();
00059 
00060   //: Dimensions:  planes x width x height x components
00061   virtual unsigned nplanes() const { return components_;}
00062   virtual unsigned ni() const { return width_; }
00063   virtual unsigned nj() const { return height_; }
00064 
00065   virtual enum vil_pixel_format pixel_format() const {return format_;}
00066 
00067   //: Create a read/write view of a copy of this data.
00068   // \return 0 if unable to get view of correct size.
00069   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00070                                                  unsigned j0, unsigned nj) const;
00071 
00072   //: Put the data in this view back into the image source.
00073   virtual bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0);
00074 
00075   char const* file_format() const;
00076   bool get_property(char const *tag, void *prop = 0) const;
00077 };
00078 
00079 #endif // vil_png_file_format_h_