PICCANTE  0.4
The hottest HDR imaging library!
filter_linear_color_space.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_LINEAR_COLOR_SPACE_HPP
19 #define PIC_FILTERING_FILTER_LINEAR_COLOR_SPACE_HPP
20 
21 #include "../filtering/filter.hpp"
22 
23 namespace pic {
24 
29 {
30 protected:
31  float *matrix;
32  int nMatrix;
33 
40  void ProcessBBox(Image *dst, ImageVec src, BBox *box)
41  {
42  if(src[0]->channels != nMatrix) {
43  return;
44  }
45 
46  int width = dst->width;
47  int channels = src[0]->channels;
48  float *data = src[0]->data;
49 
50  for(int j = box->y0; j < box->y1; j++) {
51  int c = j * width;
52 
53  for(int i = box->x0; i < box->x1; i++) {
54  int c1 = (c + i) * channels;
55 
56  for(int k = 0; k < channels; k++) {
57  float sum = 0.0f;
58  int ind = k * nMatrix;
59 
60  for(int l = 0; l < channels; l++) {
61  sum += data[c1 + l] * matrix[ind + l];
62  }
63 
64  dst->data[c1 + k] = sum;
65  }
66  }
67  }
68  }
69 
70 public:
75  {
76  matrix = NULL;
77  nMatrix = 0;
78  }
79 
81  {
82  if(matrix != NULL) {
83  delete[] matrix;
84  }
85  }
86 
92  {
93  if(matrix == NULL) {
94  matrix = new float[9];
95  }
96 
97  nMatrix = 3;
98 
99  matrix[0] = 0.4124f;
100  matrix[1] = 0.3576f;
101  matrix[2] = 0.1805f;
102  matrix[3] = 0.2126f;
103  matrix[4] = 0.7152f;
104  matrix[5] = 0.0722f;
105  matrix[6] = 0.0193f;
106  matrix[7] = 0.1192f;
107  matrix[8] = 0.9505f;
108 
109  return matrix;
110  }
111 
117  {
118  if(matrix == NULL) {
119  matrix = new float[9];
120  }
121 
122  nMatrix = 3;
123 
124  matrix[0] = 3.2406f;
125  matrix[1] = -1.5372f;
126  matrix[2] = -0.4986f;
127  matrix[3] = -0.9689f;
128  matrix[4] = 1.8758f;
129  matrix[5] = 0.0415f;
130  matrix[6] = 0.0557f;
131  matrix[7] = -0.2040f;
132  matrix[8] = 1.0570f;
133 
134  return matrix;
135  }
136 
143  static Image *execute_RGB_to_XYZ(Image *imgIn, Image *imgOut)
144  {
146 
147  flt.getRGB2XYZMatrix();
148 
149  return flt.Process(Single(imgIn), imgOut);
150  }
151 
158  static Image *execute_XYZ_to_RGB(Image *imgIn, Image *imgOut)
159  {
161 
162  flt.getXYZ2RGBMatrix();
163 
164  return flt.Process(Single(imgIn), imgOut);
165  }
166 
167 };
168 
169 } // end namespace pic
170 
171 #endif /* PIC_FILTERING_FILTER_LINEAR_COLOR_SPACE_HPP */
172 
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
The FilterLinearColorSpace class.
Definition: filter_linear_color_space.hpp:28
static Image * execute_XYZ_to_RGB(Image *imgIn, Image *imgOut)
execute_XYZ_to_RGB
Definition: filter_linear_color_space.hpp:158
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
~FilterLinearColorSpace()
Definition: filter_linear_color_space.hpp:80
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
The Filter class.
Definition: filter.hpp:50
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
float * getRGB2XYZMatrix()
getRGB2XYZMatrix
Definition: filter_linear_color_space.hpp:91
int y0
Definition: bbox.hpp:32
float * getXYZ2RGBMatrix()
getXYZ2RGBMatrix
Definition: filter_linear_color_space.hpp:116
static Image * execute_RGB_to_XYZ(Image *imgIn, Image *imgOut)
execute_RGB_to_XYZ
Definition: filter_linear_color_space.hpp:143
The Image class stores an image as buffer of float.
Definition: image.hpp:60
FilterLinearColorSpace()
FilterLinearColorSpace.
Definition: filter_linear_color_space.hpp:74
PIC_INLINE ImageVec Single(Image *img)
Single creates an std::vector which contains img; this is for filters input.
Definition: image_vec.hpp:36
Definition: bilateral_separation.hpp:25
float * matrix
Definition: filter_linear_color_space.hpp:31
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_linear_color_space.hpp:40
int width
Definition: image.hpp:80
int nMatrix
Definition: filter_linear_color_space.hpp:32