Krita Source Code Documentation
Loading...
Searching...
No Matches
KisHistogram Class Reference

#include <kis_histogram.h>

+ Inheritance diagram for KisHistogram:

Classes

class  Calculations
 

Public Member Functions

Calculations calculations ()
 
qint32 channel ()
 
void computeHistogram ()
 
enumHistogramType getHistogramType ()
 
quint32 getValue (quint8 i)
 
bool hasSelection ()
 
 KisHistogram (KisPaintDeviceSP paintdev, const QRect &bounds, KoHistogramProducer *producer, const enumHistogramType type)
 
 KisHistogram (KisPaintLayerSP layer, KoHistogramProducer *producer, const enumHistogramType type)
 
KoHistogramProducerproducer ()
 
Calculations selectionCalculations ()
 
double selectionFrom ()
 
double selectionTo ()
 
void setChannel (qint32 channel)
 
void setHistogramType (enumHistogramType type)
 
void setNoSelection ()
 
void setProducer (KoHistogramProducer *producer)
 
void setSelection (double from, double to)
 
void updateHistogram ()
 
virtual ~KisHistogram ()
 
- Public Member Functions inherited from KisShared
bool deref ()
 
bool ref ()
 
int refCount ()
 
QAtomicInt * sharedWeakReference ()
 

Private Member Functions

QVector< CalculationscalculateForRange (double from, double to)
 
Calculations calculateSingleRange (int channel, double from, double to)
 
void dump ()
 

Private Attributes

QRect m_bounds
 
qint32 m_channel {0}
 
QVector< Calculationsm_completeCalculations
 
const KisPaintDeviceSP m_paintDevice
 
KoHistogramProducerm_producer {nullptr}
 
bool m_selection {false}
 
QVector< Calculationsm_selectionCalculations
 
double m_selFrom {0.0}
 
double m_selTo {0.0}
 
enumHistogramType m_type {LINEAR}
 

Additional Inherited Members

- Protected Member Functions inherited from KisShared
 KisShared ()
 
 ~KisShared ()
 

Detailed Description

The histogram class computes the histogram data from the specified layer for the specified channel, through the use of a KoHistogramProducer. This class is only for layers and paintdevices. KisImages are not supported, but you can use the mergedImage function to create a paintdevice and feed that to this class.

A Histogram also can have a selection: this is a specific range in the current histogram that will get calculations done on it as well. If the range's begin and end are the same, it is supposed to specify a single bin in the histogram.

The calculations are done in the range 0 - 1, instead of the native range that a pixel might have, so it's not always as precise as it could be. But you can't have it all...

Definition at line 36 of file kis_histogram.h.

Constructor & Destructor Documentation

◆ KisHistogram() [1/2]

KisHistogram::KisHistogram ( KisPaintLayerSP layer,
KoHistogramProducer * producer,
const enumHistogramType type )

Definition at line 19 of file kis_histogram.cc.

22 : m_paintDevice(layer->projection())
23{
24 Q_ASSERT(producer);
25
26 KisImageSP imageSP = layer->image().toStrongRef();
27 if (imageSP) {
28 m_bounds = imageSP->bounds();
29 }
30 m_type = type;
32 m_selection = false;
33 m_channel = 0;
34
36}
KoHistogramProducer * producer()
const KisPaintDeviceSP m_paintDevice
enumHistogramType m_type
KoHistogramProducer * m_producer
void updateHistogram()
QRect bounds() const override
KisSharedPtr< T > toStrongRef() const
toStrongRef returns a KisSharedPtr which may be dereferenced.
KisImageWSP image
KisPaintDeviceSP projection() const override
Definition kis_layer.cc:820

References KisImage::bounds(), KisBaseNode::image, m_bounds, m_channel, m_producer, m_selection, m_type, producer(), KisWeakSharedPtr< T >::toStrongRef(), and updateHistogram().

◆ KisHistogram() [2/2]

KisHistogram::KisHistogram ( KisPaintDeviceSP paintdev,
const QRect & bounds,
KoHistogramProducer * producer,
const enumHistogramType type )

Definition at line 38 of file kis_histogram.cc.

