|
Shinya Kitaoka |
810553 |
#pragma once
|
|
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 |
|
|
Shinya Kitaoka |
120a6e |
namespace tcg {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Pixel Categories
|
|
Toshihiro Shimizu |
890ddd |
//**************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
struct grayscale_pixel_tag {};
|
|
Shinya Kitaoka |
120a6e |
struct rgb_pixel_tag {};
|
|
Shinya Kitaoka |
120a6e |
struct rgbm_pixel_tag : public rgb_pixel_tag {};
|
|
Shinya Kitaoka |
120a6e |
struct indexed_pixel_tag {};
|
|
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,>
|
|
Shinya Kitaoka |
120a6e |
typedef Pix pixel_type;
|
|
Shinya Kitaoka |
120a6e |
typedef grayscale_pixel_tag pixel_category;
|
|
Shinya Kitaoka |
120a6e |
typedef typename Pix::channel_type channel_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
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,>
|
|
Shinya Kitaoka |
120a6e |
typedef Pix pixel_type;
|
|
Shinya Kitaoka |
120a6e |
typedef rgb_pixel_tag pixel_category;
|
|
Shinya Kitaoka |
120a6e |
typedef typename Pix::channel_type channel_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
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,>
|
|
Shinya Kitaoka |
120a6e |
: public pixel_traits_types<pix, rgb_pixel_tag=""> {</pix,>
|
|
Shinya Kitaoka |
120a6e |
typedef Pix pixel_type;
|
|
Shinya Kitaoka |
120a6e |
typedef rgbm_pixel_tag pixel_category;
|
|
Shinya Kitaoka |
120a6e |
typedef typename Pix::channel_type channel_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
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,>
|
|
Shinya Kitaoka |
120a6e |
typedef Pix pixel_type;
|
|
Shinya Kitaoka |
120a6e |
typedef indexed_pixel_tag pixel_category;
|
|
Shinya Kitaoka |
120a6e |
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,>
|
|
Shinya Kitaoka |
120a6e |
: public pixel_traits_types<pix, grayscale_pixel_tag=""> {</pix,>
|
|
Shinya Kitaoka |
120a6e |
typedef pixel_traits_types<pix, grayscale_pixel_tag=""> tr;</pix,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
static typename tr::channel_type max_channel_value();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
static typename tr::channel_type l(const typename tr::pixel_type &pix);
|
|
Shinya Kitaoka |
120a6e |
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,>
|
|
Shinya Kitaoka |
120a6e |
typedef pixel_traits_types<pix, rgb_pixel_tag=""> tr;</pix,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
static typename tr::channel_type max_channel_value();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
static typename tr::channel_type r(const typename tr::pixel_type &pix);
|
|
Shinya Kitaoka |
120a6e |
static typename tr::channel_type &r(typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
static typename tr::channel_type g(const typename tr::pixel_type &pix);
|
|
Shinya Kitaoka |
120a6e |
static typename tr::channel_type &g(typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
static typename tr::channel_type b(const typename tr::pixel_type &pix);
|
|
Shinya Kitaoka |
120a6e |
static typename tr::channel_type &b(typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix=""></typename>
|
|
Shinya Kitaoka |
120a6e |
struct pixel_traits<pix, rgbm_pixel_tag=""></pix,>
|
|
Shinya Kitaoka |
120a6e |
: public pixel_traits<pix, rgb_pixel_tag=""> {</pix,>
|
|
Shinya Kitaoka |
120a6e |
typedef pixel_traits_types<pix, rgbm_pixel_tag=""> tr;</pix,>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
static typename tr::channel_type m(const typename tr::pixel_type &pix);
|
|
Shinya Kitaoka |
120a6e |
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,>
|
|
Shinya Kitaoka |
120a6e |
typedef pixel_traits_types<pix, indexed_pixel_tag=""> tr;</pix,>
|
|
Shinya Kitaoka |
120a6e |
typedef typename tr::pixel_type pixel_type;
|
|
Shinya Kitaoka |
120a6e |
typedef typename tr::index_type index_type;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
public:
|
|
Shinya Kitaoka |
120a6e |
static typename tr::index_type index(const typename tr::pixel_type &pix);
|
|
Shinya Kitaoka |
120a6e |
static typename tr::index_type &index(typename tr::pixel_type &pix);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace pixel_ops {
|
|
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>
|
|
Shinya Kitaoka |
120a6e |
inline PixOut _cast(const PixIn &pix, grayscale_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return PixOut(pixel_traits<pixin>::l(pix));</pixin>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixin,="" pixout="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline PixOut _cast(const PixIn &pix, rgb_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return PixOut(pixel_traits<pixin>::r(pix), pixel_traits<pixin>::g(pix),</pixin></pixin>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pixin>::b(pix));</pixin>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixin,="" pixout="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline PixOut _cast(const PixIn &pix, rgbm_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return PixOut(pixel_traits<pixin>::r(pix), pixel_traits<pixin>::g(pix),</pixin></pixin>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pixin>::b(pix), pixel_traits<pixin>::m(pix));</pixin></pixin>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixin,="" pixout="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline PixOut cast(const PixIn &pix) {
|
|
Shinya Kitaoka |
120a6e |
return _cast<pixin, pixout="">(pix,</pixin,>
|
|
Shinya Kitaoka |
120a6e |
typename pixel_traits<pixin>::pixel_category());</pixin>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixin,="" pixout="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline void _assign(PixOut &pixout, const PixIn &pixin, grayscale_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline void _assign(PixOut &pixout, const PixIn &pixin, rgb_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pixout>::r(pixout) = pixel_traits<pixin>::r(pixin);</pixin></pixout>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pixout>::g(pixout) = pixel_traits<pixin>::g(pixin);</pixin></pixout>
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline void _assign(PixOut &pixout, const PixIn &pixin, rgbm_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pixout>::r(pixout) = pixel_traits<pixin>::r(pixin);</pixin></pixout>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pixout>::g(pixout) = pixel_traits<pixin>::g(pixin);</pixin></pixout>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pixout>::b(pixout) = pixel_traits<pixin>::b(pixin);</pixin></pixout>
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline void assign(PixOut &pixout, const PixIn &pixin) {
|
|
Shinya Kitaoka |
120a6e |
_assign<pixin, pixout="">(pixout, pixin,</pixin,>
|
|
Shinya Kitaoka |
120a6e |
typename pixel_traits<pixin>::pixel_category());</pixin>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix1,="" pix2="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline Pix1 _sum(const Pix1 &a, const Pix2 &b, grayscale_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline Pix1 _sum(const Pix1 &a, const Pix2 &b, rgb_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return Pix1(pixel_traits<pix1>::r(a) + pixel_traits<pix2>::r(b),</pix2></pix1>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix1>::g(a) + pixel_traits<pix2>::g(b),</pix2></pix1>
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline Pix1 _sum(const Pix1 &a, const Pix2 &b, rgbm_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return Pix1(pixel_traits<pix1>::r(a) + pixel_traits<pix2>::r(b),</pix2></pix1>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix1>::g(a) + pixel_traits<pix2>::g(b),</pix2></pix1>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix1>::b(a) + pixel_traits<pix2>::b(b),</pix2></pix1>
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline Pix1 operator+(const Pix1 &a, const Pix2 &b) {
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline Pix1 _sub(const Pix1 &a, const Pix2 &b, grayscale_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline Pix1 _sub(const Pix1 &a, const Pix2 &b, rgb_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return Pix1(pixel_traits<pix1>::r(a) - pixel_traits<pix2>::r(b),</pix2></pix1>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix1>::g(a) - pixel_traits<pix2>::g(b),</pix2></pix1>
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline Pix1 _sub(const Pix1 &a, const Pix2 &b, rgbm_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return Pix1(pixel_traits<pix1>::r(a) - pixel_traits<pix2>::r(b),</pix2></pix1>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix1>::g(a) - pixel_traits<pix2>::g(b),</pix2></pix1>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix1>::b(a) - pixel_traits<pix2>::b(b),</pix2></pix1>
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline Pix1 operator-(const Pix1 &a, const Pix2 &b) {
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline Pix _mult(const Pix &a, Scalar k, grayscale_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return Pix(pixel_traits<pix>::l(a) * k);</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline Pix _mult(const Pix &a, Scalar k, rgb_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return Pix(pixel_traits<pix>::r(a) * k, pixel_traits<pix>::g(a) * k,</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::b(a) * k);</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline Pix _mult(const Pix &a, Scalar k, rgbm_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return Pix(pixel_traits<pix>::r(a) * k, pixel_traits<pix>::g(a) * k,</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::b(a) * k, pixel_traits<pix>::m(a) * k);</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline Pix operator*(Scalar k, const Pix &pix) {
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline Pix _div(const Pix &a, Scalar k, grayscale_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return Pix(pixel_traits<pix>::l(a) / k);</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline Pix _div(const Pix &a, Scalar k, rgb_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return Pix(pixel_traits<pix>::r(a) / k, pixel_traits<pix>::g(a) / k,</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::b(a) / k);</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline Pix _div(const Pix &a, Scalar k, rgbm_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
return Pix(pixel_traits<pix>::r(a) / k, pixel_traits<pix>::g(a) / k,</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::b(a) / k, pixel_traits<pix>::m(a) / k);</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline Pix operator/(const Pix &pix, Scalar k) {
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline void premultiply(Pix &pix, Scalar = 0) {
|
|
Shinya Kitaoka |
120a6e |
Scalar factor =
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::m(pix) / Scalar(pixel_traits<pix>::max_channel_value);</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::r(pix) = pixel_traits<pix>::r(pix) * factor;</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::g(pix) = pixel_traits<pix>::g(pix) * factor;</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline void depremultiply(Pix &pix, Scalar = 0) {
|
|
Shinya Kitaoka |
120a6e |
if (pixel_traits<pix>::channel_type m = pixel_traits<pix>::m(pix)) {</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
Scalar factor = pixel_traits<pix>::max_channel_value / Scalar(m);</pix>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::r(pix) = pixel_traits<pix>::r(pix) * factor;</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::g(pix) = pixel_traits<pix>::g(pix) * factor;</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::b(pix) = pixel_traits<pix>::b(pix) * factor;</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline Pix _blend(const Pix &p0, const Pix &p1, Scalar t, grayscale_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline Pix _blend(const Pix &p0, const Pix &p1, Scalar t, rgb_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
Scalar one_t = 1 - t;
|
|
Shinya Kitaoka |
120a6e |
return Pix(one_t * pixel_traits<pix>::r(p0) + t * pixel_traits<pix>::r(p1),</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
one_t * pixel_traits<pix>::g(p0) + t * pixel_traits<pix>::g(p1),</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline Pix _blend(const Pix &p0, const Pix &p1, Scalar t, rgbm_pixel_tag) {
|
|
Shinya Kitaoka |
120a6e |
Scalar one_t = 1 - t;
|
|
Shinya Kitaoka |
120a6e |
return Pix(one_t * pixel_traits<pix>::r(p0) + t * pixel_traits<pix>::r(p1),</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
one_t * pixel_traits<pix>::g(p0) + t * pixel_traits<pix>::g(p1),</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
one_t * pixel_traits<pix>::b(p0) + t * pixel_traits<pix>::b(p1),</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline Pix blend(const Pix &p0, const Pix &p1, Scalar t) {
|
|
Shinya Kitaoka |
120a6e |
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>
|
|
Shinya Kitaoka |
120a6e |
inline void over_premult(Pix &down, const Pix &up, Scalar = 0) {
|
|
Shinya Kitaoka |
120a6e |
Scalar t =
|
|
Shinya Kitaoka |
120a6e |
(1 -
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::m(up) / Scalar(pixel_traits<pix>::max_channel_value));</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::r(down) =</pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::r(up) + t * pixel_traits<pix>::r(down);</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::g(down) =</pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::g(up) + t * pixel_traits<pix>::g(down);</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::b(down) =</pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::b(up) + t * pixel_traits<pix>::b(down);</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::m(down) =</pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::m(up) + t * pixel_traits<pix>::m(down);</pix></pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pix,="" scalar="" typename=""></typename>
|
|
Shinya Kitaoka |
120a6e |
inline void over(Pix &down, const Pix &up, Scalar = 0) {
|
|
Shinya Kitaoka |
120a6e |
Scalar t = (1 -
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::m(up) /</pix>
|
|
Shinya Kitaoka |
120a6e |
Scalar(pixel_traits<pix>::max_channel_value)) *</pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::m(down);</pix>
|
|
Shinya Kitaoka |
120a6e |
Scalar m = pixel_traits<pix>::m(up) + t;</pix>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
Scalar up_fac = pixel_traits<pix>::m(up) / m;</pix>
|
|
Shinya Kitaoka |
120a6e |
Scalar dn_fac = t / m;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::r(down) =</pix>
|
|
Shinya Kitaoka |
120a6e |
up_fac * pixel_traits<pix>::r(up) + dn_fac * pixel_traits<pix>::r(down);</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::g(down) =</pix>
|
|
Shinya Kitaoka |
120a6e |
up_fac * pixel_traits<pix>::g(up) + dn_fac * pixel_traits<pix>::g(down);</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::b(down) =</pix>
|
|
Shinya Kitaoka |
120a6e |
up_fac * pixel_traits<pix>::b(up) + dn_fac * pixel_traits<pix>::b(down);</pix></pix>
|
|
Shinya Kitaoka |
120a6e |
pixel_traits<pix>::m(down) = m;</pix>
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Shinya Kitaoka |
120a6e |
} // namespace tcg::pixel_ops
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
#endif // TCG_PIXEL_OPS_H
|