1 // This is core/vil/file_formats/vil_pnm.h 2 #ifndef vil_pnm_file_format_h_ 3 #define vil_pnm_file_format_h_ 4 //: 5 // \file 6 // \author awf@robots.ox.ac.uk 7 // \date 16 Feb 00 8 // 9 // \verbatim 10 // Modifications 11 // 7 June 2001 - Peter Vanroose - made pbm (magic P4) working 12 // 3 October 2001 Peter Vanroose - Implemented get_property("top_row_first") 13 // 20 Sep 2002 Ian Scott - Converted to vil. 14 //\endverbatim 15 16 #include <vil/vil_image_resource.h> 17 #include <vil/vil_file_format.h> 18 #include <vil/vil_stream.h> 19 20 class vil_image_view_base; 21 22 23 //: Loader for PPM,PGM,PBM files 24 class vil_pnm_file_format : public vil_file_format 25 { 26 public: 27 char const* tag() const override; 28 vil_image_resource_sptr make_input_image(vil_stream* vs) override; 29 vil_image_resource_sptr make_output_image(vil_stream* vs, 30 unsigned ni, 31 unsigned nj, 32 unsigned nplanes, 33 vil_pixel_format format) override; 34 }; 35 36 //: Alias name for pnm; only tag() differs 37 class vil_pbm_file_format : public vil_pnm_file_format 38 { 39 public: tag()40 char const* tag() const override { return "pbm"; } 41 }; 42 43 //: Alias name for pnm; only tag() differs 44 class vil_pgm_file_format : public vil_pnm_file_format 45 { 46 public: tag()47 char const* tag() const override { return "pgm"; } 48 }; 49 50 //: Alias name for pnm; only tag() differs 51 class vil_ppm_file_format : public vil_pnm_file_format 52 { 53 public: tag()54 char const* tag() const override { return "ppm"; } 55 }; 56 57 //: Generic image implementation for PNM files 58 class vil_pnm_image : public vil_image_resource 59 { 60 vil_stream* vs_; 61 int magic_; 62 unsigned ni_; 63 unsigned nj_; 64 unsigned long int maxval_; 65 66 vil_streampos start_of_data_; 67 unsigned ncomponents_; 68 unsigned bits_per_component_; 69 70 //: Describe the format of each pixel. 71 vil_pixel_format format_; 72 73 bool read_header(); 74 bool write_header(); 75 76 friend class vil_pnm_file_format; 77 78 public: 79 vil_pnm_image (vil_stream* is, unsigned ni, 80 unsigned nj, unsigned nplanes, 81 vil_pixel_format format); 82 vil_pnm_image(vil_stream* is); 83 ~vil_pnm_image() override; 84 85 // Inherit the documentation from vil_image_resource 86 nplanes()87 unsigned nplanes() const override { return ncomponents_; } ni()88 unsigned ni() const override { return ni_; } nj()89 unsigned nj() const override { return nj_; } 90 pixel_format()91 enum vil_pixel_format pixel_format() const override {return format_; } 92 93 vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni, 94 unsigned j0, unsigned nj) const override; 95 96 bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0) override; 97 98 char const* file_format() const override; 99 bool get_property(char const *tag, void *prop = nullptr) const override; 100 }; 101 102 #endif // vil_pnm_file_format_h_ 103