42 : m_paintDevice(paintdev)
43{
44 Q_ASSERT(producer);
45
48 m_type = type;
49
50 m_selection = false;
51 m_channel = 0;
52
53 // TODO: Why does Krita crash when updateHistogram() is *not* called here?
55}
#define bounds(x, a, b)

References bounds, m_bounds, m_channel, m_producer, m_selection, m_type, producer(), and updateHistogram().

◆ ~KisHistogram()

KisHistogram::~KisHistogram ( )
virtual

Definition at line 57 of file kis_histogram.cc.

58{
59 delete m_producer;
60}

References m_producer.

Member Function Documentation

◆ calculateForRange()

QVector< KisHistogram::Calculations > KisHistogram::calculateForRange ( double from,
double to )
private

Definition at line 126 of file kis_histogram.cc.

127{
129 if (m_producer) {
130 uint count = m_producer->channels().count();
131
132 for (uint i = 0; i < count; i++) {
133 calculations.append(calculateSingleRange(i, from, to));
134 }
135 }
136 return calculations;
137}
unsigned int uint
Calculations calculateSingleRange(int channel, double from, double to)
Calculations calculations()
virtual QList< KoChannelInfo * > channels()=0

References calculateSingleRange(), calculations(), KoHistogramProducer::channels(), and m_producer.

◆ calculateSingleRange()

KisHistogram::Calculations KisHistogram::calculateSingleRange ( int channel,
double from,
double to )
private

Definition at line 139 of file kis_histogram.cc.

140{
141 Calculations c;
142
143 // XXX If from == to, we only want a specific bin, handle that properly!
144
145 double max = from, min = to, total = 0.0, mean = 0.0; //, median = 0.0, stddev = 0.0;
146 quint32 high = 0, low = (quint32) - 1, count = 0;
147
148 if (m_producer->count() == 0) {
149 // We won't get anything, even if a range is specified
150 // XXX make sure all initial '0' values are correct here!
151 return c;
152 }
153
154 qint32 totbins = m_producer->numberOfBins();
155 quint32 current;
156
157 // convert the double range into actual bins:
158 double factor = static_cast<double>(totbins) / m_producer->viewWidth();
159
160 qint32 fromBin = static_cast<qint32>((from - m_producer->viewFrom()) * factor);
161 qint32 toBin = fromBin + static_cast<qint32>((to - from) * factor);
162
163 // Min, max, count, low, high
164 for (qint32 i = fromBin; i < toBin; i++) {
165 current = m_producer->getBinAt(channel, i);
166 double pos = static_cast<double>(i) / factor + from;
167 if (current > high)
168 high = current;
169 if (current < low)
170 low = current;
171 if (current > 0) {
172 if (pos < min)
173 min = pos;
174 if (pos > max)
175 max = pos;
176 }
177 // We do the count here as well.
178 // we can't use m_producer->count() for this, because of the range
179 count += current;
180 total += current * pos;
181 }
182
183 if (count > 0)
184 mean = total / count;
185
186 c.m_high = high;
187 c.m_low = low;
188 c.m_count = count;
189 c.m_min = min;
190 c.m_max = max;
191 c.m_mean = mean;
192 c.m_total = total;
193
194 return c;
195}
qint32 channel()
virtual qreal viewFrom() const =0
virtual qint32 getBinAt(qint32 channel, qint32 position)=0
virtual qint32 numberOfBins()=0
virtual qreal viewWidth() const =0
virtual qint32 count()=0
T min(T a, T b, T c)
constexpr std::enable_if< sizeof...(values)==0, size_t >::type max()

References channel(), KoHistogramProducer::count(), KoHistogramProducer::getBinAt(), KisHistogram::Calculations::m_count, KisHistogram::Calculations::m_high, KisHistogram::Calculations::m_low, KisHistogram::Calculations::m_max, KisHistogram::Calculations::m_mean, KisHistogram::Calculations::m_min, m_producer, KisHistogram::Calculations::m_total, KoHistogramProducer::numberOfBins(), KoHistogramProducer::viewFrom(), and KoHistogramProducer::viewWidth().

◆ calculations()

KisHistogram::Calculations KisHistogram::calculations ( )

The information on the entire view for the current channel

Definition at line 116 of file kis_histogram.cc.

117{
119}
QVector< Calculations > m_completeCalculations

References m_channel, and m_completeCalculations.

