7#include "ColorFilter.h"
8#include "ColorFilterHistogram.h"
9#include "EngaugeAssert.h"
17 ColorFilterMode colorFilterMode,
19 const QRgb &rgbBackground)
const
27 ENGAUGE_ASSERT (s <= 1.0);
33 bin = FIRST_NON_EMPTY_BIN_AT_START () + s * (LAST_NON_EMPTY_BIN_AT_END () - FIRST_NON_EMPTY_BIN_AT_START ());
41 double histogramBins [],
42 ColorFilterMode colorFilterMode,
44 int &maxBinCount)
const
49 histogramBins [bin] = 0;
56 for (
int x = 0; x < image.width(); x++) {
57 for (
int y = 0; y < image.height(); y++) {
59 QColor pixel (image.pixel (x, y));
66 ENGAUGE_ASSERT ((FIRST_NON_EMPTY_BIN_AT_START () <= bin) &&
67 (LAST_NON_EMPTY_BIN_AT_END () >= bin));
68 ++(histogramBins [bin]);
70 if (histogramBins [bin] > maxBinCount) {
71 maxBinCount = histogramBins [bin];
79 ColorFilterMode colorFilterMode,
83 double s = (double) (bin - FIRST_NON_EMPTY_BIN_AT_START ()) / (
double) (LAST_NON_EMPTY_BIN_AT_END () - FIRST_NON_EMPTY_BIN_AT_START ());
84 s = qMin (qMax (s, 0.0), 1.0);
void generate(const ColorFilter &filter, double histogramBins[], ColorFilterMode colorFilterMode, const QImage &image, int &maxBinCount) const
Generate the histogram.
ColorFilterHistogram()
Single constructor.
int valueFromBin(const ColorFilter &filter, ColorFilterMode colorFilterMode, int bin)
Inverse of binFromPixel.
static int HISTOGRAM_BINS()
Number of histogram bins.
int binFromPixel(const ColorFilter &filter, ColorFilterMode colorFilterMode, const QColor &pixel, const QRgb &rgbBackground) const
Compute histogram bin number from pixel according to filter.
Class for filtering image to remove unimportant information.
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...
int zeroToOneToValue(ColorFilterMode colorFilterMode, double s) const
Inverse of pixelToZeroToOneOrMinusOne.
double pixelToZeroToOneOrMinusOne(ColorFilterMode colorFilterMode, const QColor &pixel, QRgb rgbBackground) const
Return pixel converted according to the current filter parameter, normalized to zero to one.