tahoma2d/toonz/sources/common/trop/pixelselectors.h

138 lines
3.6 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 PIXEL_SELECTORS_H
#define PIXEL_SELECTORS_H
#include "tpixel.h"
#include "tpixelgr.h"
#include "tpixelcm.h"
2016-06-15 18:43:10 +12:00
namespace TRop {
namespace borders {
2016-03-19 06:57:51 +13:00
//****************************************************************
// Standard Pixel Selectors
//****************************************************************
template <typename Pix>
2016-06-15 18:43:10 +12:00
class PixelSelector {
bool m_skip;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef Pix pixel_type;
typedef Pix value_type;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
PixelSelector(bool onlyCorners = true) : m_skip(onlyCorners) {}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
value_type transparent() const { return pixel_type::Transparent; }
bool transparent(const pixel_type &pix) const { return (pix.m == 0); }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
value_type value(const pixel_type &pix) const { return pix; }
bool equal(const pixel_type &a, const pixel_type &b) const { return a == b; }
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setSkip(bool skip) { m_skip = skip; }
bool skip(const value_type &prevLeftValue,
const value_type &leftValue) const {
return m_skip;
}
2016-03-19 06:57:51 +13:00
};
//--------------------------------------------------------------------------------
template <>
2016-06-15 18:43:10 +12:00
class PixelSelector<TPixelGR8> {
bool m_skip;
TPixelGR8 m_transpColor;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef TPixelGR8 pixel_type;
typedef TPixelGR8 value_type;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
PixelSelector(bool onlyCorners = true,
pixel_type transparentColor = pixel_type::White)
: m_skip(onlyCorners), m_transpColor(transparentColor) {}
value_type transparent() const { return m_transpColor; }
bool transparent(const pixel_type &pix) const {
return (pix == m_transpColor);
}
value_type value(const pixel_type &pix) const { return pix; }
bool equal(const pixel_type &a, const pixel_type &b) const { return a == b; }
void setSkip(bool skip) { m_skip = skip; }
bool skip(const value_type &prevLeftValue,
const value_type &leftValue) const {
return m_skip;
}
2016-03-19 06:57:51 +13:00
};
//--------------------------------------------------------------------------------
template <>
2016-06-15 18:43:10 +12:00
class PixelSelector<TPixelGR16> {
bool m_skip;
TPixelGR16 m_transpColor;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef TPixelGR16 pixel_type;
typedef TPixelGR16 value_type;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
PixelSelector(bool onlyCorners = true,
pixel_type transparentColor = pixel_type::White)
: m_skip(onlyCorners), m_transpColor(transparentColor) {}
value_type transparent() const { return m_transpColor; }
bool transparent(const pixel_type &pix) const {
return (pix == m_transpColor);
}
value_type value(const pixel_type &pix) const { return pix; }
bool equal(const pixel_type &a, const pixel_type &b) const { return a == b; }
void setSkip(bool skip) { m_skip = skip; }
bool skip(const value_type &prevLeftValue,
const value_type &leftValue) const {
return m_skip;
}
2016-03-19 06:57:51 +13:00
};
//--------------------------------------------------------------------------------
template <>
2016-06-15 18:43:10 +12:00
class PixelSelector<TPixelCM32> {
int m_tone;
bool m_skip;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef TPixelCM32 pixel_type;
typedef TUINT32 value_type;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
PixelSelector(bool onlyCorners = true, int tone = 128)
: m_tone(tone), m_skip(onlyCorners) {}
value_type transparent() const { return 0; }
bool transparent(const pixel_type &pix) const { return value(pix) == 0; }
value_type value(const pixel_type &pix) const {
return (pix.getTone() < m_tone) ? pix.getInk() : pix.getPaint();
}
bool equal(const pixel_type &a, const pixel_type &b) const {
return value(a) == value(b);
}
void setSkip(bool skip) { m_skip = skip; }
bool skip(const value_type &prevLeftValue,
const value_type &leftValue) const {
return m_skip;
}
2016-03-19 06:57:51 +13:00
};
}
2016-06-15 18:43:10 +12:00
} // namespace TRop::borders
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
#endif // PIXEL_SELECTORS_H