File: img_attributes.h

package info (click to toggle)
meshlab 1.3.0a%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 23,416 kB
  • sloc: cpp: 214,034; ansic: 4,493; makefile: 72
file content (246 lines) | stat: -rw-r--r-- 7,781 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#ifndef IMG_ATTRIBUTES_H_
#define IMG_ATTRIBUTES_H_

#include "img/img_base.h"

namespace img {

  enum COLORSPACE {
    UNDEFINED,
    RGB,
    SRGB,
    CIE_XYZ,
    CIE_LAB,
    CIE_LUV,
  };

template <typename ScalarType=double>
class ImgAttributes
{
public:

private:
  COLORSPACE _colorspace;
  
  ScalarType _gamma;
  
  ScalarType _range_min;
  ScalarType _range_max;
  
  ScalarType _reference_white_x;
  ScalarType _reference_white_y;
  ScalarType _reference_white_z;

public:
  ImgAttributes()
  : _colorspace(UNDEFINED), _gamma(ScalarType(0.0)),
    _range_min(ScalarType(0.0)), _range_max(ScalarType(0.0)),
    _reference_white_x(ScalarType(0.0)), _reference_white_y(ScalarType(0.0)), _reference_white_z(ScalarType(0.0))
  {
    STATIC_FLOAT_OR_DOUBLE_TYPECHECK( ScalarType );
  }
  
  ImgAttributes(const ImgAttributes<ScalarType>  &attributes)
  {
    STATIC_FLOAT_OR_DOUBLE_TYPECHECK( ScalarType );
    _colorspace = attributes._colorspace;
    _gamma = attributes._gamma;
    _range_min = attributes._range_min;
    _range_max = attributes._range_max;
    _reference_white_x = attributes._reference_white_x;
    _reference_white_y = attributes._reference_white_y;
    _reference_white_z = attributes._reference_white_z;
  }
  
  template<typename OtherScalarType>
  ImgAttributes(const ImgAttributes<OtherScalarType>  &attributes)
  {
    STATIC_FLOAT_OR_DOUBLE_TYPECHECK( ScalarType );
    _colorspace = attributes._colorspace;
    _gamma = static_cast<ScalarType>(attributes._gamma);
    _range_min = static_cast<ScalarType>(attributes._range_min);
    _range_max = static_cast<ScalarType>(attributes._range_max);
    _reference_white_x = static_cast<ScalarType>(attributes._reference_white_x);
    _reference_white_y = static_cast<ScalarType>(attributes._reference_white_y);
    _reference_white_z = static_cast<ScalarType>(attributes._reference_white_z);
  }
  
  template<typename OtherScalarType> 
  inline ImgAttributes< ScalarType> & operator =(const ImgAttributes<OtherScalarType> &attributes)
  {
    _colorspace = attributes._colorspace;
    _gamma = static_cast<ScalarType>(attributes._gamma);
    _range_min = static_cast<ScalarType>(attributes._range_min);
    _range_max = static_cast<ScalarType>(attributes._range_max);
    _reference_white_x = static_cast<ScalarType>(attributes._reference_white_x);
    _reference_white_y = static_cast<ScalarType>(attributes._reference_white_y);
    _reference_white_z = static_cast<ScalarType>(attributes._reference_white_z);
  }
  
  inline void reset()
  {
    _colorspace = UNDEFINED;
    _gamma = ScalarType(0.0);
    _range_min = ScalarType(0.0);
    _range_max = ScalarType(0.0);
    _reference_white_x = ScalarType(0.0);
    _reference_white_y = ScalarType(0.0);
    _reference_white_z = ScalarType(0.0);
  }

  // getters
  void getColorspace(COLORSPACE &ret_colorspace) const
  {
    ret_colorspace = _colorspace;
  }

  template<typename OtherScalarType> 
  void getGamma(OtherScalarType &ret_gamma) const
  {
    STATIC_FLOAT_OR_DOUBLE_TYPECHECK( OtherScalarType );
    ret_gamma = static_cast<OtherScalarType>(_gamma);
  }

  template<typename OtherScalarType> 
  void getRange(OtherScalarType &ret_range_min, OtherScalarType &ret_range_max) const
  {
    STATIC_FLOAT_OR_DOUBLE_TYPECHECK( OtherScalarType );
    ret_range_min = static_cast<OtherScalarType>(_range_min);
    ret_range_max = static_cast<OtherScalarType>(_range_max);
  }

