Go to the documentation of this file.
27 qDeleteAll (m_strategies);
33 const long MASK = 0xf0f0f0f0;
34 return (rgb1 & MASK) == (rgb2 & MASK);
37 void ColorFilter::createStrategies ()
47 QImage &imageFiltered,
57 for (
int x = 0; x < imageOriginal.width(); x++) {
58 for (
int y = 0; y < imageOriginal.height (); y++) {
60 QColor pixel = imageOriginal.pixel (x, y);
62 if (pixel.rgb() != rgbBackground) {
71 imageFiltered.setPixel (x, y, (isOn ?
72 QColor (Qt::black).rgb () :
73 QColor (Qt::white).rgb ()));
81 ColorList colorCounts;
82 for (
int x = 0; x < image->width (); x++) {
83 mergePixelIntoColorCounts (image->pixel (x, 0), colorCounts);
84 mergePixelIntoColorCounts (image->pixel (x, image->height () - 1), colorCounts);
86 for (
int y = 0; y < image->height (); y++) {
87 mergePixelIntoColorCounts (image->pixel (0, y), colorCounts);
88 mergePixelIntoColorCounts (image->pixel (image->width () - 1, y), colorCounts);
94 for (ColorList::const_iterator itr = colorCounts.begin (); itr != colorCounts.end (); itr++) {
95 if ((*itr).count > entryMax.
count) {
100 return entryMax.
color.rgb();
103 void ColorFilter::mergePixelIntoColorCounts (QRgb pixel,
104 ColorList &colorCounts)
const
112 for (ColorList::iterator itr = colorCounts.begin (); itr != colorCounts.end (); itr++) {
114 (*itr).color.rgb())) {
122 colorCounts.append (entry);
134 (x < image.width()) &&
135 (y < image.height())) {
139 const int BLACK_WHITE_THRESHOLD = 255 / 2;
140 int gray = qGray (
pixelRGB (image, x, y));
141 rtn = (gray < BLACK_WHITE_THRESHOLD);
152 double high0To1)
const
160 if (low0To1 <= high0To1) {
163 rtn = (low0To1 <= s) && (s <= high0To1);
168 rtn = (s <= high0To1) || (low0To1 <= s);
178 QRgb rgbBackground)
const
180 if (m_strategies.contains (colorFilterMode)) {
198 if (m_strategies.contains (colorFilterMode)) {
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()
Destructor deallocates memory.
Leaf class for value strategy for ColorFilter.
QRgb pixelRGB(const QImage &image, int x, int y)
Get pixel method for any bit depth.
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.
Leaf class for hue strategy for ColorFilter.
virtual int zeroToOneToValue(double s) const =0
Return the low value normalized to 0 to 1.
QColor color
Unique color entry.
@ COLOR_FILTER_MODE_SATURATION
unsigned int count
Number of times this color has appeared.
int zeroToOneToValue(ColorFilterMode colorFilterMode, double s) const
Inverse of pixelToZeroToOneOrMinusOne.
virtual double pixelToZeroToOne(const QColor &pixel, QRgb rgbBackground) const =0
Return a normalized value of 0 to 1 given input pixel.
Leaf class for intensity strategy for ColorFilter.
Leaf class for saturation strategy for ColorFilter.
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.
@ COLOR_FILTER_MODE_INTENSITY
Leaf class for foreground strategy for ColorFilter.
@ COLOR_FILTER_MODE_VALUE
ColorFilter()
Single constructor.
Base class for strategy pattern whose subclasses process the different color filter settings modes (o...
@ COLOR_FILTER_MODE_FOREGROUND
Helper class so ColorFilter class can compute the background color.
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
bool colorCompare(QRgb rgb1, QRgb rgb2) const
See if the two color values are close enough to be considered to be the same.