lab.hpp

Go to the documentation of this file.
00001 /*
00002   Copyright 2005-2006 Adobe Systems Incorporated
00003   Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004   or a copy at http://opensource.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef GIL_LAB_H
00010 #define GIL_LAB_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 //forward declarations for pixel and color_base
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 lab_t { 
00039     typedef lab_t base;
00040     BOOST_STATIC_CONSTANT(int, num_channels=3);
00041 };
00042 
00043 namespace detail {
00050     template <typename T>
00051     struct color_base<T,lab_t> : public homogeneous_color_base<T> {
00052         T luminance,a,b;
00053         color_base() {}
00054         color_base(T v0, T v1, T v2) : luminance(v0), a(v1), b(v2) {}
00055         template <typename T1, typename C1> color_base(const color_base<T1,C1>& c) : luminance(c.luminance), a(c.a), b(c.b) {}
00056         template <typename T1, typename C1> color_base(      color_base<T1,C1>& c) : luminance(c.luminance), a(c.a), b(c.b) {}
00057     };
00058 }
00059 ADOBE_GIL_NAMESPACE_END
00060 
00061 #include "pixel_iterator.hpp"
00062 
00063 // these need to be defined after including pixel...
00064 ADOBE_GIL_NAMESPACE_BEGIN
00065 
00069 
00076 template <typename IC>
00077 struct planar_ptr<IC,lab_t> : public planar_ptr_base<IC,lab_t> {
00078     typedef planar_ptr_base<IC,lab_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 il, IC ia, IC ib) : parent_t(il,ia,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,lab_t> byte_advanced_ref(const planar_ptr_base<IC,lab_t>& p, std::ptrdiff_t byteDiff) {
00115     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));
00116 }
00117 
00118 
00119 namespace detail {
00120 template <typename Cs,int N> struct channel_accessor;
00121 
00123 template <>
00124 struct channel_accessor<lab_t,0> {
00125     template <typename P> typename P::template kth_element_t<0>::reference       operator()(      P& p) const {return p.luminance;}
00126     template <typename P> typename P::template kth_element_t<0>::const_reference operator()(const P& p) const {return p.luminance;}
00127 };
00128 
00130 template <>
00131 struct channel_accessor<lab_t,1> {
00132     template <typename P> typename P::template kth_element_t<1>::reference       operator()(      P& p) const {return p.a;}
00133     template <typename P> typename P::template kth_element_t<1>::const_reference operator()(const P& p) const {return p.a;}
00134 };
00135 
00137 template <>
00138 struct channel_accessor<lab_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 } // namespace detail
00143 
00146 template <typename IC>
00147 inline typename type_from_x_iterator<planar_ptr<IC,lab_t> >::view_t planar_lab_view(int width, int height, IC l, IC a, IC b, std::ptrdiff_t rowsize_in_bytes) {
00148     typedef typename type_from_x_iterator<planar_ptr<IC,lab_t> >::view_t RVIEW;
00149     return RVIEW(width, height, typename RVIEW::locator(planar_ptr<IC,lab_t>(l,a,b), rowsize_in_bytes));
00150 }
00151 
00152 ADOBE_GIL_NAMESPACE_END
00153 
00154 #endif

Copyright © 2006 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google