PICCANTE  0.4
The hottest HDR imaging library!
filter_combine.hpp
Go to the documentation of this file.
1 /*
2 
3 PICCANTE
4 The hottest HDR imaging library!
5 http://vcg.isti.cnr.it/piccante
6 
7 Copyright (C) 2014
8 Visual Computing Laboratory - ISTI CNR
9 http://vcg.isti.cnr.it
10 First author: Francesco Banterle
11 
12 This Source Code Form is subject to the terms of the Mozilla Public
13 License, v. 2.0. If a copy of the MPL was not distributed with this
14 file, You can obtain one at http://mozilla.org/MPL/2.0/.
15 
16 */
17 
18 #ifndef PIC_FILTERING_FILTER_COMBINE_HPP
19 #define PIC_FILTERING_FILTER_COMBINE_HPP
20 
21 #include "../filtering/filter.hpp"
22 
23 #include "../filtering/filter_channel.hpp"
24 
25 namespace pic {
26 
30 class FilterCombine: public Filter
31 {
32 protected:
33 
38  virtual void f(FilterFData *data)
39  {
40  int k2 = 0;
41 
42  for(auto i = 0; i < data->nSrc; i++) {
43  float *tmp_src = (*data->src[i])(data->x, data->y);
44 
45  for(int k = 0; k < data->src[i]->channels; k++) {
46  data->out[k2] = tmp_src[k];
47  k2++;
48  }
49  }
50  }
51 
58  /*
59  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
60  {
61  for(int p = box->z0; p < box->z1; p++) {
62  for(int j = box->y0; j < box->y1; j++) {
63  for(int i = box->x0; i < box->x1; i++) {
64  int c = p * dst->tstride + j * dst->ystride + i * dst->xstride;
65  int k2 = 0;
66 
67  for(unsigned int im = 0; im < src.size(); im++) {
68  int c2 = p * src[im]->tstride + j * src[im]->ystride + i * src[im]->xstride;
69 
70  for(int k = 0; k < src[im]->channels; k++) {
71  dst->data[c + k2] = src[im]->data[c2 + k];
72  k2++;
73  }
74  }
75  }
76  }
77  }
78  }*/
79 
86  Image *setupAux(ImageVec imgIn, Image *imgOut)
87  {
88  int channels = imgIn[0]->channels;
89  for(unsigned int i = 1; i < imgIn.size(); i++) {
90  channels += imgIn[i]->channels;
91 
92  if(!imgIn[0]->isSimilarType(imgIn[i])) {
93  return NULL;
94  }
95  }
96 
97  if(imgOut == NULL) {
98  imgOut = new Image(imgIn[0]->frames, imgIn[0]->width, imgIn[0]->height,
99  channels);
100  } else {
101  bool bAllocate = false;
102  if(!imgOut->isValid()) {
103  bAllocate = true;
104  } else {
105  bAllocate = imgOut->channels != channels;
106  }
107 
108  if(bAllocate) {
109  imgOut = new Image(imgIn[0]->frames, imgIn[0]->width, imgIn[0]->height,
110  channels);
111  }
112  }
113 
114  return imgOut;
115  }
116 
117 public:
118 
123  {
124 
125  }
126 
134  static Image *addAlpha(Image *imgIn, Image *imgOut, float value)
135  {
136  //create an alpha channel
137  Image *alpha = new Image(imgIn->frames, imgIn->width, imgIn->height, 1);
138  *alpha = value;
139 
140  //add the channel to the image
141  ImageVec src;
142  src.push_back(imgIn);
143  src.push_back(alpha);
144 
145  FilterCombine filterC;
146  imgOut = filterC.Process(src, imgOut);
147 
148  delete alpha;
149  return imgOut;
150  }
151 
158  static Image *execute(ImageVec imgIn, Image *imgOut)
159  {
160  FilterCombine filterC;
161  return filterC.Process(imgIn, imgOut);
162  }
163 
170  static Image *getOnlyRGB(Image *imgIn, Image *imgOut)
171  {
172  ImageVec src;
173  FilterChannel filter(SingleInt(0));
174 
175  for(int i = 0; i < 3; i++) {
176  Image *out = filter.Process(Single(imgIn), NULL);
177  src.push_back(out);
178  filter.update(SingleInt(i + 1));
179  }
180 
181  imgOut = execute(src, NULL);
182 
183  return imgOut;
184  }
185 };
186 
187 } // end namespace pic
188 
189 #endif /* PIC_FILTERING_FILTER_COMBINE_HPP */
190 
FilterCombine()
FilterCombine.
Definition: filter_combine.hpp:122
int y
Definition: filter.hpp:39
int channels
Definition: image.hpp:80
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
The Filter class.
Definition: filter.hpp:50
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
Definition: filter.hpp:37
int frames
Definition: image.hpp:80
float * out
Definition: filter.hpp:40
The FilterCombine class.
Definition: filter_combine.hpp:30
void update(std::vector< int > channels_vec)
update
Definition: filter_channel.hpp:103
The FilterChannel class.
Definition: filter_channel.hpp:56
int x
Definition: filter.hpp:39
static Image * addAlpha(Image *imgIn, Image *imgOut, float value)
addAlpha
Definition: filter_combine.hpp:134
The Image class stores an image as buffer of float.
Definition: image.hpp:60
static Image * getOnlyRGB(Image *imgIn, Image *imgOut)
getOnlyRGB
Definition: filter_combine.hpp:170
static Image * execute(ImageVec imgIn, Image *imgOut)
execute
Definition: filter_combine.hpp:158
ImageVec src
Definition: filter.hpp:43
PIC_INLINE ImageVec Single(Image *img)
Single creates an std::vector which contains img; this is for filters input.
Definition: image_vec.hpp:36
int nSrc
Definition: filter.hpp:44
Definition: bilateral_separation.hpp:25
bool isValid()
isValid checks if the current image is valid, which means if they have an allocated buffer or not...
PIC_INLINE std::vector< int > SingleInt(int v0)
SingleInt.
Definition: filter_channel.hpp:30
virtual void f(FilterFData *data)
f
Definition: filter_combine.hpp:38
int width
Definition: image.hpp:80
int height
Definition: image.hpp:80
Image * setupAux(ImageVec imgIn, Image *imgOut)
ProcessBBox.
Definition: filter_combine.hpp:86