cgv
image_reader.h
1 #pragma once
2 
3 #include <cgv/base/base.h>
4 #include <cgv/data/data_view.h>
5 
6 #include "lib_begin.h"
7 
8 using namespace cgv::data;
9 
10 namespace cgv {
11  namespace media {
13  namespace image {
14 
15 class CGV_API image_reader;
16 
18 class CGV_API abst_image_reader : public cgv::base::base
19 {
20 public:
21  friend class image_reader;
23  virtual abst_image_reader* clone() const = 0;
25  virtual const std::string& get_last_error() const = 0;
27  virtual const char* get_supported_extensions() const = 0;
29  virtual bool open(const std::string& file_name, data_format& df, std::vector<data_format>* palette_formats) = 0;
31  virtual bool supports_per_line_read() const = 0;
33  virtual bool supports_multiple_images() const;
35  virtual unsigned get_nr_images() const;
37  virtual float get_image_duration() const;
39  virtual unsigned get_current_image() const;
41  virtual bool seek_image(unsigned idx);
43 
45  virtual bool read_palette(unsigned int i, const data_view& dv);
47  virtual bool read_line(const data_format& df, const data_view& dv) = 0;
49 
53  virtual bool read_image(const data_format& df, const data_view& dv) = 0;
55  virtual bool close() = 0;
56 
57 };
58 
62 class CGV_API image_reader : public cgv::base::base
63 {
64 protected:
68  std::vector<data_format>* palette_formats;
72  std::string last_error;
74  bool set_void(const std::string& property, const std::string& type, const void* value);
76  bool get_void(const std::string& property, const std::string& type, void* value);
77 public:
83  image_reader(data_format& file_format, std::vector<data_format>* palette_formats = 0);
84  ~image_reader() {}
86  std::string get_type_name() const;
88  static const std::string& get_supported_extensions(char sep = ';');
90  static std::string construct_filter_string();
92  std::string get_property_declarations();
94  const std::string& get_last_error() const;
101  bool read_image(const std::string& file_name, data_view& dv, std::vector<data_view> *palettes = 0);
104  bool read_image(const std::string& file_name, const data_view& dv, const std::vector<data_view> *palettes = 0);
106  bool open(const std::string& file_name);
108  data_format* get_file_format() const;
110  bool supports_multiple_images() const;
112  unsigned get_nr_images() const;
114  float get_image_duration() const;
116  unsigned get_current_image() const;
118  bool seek_image(unsigned idx);
120 
122  bool read_palette(unsigned int i, data_view& dv);
124 
126  bool read_palette(unsigned int i, const data_view& dv);
128  bool supports_per_line_read() const;
133  bool read_line(data_view& dv);
135  bool read_line(const data_view& dv);
137 
142  bool read_image(data_view& dv, std::vector<data_view> *palettes = 0);
144  bool read_image(const data_view& dv, const std::vector<data_view> *palettes = 0);
146  bool close();
147 };
148 
149  }
150  }
151 }
152 
153 #include <cgv/config/lib_end.h>
cgv::media::image::image_reader::last_error
std::string last_error
last error message in case no reader is available
Definition: image_reader.h:72
cgv::media::image::abst_image_reader::read_image
virtual bool read_image(const data_format &df, const data_view &dv)=0
read an image into the given data pointer.
cgv::media::image::abst_image_reader::close
virtual bool close()=0
close the image file
cgv::media::image::image_reader::file_format_ptr
data_format * file_format_ptr
store the data format
Definition: image_reader.h:66
cgv::media::image::image_reader::palette_formats
std::vector< data_format > * palette_formats
store a pointer to the palette format vector
Definition: image_reader.h:68
cgv::media::image::abst_image_reader::clone
virtual abst_image_reader * clone() const =0
construct a copy of the reader
cgv::media::image::image_reader
Definition: image_reader.h:63
cgv::media::image::abst_image_reader
abstract interface for image readers
Definition: image_reader.h:19
cgv::media::image::image_reader::rd
abst_image_reader * rd
store a pointer to the chosen reader
Definition: image_reader.h:70
cgv::media::image::abst_image_reader::open
virtual bool open(const std::string &file_name, data_format &df, std::vector< data_format > *palette_formats)=0
open the file and read the image header in order to determine the data format
cgv::data
namespace for data management components
Definition: ascii_io_reflection_handlers.cxx:15
cgv::data::data_view
Definition: data_view.h:155
cgv::data::data_format
Definition: data_format.h:18
cgv::media::image::abst_image_reader::get_last_error
virtual const std::string & get_last_error() const =0
return a reference to the last error message
cgv::base::base
Definition: base.h:57
cgv::type::info::get_type_name
const char * get_type_name(TypeId tid)
function that returns the name of a type specified through TypeId
Definition: type_id.cxx:117
cgv::media::image::abst_image_reader::supports_per_line_read
virtual bool supports_per_line_read() const =0
whether the reader supports per line reading (only valid after successful opening an image file
cgv::media::image::abst_image_reader::read_line
virtual bool read_line(const data_format &df, const data_view &dv)=0
read the next line into the given data pointer, set data format if not yet specified and allocate the...
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::media::image::abst_image_reader::get_supported_extensions
virtual const char * get_supported_extensions() const =0
return a string containing a colon separated list of extensions that can be read with this reader