00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef GIL_HSB_H
00010 #define GIL_HSB_H
00011
00019
00020 #include "gil_config.hpp"
00021 #include "metafunctions.hpp"
00022 #include <boost/type_traits.hpp>
00023
00024 ADOBE_GIL_NAMESPACE_BEGIN
00025
00026
00027 template <typename T, typename C> struct pixel;
00028 namespace detail { template <typename T, typename C> struct color_base; }
00029 template <typename IC, typename C> struct planar_ptr;
00030 template <typename IC, typename C> struct planar_ptr_base;
00031
00035
00038 struct hsb_t {
00039 typedef hsb_t base;
00040 BOOST_STATIC_CONSTANT(int, num_channels=3);
00041 };
00042
00043 namespace detail {
00050 template <typename T>
00051 struct color_base<T,hsb_t> : public homogeneous_color_base<T> {
00052 T h,s,b;
00053 color_base() {}
00054 color_base(T v0, T v1, T v2) : h(v0), s(v1), b(v2) {}
00055 template <typename T1, typename C1> color_base(const color_base<T1,C1>& c) : h(c.h), s(c.s), b(c.b) {}
00056 template <typename T1, typename C1> color_base( color_base<T1,C1>& c) : h(c.h), s(c.s), b(c.b) {}
00057 };
00058 }
00059 ADOBE_GIL_NAMESPACE_END
00060
00061 #include "pixel_iterator.hpp"
00062
00063
00064 ADOBE_GIL_NAMESPACE_BEGIN
00065
00069
00076 template <typename IC>
00077 struct planar_ptr<IC,hsb_t> : public planar_ptr_base<IC,hsb_t> {
00078 typedef planar_ptr_base<IC,hsb_t> parent_t;
00079 typedef typename parent_t::value_type value_type;
00080 typedef typename parent_t::reference reference;
00081 typedef typename parent_t::color_space_t color_space_t;
00082
00083 planar_ptr() : parent_t(0,0,0) {}
00084 planar_ptr(IC ih, IC is, IC ib) : parent_t(ih,is,ib) {}
00085
00086 template <typename IC1,typename C1> planar_ptr(const planar_ptr<IC1,C1>& ptr) : parent_t(ptr) {}
00087 template <typename IC1,typename C1> planar_ptr& operator=(const planar_ptr<IC1,C1>& ptr) { parent_t::operator=(ptr); return *this; }
00088
00092 template <typename P> planar_ptr(P* pix) :
00093 parent_t(&pix->template semantic_channel<0>(),&pix->template semantic_channel<1>(), &pix->template semantic_channel<2>()) {
00094 boost::function_requires<PixelsCompatibleConcept<P,value_type> >();
00095 }
00096
00097 template <typename P> planar_ptr& operator=(P* pix) {
00098 boost::function_requires<PixelsCompatibleConcept<P,value_type> >();
00099 this->template semantic_channel<0>()=&pix->template semantic_channel<0>();
00100 this->template semantic_channel<1>()=&pix->template semantic_channel<1>();
00101 this->template semantic_channel<2>()=&pix->template semantic_channel<2>();
00102 return *this;
00103 }
00104
00105 reference dereference() const { return reference(*(this->template semantic_channel<0>()),
00106 *(this->template semantic_channel<1>()),
00107 *(this->template semantic_channel<2>())); }
00108 };
00109
00110
00113 template <typename IC>
00114 inline planar_ref<typename std::iterator_traits<IC>::reference,hsb_t> byte_advanced_ref(const planar_ptr_base<IC,hsb_t>& p, ptrdiff_t byteDiff) {
00115 return planar_ref<typename std::iterator_traits<IC>::reference,hsb_t>(*byte_advanced(p.h, byteDiff), *byte_advanced(p.s, byteDiff), *byte_advanced(p.b, byteDiff));
00116 }
00117
00118
00119 namespace detail {
00120 template <typename Cs,int N> struct channel_accessor;
00121
00123 template <>
00124 struct channel_accessor<hsb_t,0> {
00125 template <typename P> typename P::template kth_element_t<0>::reference operator()( P& p) const {return p.h;}
00126 template <typename P> typename P::template kth_element_t<0>::const_reference operator()(const P& p) const {return p.h;}
00127 };
00128
00130 template <>
00131 struct channel_accessor<hsb_t,1> {
00132 template <typename P> typename P::template kth_element_t<1>::reference operator()( P& p) const {return p.s;}
00133 template <typename P> typename P::template kth_element_t<1>::const_reference operator()(const P& p) const {return p.s;}
00134 };
00135
00137 template <>
00138 struct channel_accessor<hsb_t,2> {
00139 template <typename P> typename P::template kth_element_t<2>::reference operator()( P& p) const {return p.b;}
00140 template <typename P> typename P::template kth_element_t<2>::const_reference operator()(const P& p) const {return p.b;}
00141 };
00142 }
00143
00146 template <typename IC>
00147 inline typename type_from_x_iterator<planar_ptr<IC,hsb_t> >::view_t planar_hsb_view(int width, int height, IC h, IC s, IC b, std::ptrdiff_t rowsize_in_bytes) {
00148 typedef typename type_from_x_iterator<planar_ptr<IC,hsb_t> >::view_t RVIEW;
00149 return RVIEW(width, height, typename RVIEW::locator(planar_ptr<IC,hsb_t>(h,s,b), rowsize_in_bytes));
00150 }
00151
00152 ADOBE_GIL_NAMESPACE_END
00153
00154 #endif