MeteoIODoc  MeteoIODoc-2.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PNGIO.h
Go to the documentation of this file.
1 /***********************************************************************************/
2 /* Copyright 2011 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
3 /***********************************************************************************/
4 /* This file is part of MeteoIO.
5  MeteoIO is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  MeteoIO is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef PNGIO_H
19 #define PNGIO_H
20 
21 #include <meteoio/IOInterface.h>
22 #include <meteoio/Graphics.h>
23 
24 #include <string>
25 #include <png.h>
26 
27 namespace mio {
36 class PNGIO : public IOInterface {
37  public:
38  PNGIO(const std::string& configfile);
39  PNGIO(const PNGIO&);
40  PNGIO(const Config& cfgreader);
41  ~PNGIO() throw();
42 
43  PNGIO& operator=(const PNGIO&);
44 
45  virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& filename);
46  virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
47 
48  private:
49  void setOptions();
50  static void parse_size(const std::string& size_spec, size_t& width, size_t& height);
51  double getScaleFactor(const size_t& grid_w, const size_t& grid_h) const;
52  Grid2DObject scaleGrid(const Grid2DObject& grid_in) const;
53  size_t setLegend(const size_t &ncols, const size_t &nrows, const double &min, const double &max, Array2D<double> &legend_array) const;
54  static void setPalette(const Gradient &gradient, png_structp& png_ptr, png_infop& info_ptr, png_color *palette);
55  void createMetadata(const Grid2DObject& grid);
56  void writeMetadata(png_structp &png_ptr, png_infop &info_ptr);
57  void setFile(const std::string& filename, png_structp& png_ptr, png_infop& info_ptr, const size_t &width, const size_t &height);
58  void writeWorldFile(const Grid2DObject& grid_in, const std::string& filename) const;
59  void writeDataSection(const Grid2DObject &grid, const Array2D<double> &legend_array, const Gradient &gradient, const size_t &full_width, const png_structp &png_ptr, png_infop& info_ptr);
60  void closePNG(png_structp& png_ptr, png_infop& info_ptr, png_color *palette);
61  static std::string decimal_to_dms(const double& decimal);
62 
63  const Config cfg;
64  FILE *fp; //since passing fp always fail...
65  bool autoscale;
66  bool has_legend;
67  bool has_world_file;
68  bool optimize_for_speed;
69  bool indexed_png;
70  unsigned char nr_levels;
71  std::string coordout, coordoutparam; //projection parameters
72  std::string grid2dpath;
73 
74  std::string scaling;
75  size_t min_w, min_h, max_w, max_h;
76 
77  std::vector<std::string> metadata_key, metadata_text;
78 
79  static const double plugin_nodata; //plugin specific nodata value, e.g. -999
80  static const unsigned char channel_depth;
81  static const unsigned char channel_max_color;
82  static const unsigned char transparent_grey;
83 };
84 
85 } //namespace
86 #endif
A class representing the IO Layer of the software Alpine3D. For each type of IO (File, DB, Webservice, etc) a derived class is to be created that holds the specific implementation of the appropriate virtual methods. The IOHandler class is a wrapper class that is able to deal with all above implementations of the IOInterface abstract base class.
Definition: IOInterface.h:43
PNGIO & operator=(const PNGIO &)
Assignement operator, required because of pointer member.
Definition: PNGIO.cc:131
This plugin write 2D grids as PNG images.
Definition: PNGIO.h:36
~PNGIO()
Definition: PNGIO.cc:154
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition: Config.h:58
A class to represent 2D Grids. Typical application as DEM or Landuse Model.
Definition: Grid2DObject.h:37
This converts numeric values into rgb values. The object is initialized with the range that the gradi...
Definition: Graphics.h:180
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:79
PNGIO(const std::string &configfile)
Definition: PNGIO.cc:109
virtual void write2DGrid(const Grid2DObject &grid_in, const std::string &filename)
Write a Grid2DObject The filename is specified relative to GRID2DPATH for most plugins.
Definition: PNGIO.cc:430
Parameters
Definition: MeteoData.h:44