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

A class that can render different KisHistograms. It renders a somewhat smooth shape (with different colors for rgb, cmyk and xyz channels). It can also render the different channels of a colorspace overlapped. More...

#include <KisHistogramPainter.h>

Classes

class  Private
 

Public Member Functions

QList< int > availableChannels () const
 Get a list containing all the indices of the channels that were setup using the "setup" function.
 
const QVector< int > & channels () const
 Get the list of channels that are currently activated (the only ones that will be painted)
 
QColor defaultColor () const
 Returns the color that is being used to paint a generic histogram. All the histogram channels will use this color with the exception of the red, green and blue channels in a rgba histogram; the cyan, magenta, yellow and black channels in a cmyka histogram; and the x, y, and z channels in a xyz histogram.
 
bool isLogarithmic () const
 Returns true if the histogram shape being painted is formed by the logarithmic mapping of the original histogram values instead of the values themselves.
 
 KisHistogramPainter ()
 
QImage paint (const QSize &imageSize)
 Returns a RGBA image of size "imageSize" with the result of rendering the selected histogram channels on it.
 
QImage paint (int w, int h)
 Returns a RGBA image of size "w"x"h" with the result of rendering the selected histogram channels on it.
 
void paint (QPainter &painter, const QRect &rect)
 Paints the selected histogram channels in the given rect using the given painter.
 
qreal scale () const
 Return the vertical scale that is used to paint the histogram shape. A scale of 1 will paint all the histogram in the given rect. Scales less that 1 are not allowed.
 
void setChannel (int channel)
 Set currently active channel (the one that will be painted)
 
void setChannels (const QVector< int > &channels)
 Set currently active channels (the ones that will be painted)
 
void setDefaultColor (const QColor &newDefaultColor)
 Set the default color used when there is no preference to color the selected histogram channel.
 
void setLogarithmic (bool logarithmic)
 Set if the histogram shape being shown is formed by the logarithmic mapping of the original histogram values instead of the values themselves.
 
void setScale (qreal newScale)
 Set the scale used to paint the histograms.
 
void setScaleToCutLongPeaks ()
 Sometimes there can be some outliers in the histogram that show in the painted shape as long vertical peaks. Since a scale of 1 will show all the histogram, this can make its interesting parts too small to take any valuable information from them. This function will try to come up with a scale value that favors those interesting parts over the long peaks, which will be pushed and will look cut.
 
void setScaleToFit ()
 Set the scale used to paint the histograms to 1.
 
void setup (KisHistogram *histogram, const KoColorSpace *colorSpace, QVector< int > channels={})
 Sets up the painter by passing a KisHistogram, the color space for the histogram and the channels that must be set up for it.
 
int totalNumberOfAvailableChannels () const
 Get the number of channels that are being used. It can be less than the total number of channels in the KisHistogram. This can be set by using the setup function.
 
 ~KisHistogramPainter ()
 

Private Attributes

QScopedPointer< Privatem_d
 

Detailed Description

A class that can render different KisHistograms. It renders a somewhat smooth shape (with different colors for rgb, cmyk and xyz channels). It can also render the different channels of a colorspace overlapped.

Definition at line 27 of file KisHistogramPainter.h.

Constructor & Destructor Documentation

◆ KisHistogramPainter()

KisHistogramPainter::KisHistogramPainter ( )

Definition at line 289 of file KisHistogramPainter.cpp.

290 : m_d(new Private)
291{
292 m_d->defaultColor = Qt::gray;
293}
QScopedPointer< Private > m_d

References m_d.

◆ ~KisHistogramPainter()

KisHistogramPainter::~KisHistogramPainter ( )

Definition at line 295 of file KisHistogramPainter.cpp.

296{}

Member Function Documentation

◆ availableChannels()

QList< int > KisHistogramPainter::availableChannels ( ) const

Get a list containing all the indices of the channels that were setup using the "setup" function.

See also
setup

Definition at line 366 of file KisHistogramPainter.cpp.

367{
368 return m_d->histogramChannelShapeInfo.keys();
369}

References m_d.

◆ channels()

const QVector< int > & KisHistogramPainter::channels ( ) const

Get the list of channels that are currently activated (the only ones that will be painted)

See also
setChannel
setChannels

Definition at line 371 of file KisHistogramPainter.cpp.

372{
373 return m_d->channelsToPaint;
374}

References m_d.

◆ defaultColor()

QColor KisHistogramPainter::defaultColor ( ) const

Returns the color that is being used to paint a generic histogram. All the histogram channels will use this color with the exception of the red, green and blue channels in a rgba histogram; the cyan, magenta, yellow and black channels in a cmyka histogram; and the x, y, and z channels in a xyz histogram.

See also
setDefaultColor

Definition at line 386 of file KisHistogramPainter.cpp.

387{
388 return m_d->defaultColor;
389}

References m_d.

◆ isLogarithmic()

bool KisHistogramPainter::isLogarithmic ( ) const

Returns true if the histogram shape being painted is formed by the logarithmic mapping of the original histogram values instead of the values themselves.

See also
setLogarithmic

