Krita Source Code Documentation
Loading...
Searching...
No Matches
KisScreentoneGeneratorUnAlignedTemplateSampler< Template > Class Template Reference

#include <KisScreentoneGeneratorTemplateSampler.h>

Public Member Functions

 KisScreentoneGeneratorUnAlignedTemplateSampler (const Template &the_template)
 
qreal operator() (qreal x, qreal y) const
 

Private Attributes

const Template & m_template
 

Detailed Description

template<typename Template>
class KisScreentoneGeneratorUnAlignedTemplateSampler< Template >

Definition at line 51 of file KisScreentoneGeneratorTemplateSampler.h.

Constructor & Destructor Documentation

◆ KisScreentoneGeneratorUnAlignedTemplateSampler()

template<typename Template >
KisScreentoneGeneratorUnAlignedTemplateSampler< Template >::KisScreentoneGeneratorUnAlignedTemplateSampler ( const Template & the_template)
inline

Member Function Documentation

◆ operator()()

template<typename Template >
qreal KisScreentoneGeneratorUnAlignedTemplateSampler< Template >::operator() ( qreal x,
qreal y ) const
inline

Definition at line 58 of file KisScreentoneGeneratorTemplateSampler.h.

59 {
60 // Get the coordinates in screen space
61 qreal xx, yy;
62 m_template.imageToScreenTransform().map(x, y, &xx, &yy);
63 // Convert to coordinate inside the macrocell
64 xx -= std::floor(xx / m_template.macrocellSize().width()) * m_template.macrocellSize().width();
65 yy -= std::floor(yy / m_template.macrocellSize().height()) * m_template.macrocellSize().height();
66 // Get template coordinates
67 QPointF templatePoint = m_template.screenToTemplateTransform().map(QPointF(xx, yy)) +
68 m_template.originOffset();
69
70 // Bilinear interpolation
71 // Get integer coordinates of the template points to use in the interpolation
72 const int ix0 =
73 templatePoint.x() < 0.0 ? m_template.templateSize().width() - 1 :
74 (templatePoint.x() >= m_template.templateSize().width() ? 0.0 :
75 static_cast<int>(std::floor(templatePoint.x())));
76 const int iy0 =
77 templatePoint.y() < 0.0 ? m_template.templateSize().height() - 1 :
78 (templatePoint.y() >= m_template.templateSize().height() ? 0.0 :
79 static_cast<int>(std::floor(templatePoint.y())));
80 const int ix1 = ix0 == m_template.templateSize().width() - 1 ? 0 : ix0 + 1;
81 const int iy1 = iy0 == m_template.templateSize().height() - 1 ? 0 : iy0 + 1;
82 // Get the template values for the points
83 const qreal topLeftValue = m_template.templateData()[iy0 * m_template.templateSize().width() + ix0];
84 const qreal topRightValue = m_template.templateData()[iy0 * m_template.templateSize().width() + ix1];
85 const qreal bottomLeftValue = m_template.templateData()[iy1 * m_template.templateSize().width() + ix0];
86 const qreal bottomRightValue = m_template.templateData()[iy1 * m_template.templateSize().width() + ix1];
87 // Get the fractional part of the point to use in the interpolation
88 const qreal fractionalX = templatePoint.x() - std::floor(templatePoint.x());
89 const qreal fractionalY = templatePoint.y() - std::floor(templatePoint.y());
90 // Perform bilinear interpolation
91 const qreal a = topLeftValue * (1.0 - fractionalX) + topRightValue * fractionalX;
92 const qreal b = bottomLeftValue * (1.0 - fractionalX) + bottomRightValue * fractionalX;
93 const qreal c = a * (1.0 - fractionalY) + b * fractionalY;
94 // ----
95 return c;
96 }

References KisScreentoneGeneratorUnAlignedTemplateSampler< Template >::m_template.

Member Data Documentation

◆ m_template

template<typename Template >
const Template& KisScreentoneGeneratorUnAlignedTemplateSampler< Template >::m_template
private

Definition at line 99 of file KisScreentoneGeneratorTemplateSampler.h.


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