◆ channel()

qint32 KisHistogram::channel ( )
inline

Definition at line 148 of file kis_histogram.h.

148 {
149 return m_channel;
150 }

◆ computeHistogram()

void KisHistogram::computeHistogram ( )

(Re)computes the mathematical information from the information currently in the producer. Needs to be called when you change the selection and want to get that information

Definition at line 98 of file kis_histogram.cc.

99{
100 if (!m_producer) return;
101
104
105 if (m_selection) {
107 } else {
109 }
110
111#if 1
112 dump();
113#endif
114}
QVector< Calculations > m_selectionCalculations
QVector< Calculations > calculateForRange(double from, double to)

References calculateForRange(), dump(), m_completeCalculations, m_producer, m_selection, m_selectionCalculations, m_selFrom, m_selTo, KoHistogramProducer::viewFrom(), and KoHistogramProducer::viewWidth().

◆ dump()

void KisHistogram::dump ( )
private

Definition at line 198 of file kis_histogram.cc.

199{
200 dbgMath << "Histogram";
201
202 switch (m_type) {
203 case LINEAR:
204 dbgMath << "Linear histogram";
205 break;
206 case LOGARITHMIC:
207 dbgMath << "Logarithmic histogram";
208 }
209
210 dbgMath << "Dumping channel" << m_channel;
211 Calculations c = calculations();
212
213 /* for( int i = 0; i <256; ++i ) {
214 dbgMath <<"Value"
215 << QString().setNum(i)
216 << ": "
217 << QString().setNum(m_values[i])
218 << "\n";
219 }*/
220 dbgMath << "";
221
222 dbgMath << "Max:" << QString().setNum(c.getMax()) << "";
223 dbgMath << "Min:" << QString().setNum(c.getMin()) << "";
224 dbgMath << "High:" << QString().setNum(c.getHighest()) << "";
225 dbgMath << "Low:" << QString().setNum(c.getLowest()) << "";
226 dbgMath << "Mean:" << m_producer->positionToString(c.getMean()) << "";
227 dbgMath << "Total:" << QString().setNum(c.getTotal()) << "";
228 // dbgMath <<"Median:" << QString().setNum(m_median) <<"";
229 // dbgMath <<"Stddev:" << QString().setNum(m_stddev) <<"";
230 // dbgMath <<"percentile:" << QString().setNum(m_percentile) <<"";
231
232 dbgMath << "";
233}
virtual QString positionToString(qreal pos) const =0
#define dbgMath
Definition kis_debug.h:54
@ LOGARITHMIC
@ LINEAR

References calculations(), dbgMath, KisHistogram::Calculations::getHighest(), KisHistogram::Calculations::getLowest(), KisHistogram::Calculations::getMax(), KisHistogram::Calculations::getMean(), KisHistogram::Calculations::getMin(), KisHistogram::Calculations::getTotal(), LINEAR, LOGARITHMIC, m_channel, m_producer, m_type, and KoHistogramProducer::positionToString().

◆ getHistogramType()

enumHistogramType KisHistogram::getHistogramType ( )
inline

Definition at line 131 of file kis_histogram.h.

131 {
132 return m_type;
133 }

◆ getValue()

quint32 KisHistogram::getValue ( quint8 i)
inline

Definition at line 127 of file kis_histogram.h.

127 {
128 return m_producer->getBinAt(m_channel, i);
129 }

◆ hasSelection()

bool KisHistogram::hasSelection ( )
inline

Definition at line 152 of file kis_histogram.h.

152 {
153 return m_selection;
154 }

◆ producer()

KoHistogramProducer * KisHistogram::producer ( )
inline

Definition at line 145 of file kis_histogram.h.

145 {
146 return m_producer;
147 }

◆ selectionCalculations()

KisHistogram::Calculations KisHistogram::selectionCalculations ( )

The information on the current selection for the current channel

Definition at line 121 of file kis_histogram.cc.

122{
124}

References m_channel, and m_selectionCalculations.

◆ selectionFrom()

double KisHistogram::selectionFrom ( )
inline

Definition at line 155 of file kis_histogram.h.

155 {
156 return m_selFrom;
157 }

◆ selectionTo()

double KisHistogram::selectionTo ( )
inline

