Loading...
Searching...
No Matches
ImageFile.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_IMAGE_IMAGEFILE_H_
32#define DRAIN_IMAGE_IMAGEFILE_H_
33
34#include "MagickDrain.h"
35
36#include <string>
37
38#include "ImageChannel.h"
39#include "Image.h"
40#include "ImageT.h"
41
42// #include "drain/util/MetaDataReader.h"
43
44
45namespace drain
46{
47namespace image
48{
49
50
52{
53public:
54
55 static // inline //
56 void read(Image &img, const std::string & path); /*{
57
58 drain::Logger mout(getImgLog(), __FILE__, __FUNCTION__);
59 if (FilePnm::fileNameRegExp.test(path)){
60 mout.debug("file format: PNM" );
61 FilePnm::read(img, path); // , commentReader
62 }
63 else {
64 if (FilePng::fileNameRegExp.test(path))
65 mout.debug("file format: PNG" );
66 else
67 mout.warn("unrecognized extension, assuming PNG" );
68 FilePng::read(img, path); // , commentReader
69 }
70 }
71 */
72
73 static
74 void readFrame(ImageFrame &img, const std::string & path);
75
76 /*
77 static inline
78 void readFrame(ImageFrame &img, const std::string & path){
79
80 drain::Logger mout(getImgLog(), __FILE__, __FUNCTION__);
81 if (FilePng::fileNameRegExp.test(path)){
82 mout.debug("file format: PNG" );
83 FilePng::read(img, path);
84 }
85 else if (FilePnm::fileNameRegExp.test(path)){
86 mout.debug("file format: PNM" );
87 FilePnm::readFrame(img, path);
88 }
89 else {
90 mout.warn("unrecognized extension, assuming png" );
91 FilePng::read(img, path);
92 }
93 }
94 */
95
96/*
97 template <class T>
98 static void read(ImageT<T> &img, const std::string &path){
99#ifdef DRAIN_MAGICK_yes
100 Magick::ImageT magickImage;
101 magickImage.read(path);
102 MagickDrain::convert(magickImage,img);
103#else
104 // Todo PNM support
105 //FilePng::read(img,path);
106 //FilePng::read(img,path);
107#endif
108 }
109*/
110
111 //static void read(Image<unsigned char> &image,const std::string &path);
112 static // inline
113 void write(const ImageFrame &img,const std::string &path);
114 /*{
115
116 drain::Logger mout(getImgLog(), __FILE__, __FUNCTION__);
117
118 if (FilePng::fileNameRegExp.test(path)){
119 mout.debug("file format: PNG" );
120 FilePng::write(img, path);
121 }
122 else if (FilePnm::fileNameRegExp.test(path)){
123 mout.debug("file format: PNM" );
124 FilePnm::write(img, path);
125 }
126 else {
127 mout.warn("unrecognized extension, assuming png" );
128 FilePng::write(img, path);
129 }
130 }
131 */
132
133 /*
134 template <class T>
135 static void write(const ImageT<T> &img,const std::string &path){
136#ifdef DRAIN_MAGICK_yes
137
138 Magick::ImageT magickImage;
139 magickImage.size("1x1");
140 magickImage.magick("RGBA");
141
142 if (Debug > 1)
143 std::cerr << "Converting image to Magick image." << std::endl;
144
145 MagickDrain::convert(img,magickImage);
146
147 if (Debug > 0)
148 std::cerr << "Writing image" << img.getName() << " to "<< path << std::endl;
149
150 magickImage.write(path);
151#else
152 FilePng::write(img,path);
153#endif
154 }
155 */
156
158
165 static
166 void writeIndexed(const ImageFrame &image, const std::string & pathPrefix, int i=-1, int digits=3);
167
168protected:
169
171
177 template <class T>
178 static
179 void initialize(T &, const std::type_info & t, const Geometry & g);
180
181 static
182 int index;
183
184};
185
186
187} // image
188
189} // drain
190
191#endif /*FILE_H_*/
192
193// Drain
Definition Geometry.h:145
Definition ImageFile.h:52
static void writeIndexed(const ImageFrame &image, const std::string &pathPrefix, int i=-1, int digits=3)
Writes image to a file, naming it: prefix + index + ".png", using desired number of leading zeros.
Definition ImageFile.cpp:116
static void initialize(T &, const std::type_info &t, const Geometry &g)
Sets target type and geometry.
Image with static geometry.
Definition ImageFrame.h:67
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:184
Definition DataSelector.cpp:1277