x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
color_base.hpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\gil\color_base.hpp
旋转
特效
属性
历史版本
/* Copyright 2005-2007 Adobe Systems Incorporated Use, modification and distribution are subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). See http://opensource.adobe.com/gil for most recent version including documentation. */ /*************************************************************************************************/ #ifndef GIL_COLOR_BASE_HPP #define GIL_COLOR_BASE_HPP //////////////////////////////////////////////////////////////////////////////////////// /// \file /// \brief pixel class and related utilities /// \author Lubomir Bourdev and Hailin Jin \n /// Adobe Systems Incorporated /// \date 2005-2007 \n Last updated on May 6, 2007 /// //////////////////////////////////////////////////////////////////////////////////////// #include
#include
#include
#include
#include
#include
#include "gil_config.hpp" #include "utilities.hpp" #include "gil_concept.hpp" namespace boost { namespace gil { // Forward-declare template
P* memunit_advanced(const P* p, std::ptrdiff_t diff); // Forward-declare semantic_at_c template
typename disable_if
,typename kth_semantic_element_reference_type
::type>::type semantic_at_c(ColorBase& p); template
typename kth_semantic_element_const_reference_type
::type semantic_at_c(const ColorBase& p); // Forward declare element_reference_type template
struct element_reference_type; template
struct element_const_reference_type; template
struct kth_element_type; template
struct kth_element_type
: public kth_element_type
{}; template
struct kth_element_reference_type; template
struct kth_element_reference_type
: public kth_element_reference_type
{}; template
struct kth_element_const_reference_type; template
struct kth_element_const_reference_type
: public kth_element_const_reference_type
{}; namespace detail { template
struct mapping_transform : public mpl::at
>::type >::type {}; /// \defgroup ColorBaseModelHomogeneous detail::homogeneous_color_base /// \ingroup ColorBaseModel /// \brief A homogeneous color base holding one color element. Models HomogeneousColorBaseConcept or HomogeneousColorBaseValueConcept /// If the element type models Regular, this class models HomogeneousColorBaseValueConcept. /// \brief A homogeneous color base holding one color element. Models HomogeneousColorBaseConcept or HomogeneousColorBaseValueConcept /// \ingroup ColorBaseModelHomogeneous template
struct homogeneous_color_base
{ private: Element _v0; public: typedef Layout layout_t; typename element_reference_type
::type at(mpl::int_<0>) { return _v0; } typename element_const_reference_type
::type at(mpl::int_<0>) const { return _v0; } homogeneous_color_base() {} homogeneous_color_base(Element v) : _v0(v) {} // grayscale pixel values are convertible to channel type operator Element () const { return _v0; } template
homogeneous_color_base(const homogeneous_color_base
& c) : _v0(at_c<0>(c)) {} }; /// \brief A homogeneous color base holding two color elements. Models HomogeneousColorBaseConcept or HomogeneousColorBaseValueConcept /// \ingroup ColorBaseModelHomogeneous template
struct homogeneous_color_base
{ private: Element _v0, _v1; public: typedef Layout layout_t; typename element_reference_type
::type at(mpl::int_<0>) { return _v0; } typename element_const_reference_type
::type at(mpl::int_<0>) const { return _v0; } typename element_reference_type
::type at(mpl::int_<1>) { return _v1; } typename element_const_reference_type
::type at(mpl::int_<1>) const { return _v1; } homogeneous_color_base() {} explicit homogeneous_color_base(Element v) : _v0(v), _v1(v) {} homogeneous_color_base(Element v0, Element v1) : _v0(v0), _v1(v1) {} template
homogeneous_color_base(const homogeneous_color_base
& c) : _v0(at_c
::value>(c)), _v1(at_c
::value>(c)) {} // Support for l-value reference proxy copy construction template
homogeneous_color_base( homogeneous_color_base
& c) : _v0(at_c
::value>(c)), _v1(at_c
::value>(c)) {} // Support for planar_pixel_iterator construction and dereferencing template
homogeneous_color_base(P* p,bool) : _v0(&semantic_at_c<0>(*p)), _v1(&semantic_at_c<1>(*p)) {} template
Ref deref() const { return Ref(*semantic_at_c<0>(*this), *semantic_at_c<1>(*this)); } // Support for planar_pixel_reference offset constructor template
homogeneous_color_base(const Ptr& ptr, std::ptrdiff_t diff) : _v0(*memunit_advanced(semantic_at_c<0>(ptr),diff)), _v1(*memunit_advanced(semantic_at_c<1>(ptr),diff)) {} // Support for planar_pixel_reference operator[] Element at_c_dynamic(size_t i) const { if (i==0) return _v0; return _v1; } }; /// \brief A homogeneous color base holding three color elements. Models HomogeneousColorBaseConcept or HomogeneousColorBaseValueConcept /// \ingroup ColorBaseModelHomogeneous template
struct homogeneous_color_base
{ private: Element _v0, _v1, _v2; public: typedef Layout layout_t; typename element_reference_type
::type at(mpl::int_<0>) { return _v0; } typename element_const_reference_type
::type at(mpl::int_<0>) const { return _v0; } typename element_reference_type
::type at(mpl::int_<1>) { return _v1; } typename element_const_reference_type
::type at(mpl::int_<1>) const { return _v1; } typename element_reference_type
::type at(mpl::int_<2>) { return _v2; } typename element_const_reference_type
::type at(mpl::int_<2>) const { return _v2; } homogeneous_color_base() {} explicit homogeneous_color_base(Element v) : _v0(v), _v1(v), _v2(v) {} homogeneous_color_base(Element v0, Element v1, Element v2) : _v0(v0), _v1(v1), _v2(v2) {} template
homogeneous_color_base(const homogeneous_color_base
& c) : _v0(at_c
::value>(c)), _v1(at_c
::value>(c)), _v2(at_c
::value>(c)) {} // Support for l-value reference proxy copy construction template
homogeneous_color_base( homogeneous_color_base
& c) : _v0(at_c
::value>(c)), _v1(at_c
::value>(c)), _v2(at_c
::value>(c)) {} // Support for planar_pixel_iterator construction and dereferencing template
homogeneous_color_base(P* p,bool) : _v0(&semantic_at_c<0>(*p)), _v1(&semantic_at_c<1>(*p)), _v2(&semantic_at_c<2>(*p)) {} template
Ref deref() const { return Ref(*semantic_at_c<0>(*this), *semantic_at_c<1>(*this), *semantic_at_c<2>(*this)); } // Support for planar_pixel_reference offset constructor template
homogeneous_color_base(const Ptr& ptr, std::ptrdiff_t diff) : _v0(*memunit_advanced(semantic_at_c<0>(ptr),diff)), _v1(*memunit_advanced(semantic_at_c<1>(ptr),diff)), _v2(*memunit_advanced(semantic_at_c<2>(ptr),diff)) {} // Support for planar_pixel_reference operator[] Element at_c_dynamic(size_t i) const { switch (i) { case 0: return _v0; case 1: return _v1; } return _v2; } }; /// \brief A homogeneous color base holding four color elements. Models HomogeneousColorBaseConcept or HomogeneousColorBaseValueConcept /// \ingroup ColorBaseModelHomogeneous template
struct homogeneous_color_base
{ private: Element _v0, _v1, _v2, _v3; public: typedef Layout layout_t; typename element_reference_type
::type at(mpl::int_<0>) { return _v0; } typename element_const_reference_type
::type at(mpl::int_<0>) const { return _v0; } typename element_reference_type
::type at(mpl::int_<1>) { return _v1; } typename element_const_reference_type
::type at(mpl::int_<1>) const { return _v1; } typename element_reference_type
::type at(mpl::int_<2>) { return _v2; } typename element_const_reference_type
::type at(mpl::int_<2>) const { return _v2; } typename element_reference_type
::type at(mpl::int_<3>) { return _v3; } typename element_const_reference_type
::type at(mpl::int_<3>) const { return _v3; } homogeneous_color_base() {} explicit homogeneous_color_base(Element v) : _v0(v), _v1(v), _v2(v), _v3(v) {} homogeneous_color_base(Element v0, Element v1, Element v2, Element v3) : _v0(v0), _v1(v1), _v2(v2), _v3(v3) {} template
homogeneous_color_base(const homogeneous_color_base
& c) : _v0(at_c
::value>(c)), _v1(at_c
::value>(c)), _v2(at_c
::value>(c)), _v3(at_c
::value>(c)) {} // Support for l-value reference proxy copy construction template
homogeneous_color_base( homogeneous_color_base
& c) : _v0(at_c
::value>(c)), _v1(at_c
::value>(c)), _v2(at_c
::value>(c)), _v3(at_c
::value>(c)) {} // Support for planar_pixel_iterator construction and dereferencing template
homogeneous_color_base(P* p,bool) : _v0(&semantic_at_c<0>(*p)), _v1(&semantic_at_c<1>(*p)), _v2(&semantic_at_c<2>(*p)), _v3(&semantic_at_c<3>(*p)) {} template
Ref deref() const { return Ref(*semantic_at_c<0>(*this), *semantic_at_c<1>(*this), *semantic_at_c<2>(*this), *semantic_at_c<3>(*this)); } // Support for planar_pixel_reference offset constructor template
homogeneous_color_base(const Ptr& ptr, std::ptrdiff_t diff) : _v0(*memunit_advanced(semantic_at_c<0>(ptr),diff)), _v1(*memunit_advanced(semantic_at_c<1>(ptr),diff)), _v2(*memunit_advanced(semantic_at_c<2>(ptr),diff)), _v3(*memunit_advanced(semantic_at_c<3>(ptr),diff)) {} // Support for planar_pixel_reference operator[] Element at_c_dynamic(size_t i) const { switch (i) { case 0: return _v0; case 1: return _v1; case 2: return _v2; } return _v3; } }; /// \brief A homogeneous color base holding five color elements. Models HomogeneousColorBaseConcept or HomogeneousColorBaseValueConcept /// \ingroup ColorBaseModelHomogeneous template
struct homogeneous_color_base
{ private: Element _v0, _v1, _v2, _v3, _v4; public: typedef Layout layout_t; typename element_reference_type
::type at(mpl::int_<0>) { return _v0; } typename element_const_reference_type
::type at(mpl::int_<0>) const { return _v0; } typename element_reference_type
::type at(mpl::int_<1>) { return _v1; } typename element_const_reference_type
::type at(mpl::int_<1>) const { return _v1; } typename element_reference_type
::type at(mpl::int_<2>) { return _v2; } typename element_const_reference_type
::type at(mpl::int_<2>) const { return _v2; } typename element_reference_type
::type at(mpl::int_<3>) { return _v3; } typename element_const_reference_type
::type at(mpl::int_<3>) const { return _v3; } typename element_reference_type
::type at(mpl::int_<4>) { return _v4; } typename element_const_reference_type
::type at(mpl::int_<4>) const { return _v4; } homogeneous_color_base() {} explicit homogeneous_color_base(Element v) : _v0(v), _v1(v), _v2(v), _v3(v), _v4(v) {} homogeneous_color_base(Element v0, Element v1, Element v2, Element v3, Element v4) : _v0(v0), _v1(v1), _v2(v2), _v3(v3), _v4(v4) {} template
homogeneous_color_base(const homogeneous_color_base
& c) : _v0(at_c
::value>(c)), _v1(at_c
::value>(c)), _v2(at_c
::value>(c)), _v3(at_c
::value>(c)), _v4(at_c
::value>(c)) {} // Support for l-value reference proxy copy construction template
homogeneous_color_base( homogeneous_color_base
& c) : _v0(at_c
::value>(c)), _v1(at_c
::value>(c)), _v2(at_c
::value>(c)), _v3(at_c
::value>(c)), _v4(at_c
::value>(c)) {} // Support for planar_pixel_iterator construction and dereferencing template
homogeneous_color_base(P* p,bool) : _v0(&semantic_at_c<0>(*p)), _v1(&semantic_at_c<1>(*p)), _v2(&semantic_at_c<2>(*p)), _v3(&semantic_at_c<3>(*p)), _v4(&semantic_at_c<4>(*p)) {} template
Ref deref() const { return Ref(*semantic_at_c<0>(*this), *semantic_at_c<1>(*this), *semantic_at_c<2>(*this), *semantic_at_c<3>(*this), *semantic_at_c<4>(*this)); } // Support for planar_pixel_reference offset constructor template
homogeneous_color_base(const Ptr& ptr, std::ptrdiff_t diff) : _v0(*memunit_advanced(semantic_at_c<0>(ptr),diff)), _v1(*memunit_advanced(semantic_at_c<1>(ptr),diff)), _v2(*memunit_advanced(semantic_at_c<2>(ptr),diff)), _v3(*memunit_advanced(semantic_at_c<3>(ptr),diff)), _v4(*memunit_advanced(semantic_at_c<4>(ptr),diff)) {} // Support for planar_pixel_reference operator[] Element at_c_dynamic(size_t i) const { switch (i) { case 0: return _v0; case 1: return _v1; case 2: return _v2; case 3: return _v3; } return _v4; } }; // The following way of casting adjacent channels (the contents of color_base) into an array appears to be unsafe // -- there is no guarantee that the compiler won't add any padding between adjacent channels. // Note, however, that GIL _must_ be compiled with compiler settings ensuring there is no padding in the color base structs. // This is because the color base structs must model the interleaved organization in memory. In other words, the client may // have existing RGB image in the form "RGBRGBRGB..." and we must be able to represent it with an array of RGB color bases (i.e. RGB pixels) // with no padding. We have tested with char/int/float/double channels on gcc and VC and have so far discovered no problem. // We have even tried using strange channels consisting of short + char (3 bytes). With the default 4-byte alignment on VC, the size // of this channel is padded to 4 bytes, so an RGB pixel of it will be 4x3=12 bytes. The code below will still work properly. // However, the client must nevertheless ensure that proper compiler settings are used for their compiler and their channel types. template
typename element_reference_type
>::type dynamic_at_c(homogeneous_color_base
& cb, std::size_t i) { assert(i
(&cb))[i]; } template
typename element_const_reference_type
>::type dynamic_at_c(const homogeneous_color_base
& cb, std::size_t i) { assert(i
(&cb))[i]; } template
typename element_reference_type
>::type dynamic_at_c(const homogeneous_color_base
& cb, std::size_t i) { assert(i
typename element_const_reference_type
>::type dynamic_at_c(const homogeneous_color_base
& cb, std::size_t i) { assert(i
struct kth_element_type
, K> { typedef Element type; }; template
struct kth_element_reference_type
, K> : public add_reference
{}; template
struct kth_element_const_reference_type
, K> : public add_reference
::type> {}; /// \brief Provides mutable access to the K-th element, in physical order /// \ingroup ColorBaseModelHomogeneous template
inline typename add_reference
::type at_c( detail::homogeneous_color_base
& p) { return p.at(mpl::int_
()); } /// \brief Provides constant access to the K-th element, in physical order /// \ingroup ColorBaseModelHomogeneous template
inline typename add_reference
::type>::type at_c(const detail::homogeneous_color_base
& p) { return p.at(mpl::int_
()); } namespace detail { struct swap_fn { template
void operator()(T& x, T& y) const { using std::swap; swap(x,y); } }; } template
inline void swap(detail::homogeneous_color_base
& x, detail::homogeneous_color_base
& y) { static_for_each(x,y,detail::swap_fn()); } } } // namespace boost::gil #endif
color_base.hpp
网页地址
文件地址
上一页
7/34
下一页
下载
( 20 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.