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