Definition at line 444 of file KisHistogramPainter.cpp.

445{
446 return m_d->isLogarithmic;
447}

References m_d.

◆ paint() [1/3]

QImage KisHistogramPainter::paint ( const QSize & imageSize)

Returns a RGBA image of size "imageSize" with the result of rendering the selected histogram channels on it.

Definition at line 345 of file KisHistogramPainter.cpp.

346{
347 return m_d->paintChannels(imageSize, m_d->channelsToPaint, m_d->isLogarithmic);
348}

References m_d.

◆ paint() [2/3]

QImage KisHistogramPainter::paint ( int w,
int h )

Returns a RGBA image of size "w"x"h" with the result of rendering the selected histogram channels on it.

Definition at line 350 of file KisHistogramPainter.cpp.

351{
352 return paint(QSize(w, h));
353}
QImage paint(const QSize &imageSize)
Returns a RGBA image of size "imageSize" with the result of rendering the selected histogram channels...

References paint().

◆ paint() [3/3]

void KisHistogramPainter::paint ( QPainter & painter,
const QRect & rect )

Paints the selected histogram channels in the given rect using the given painter.

Definition at line 355 of file KisHistogramPainter.cpp.

356{
357 const QImage image = m_d->paintChannels(rect.size(), m_d->channelsToPaint, m_d->isLogarithmic);
358 painter.drawImage(rect.topLeft(), image);
359}

References m_d.

◆ scale()

qreal KisHistogramPainter::scale ( ) const

Return the vertical scale that is used to paint the histogram shape. A scale of 1 will paint all the histogram in the given rect. Scales less that 1 are not allowed.

See also
setScale
setScaleToFit
setScaleToCutLongPeaks

Definition at line 396 of file KisHistogramPainter.cpp.

397{
398 return m_d->scale;
399}

References m_d.

◆ setChannel()

void KisHistogramPainter::setChannel ( int channel)

Set currently active channel (the one that will be painted)

See also
channels
setChannels

Definition at line 376 of file KisHistogramPainter.cpp.

377{
378 setChannels({channel});
379}
void setChannels(const QVector< int > &channels)
Set currently active channels (the ones that will be painted)

References setChannels().

◆ setChannels()

void KisHistogramPainter::setChannels ( const QVector< int > & channels)

Set currently active channels (the ones that will be painted)

See also
channels
setChannel

Definition at line 381 of file KisHistogramPainter.cpp.

382{
383 m_d->channelsToPaint = channels;
384}
const QVector< int > & channels() const
Get the list of channels that are currently activated (the only ones that will be painted)

References channels(), and m_d.

◆ setDefaultColor()

void KisHistogramPainter::setDefaultColor ( const QColor & newDefaultColor)

Set the default color used when there is no preference to color the selected histogram channel.

See also
defaultColor

Definition at line 391 of file KisHistogramPainter.cpp.

392{
393 m_d->defaultColor = newDefaultColor;
394}

References m_d.

◆ setLogarithmic()

void KisHistogramPainter::setLogarithmic ( bool logarithmic)

Set if the histogram shape being shown is formed by the logarithmic mapping of the original histogram values instead of the values themselves.

See also
isLogarithmic

Definition at line 449 of file KisHistogramPainter.cpp.

450{
451 m_d->isLogarithmic = logarithmic;
452}

References m_d.

◆ setScale()

void KisHistogramPainter::setScale ( qreal newScale)

Set the scale used to paint the histograms.

See also
scale
setScaleToFit
setScaleToCutLongPeaks

Definition at line 401 of file KisHistogramPainter.cpp.

402{
403 m_d->scale = newScale;
404}

References m_d.

◆ setScaleToCutLongPeaks()

void KisHistogramPainter::setScaleToCutLongPeaks ( )

Sometimes there can be some outliers in the histogram that show in the painted shape as long vertical peaks. Since a scale of 1 will show all the histogram, this can make its interesting parts too small to take any valuable information from them. This function will try to come up with a scale value that favors those interesting parts over the long peaks, which will be pushed and will look cut.

See also
scale
setScale
setScaleToFit

Definition at line 411 of file KisHistogramPainter.cpp.

412{
413 qreal overallHighest = 0.0;
414 qreal fittedChannelHighest = 0.0;
415 qreal bestCutOffHeight = 0.0;
416 for (int channel : m_d->channelsToPaint) {
417 if (!m_d->histogramChannelShapeInfo.contains(channel)) {
418 continue;
419 }
420
421 const qreal channelBestCutOffHeight =
423 ? m_d->histogramChannelShapeInfo[channel].logarithmicBestCutOffHeight
424 : m_d->histogramChannelShapeInfo[channel].linearBestCutOffHeight;
425 const qreal channelHighest = static_cast<qreal>(m_d->histogramChannelShapeInfo[channel].highest);
426
427 if (channelBestCutOffHeight * channelHighest > bestCutOffHeight * fittedChannelHighest) {
428 bestCutOffHeight = channelBestCutOffHeight;
429 fittedChannelHighest = channelHighest;
430 }
431
432 if (channelHighest > overallHighest) {
433 overallHighest = channelHighest;
434 }
435 }
436 const qreal overallBestCutOffHeight = bestCutOffHeight * fittedChannelHighest / overallHighest;
437 if (overallBestCutOffHeight < 0.8) {
438 setScale(1.0 / overallBestCutOffHeight);
439 } else {
440 setScale(1.0);
441 }
442}
bool isLogarithmic() const
Returns true if the histogram shape being painted is formed by the logarithmic mapping of the origina...
void setScale(qreal newScale)
Set the scale used to paint the histograms.

