tahoma2d/toonz/sources/include/tcg/pixel.h

139 lines
3.7 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TCG_PIXEL_H
#define TCG_PIXEL_H
// tcg includes
#include "pixel_ops.h"
// STD includes
#include <limits>
2016-06-15 18:43:10 +12:00
namespace tcg {
2016-03-19 06:57:51 +13:00
//***********************************************************
// Tcg Pixel Types definition
//***********************************************************
template <typename Chan, typename pixel_category>
struct Pixel;
template <typename Chan>
struct Pixel<Chan, grayscale_pixel_tag> {
2016-06-15 18:43:10 +12:00
typedef grayscale_pixel_tag pixel_category;
typedef Chan channel_type;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
channel_type l;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
Pixel() : l() {}
Pixel(channel_type _l) : l(_l) {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool operator==(const Pixel &other) const { return l == other.l; }
bool operator!=(const Pixel &other) const { return l != other.l; }
2016-03-19 06:57:51 +13:00
};
template <typename Chan>
struct Pixel<Chan, rgb_pixel_tag> {
2016-06-15 18:43:10 +12:00
typedef rgb_pixel_tag pixel_category;
typedef Chan channel_type;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
channel_type r, g, b;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
Pixel() : r(), g(), b() {}
Pixel(channel_type _r, channel_type _g, channel_type _b)
: r(_r), g(_g), b(_b) {}
bool operator==(const Pixel &other) const {
return (r == other.r) && (g == other.g) && (g == other.g);
}
bool operator!=(const Pixel &other) const {
return (r != other.r) || (g != other.g) || (g != other.g);
}
2016-03-19 06:57:51 +13:00
};
template <typename Chan>
struct Pixel<Chan, rgbm_pixel_tag> {
2016-06-15 18:43:10 +12:00
typedef rgbm_pixel_tag pixel_category;
typedef Chan channel_type;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
channel_type r, g, b, m;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
Pixel() : r(), g(), b(), m() {}
Pixel(channel_type _r, channel_type _g, channel_type _b, channel_type _m)
: r(_r), g(_g), b(_b), m(_m) {}
bool operator==(const Pixel &other) const {
return (r == other.r) && (g == other.g) && (g == other.g) && (m == other.m);
}
bool operator!=(const Pixel &other) const {
return (r != other.r) || (g != other.g) || (g != other.g) || (m != other.m);
}
2016-03-19 06:57:51 +13:00
};
//***********************************************************
// Tcg Pixel traits
//***********************************************************
2016-06-15 18:43:10 +12:00
namespace pixel_ops {
2016-03-19 06:57:51 +13:00
template <typename Chan>
struct pixel_traits<Pixel<Chan, grayscale_pixel_tag>, grayscale_pixel_tag> {
2016-06-15 18:43:10 +12:00
typedef Pixel<Chan, grayscale_pixel_tag> pixel_type;
typedef grayscale_pixel_tag pixel_category;
typedef Chan channel_type;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
enum { channels_count = 1 };
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static channel_type max_channel_value() {
return (std::numeric_limits<channel_type>::max)();
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static channel_type l(const pixel_type &pix) { return pix.l; }
static channel_type &l(pixel_type &pix) { return pix.l; }
2016-03-19 06:57:51 +13:00
};
template <typename Chan>
struct pixel_traits<Pixel<Chan, rgb_pixel_tag>, rgb_pixel_tag> {
2016-06-15 18:43:10 +12:00
typedef Pixel<Chan, rgb_pixel_tag> pixel_type;
typedef rgb_pixel_tag pixel_category;
typedef Chan channel_type;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
enum { channels_count = 3 };
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static channel_type max_channel_value() {
return (std::numeric_limits<channel_type>::max)();
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static channel_type r(const pixel_type &pix) { return pix.r; }
static channel_type &r(pixel_type &pix) { return pix.r; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static channel_type g(const pixel_type &pix) { return pix.g; }
static channel_type &g(pixel_type &pix) { return pix.g; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static channel_type b(const pixel_type &pix) { return pix.b; }
static channel_type &b(pixel_type &pix) { return pix.b; }
2016-03-19 06:57:51 +13:00
};
template <typename Chan>
struct pixel_traits<Pixel<Chan, rgbm_pixel_tag>, rgbm_pixel_tag>
2016-06-15 18:43:10 +12:00
: public pixel_traits<Pixel<Chan, rgb_pixel_tag>, rgb_pixel_tag> {
typedef Pixel<Chan, rgbm_pixel_tag> pixel_type;
typedef rgbm_pixel_tag pixel_category;
typedef Chan channel_type;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
enum { channels_count = 4 };
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static channel_type m(const pixel_type &pix) { return pix.m; }
static channel_type &m(pixel_type &pix) { return pix.m; }
2016-03-19 06:57:51 +13:00
};
}
2016-06-15 18:43:10 +12:00
} // namespace tcg::pixel_ops
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
#endif // TCG_PIXEL_H