Loading...
Searching...
No Matches
FileTIFF.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25 */
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31#ifndef DRAIN_TIFF_H_EXPERIMENTAL
32#define DRAIN_TIFF_H_EXPERIMENTAL
33
34#include <drain/Log.h>
35#include "drain/util/FileInfo.h"
36#include "drain/Dictionary.h"
37#include "drain/util/Time.h"
38#include "Image.h"
39
40#ifndef USE_GEOTIFF_NO
41
42#include <xtiffio.h>
43#endif
44
45namespace drain
46{
47
48namespace image
49{
50
51
52
54
56class FileTIFF { //: public FileHandler{
57public:
58
59
60 static
61 const drain::FileInfo fileInfo;
62
63 // OLD (Weak?)
65
66 static const dict_t compressionDict;
67 /*
68 static
69 const dict_t & getCompressionDict();
70 */
71
72 // https://www.awaresystems.be/imaging/tiff/tifftags/compression.html
73 // https://gdal.org/drivers/raster/cog.html
74 static dict_t::value_t defaultCompression; // COMPRESSION_NONE = 1; COMPRESSION_LZW = 5;
75 // static int defaultCompressionLevel; // COMPRESSION_NONE = 1; COMPRESSION_LZW = 5;
76
77 static drain::Frame2D<int> defaultTile;
78
79
80#ifndef USE_GEOTIFF_NO
81
82
83 inline
84 FileTIFF(const std::string & path = "", const std::string & mode = "w") : tif(nullptr), tile(defaultTile){ // FileHandler(__FUNCTION__),
85 if (!path.empty())
86 open(path, mode);
87 //tif = XTIFFOpen(path.c_str(), mode);
88 }
89
90 virtual inline
91 ~FileTIFF(){
92 //mout.special("Closing FileTIFF");
93 close();
94 }
95
96 virtual inline
97 void open(const std::string & path, const std::string & mode = "w"){
98 tif = XTIFFOpen(path.c_str(), mode.c_str());
99 }
100
101 virtual inline
102 bool isOpen() const {
103 return (tif != nullptr);
104 }
105
106 virtual inline
107 void close(){
108 if (isOpen()){
109 drain::Logger mout(__FILE__, __FUNCTION__);
110 mout.debug("Closing TIFF...");
111 XTIFFClose(tif);
112 tif = nullptr;
113 }
114 }
115
116 inline
117 int setField(int tag, const std::string & value){
118 if (!isOpen()){
119 drain::Logger mout(__FILE__, __FUNCTION__);
120 mout.error("TIFF file not open");
121 }
122 return TIFFSetField(tif, tag, value.c_str());
123 }
124
125 template <class T>
126 inline
127 int setField(int tag, const std::vector<T> & value){
128 if (!isOpen()){
129 drain::Logger mout(__FILE__, __FUNCTION__);
130 mout.error("TIFF file not open");
131 //return 0;
132 }
133 return TIFFSetField(tif, tag, value.size(), &value.at(0));
134 }
135
136 template <class T>
137 inline
138 int setField(int tag, T value){
139 if (!isOpen()){
140 drain::Logger mout(__FILE__, __FUNCTION__);
141 mout.error("TIFF file not open");
142 //return 0;
143 }
144 return TIFFSetField(tif, tag, value);
145 }
146
147
148 inline
149 void useDefaultTileSize(){
150 this->tile = defaultTile;
151 }
152
153 inline
154 void setTileSize(int tileWidth, int tileHeight = 0){
155 if (tileWidth == 0){
156 tile = {0,0};
157 //this->tile = defaultTile;
158 }
159 else {
160 tile.setWidth(tileWidth);
161 if (tileHeight == 0){
162 tileHeight = tileWidth;
163 }
164 tile.setHeight(tileHeight);
165 }
166 }
167
170 void setTime(const drain::Time & time);
171
175 void setDefaults(); //, int tileWidth=0, int tileHeight = 0);
176 //void setDefaults(const drain::image::ImageConf & src); //, int tileWidth=0, int tileHeight = 0);
177
178 void writeImageData(const drain::image::Image & src);
179
181
184 static
185 void write(const std::string & path, const drain::image::Image & src);
186
187
188protected:
189
190 TIFF *tif;
191
193
194
195#endif
196
197};
198
199} // image::
200
201} // drain::
202
203
204
205#endif
Two-way mapping between strings and objects of template class T.
Definition Dictionary.h:61
Definition FileInfo.h:47
Something that has width and height.
Definition Frame.h:53
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:667
Logger & error(const TT &... args)
Echoes.
Definition Log.h:417
Utility for handling time. Internally, uses tm (C time structure).
Definition Time.h:53
For writing images in basic TIFF format. Reading not supported currently.
Definition FileTIFF.h:56
static void write(const std::string &path, const drain::image::Image &src)
Default implementation.
Definition FileTIFF.cpp:320
void writeImageData(const drain::image::Image &src)
Definition FileTIFF.cpp:106
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:183
Definition DataSelector.cpp:1277