FotoSHOCK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
FillFunc.hpp
1 /*
2  * Copyright 2011, 2012 Lukas Jirkovsky
3  *
4  * This file is part of FotoSHOCKcore.
5  *
6  * FotoSHOCKcore is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, version 3 of the License.
9  *
10  * FotoSHOCKcore is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with FotoSHOCKcore. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef FILLFUNC_H
20 #define FILLFUNC_H
21 
22 #include "PixelData.hpp"
23 #include "ValueType.hpp"
24 
25 #include <cstring>
26 #include <string>
27 
28 namespace FotoSHOCKcore {
29 
37 template <typename Format>
38 class FillFunctor {
39  public:
40  FillFunctor(PixelData format, const std::string color) : m_format(format) {
41  m_color = new Format[format.numOfBands()];
42  if (color == "white") {
43  // TODO: support for other color spaces
44  for (int i = 0; i < format.numOfBands(); i++) {
45  switch(format.format()) {
46  #define FORMAT_DO_STH(T,U) m_color[i] = ValueTypeInfo<T>::max();
47  case_ANY;
48  #undef FORMAT_DO_STH
49  }
50  }
51  }
52 
53  else if (color == "black") {
54  // TODO: support for other color spaces
55  for (int i = 0; i < format.numOfBands(); i++) {
56  switch(format.format()) {
57  #define FORMAT_DO_STH(T,U) m_color[i] = ValueTypeInfo<T>::min();
58  case_ANY;
59  #undef FORMAT_DO_STH
60  }
61  }
62  }
63  };
64 
65  FillFunctor(const FillFunctor<Format>& other) : m_format(other.m_format) {
66  m_color = new Format[m_format.numOfBands()];
67  std::memcpy(m_color, other.m_color, m_format.numOfBands() * sizeof(Format));
68  }
69 
70  ~FillFunctor() {
71  delete[] m_color;
72  }
73 
74  void operator()(Format* /*in*/, Format* out) {
75  for (int i = 0; i < m_format.numOfBands(); i++) {
76  out[i] = m_color[i];
77  }
78  }
79 
80  private:
81  const PixelData m_format;
82  Format* m_color;
83 };
84 
85 }
86 
87 #endif