  template<typename OtherScalarType> 
  void getReferenceWhite(OtherScalarType &ret_reference_white_x, OtherScalarType &ret_reference_white_y, OtherScalarType &ret_reference_white_z) const
  {
    STATIC_FLOAT_OR_DOUBLE_TYPECHECK( OtherScalarType );
    ret_reference_white_x = static_cast<OtherScalarType>(_reference_white_x);
    ret_reference_white_y = static_cast<OtherScalarType>(_reference_white_y);
    ret_reference_white_z = static_cast<OtherScalarType>(_reference_white_z);
  }

  // setters
  void setColorspace(COLORSPACE arg_colorspace)
  {
    _colorspace = arg_colorspace;
  }
  
  void setGamma(ScalarType arg_gamma)
  {
    _gamma = arg_gamma;
  }
  
  void setRange(ScalarType arg_range_min, ScalarType arg_range_max)
  {
    assert(arg_range_min<=arg_range_max);
    _range_min = arg_range_min;
    _range_max = arg_range_max;
  }
  
  void setReferenceWhite(ScalarType arg_reference_white_x, ScalarType arg_reference_white_y, ScalarType arg_reference_white_z)
  {
    _reference_white_x = arg_reference_white_x;
    _reference_white_y = arg_reference_white_y;
    _reference_white_z = arg_reference_white_z;
  }

  void setColorspace(const ImgAttributes<ScalarType> &attributes)
  {
    _colorspace = attributes._colorspace;
  }
  
  void setGamma(const ImgAttributes<ScalarType> &attributes)
  {
    _gamma = attributes._gamma;
  }
  
  void setRange(const ImgAttributes<ScalarType> &attributes)
  {
    _range_min = attributes._range_min;
    _range_max = attributes._range_max;
  }
  
  void setReferenceWhite(const ImgAttributes<ScalarType> &attributes)
  {
    _reference_white_x = attributes._reference_white_x;
    _reference_white_y = attributes._reference_white_y;
    _reference_white_z = attributes._reference_white_z;
  }

  // checks
  bool hasColorspace(COLORSPACE arg_colorspace) const
  {
    return _colorspace == arg_colorspace;
  }
  
  bool hasGamma(ScalarType arg_gamma) const
  {
    return _gamma == arg_gamma;
  }
  
  
  bool hasRange(ScalarType arg_range_min, ScalarType arg_range_max) const
  {
    return (_range_min == arg_range_min) &&
           (_range_max == arg_range_max);
  }
  
  bool hasReferenceWhite(ScalarType arg_reference_white_x, ScalarType arg_reference_white_y, ScalarType arg_reference_white_z) const
  {
    return (_reference_white_x == arg_reference_white_x) &&
           (_reference_white_y == arg_reference_white_y) &&
           (_reference_white_z == arg_reference_white_z);
  }
  
  bool hasColorspace(const ImgAttributes<ScalarType> &attributes) const
  {
    return _colorspace == attributes._colorspace;
  }
  
  bool hasGamma(const ImgAttributes<ScalarType> &attributes) const
  {
    return _gamma == attributes._gamma;
  }
  
  bool hasRange(const ImgAttributes<ScalarType> &attributes) const
  {
    return (_range_min == attributes._range_min) &&
           (_range_max == attributes._range_max);
  }
  
  bool hasReferenceWhite(const ImgAttributes<ScalarType> &attributes) const
  {
    return (_reference_white_x == attributes._reference_white_x) &&
           (_reference_white_y == attributes._reference_white_y) &&
           (_reference_white_z == attributes._reference_white_z);
  }
  
  
  bool operator==(const ImgAttributes<ScalarType> &attributes) const
  {
    return hasColorspace(attributes) && 
           hasGamma(attributes) &&
           hasRange(attributes) &&
           hasReferenceWhite(attributes);
  }

  static ImgAttributes createImgAttributes(COLORSPACE arg_colorspace = ScalarType(UNDEFINED),
                                   ScalarType arg_gamma = ScalarType(0.0),
                                   ScalarType arg_range_min = ScalarType(0.0),
                                   ScalarType arg_range_max = ScalarType(0.0),
                                   ScalarType arg_reference_white_x = ScalarType(0.0),
                                   ScalarType arg_reference_white_y = ScalarType(0.0),
                                   ScalarType arg_reference_white_z = ScalarType(0.0))
  {
    ImgAttributes attributes;
    attributes.setColorspace(arg_colorspace);
    attributes.setGamma(arg_gamma);
    attributes.setRange(arg_range_min, arg_range_max);
    attributes.setReferenceWhite(arg_reference_white_x, arg_reference_white_y, arg_reference_white_z);
    return attributes;
  }
  
};

} // end namespace img

#endif /*IMG_ATTRIBUTES_H_*/