|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifndef TCG_PIXEL_OPS_H
|
|
Toshihiro Shimizu |
890ddd |
#define TCG_PIXEL_OPS_H
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// tcg includes
|
|
Toshihiro Shimizu |
890ddd |
#include "base.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace tcg
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Pixel Categories
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
struct grayscale_pixel_tag {
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
struct rgb_pixel_tag {
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
struct rgbm_pixel_tag : public rgb_pixel_tag {
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
struct indexed_pixel_tag {
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Pixel Traits Types
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" pix::pixel_category="" pixel_category="typename" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct pixel_traits_types;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct pixel_traits_types<pix, grayscale_pixel_tag=""> {</pix,>
|
|
Toshihiro Shimizu |
890ddd |
typedef Pix pixel_type;
|
|
Toshihiro Shimizu |
890ddd |
typedef grayscale_pixel_tag pixel_category;
|
|
Toshihiro Shimizu |
890ddd |
typedef typename Pix::channel_type channel_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
enum { channels_count = 1 };
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct pixel_traits_types<pix, rgb_pixel_tag=""> {</pix,>
|
|
Toshihiro Shimizu |
890ddd |
typedef Pix pixel_type;
|
|
Toshihiro Shimizu |
890ddd |
typedef rgb_pixel_tag pixel_category;
|
|
Toshihiro Shimizu |
890ddd |
typedef typename Pix::channel_type channel_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
enum { channels_count = 3 };
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct pixel_traits_types<pix, rgbm_pixel_tag=""></pix,>
|
|
Toshihiro Shimizu |
890ddd |
: public pixel_traits_types<pix, rgb_pixel_tag=""> {</pix,>
|
|
Toshihiro Shimizu |
890ddd |
typedef Pix pixel_type;
|
|
Toshihiro Shimizu |
890ddd |
typedef rgbm_pixel_tag pixel_category;
|
|
Toshihiro Shimizu |
890ddd |
typedef typename Pix::channel_type channel_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
enum { channels_count = 4 };
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct pixel_traits_types<pix, indexed_pixel_tag=""> {</pix,>
|
|
Toshihiro Shimizu |
890ddd |
typedef Pix pixel_type;
|
|
Toshihiro Shimizu |
890ddd |
typedef indexed_pixel_tag pixel_category;
|
|
Toshihiro Shimizu |
890ddd |
typedef typename Pix::index_type index_type;
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Pixel Traits
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" pix::pixel_category="" pixel_category="typename" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct pixel_traits;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct pixel_traits<pix, grayscale_pixel_tag=""></pix,>
|
|
Toshihiro Shimizu |
890ddd |
: public pixel_traits_types<pix, grayscale_pixel_tag=""> {</pix,>
|
|
Toshihiro Shimizu |
890ddd |
typedef pixel_traits_types<pix, grayscale_pixel_tag=""> tr;</pix,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::channel_type max_channel_value();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::channel_type l(const typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::channel_type &l(typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct pixel_traits<pix, rgb_pixel_tag=""> {</pix,>
|
|
Toshihiro Shimizu |
890ddd |
typedef pixel_traits_types<pix, rgb_pixel_tag=""> tr;</pix,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::channel_type max_channel_value();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::channel_type r(const typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::channel_type &r(typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::channel_type g(const typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::channel_type &g(typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::channel_type b(const typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::channel_type &b(typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct pixel_traits<pix, rgbm_pixel_tag=""> : public pixel_traits<pix, rgb_pixel_tag=""> {</pix,></pix,>
|
|
Toshihiro Shimizu |
890ddd |
typedef pixel_traits_types<pix, rgbm_pixel_tag=""> tr;</pix,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::channel_type m(const typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::channel_type &m(typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct pixel_traits<pix, indexed_pixel_tag=""> {</pix,>
|
|
Toshihiro Shimizu |
890ddd |
typedef pixel_traits_types<pix, indexed_pixel_tag=""> tr;</pix,>
|
|
Toshihiro Shimizu |
890ddd |
typedef typename tr::pixel_type pixel_type;
|
|
Toshihiro Shimizu |
890ddd |
typedef typename tr::index_type index_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::index_type index(const typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
static typename tr::index_type &index(typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace pixel_ops
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Pixel Functions
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixin,="" pixout="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline PixOut _cast(const PixIn &pix, grayscale_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return PixOut(pixel_traits<pixin>::l(pix));</pixin>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixin,="" pixout="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline PixOut _cast(const PixIn &pix, rgb_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return PixOut(pixel_traits<pixin>::r(pix), pixel_traits<pixin>::g(pix), pixel_traits<pixin>::b(pix));</pixin></pixin></pixin>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixin,="" pixout="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline PixOut _cast(const PixIn &pix, rgbm_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return PixOut(pixel_traits<pixin>::r(pix), pixel_traits<pixin>::g(pix), pixel_traits<pixin>::b(pix),</pixin></pixin></pixin>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pixin>::m(pix));</pixin>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixin,="" pixout="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline PixOut cast(const PixIn &pix)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return _cast<pixin, pixout="">(pix, typename pixel_traits<pixin>::pixel_category());</pixin></pixin,>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixin,="" pixout="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline void _assign(PixOut &pixout, const PixIn &pixin, grayscale_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pixout>::l(pixout) = pixel_traits<pixin>::l(pixin);</pixin></pixout>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixin,="" pixout="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline void _assign(PixOut &pixout, const PixIn &pixin, rgb_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pixout>::r(pixout) = pixel_traits<pixin>::r(pixin);</pixin></pixout>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pixout>::g(pixout) = pixel_traits<pixin>::g(pixin);</pixin></pixout>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pixout>::b(pixout) = pixel_traits<pixin>::b(pixin);</pixin></pixout>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixin,="" pixout="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline void _assign(PixOut &pixout, const PixIn &pixin, rgbm_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pixout>::r(pixout) = pixel_traits<pixin>::r(pixin);</pixin></pixout>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pixout>::g(pixout) = pixel_traits<pixin>::g(pixin);</pixin></pixout>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pixout>::b(pixout) = pixel_traits<pixin>::b(pixin);</pixin></pixout>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pixout>::m(pixout) = pixel_traits<pixin>::m(pixin);</pixin></pixout>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixin,="" pixout="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline void assign(PixOut &pixout, const PixIn &pixin)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
_assign<pixin, pixout="">(pixout, pixin, typename pixel_traits<pixin>::pixel_category());</pixin></pixin,>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix1,="" pix2="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix1 _sum(const Pix1 &a, const Pix2 &b, grayscale_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix1(pixel_traits<pix1>::l(a) + pixel_traits<pix2>::l(b));</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix1,="" pix2="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix1 _sum(const Pix1 &a, const Pix2 &b, rgb_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix1(pixel_traits<pix1>::r(a) + pixel_traits<pix2>::r(b),</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix1>::g(a) + pixel_traits<pix2>::g(b),</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix1>::b(a) + pixel_traits<pix2>::b(b));</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix1,="" pix2="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix1 _sum(const Pix1 &a, const Pix2 &b, rgbm_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix1(pixel_traits<pix1>::r(a) + pixel_traits<pix2>::r(b),</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix1>::g(a) + pixel_traits<pix2>::g(b),</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix1>::b(a) + pixel_traits<pix2>::b(b),</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix1>::m(a) + pixel_traits<pix2>::m(b));</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix1,="" pix2="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix1 operator+(const Pix1 &a, const Pix2 &b)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return _sum(a, b, typename pixel_traits<pix2>::pixel_category());</pix2>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix1,="" pix2="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix1 _sub(const Pix1 &a, const Pix2 &b, grayscale_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix1(pixel_traits<pix1>::l(a) - pixel_traits<pix2>::l(b));</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix1,="" pix2="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix1 _sub(const Pix1 &a, const Pix2 &b, rgb_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix1(pixel_traits<pix1>::r(a) - pixel_traits<pix2>::r(b),</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix1>::g(a) - pixel_traits<pix2>::g(b),</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix1>::b(a) - pixel_traits<pix2>::b(b));</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix1,="" pix2="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix1 _sub(const Pix1 &a, const Pix2 &b, rgbm_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix1(pixel_traits<pix1>::r(a) - pixel_traits<pix2>::r(b),</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix1>::g(a) - pixel_traits<pix2>::g(b),</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix1>::b(a) - pixel_traits<pix2>::b(b),</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix1>::m(a) - pixel_traits<pix2>::m(b));</pix2></pix1>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix1,="" pix2="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix1 operator-(const Pix1 &a, const Pix2 &b)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return _sub(a, b, typename pixel_traits<pix2>::pixel_category());</pix2>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix _mult(const Pix &a, Scalar k, grayscale_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix(pixel_traits<pix>::l(a) * k);</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix _mult(const Pix &a, Scalar k, rgb_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix(pixel_traits<pix>::r(a) * k,</pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::g(a) * k,</pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::b(a) * k);</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix _mult(const Pix &a, Scalar k, rgbm_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix(pixel_traits<pix>::r(a) * k,</pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::g(a) * k,</pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::b(a) * k,</pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::m(a) * k);</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix operator*(Scalar k, const Pix &pix)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return _mult(pix, k, typename pixel_traits<pix>::pixel_category());</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix _div(const Pix &a, Scalar k, grayscale_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix(pixel_traits<pix>::l(a) / k);</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix _div(const Pix &a, Scalar k, rgb_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix(pixel_traits<pix>::r(a) / k,</pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::g(a) / k,</pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::b(a) / k);</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix _div(const Pix &a, Scalar k, rgbm_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix(pixel_traits<pix>::r(a) / k,</pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::g(a) / k,</pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::b(a) / k,</pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::m(a) / k);</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix operator/(const Pix &pix, Scalar k)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return _div(pix, k, typename pixel_traits<pix>::pixel_category());</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline void premultiply(Pix &pix, Scalar = 0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Scalar factor = pixel_traits<pix>::m(pix) / Scalar(pixel_traits<pix>::max_channel_value);</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::r(pix) = pixel_traits<pix>::r(pix) * factor;</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::g(pix) = pixel_traits<pix>::g(pix) * factor;</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::b(pix) = pixel_traits<pix>::b(pix) * factor;</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline void depremultiply(Pix &pix, Scalar = 0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (pixel_traits<pix>::channel_type m = pixel_traits<pix>::m(pix)) {</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
Scalar factor = pixel_traits<pix>::max_channel_value / Scalar(m);</pix>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::r(pix) = pixel_traits<pix>::r(pix) * factor;</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::g(pix) = pixel_traits<pix>::g(pix) * factor;</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::b(pix) = pixel_traits<pix>::b(pix) * factor;</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix _blend(const Pix &p0, const Pix &p1, Scalar t, grayscale_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return Pix((1 - t) * pixel_traits<pix>::l(p0) + t * pixel_traits<pix>::l(p1));</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix _blend(const Pix &p0, const Pix &p1, Scalar t, rgb_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Scalar one_t = 1 - t;
|
|
Toshihiro Shimizu |
890ddd |
return Pix(
|
|
Toshihiro Shimizu |
890ddd |
one_t * pixel_traits<pix>::r(p0) + t * pixel_traits<pix>::r(p1),</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
one_t * pixel_traits<pix>::g(p0) + t * pixel_traits<pix>::g(p1),</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
one_t * pixel_traits<pix>::m(p0) + t * pixel_traits<pix>::b(p1));</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix _blend(const Pix &p0, const Pix &p1, Scalar t, rgbm_pixel_tag)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Scalar one_t = 1 - t;
|
|
Toshihiro Shimizu |
890ddd |
return Pix(
|
|
Toshihiro Shimizu |
890ddd |
one_t * pixel_traits<pix>::r(p0) + t * pixel_traits<pix>::r(p1),</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
one_t * pixel_traits<pix>::g(p0) + t * pixel_traits<pix>::g(p1),</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
one_t * pixel_traits<pix>::b(p0) + t * pixel_traits<pix>::b(p1),</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
one_t * pixel_traits<pix>::m(p0) + t * pixel_traits<pix>::m(p1));</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline Pix blend(const Pix &p0, const Pix &p1, Scalar t)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return _blend(p0, p1, t, pixel_traits<pix>::pixel_category());</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline void over_premult(Pix &down, const Pix &up, Scalar = 0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Scalar t = (1 - pixel_traits<pix>::m(up) / Scalar(pixel_traits<pix>::max_channel_value));</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::r(down) = pixel_traits<pix>::r(up) + t * pixel_traits<pix>::r(down);</pix></pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::g(down) = pixel_traits<pix>::g(up) + t * pixel_traits<pix>::g(down);</pix></pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::b(down) = pixel_traits<pix>::b(up) + t * pixel_traits<pix>::b(down);</pix></pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::m(down) = pixel_traits<pix>::m(up) + t * pixel_traits<pix>::m(down);</pix></pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
inline void over(Pix &down, const Pix &up, Scalar = 0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
Scalar t = (1 - pixel_traits<pix>::m(up) / Scalar(pixel_traits<pix>::max_channel_value)) *</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::m(down);</pix>
|
|
Toshihiro Shimizu |
890ddd |
Scalar m = pixel_traits<pix>::m(up) + t;</pix>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Scalar up_fac = pixel_traits<pix>::m(up) / m;</pix>
|
|
Toshihiro Shimizu |
890ddd |
Scalar dn_fac = t / m;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::r(down) = up_fac * pixel_traits<pix>::r(up) + dn_fac * pixel_traits<pix>::r(down);</pix></pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::g(down) = up_fac * pixel_traits<pix>::g(up) + dn_fac * pixel_traits<pix>::g(down);</pix></pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::b(down) = up_fac * pixel_traits<pix>::b(up) + dn_fac * pixel_traits<pix>::b(down);</pix></pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
pixel_traits<pix>::m(down) = m;</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} // namespace tcg::pixel_ops
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#endif // TCG_PIXEL_OPS_H
|