00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef GIL_CMYK_H
00010 #define GIL_CMYK_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 cmyk_t {
00038 typedef cmyk_t base;
00039 BOOST_STATIC_CONSTANT(int, num_channels=4);
00040 };
00041
00042 namespace detail {
00052 template <typename T>
00053 struct color_base<T,cmyk_t> : public homogeneous_color_base<T> {
00054 T cyan,magenta,yellow,black;
00055 color_base() {}
00056 color_base(T v0, T v1, T v2, T v3) :
00057 cyan(v0), magenta(v1), yellow(v2), black(v3) {}
00058 template <typename T1, typename C1> color_base(const color_base<T1,C1>& cb) :
00059 cyan(cb.cyan), magenta(cb.magenta), yellow(cb.yellow), black(cb.black) {}
00060 template <typename T1, typename C1> color_base( color_base<T1,C1>& cb) :
00061 cyan(cb.cyan), magenta(cb.magenta), yellow(cb.yellow), black(cb.black) {}
00062 };
00063
00064 }
00065
00066 ADOBE_GIL_NAMESPACE_END
00067
00068 #include "pixel_iterator.hpp"
00069
00070
00071 ADOBE_GIL_NAMESPACE_BEGIN
00072
00076
00077
00084 template <typename IC>
00085 struct planar_ptr<IC,cmyk_t> : public planar_ptr_base<IC,cmyk_t> {
00086 typedef planar_ptr_base<IC,cmyk_t> parent_t;
00087 typedef typename parent_t::value_type value_type;
00088 typedef typename parent_t::reference reference;
00089 typedef typename parent_t::color_space_t color_space_t;
00090
00091 planar_ptr() : parent_t(0,0,0,0) {}
00092 planar_ptr(IC ic, IC im, IC iy, IC ik) : parent_t(ic,im,iy,ik) {}
00093
00094 template <typename IC1,typename C1> planar_ptr(const planar_ptr<IC1,C1>& ptr) : parent_t(ptr) {}
00095 template <typename IC1,typename C1> planar_ptr& operator=(const planar_ptr<IC1,C1>& ptr) {return parent_t::operator=(ptr);}
00096
00100 template <typename P> planar_ptr(P* pix) :
00101 parent_t(&pix->template semantic_channel<0>(),&pix->template semantic_channel<1>(), &pix->template semantic_channel<2>(), &pix->template semantic_channel<3>()) {
00102 boost::function_requires<PixelsCompatibleConcept<P,value_type> >();
00103 }
00104
00105 template <typename P> planar_ptr& operator=(P* pix) {
00106 boost::function_requires<PixelsCompatibleConcept<P,value_type> >();
00107 this->template semantic_channel<0>()=&pix->template semantic_channel<0>();
00108 this->template semantic_channel<1>()=&pix->template semantic_channel<1>();
00109 this->template semantic_channel<2>()=&pix->template semantic_channel<2>();
00110 this->template semantic_channel<3>()=&pix->template semantic_channel<3>();
00111 return *this;
00112 }
00113
00114 reference dereference() const { return reference(*(this->template semantic_channel<0>()),
00115 *(this->template semantic_channel<1>()),
00116 *(this->template semantic_channel<2>()),
00117 *(this->template semantic_channel<3>())); }
00118 };
00119
00122 template <typename IC>
00123 inline planar_ref<typename std::iterator_traits<IC>::reference,cmyk_t> byte_advanced_ref(const planar_ptr_base<IC,cmyk_t>& p, std::ptrdiff_t byteDiff) {
00124 return planar_ref<typename std::iterator_traits<IC>::reference,cmyk_t>(*byte_advanced(p.cyan, byteDiff), *byte_advanced(p.magenta, byteDiff),
00125 *byte_advanced(p.yellow, byteDiff), *byte_advanced(p.black, byteDiff));
00126 }
00127
00128 namespace detail {
00129 template <typename CS,int N> struct channel_accessor;
00130
00132 template <>
00133 struct channel_accessor<cmyk_t,0> {
00134 template <typename P> typename P::template kth_element_t<0>::reference operator()( P& p) const {return p.cyan;}
00135 template <typename P> typename P::template kth_element_t<0>::const_reference operator()(const P& p) const {return p.cyan;}
00136 };
00137
00139 template <>
00140 struct channel_accessor<cmyk_t,1> {
00141 template <typename P> typename P::template kth_element_t<1>::reference operator()( P& p) const {return p.magenta;}
00142 template <typename P> typename P::template kth_element_t<1>::const_reference operator()(const P& p) const {return p.magenta;}
00143 };
00144
00146 template <>
00147 struct channel_accessor<cmyk_t,2> {
00148 template <typename P> typename P::template kth_element_t<2>::reference operator()( P& p) const {return p.yellow;}
00149 template <typename P> typename P::template kth_element_t<2>::const_reference operator()(const P& p) const {return p.yellow;}
00150 };
00151
00153 template <>
00154 struct channel_accessor<cmyk_t,3> {
00155 template <typename P> typename P::template kth_element_t<3>::reference operator()( P& p) const {return p.black;}
00156 template <typename P> typename P::template kth_element_t<3>::const_reference operator()(const P& p) const {return p.black;}
00157 };
00158
00159 }
00160
00161 ADOBE_GIL_NAMESPACE_END
00162
00163 #endif