Loading...
Searching...
No Matches
ResizeOp.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 ResizeOP_H_
32#define ResizeOP_H_
33
34#include "ImageOp.h"
35
36namespace drain
37{
38
39namespace image
40{
41// help copy
42
43
45
65class ResizeOp : public ImageOp {
66
67public:
68
69 ResizeOp(size_t width=0, size_t height=0, const std::string & interpolation = "n") : ImageOp(__FUNCTION__, "Resize geometry and scale intensities") {
70 this->parameters.link("width", this->width=width, "pix");
71 this->parameters.link("height", this->height=height, "pix");
72 this->parameters.link("interpolation", this->interpolation=interpolation, "n=nearest,b=bilinear");
73 this->parameters.link("scale", this->scale = 1.0, "rescaling factor");
74 }
75
76 inline
77 void setWidth(size_t w){
78 this->width = w;
79 }
80
81 inline
82 void setHeight(size_t h){
83 this->height = h;
84 }
85
86 inline
87 void setGeometry(const AreaGeometry & area){
88 this->width = area.getWidth();
89 this->height = area.getHeight();
90 }
91
92 inline
93 void setScale(double s){
94 this->scale = s;
95 }
96
98
102 inline
103 void setScale(int d, int n){
104 this->scale = static_cast<double>(d) / static_cast<double>(n);
105 }
106
107
108 size_t width;
109 size_t height;
110 std::string interpolation;
111 double scale;
112 //
113 virtual
114 // void make Compatible(const ImageFrame & src, Image & dst) const;
115 void getDstConf(const ImageConf &srcConf, ImageConf & dstConf) const;
116
117 inline
118 void traverseChannels(const ImageTray<const Channel> & src, ImageTray<Channel> & dst) const {
119 drain::Logger mout(getImgLog(), __FILE__, __FUNCTION__); //REPL this->name+"[const ChannelTray &, ChannelTray &]", __FUNCTION__);
120 traverseChannelsEqually(src, dst);
121 }
122
124
127 virtual
128 void traverseChannel(const Channel & src, Channel & dst) const;
129
131
134 virtual // TODO: deprecated?
135 inline
136 void traverseChannel(const Channel & src, const Channel & srcAlpha, Channel & dst, Channel & dstAlpha) const {
137 drain::Logger mout(getImgLog(), __FILE__, __FUNCTION__); //REPL this->name+"[2+2]", __FUNCTION__);
138 mout.note("delegating to: 2 x traverseChannel(2)" );
139 traverseChannel(src, dst);
140 traverseChannel(srcAlpha, dstAlpha);
141 }
142
143protected:
144
145 inline
146 double getRounds(double value, int & cFloor, int & cCeil) const {
147 double f = floor(value);
148 cFloor = static_cast<int>(f);
149 cCeil = static_cast<int>(ceil(value));
150 return (value-f);
151 }
152
153
154};
155
156
157} // image::
158
159} // drain::
160
161#endif /*ResizeOP_H_*/
162
163// Drain
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & note(const TT &... args)
For top-level information.
Definition Log.h:489
Image with static geometry.
Definition ImageChannel.h:60
Struct for image (excluding data)
Definition ImageConf.h:333
virtual int srcAlpha() const
Tell if alpha channel(s) is required in input.
Definition ImageMod.h:66
Base class for image processing functions.
Definition ImageOp.h:49
void traverseChannelsEqually(const ImageTray< const Channel > &src, ImageTray< Channel > &dst) const
Calls processWithTemp() if the frames overlap.
Definition ImageOp.cpp:414
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:267
Resizes the image, stretching the image correspondingly.
Definition ResizeOp.h:65
virtual void getDstConf(const ImageConf &srcConf, ImageConf &dstConf) const
Given source image, determine respective dest image configuration.
Definition ResizeOp.cpp:38
void setScale(int d, int n)
Sets scale to fraction d/n.
Definition ResizeOp.h:103
virtual void traverseChannel(const Channel &src, Channel &dst) const
The main functionality called by traverseFrame() after image compatibility check and tmp allocations.
Definition ResizeOp.cpp:55
virtual void traverseChannel(const Channel &src, const Channel &srcAlpha, Channel &dst, Channel &dstAlpha) const
The main functionality called by traverseFrame() after image compatibility check and tmp allocations.
Definition ResizeOp.h:136
Definition DataSelector.cpp:1277