chalk

kis_histogram.h
1/*
2 * Copyright (c) 2004 Boudewijn Rempt
3 * (c) 2005 Bart Coppens <kde@bartcoppens.be>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19#ifndef KIS_HISTOGRAM_
20#define KIS_HISTOGRAM_
21
22#include "kis_types.h"
23#include "kis_colorspace.h"
24#include "kis_histogram_producer.h"
25
26enum enumHistogramType {
27 LINEAR,
28 LOGARITHMIC
29};
43class KisHistogram : public TDEShared {
44
45public:
50 class Calculations {
51
52 double m_max, m_min, m_mean, m_total, m_median, m_stddev;
53
54 TQ_UINT32 m_high, m_low, m_count;
55
56 friend class KisHistogram;
57
58 public:
59
60 Calculations() : m_max(0.0), m_min(0.0), m_mean(0.0), m_total(0.0), m_median(0.0),
61 m_stddev(0.0), m_high(0), m_low(0), m_count(0) {}
66 inline double getMax() { return m_max; }
71 inline double getMin() { return m_min; }
73 inline TQ_UINT32 getHighest() { return m_high; }
75 inline TQ_UINT32 getLowest() { return m_low; }
77 inline double getMean() { return m_mean; }
78 //double getMedian() { return m_median; }
79 //double getStandardDeviation() { return m_stddev; }
81 inline TQ_UINT32 getCount() { return m_count; }
83 inline double getTotal() { return m_total; }
84 //TQ_UINT8 getPercentile() { return m_percentile; } // What is this exactly? XXX
85 };
86
87 KisHistogram(KisPaintLayerSP layer,
88 KisHistogramProducerSP producer,
89 const enumHistogramType type);
90
91 KisHistogram(KisPaintDeviceSP paintdev,
92 KisHistogramProducerSP producer,
93 const enumHistogramType type);
94
95 virtual ~KisHistogram();
96
98 void updateHistogram();
99
104 void computeHistogram();
105
107 Calculations calculations();
109 Calculations selectionCalculations();
110
111 inline TQ_UINT32 getValue(TQ_UINT8 i) { return m_producer->getBinAt(m_channel, i); }
112
113 inline enumHistogramType getHistogramType() { return m_type; }
114 inline void setHistogramType(enumHistogramType type) { m_type = type; }
115 inline void setProducer(KisHistogramProducerSP producer) { m_producer = producer; }
116 inline void setChannel(TQ_INT32 channel) { m_channel = channel; }
117 inline KisHistogramProducerSP producer() { return m_producer; }
118 inline TQ_INT32 channel() { return m_channel; }
119
120 inline bool hasSelection() { return m_selection; }
121 inline double selectionFrom() { return m_selFrom; }
122 inline double selectionTo() { return m_selTo; }
123 inline void setNoSelection() { m_selection = false; }
125 inline void setSelection(double from, double to)
126 { m_selection = true; m_selFrom = from; m_selTo = to; }
127
128
129private:
130 // Dump the histogram to debug.
131 void dump();
132 TQValueVector<Calculations> calculateForRange(double from, double to);
133 Calculations calculateSingleRange(int channel, double from, double to);
134
135 KisPaintDeviceSP m_device;
136 KisHistogramProducerSP m_producer;
137
138 enumHistogramType m_type;
139
140 TQ_INT32 m_channel;
141 double m_selFrom, m_selTo;
142 bool m_selection;
143
144 KisPaintDeviceSP m_dev;
145
146 TQValueVector<Calculations> m_completeCalculations, m_selectionCalculations;
147};
148
149
150#endif // KIS_HISTOGRAM_WIDGET_
double getMean()
This function return the mean of value of the histogram.
double getMax()
This function return the maximum bound of the histogram (values at greater position than the maximum ...
TQ_UINT32 getHighest()
This function return the highest value of the histogram.
TQ_UINT32 getLowest()
This function return the lowest value of the histogram.
double getTotal()
The sum of (the contents of every bin * the double value of that bin).
double getMin()
This function return the minimum bound of the histogram (values at smaller position than the minimum ...
TQ_UINT32 getCount()
This function return the number of pixels used by the histogram.
The histogram class computes the histogram data from the specified layer for the specified channel,...
Calculations selectionCalculations()
The information on the current selection for the current channel.
void setSelection(double from, double to)
Sets the current selection.
void computeHistogram()
(Re)computes the mathematical information from the information currently in the producer.
Calculations calculations()
The information on the entire view for the current channel.
void updateHistogram()
Updates the information in the producer.