forked from funkey/gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNormalize.h
65 lines (41 loc) · 1.07 KB
/
Normalize.h
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
#ifndef NORMALIZE_H__
#define NORMALIZE_H__
#include <boost/concept_check.hpp>
#include <gui/IsImage.h>
namespace gui {
namespace detail {
/**
* Image wrapper that divides floating pixel values by a given value.
*/
template <typename Image>
class normalize_impl {
public:
typedef normalize_impl<Image> type;
typedef typename Image::value_type value_type;
normalize_impl(const Image& ra, const value_type& div) :
_ra(ra),
_div(div),
_height(ra.height()) {}
const value_type operator()(unsigned int x, unsigned int y) const {
return _ra(x, y)/_div;
}
const unsigned int width() const {
return _ra.width();
}
const unsigned int height() const {
return _ra.height();
}
private:
const Image& _ra;
value_type _div;
unsigned int _height;
};
} // namespace detail
template <typename Image>
typename detail::normalize_impl<Image>::type
normalize(const Image& ra, const typename Image::value_type& value_type) {
BOOST_CONCEPT_ASSERT((IsImage<Image>));
return detail::normalize_impl<Image>(ra, value_type);
}
} // namespace gui
#endif // NORMALIZE_H__