Engauge Digitizer  2
ColorFilter.h
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #ifndef COLOR_FILTER_H
8 #define COLOR_FILTER_H
9 
10 #include "ColorFilterEntry.h"
11 #include "ColorFilterMode.h"
12 #include <QList>
13 #include <QMap>
14 #include <QRgb>
15 
17 class QImage;
18 
21 {
22 public:
24  ColorFilter();
25 
27  bool colorCompare (QRgb rgb1,
28  QRgb rgb2) const;
29 
31  void filterImage (const QImage &imageOriginal,
32  QImage &imageFiltered,
33  ColorFilterMode colorFilterMode,
34  double low,
35  double high,
36  QRgb rgbBackground);
37 
41  QRgb marginColor(const QImage *image) const;
42 
44  bool pixelFilteredIsOn (const QImage &image,
45  int x,
46  int y) const;
47 
50  double pixelToZeroToOneOrMinusOne (ColorFilterMode colorFilterMode,
51  const QColor &pixel,
52  QRgb rgbBackground) const;
53 
55  bool pixelUnfilteredIsOn (ColorFilterMode colorFilterMode,
56  const QColor &pixel,
57  QRgb rgbBackground,
58  double low0To1,
59  double high0To1) const;
60 
62  int zeroToOneToValue (ColorFilterMode colorFilterMode,
63  double s) const;
64 
65 private:
66 
67  void createStrategies ();
68 
69  typedef QList<ColorFilterEntry> ColorList;
70 
71  void mergePixelIntoColorCounts (QRgb pixel,
72  ColorList &colorCounts) const;
73 
74  // Strategies for mode-specific computations
75  QMap<ColorFilterMode, ColorFilterStrategyAbstractBase*> m_strategies;
76 
77 };
78 
79 #endif // COLOR_FILTER_H
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...
Definition: ColorFilter.cpp:73
bool colorCompare(QRgb rgb1, QRgb rgb2) const
See if the two color values are close enough to be considered to be the same.
Definition: ColorFilter.cpp:25
bool pixelFilteredIsOn(const QImage &image, int x, int y) const
Return true if specified filtered 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...
Class for filtering image to remove unimportant information.
Definition: ColorFilter.h:20
int zeroToOneToValue(ColorFilterMode colorFilterMode, double s) const
Inverse of pixelToZeroToOneOrMinusOne.
Base class for strategy pattern whose subclasses process the different color filter settings modes (o...
ColorFilter()
Single constructor.
Definition: ColorFilter.cpp:20
bool pixelUnfilteredIsOn(ColorFilterMode colorFilterMode, const QColor &pixel, QRgb rgbBackground, double low0To1, double high0To1) const
Return true if specified unfiltered 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.
Definition: ColorFilter.cpp:41