28 qDeleteAll (m_strategies);
34 const long MASK = 0xf0f0f0f0;
35 return (rgb1 & MASK) == (rgb2 & MASK);
38void ColorFilter::createStrategies ()
48 QImage &imageFiltered,
58 for (
int x = 0; x < imageOriginal.width(); x++) {
59 for (
int y = 0; y < imageOriginal.height (); y++) {
61 QColor pixel = imageOriginal.pixel (x, y);
63 if (pixel.rgb() != rgbBackground) {
72 imageFiltered.setPixel (x, y, (isOn ?
73 QColor (Qt::black).rgb () :
74 QColor (Qt::white).rgb ()));
82 ColorList colorCounts;
83 for (
int x = 0; x < image->width (); x++) {
84 mergePixelIntoColorCounts (image->pixel (x, 0), colorCounts);
85 mergePixelIntoColorCounts (image->pixel (x, image->height () - 1), colorCounts);
87 for (
int y = 0; y < image->height (); y++) {
88 mergePixelIntoColorCounts (image->pixel (0, y), colorCounts);
89 mergePixelIntoColorCounts (image->pixel (image->width () - 1, y), colorCounts);
95 for (ColorList::const_iterator itr = colorCounts.begin (); itr != colorCounts.end (); itr++) {
96 if ((*itr).count > entryMax.
count) {
101 return entryMax.
color.rgb();
104void ColorFilter::mergePixelIntoColorCounts (QRgb pixel,
105 ColorList &colorCounts)
const
113 for (ColorList::iterator itr = colorCounts.begin (); itr != colorCounts.end (); itr++) {
115 (*itr).color.rgb())) {
123 colorCounts.append (entry);
135 (x < image.width()) &&
136 (y < image.height())) {
140 const int BLACK_WHITE_THRESHOLD = 255 / 2;
141 int gray = qGray (
pixelRGB (image, x, y));
142 rtn = (gray < BLACK_WHITE_THRESHOLD);
153 double high0To1)
const
161 if (low0To1 <= high0To1) {
164 rtn = (low0To1 <= s) && (s <= high0To1);
169 rtn = (s <= high0To1) || (low0To1 <= s);
179 QRgb rgbBackground)
const
181 if (m_strategies.contains (colorFilterMode)) {
200 if (m_strategies.contains (colorFilterMode)) {
@ COLOR_FILTER_MODE_FOREGROUND
@ COLOR_FILTER_MODE_VALUE
@ COLOR_FILTER_MODE_INTENSITY
@ COLOR_FILTER_MODE_SATURATION
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
log4cpp::Category * mainCat
Base class for strategy pattern whose subclasses process the different color filter settings modes (o...
virtual double pixelToZeroToOne(const QColor &pixel, QRgb rgbBackground) const =0
Return a normalized value of 0 to 1 given input pixel.
virtual int zeroToOneToValue(double s) const =0
Return the low value normalized to 0 to 1.
Leaf class for foreground strategy for ColorFilter.
Leaf class for hue strategy for ColorFilter.
Leaf class for intensity strategy for ColorFilter.
Leaf class for saturation strategy for ColorFilter.
Leaf class for value strategy for ColorFilter.
QRgb marginColor(const QImage *image) const
Identify the margin color of the image, which is defined as the most common color in the four margins...
bool pixelFilteredIsOn(const QImage &image, int x, int y) const
Return true if specified filtered pixel is on.
void filterImage(const QImage &imageOriginal, QImage &imageFiltered, ColorFilterMode colorFilterMode, double low, double high, QRgb rgbBackground)
Filter the original image according to the specified filtering parameters.
~ColorFilter()
Destructor deallocates memory.
int zeroToOneToValue(ColorFilterMode colorFilterMode, double s) const
Inverse of pixelToZeroToOneOrMinusOne.
bool pixelUnfilteredIsOn(ColorFilterMode colorFilterMode, const QColor &pixel, QRgb rgbBackground, double low0To1, double high0To1) const
Return true if specified unfiltered pixel is on.
double pixelToZeroToOneOrMinusOne(ColorFilterMode colorFilterMode, const QColor &pixel, QRgb rgbBackground) const
Return pixel converted according to the current filter parameter, normalized to zero to one.
ColorFilter()
Single constructor.
bool colorCompare(QRgb rgb1, QRgb rgb2) const
See if the two color values are close enough to be considered to be the same.
#define LOG4CPP_ERROR_S(logger)
QRgb pixelRGB(const QImage &image, int x, int y)
Get pixel method for any bit depth.
Helper class so ColorFilter class can compute the background color.
QColor color
Unique color entry.
unsigned int count
Number of times this color has appeared.