Loading...
Searching...
No Matches
ImageChannel.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 IMAGE_CHANNEL_H_
32#define IMAGE_CHANNEL_H_ "ImageFrame 0.9, 2011.09.25 Markus.Peura@fmi.fi"
33
34#include <stddef.h> // size_t
35
36
37#include <drain/CastableIterator.h>
38
39#include "ImageFrame.h"
40
41
42namespace drain
43{
44
46namespace image
47{
48
49
51
58class Channel : public ImageFrame {
59
60public:
61
62 inline
63 Channel(){
64 };
65
66 // TODO: CHECK: only type/scaling/geometry/coordinate-policy are copied via setters (per the
67 // comment above, a general conf copy was rejected as "TOO GENERAL, discards scalingPtr");
68 // the pixel buffer itself is not copied. Confirm this is the intended (metadata-only) copy
69 // semantics. Also causes -Wdeprecated-copy (user-declared copy ctor, no operator=); given the
70 // above, a blind `=default` operator= is not obviously equivalent, so needs the same look.
71 inline
72 Channel(const Channel & channel) : ImageFrame(){
73 //conf.setConf() TOO GENERAL, discards scalingPtr
74 setStorageType(channel.getType());
75 conf.setScaling(channel.getScaling()); // NOTE: pointer-selected
76 conf.setGeometry(channel.getGeometry());
77 setCoordinatePolicy(channel.getCoordinatePolicy());
78 //conf.setConf(channel.getConf());
79
80 // conf.setEncoding(channel.getEncoding());
81 };
82
83 virtual inline
84 Channel & getChannel(size_t i){
85 if (i != 0)
86 throw std::runtime_error("Channel: getChannel(i) with i>0");
87 return *this;
88 };
89
90
91 virtual inline
92 const Channel & getChannel(size_t i) const {
93 if (i != 0)
94 throw std::runtime_error("Channel: getChannel(i) with i>0");
95 return *this;
96 }
97
98 virtual inline
99 Channel & getAlphaChannel(size_t i=0){
100 throw std::runtime_error("Channel: getAlphaChannel() impossible");
101 return *this;
102 };
103
104 virtual inline
105 const Channel & getAlphaChannel(size_t i=0) const {
106 throw std::runtime_error("Channel: getAlphaChannel() impossible");
107 return *this;
108 };
109
110
111};
112
114
117class ChannelView : public Channel {
118
119public:
120
121 inline
122 ChannelView(){
123 };
124
125 inline
126 ChannelView(const ChannelView & channel) : Channel(channel) {
127 //std::cerr << "ChannelView copy constr\n";
128 };
129
130 inline
131 ChannelView(const ImageFrame & src, size_t channel = 0) {
132 setView(src, channel);
133 };
134
135 inline
136 void setView(const ImageFrame & src, size_t channel){
137 ImageFrame::setView(src, channel, 1);
138 conf.channels.set(1,0);
139 }
140
141 inline
142 void setView(const Channel & src){
143 ImageFrame::setView(src, 0, 1);
144 conf.channels.set(1,0);
145 }
146
147
148
149};
150
151
153class MultiChannel : public ImageFrame {
154
155public:
156
157 inline
158 MultiChannel(){};
159
160 // TODO: CHECK: only scaling is copied via setter (unlike Channel's copy constructor above,
161 // geometry and coordinate policy are not copied, nor is the pixel buffer). Confirm intentional.
162 // Also causes -Wdeprecated-copy (user-declared copy ctor, no operator=); see Channel above.
163 inline
164 MultiChannel(const MultiChannel & img) : ImageFrame(){
165 this->conf.setScaling(img.getScaling());
166 };
167
168
169 Channel & getChannel(size_t i);
170
171 const Channel & getChannel(size_t i) const;
172
173 Channel & getAlphaChannel(size_t i=0);
174
175 const Channel & getAlphaChannel(size_t i=0) const;
176
177
178 // hide?
179 inline
180 const std::vector<ChannelView> & getChannelVector() const {
182 return channelVector;
183 };
184
185protected:
186
187 void updateChannelVector() const;
188
189 mutable std::vector<ChannelView> channelVector;
190
191
192};
193
194
195
196} // image::
197} // drain::
198
199#endif /* IMAGE_FRAME_H_*/
200
201// Drain
virtual void setScaling(double scale, double offset)
Set linear scaling.
Definition ValueScaling.h:136
View to a single channel.
Definition ImageChannel.h:117
Image with static geometry.
Definition ImageChannel.h:58
Image with static geometry.
Definition ImageFrame.h:62
void setStorageType(const std::type_info &type)
Sets the storage type of the image - typically unsigned char, unsigned int or float....
Definition ImageFrame.cpp:62
void setView(const ImageFrame &src, size_t channelStart, size_t channelCount, bool catenate=false)
Sets the image to view the data and scaling of another image.
Definition ImageFrame.cpp:142
const CoordinatePolicy & getCoordinatePolicy() const
Coord policy.
Definition ImageLike.h:179
const std::type_info & getType() const
Get the storage type.
Definition ImageLike.h:105
Multi-channel ImageFrame.
Definition ImageChannel.h:153
void updateChannelVector() const
Updates channel vector. Copies scaling of the host image.
Definition ImageChannel.cpp:94
Definition Data.h:1473