Definition at line 158 of file kis_histogram.h.

158 {
159 return m_selTo;
160 }

◆ setChannel()

void KisHistogram::setChannel ( qint32 channel)
inline

Definition at line 141 of file kis_histogram.h.

141 {
142 Q_ASSERT(m_channel < m_completeCalculations.size());
144 }

◆ setHistogramType()

void KisHistogram::setHistogramType ( enumHistogramType type)
inline

Definition at line 134 of file kis_histogram.h.

134 {
135 m_type = type;
136 }

◆ setNoSelection()

void KisHistogram::setNoSelection ( )
inline

Definition at line 161 of file kis_histogram.h.

161 {
162 m_selection = false;
163 }

◆ setProducer()

void KisHistogram::setProducer ( KoHistogramProducer * producer)
inline

Definition at line 137 of file kis_histogram.h.

137 {
138 m_channel = 0;
140 }

◆ setSelection()

void KisHistogram::setSelection ( double from,
double to )
inline

Sets the current selection

Definition at line 165 of file kis_histogram.h.

165 {
166 m_selection = true; m_selFrom = from; m_selTo = to;
167 }

◆ updateHistogram()

void KisHistogram::updateHistogram ( )

Updates the information in the producer

Definition at line 62 of file kis_histogram.cc.

63{
64 if (m_bounds.isEmpty()) {
65 int numChannels = m_producer->channels().count();
66
68 m_completeCalculations.resize(numChannels);
69
71 m_completeCalculations.resize(numChannels);
72
73 return;
74 }
75
78
79 // Let the producer do it's work
81
82
83 // XXX: the original code depended on their being a selection mask in the iterator
84 // if the paint device had a selection. When we changed that to passing an
85 // explicit selection to the createRectIterator call, that broke because
86 // paint devices didn't know about their selections anymore.
87 // updateHistogram should get a selection parameter.
88 int numConseqPixels = srcIt.nConseqPixels();
89 while (srcIt.nextPixels(numConseqPixels)) {
90
91 numConseqPixels = srcIt.nConseqPixels();
92 m_producer->addRegionToBin(srcIt.oldRawData(), 0, numConseqPixels, cs);
93 }
94
96}
void computeHistogram()
const KoColorSpace * colorSpace() const
virtual void clear()=0
virtual void addRegionToBin(const quint8 *pixels, const quint8 *selectionMask, quint32 nPixels, const KoColorSpace *colorSpace)=0

References KoHistogramProducer::addRegionToBin(), KoHistogramProducer::channels(), KoHistogramProducer::clear(), KisPaintDevice::colorSpace(), computeHistogram(), m_bounds, m_completeCalculations, m_paintDevice, m_producer, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nConseqPixels(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixels(), and KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::oldRawData().

Member Data Documentation

◆ m_bounds

QRect KisHistogram::m_bounds
private

Definition at line 177 of file kis_histogram.h.

◆ m_channel

qint32 KisHistogram::m_channel {0}
private

Definition at line 181 of file kis_histogram.h.

181{0};

◆ m_completeCalculations

QVector<Calculations> KisHistogram::m_completeCalculations
private

Definition at line 186 of file kis_histogram.h.

◆ m_paintDevice

const KisPaintDeviceSP KisHistogram::m_paintDevice
private

Definition at line 176 of file kis_histogram.h.

◆ m_producer

KoHistogramProducer* KisHistogram::m_producer {nullptr}
private

Definition at line 178 of file kis_histogram.h.

178{nullptr};

◆ m_selection

bool KisHistogram::m_selection {false}
private

Definition at line 184 of file kis_histogram.h.

184{false};

◆ m_selectionCalculations

QVector<Calculations> KisHistogram::m_selectionCalculations
private

Definition at line 186 of file kis_histogram.h.

◆ m_selFrom

double KisHistogram::m_selFrom {0.0}
private

Definition at line 182 of file kis_histogram.h.

182{0.0};

◆ m_selTo

double KisHistogram::m_selTo {0.0}
private

Definition at line 183 of file kis_histogram.h.

183{0.0};

◆ m_type

enumHistogramType KisHistogram::m_type {LINEAR}
private

Definition at line 179 of file kis_histogram.h.

179{LINEAR};

The documentation for this class was generated from the following files: