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

#include <KisDitherUtil.h>

Public Types

enum  PatternValueMode { Auto , Lightness , Alpha }
 
enum  ThresholdMode { Pattern , Noise }
 

Public Member Functions

 KisDitherUtil ()
 
void setConfiguration (const KisFilterConfiguration &config, const QString &prefix="")
 
qreal threshold (const QPoint &pos)
 

Private Member Functions

void setNoiseSeed (const quint64 &noiseSeed)
 
void setPattern (const QString &md5sum, const QString &patternName, const PatternValueMode valueMode, KisResourcesInterfaceSP resourcesInterface)
 
void setSpread (const qreal &spread)
 
void setThresholdMode (const ThresholdMode thresholdMode)
 

Private Attributes

quint64 m_noiseSeed
 
KoPatternSP m_pattern
 
bool m_patternUseAlpha
 
PatternValueMode m_patternValueMode
 
qreal m_spread
 
ThresholdMode m_thresholdMode
 

Detailed Description

Definition at line 20 of file KisDitherUtil.h.

Member Enumeration Documentation

◆ PatternValueMode

Enumerator
Auto 
Lightness 
Alpha 

Definition at line 27 of file KisDitherUtil.h.

◆ ThresholdMode

Enumerator
Pattern 
Noise 

Definition at line 23 of file KisDitherUtil.h.

23 {
24 Pattern,
25 Noise
26 };

Constructor & Destructor Documentation

◆ KisDitherUtil()

KisDitherUtil::KisDitherUtil ( )

Definition at line 15 of file KisDitherUtil.cpp.

Member Function Documentation

◆ setConfiguration()

void KisDitherUtil::setConfiguration ( const KisFilterConfiguration & config,
const QString & prefix = "" )

Definition at line 85 of file KisDitherUtil.cpp.

86{
87 setThresholdMode(ThresholdMode(config.getInt(prefix + "thresholdMode")));
88 setPattern(config.getString(prefix + "md5sum"), config.getString(prefix + "pattern"), PatternValueMode(config.getInt(prefix + "patternValueMode")), config.resourcesInterface());
89 setNoiseSeed(quint64(config.getInt(prefix + "noiseSeed")));
90 setSpread(config.getDouble(prefix + "spread"));
91}
void setPattern(const QString &md5sum, const QString &patternName, const PatternValueMode valueMode, KisResourcesInterfaceSP resourcesInterface)
void setNoiseSeed(const quint64 &noiseSeed)
void setSpread(const qreal &spread)
void setThresholdMode(const ThresholdMode thresholdMode)
KisResourcesInterfaceSP resourcesInterface
QString getString(const QString &name, const QString &def=QString()) const
int getInt(const QString &name, int def=0) const
double getDouble(const QString &name, double def=0.0) const

References KisPropertiesConfiguration::getDouble(), KisPropertiesConfiguration::getInt(), KisPropertiesConfiguration::getString(), KisFilterConfiguration::resourcesInterface, setNoiseSeed(), setPattern(), setSpread(), and setThresholdMode().

◆ setNoiseSeed()

void KisDitherUtil::setNoiseSeed ( const quint64 & noiseSeed)
private

Definition at line 58 of file KisDitherUtil.cpp.

59{
60 m_noiseSeed = noiseSeed;
61}

References m_noiseSeed.

◆ setPattern()

void KisDitherUtil::setPattern ( const QString & md5sum,
const QString & patternName,
const PatternValueMode valueMode,
KisResourcesInterfaceSP resourcesInterface )
private

Definition at line 26 of file KisDitherUtil.cpp.

27{
28 m_patternValueMode = valueMode;
29
30 auto source = resourcesInterface->source<KoPattern>(ResourceType::Patterns);
31 m_pattern = source.bestMatch(md5sum, "", patternName);
32
34 // Automatically pick between lightness-based and alpha-based patterns by whichever has maximum range
35
36 // FIXME QT6: remove after we derecate Qt5 (and use float all the time)
37 using float_type = decltype(std::declval<QColor>().alphaF());
38
39 float_type lightnessMin = 1.0, lightnessMax = 0.0;
40 float_type alphaMin = 1.0, alphaMax = 0.0;
41 const QImage &image = m_pattern->pattern();
42 for (int y = 0; y < image.height(); ++y) {
43 for (int x = 0; x < image.width(); ++x) {
44 const QColor pixel = image.pixelColor(x, y);
45 lightnessMin = std::min(lightnessMin, pixel.lightnessF());
46 lightnessMax = std::max(lightnessMax, pixel.lightnessF());
47 alphaMin = std::min(alphaMin, pixel.alphaF());
48 alphaMax = std::max(alphaMax, pixel.alphaF());
49 }
50 }
51 m_patternUseAlpha = (alphaMax - alphaMin > lightnessMax - lightnessMin);
52 }
53 else {
55 }
56}
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
KoPatternSP m_pattern
Write API docs here.
Definition KoPattern.h:21
const QString Patterns

References Alpha, Auto, m_pattern, m_patternUseAlpha, m_patternValueMode, m_thresholdMode, Pattern, ResourceType::Patterns, and source().

◆ setSpread()

void KisDitherUtil::setSpread ( const qreal & spread)
private

Definition at line 63 of file KisDitherUtil.cpp.

64{
65 m_spread = spread;
66}

References m_spread.

◆ setThresholdMode()

void KisDitherUtil::setThresholdMode ( const ThresholdMode thresholdMode)
private

Definition at line 21 of file KisDitherUtil.cpp.

22{
23 m_thresholdMode = thresholdMode;
24}

References m_thresholdMode.

◆ threshold()

qreal KisDitherUtil::threshold ( const QPoint & pos)

Definition at line 68 of file KisDitherUtil.cpp.

69{
70 qreal threshold;
72 const QImage &image = m_pattern->pattern();
73 const QColor color = image.pixelColor(pos.x() % image.width(), pos.y() % image.height());
74 threshold = (m_patternUseAlpha ? color.alphaF() : color.lightnessF());
75 }
78 threshold = random.doubleRandomAt(pos.x(), pos.y());
79 }
80 else threshold = 0.5;
81
82 return 0.5 - (m_spread / 2.0) + threshold * m_spread;
83}
qreal threshold(const QPoint &pos)

References m_noiseSeed, m_pattern, m_patternUseAlpha, m_spread, m_thresholdMode, Noise, Pattern, and threshold().

Member Data Documentation

◆ m_noiseSeed

quint64 KisDitherUtil::m_noiseSeed
private

Definition at line 49 of file KisDitherUtil.h.

◆ m_pattern

KoPatternSP KisDitherUtil::m_pattern
private

Definition at line 48 of file KisDitherUtil.h.

◆ m_patternUseAlpha

bool KisDitherUtil::m_patternUseAlpha
private

Definition at line 50 of file KisDitherUtil.h.

◆ m_patternValueMode

PatternValueMode KisDitherUtil::m_patternValueMode
private

Definition at line 47 of file KisDitherUtil.h.

◆ m_spread

qreal KisDitherUtil::m_spread
private

Definition at line 51 of file KisDitherUtil.h.

◆ m_thresholdMode

ThresholdMode KisDitherUtil::m_thresholdMode
private

Definition at line 46 of file KisDitherUtil.h.


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