21#include <tqdatetime.h>
24#include "kis_histogram.h"
25#include "kis_paint_layer.h"
26#include "kis_iterators_pixel.h"
27#include "kis_colorspace.h"
28#include "kis_debug_areas.h"
30KisHistogram::KisHistogram(KisPaintLayerSP layer,
31 KisHistogramProducerSP producer,
32 const enumHistogramType type)
34 m_dev = layer->paintDevice();
36 m_producer = producer;
43KisHistogram::KisHistogram(KisPaintDeviceSP paintdev,
44 KisHistogramProducerSP producer,
45 const enumHistogramType type)
49 m_producer = producer;
56KisHistogram::~KisHistogram()
63 m_dev->exactBounds(x,y,w,h);
64 KisRectIteratorPixel srcIt = m_dev->createRectIterator(x,y,w,h,
false);
76 m_producer->addRegionToBin(0, 0, 0, cs);
78 while ( !srcIt.
isDone() ) {
79 i = srcIt.nConseqPixels();
80 m_producer->addRegionToBin(srcIt.
rawData(), srcIt.selectionMask(), i, cs);
90 m_completeCalculations = calculateForRange(m_producer->viewFrom(),
91 m_producer->viewFrom() + m_producer->viewWidth());
94 m_selectionCalculations = calculateForRange(m_selFrom, m_selTo);
96 m_selectionCalculations.clear();
105 return m_completeCalculations.at(m_channel);
109 return m_selectionCalculations.at(m_channel);
112TQValueVector<KisHistogram::Calculations> KisHistogram::calculateForRange(
double from,
double to) {
114 uint count = m_producer->channels().count();
116 for (uint i = 0; i < count; i++) {
128 double max = from, min = to, total = 0.0, mean = 0.0;
129 TQ_UINT32 high = 0, low = (TQ_UINT32) -1, count = 0;
131 if (m_producer->count() == 0) {
137 TQ_INT32 totbins = m_producer->numberOfBins();
141 double factor =
static_cast<double>(totbins) / m_producer->viewWidth();
143 TQ_INT32 fromBin =
static_cast<TQ_INT32
>((from - m_producer->viewFrom()) * factor);
144 TQ_INT32 toBin = fromBin +
static_cast<TQ_INT32
>((to - from) * factor);
147 for (TQ_INT32 i = fromBin; i < toBin; i++) {
148 current = m_producer->getBinAt(channel, i);
149 double pos =
static_cast<double>(i) / factor + from;
163 total += current * pos;
167 mean = total / count;
181void KisHistogram::dump() {
182 kdDebug(DBG_AREA_MATH) <<
"Histogram\n";
186 kdDebug(DBG_AREA_MATH) <<
"Linear histogram\n";
189 kdDebug(DBG_AREA_MATH) <<
"Logarithmic histogram\n";
192 kdDebug(DBG_AREA_MATH) <<
"Dumping channel " << m_channel << endl;
202 kdDebug(DBG_AREA_MATH) <<
"\n";
204 kdDebug(DBG_AREA_MATH) <<
"Max: " << TQString(TQString().setNum(c.getMax())) <<
"\n";
205 kdDebug(DBG_AREA_MATH) <<
"Min: " << TQString(TQString().setNum(c.getMin())) <<
"\n";
206 kdDebug(DBG_AREA_MATH) <<
"High: " << TQString(TQString().setNum(c.getHighest())) <<
"\n";
207 kdDebug(DBG_AREA_MATH) <<
"Low: " << TQString(TQString().setNum(c.getLowest())) <<
"\n";
208 kdDebug(DBG_AREA_MATH) <<
"Mean: " << TQString(m_producer->positionToString(c.getMean())) <<
"\n";
209 kdDebug(DBG_AREA_MATH) <<
"Total: " << TQString(TQString().setNum(c.getTotal())) <<
"\n";
214 kdDebug(DBG_AREA_MATH) <<
"\n";
A colorspace is the definition of a certain color model in Chalk.
Class that stores the result of histogram calculations.
Calculations selectionCalculations()
The information on the current selection for the current channel.
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.
TQ_UINT8 * rawData() const
returns a pointer to the pixel data. Do NOT interpret the data - leave that to a colorstrategy
bool isDone() const
returns true when iterators has reached the end