References isLogarithmic(), m_d, and setScale().

◆ setScaleToFit()

void KisHistogramPainter::setScaleToFit ( )

Set the scale used to paint the histograms to 1.

See also
scale
setScale
setScaleToCutLongPeaks

Definition at line 406 of file KisHistogramPainter.cpp.

407{
408 setScale(1.0);
409}

References setScale().

◆ setup()

void KisHistogramPainter::setup ( KisHistogram * histogram,
const KoColorSpace * colorSpace,
QVector< int > channels = {} )

Sets up the painter by passing a KisHistogram, the color space for the histogram and the channels that must be set up for it.

Parameters
histogramA KisHistogram pointer to take the info from. The histogram pointer is not stored or owned internally, so you can safely delete it if you don't need it
colorSpacesThe color space associated with the histogram. It is used to color different channels. For example, the histogram for the red channel of a rgb histogram will be painted as a red shape
channelsA collection that contains the channel indices for the channels that must be used to compute the histogram. For example, if the histogram is a Lab histogram, and you are interested only in the lightness channel, the vector should have only one element, the number 0 (index of the lightness channel). If the collection is empty, then all the channels will be used

Definition at line 298 of file KisHistogramPainter.cpp.

299{
300 Q_ASSERT(histogram);
301 Q_ASSERT(colorSpace);
302
303 const int nChannels = static_cast<int>(colorSpace->channelCount());
304
305 if (channels.size() == 0) {
306 for (int i = 0; i < nChannels; ++i) {
307 channels.append(i);
308 }
309 }
310
311 m_d->histogramChannelShapeInfo.clear();
312
313 for (int channel : channels) {
314 if (channel < 0 || channel >= nChannels || m_d->histogramChannelShapeInfo.contains(channel)) {
315 continue;
316 }
317 histogram->setChannel(channel);
318 const quint32 highest = histogram->calculations().getHighest();
319 QPair<QPolygonF, QPolygonF> shapes = Private::computeHistogramShape(histogram, channel, highest);
320 const QPair<QColor, QPainter::CompositionMode> channelPaintingInfo =
321 Private::computeChannelPaintingInfo(colorSpace, channel);
322 const qreal linearBestCutOffHeight = Private::bestCutOffHeight(shapes.first);
323 const qreal logarithmicBestCutOffHeight = Private::bestCutOffHeight(shapes.second);
324
325 Private::smoothHistogramShape(shapes.first);
326 Private::smoothHistogramShape(shapes.second);
328 Private::simplifyHistogramShape(shapes.second);
329
330 m_d->histogramChannelShapeInfo.insert(
331 channel,
332 {
333 shapes.first,
334 shapes.second,
335 highest,
336 linearBestCutOffHeight,
337 logarithmicBestCutOffHeight,
338 channelPaintingInfo.first,
339 channelPaintingInfo.second
340 }
341 );
342 }
343}
static qreal bestCutOffHeight(QPolygonF polygon)
static void smoothHistogramShape(QPolygonF &polygon)
static QPair< QColor, QPainter::CompositionMode > computeChannelPaintingInfo(const KoColorSpace *colorSpace, int channel)
static void simplifyHistogramShape(QPolygonF &polygon)
static QPair< QPolygonF, QPolygonF > computeHistogramShape(KisHistogram *histogram, int channel, quint32 highest)
quint32 getHighest()
This function return the highest value of the histogram.
void setChannel(qint32 channel)
Calculations calculations()
virtual quint32 channelCount() const =0

References KisHistogramPainter::Private::bestCutOffHeight(), KisHistogram::calculations(), KoColorSpace::channelCount(), channels(), KisHistogramPainter::Private::computeChannelPaintingInfo(), KisHistogramPainter::Private::computeHistogramShape(), KisHistogram::Calculations::getHighest(), m_d, KisHistogram::setChannel(), KisHistogramPainter::Private::simplifyHistogramShape(), and KisHistogramPainter::Private::smoothHistogramShape().

◆ totalNumberOfAvailableChannels()

int KisHistogramPainter::totalNumberOfAvailableChannels ( ) const

Get the number of channels that are being used. It can be less than the total number of channels in the KisHistogram. This can be set by using the setup function.

See also
setup

Definition at line 361 of file KisHistogramPainter.cpp.

362{
363 return m_d->histogramChannelShapeInfo.size();
364}

References m_d.

Member Data Documentation

◆ m_d

QScopedPointer<Private> KisHistogramPainter::m_d
private

Definition at line 165 of file KisHistogramPainter.h.


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