Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef PIXEL_SELECTORS_H
Toshihiro Shimizu 890ddd
#define PIXEL_SELECTORS_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tpixel.h"
Toshihiro Shimizu 890ddd
#include "tpixelgr.h"
Toshihiro Shimizu 890ddd
#include "tpixelcm.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace TRop
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
namespace borders
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
//    Standard Pixel Selectors
Toshihiro Shimizu 890ddd
//****************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pix=""></typename>
Toshihiro Shimizu 890ddd
class PixelSelector
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool m_skip;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef Pix pixel_type;
Toshihiro Shimizu 890ddd
	typedef Pix value_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	PixelSelector(bool onlyCorners = true)
Toshihiro Shimizu 890ddd
		: m_skip(onlyCorners) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	value_type transparent() const { return pixel_type::Transparent; }
Toshihiro Shimizu 890ddd
	bool transparent(const pixel_type &pix) const { return (pix.m == 0); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	value_type value(const pixel_type &pix) const { return pix; }
Toshihiro Shimizu 890ddd
	bool equal(const pixel_type &a, const pixel_type &b) const { return a == b; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setSkip(bool skip) { m_skip = skip; }
Toshihiro Shimizu 890ddd
	bool skip(const value_type &prevLeftValue, const value_type &leftValue) const { return m_skip; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
class PixelSelector<tpixelgr8></tpixelgr8>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool m_skip;
Toshihiro Shimizu 890ddd
	TPixelGR8 m_transpColor;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef TPixelGR8 pixel_type;
Toshihiro Shimizu 890ddd
	typedef TPixelGR8 value_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	PixelSelector(bool onlyCorners = true,
Toshihiro Shimizu 890ddd
				  pixel_type transparentColor = pixel_type::White)
Toshihiro Shimizu 890ddd
		: m_skip(onlyCorners), m_transpColor(transparentColor) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	value_type transparent() const { return m_transpColor; }
Toshihiro Shimizu 890ddd
	bool transparent(const pixel_type &pix) const { return (pix == m_transpColor); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	value_type value(const pixel_type &pix) const { return pix; }
Toshihiro Shimizu 890ddd
	bool equal(const pixel_type &a, const pixel_type &b) const { return a == b; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setSkip(bool skip) { m_skip = skip; }
Toshihiro Shimizu 890ddd
	bool skip(const value_type &prevLeftValue, const value_type &leftValue) const { return m_skip; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
class PixelSelector<tpixelgr16></tpixelgr16>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	bool m_skip;
Toshihiro Shimizu 890ddd
	TPixelGR16 m_transpColor;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef TPixelGR16 pixel_type;
Toshihiro Shimizu 890ddd
	typedef TPixelGR16 value_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	PixelSelector(bool onlyCorners = true,
Toshihiro Shimizu 890ddd
				  pixel_type transparentColor = pixel_type::White)
Toshihiro Shimizu 890ddd
		: m_skip(onlyCorners), m_transpColor(transparentColor) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	value_type transparent() const { return m_transpColor; }
Toshihiro Shimizu 890ddd
	bool transparent(const pixel_type &pix) const { return (pix == m_transpColor); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	value_type value(const pixel_type &pix) const { return pix; }
Toshihiro Shimizu 890ddd
	bool equal(const pixel_type &a, const pixel_type &b) const { return a == b; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setSkip(bool skip) { m_skip = skip; }
Toshihiro Shimizu 890ddd
	bool skip(const value_type &prevLeftValue, const value_type &leftValue) const { return m_skip; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//--------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Toshihiro Shimizu 890ddd
class PixelSelector<tpixelcm32></tpixelcm32>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int m_tone;
Toshihiro Shimizu 890ddd
	bool m_skip;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef TPixelCM32 pixel_type;
Toshihiro Shimizu 890ddd
	typedef TUINT32 value_type;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	PixelSelector(bool onlyCorners = true, int tone = 128)
Toshihiro Shimizu 890ddd
		: m_tone(tone), m_skip(onlyCorners) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	value_type transparent() const { return 0; }
Toshihiro Shimizu 890ddd
	bool transparent(const pixel_type &pix) const { return value(pix) == 0; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	value_type value(const pixel_type &pix) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return (pix.getTone() < m_tone) ? pix.getInk() : pix.getPaint();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	bool equal(const pixel_type &a, const pixel_type &b) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return value(a) == value(b);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setSkip(bool skip) { m_skip = skip; }
Toshihiro Shimizu 890ddd
	bool skip(const value_type &prevLeftValue, const value_type &leftValue) const { return m_skip; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
} //namespace TRop::borders
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif //PIXEL_SELECTORS_H