00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef GIL_LAB_H
00010 #define GIL_LAB_H
00011
00019
00020 #include "gil_config.hpp"
00021 #include <boost/type_traits.hpp>
00022
00023 ADOBE_GIL_NAMESPACE_BEGIN
00024
00025
00026 template <typename T, typename C> struct pixel;
00027 namespace detail { template <typename T, typename C> struct color_base; }
00028 template <typename IC, typename C> struct planar_ptr;
00029 template <typename IC, typename C> struct planar_ptr_base;
00030
00034
00037 struct lab_t {
00038 typedef lab_t base;
00039 BOOST_STATIC_CONSTANT(int, num_channels=3);
00040 };
00041
00042 namespace detail {
00049 template <typename T>
00050 struct color_base<T,lab_t> : public homogeneous_color_base<T> {
00051 T luminance,a,b;
00052 color_base() {}
00053 color_base(T v0, T v1, T v2) : luminance(v0), a(v1), b(v2) {}
00054 template <typename T1, typename C1> color_base(const color_base<T1,C1>& c) : luminance(c.luminance), a(c.a), b(c.b) {}
00055 template <typename T1, typename C1> color_base( color_base<T1,C1>& c) : luminance(c.luminance), a(c.a), b(c.b) {}
00056 };
00057 }
00058 ADOBE_GIL_NAMESPACE_END
00059
00060 #include "pixel_iterator.hpp"
00061
00062
00063 ADOBE_GIL_NAMESPACE_BEGIN
00064
00068
00075 template <typename IC>
00076 struct planar_ptr<IC,lab_t> : public planar_ptr_base<IC,lab_t> {
00077 typedef planar_ptr_base<IC,lab_t> parent_t;
00078 typedef typename parent_t::value_type value_type;
00079 typedef typename parent_t::reference reference;
00080 typedef typename parent_t::color_space_t color_space_t;
00081
00082 planar_ptr() : parent_t(0,0,0) {}
00083 planar_ptr(IC il, IC ia, IC ib) : parent_t(il,ia,ib) {}
00084
00085 template <typename IC1,typename C1> planar_ptr(const planar_ptr<IC1,C1>& ptr) : parent_t(ptr) {}
00086 template <typename IC1,typename C1> planar_ptr& operator=(const planar_ptr<IC1,C1>& ptr) { parent_t::operator=(ptr); return *this; }
00087
00091 template <typename P> planar_ptr(P* pix) :
00092 parent_t(&pix->template semantic_channel<0>(),&pix->template semantic_channel<1>(), &pix->template semantic_channel<2>()) {
00093 boost::function_requires<PixelsCompatibleConcept<P,value_type> >();
00094 }
00095
00096 template <typename P> planar_ptr& operator=(P* pix) {
00097 boost::function_requires<PixelsCompatibleConcept<P,value_type> >();
00098 this->template semantic_channel<0>()=&pix->template semantic_channel<0>();
00099 this->template semantic_channel<1>()=&pix->template semantic_channel<1>();
00100 this->template semantic_channel<2>()=&pix->template semantic_channel<2>();
00101 return *this;
00102 }
00103
00104 reference dereference() const { return reference(*(this->template semantic_channel<0>()),
00105 *(this->template semantic_channel<1>()),
00106 *(this->template semantic_channel<2>())); }
00107 };
00108
00109
00112 template <typename IC>
00113 inline planar_ref<typename std::iterator_traits<IC>::reference,lab_t> byte_advanced_ref(const planar_ptr_base<IC,lab_t>& p, std::ptrdiff_t byteDiff) {
00114 return planar_ref<typename std::iterator_traits<IC>::reference,lab_t>(*byte_advanced(p.luminance, byteDiff), *byte_advanced(p.a, byteDiff), *byte_advanced(p.b, byteDiff));
00115 }
00116
00117
00118 namespace detail {
00119 template <typename CS,int N> struct channel_accessor;
00120
00122 template <>
00123 struct channel_accessor<lab_t,0> {
00124 template <typename P> typename P::template kth_element_t<0>::reference operator()( P& p) const {return p.luminance;}
00125 template <typename P> typename P::template kth_element_t<0>::const_reference operator()(const P& p) const {return p.luminance;}
00126 };
00127
00129 template <>
00130 struct channel_accessor<lab_t,1> {
00131 template <typename P> typename P::template kth_element_t<1>::reference operator()( P& p) const {return p.a;}
00132 template <typename P> typename P::template kth_element_t<1>::const_reference operator()(const P& p) const {return p.a;}
00133 };
00134
00136 template <>
00137 struct channel_accessor<lab_t,2> {
00138 template <typename P> typename P::template kth_element_t<2>::reference operator()( P& p) const {return p.b;}
00139 template <typename P> typename P::template kth_element_t<2>::const_reference operator()(const P& p) const {return p.b;}
00140 };
00141 }
00142 ADOBE_GIL_NAMESPACE_END
00143
00144 #endif