Commit d2e9a09b authored by Boudewijn Rempt's avatar Boudewijn Rempt

Fix slow posterize filter

Create the non-linear gamma transforms beforehand.

Patch by Carl Olsson, thanks!

Differential Revision: https://phabricator.kde.org/D21529
parent 3abfec8a
......@@ -68,6 +68,22 @@ KisPosterizeColorTransformation::KisPosterizeColorTransformation(int steps, cons
{
m_step = KoColorSpaceMathsTraits<quint16>::max / steps;
m_halfStep = m_step / 2;
m_fromConversion = KoColorSpaceRegistry::instance()->createColorConverter(
m_colorSpace,
KoColorSpaceRegistry::instance()->rgb16("sRGB-elle-V2-srgbtrc.icc"),
KoColorConversionTransformation::internalRenderingIntent(),
KoColorConversionTransformation::internalConversionFlags());
m_toConversion = KoColorSpaceRegistry::instance()->createColorConverter(
KoColorSpaceRegistry::instance()->rgb16("sRGB-elle-V2-srgbtrc.icc"),
m_colorSpace,
KoColorConversionTransformation::internalRenderingIntent(),
KoColorConversionTransformation::internalConversionFlags());
}
KisPosterizeColorTransformation::~KisPosterizeColorTransformation()
{
delete m_fromConversion;
delete m_toConversion;
}
KisConfigWidget* KisFilterPosterize::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, bool) const
......@@ -89,20 +105,9 @@ void KisPosterizeColorTransformation::transform(const quint8* src, quint8* dst,
{
quint16 m_rgba[4];
quint16 m_mod[4];
KoColorConversionTransformation* t =
KoColorSpaceRegistry::instance()->createColorConverter(m_colorSpace,
KoColorSpaceRegistry::instance()->rgb16("sRGB-elle-V2-srgbtrc.icc"),
KoColorConversionTransformation::internalRenderingIntent(),
KoColorConversionTransformation::internalConversionFlags());
KoColorConversionTransformation* b =
KoColorSpaceRegistry::instance()->createColorConverter(
KoColorSpaceRegistry::instance()->rgb16("sRGB-elle-V2-srgbtrc.icc"),
m_colorSpace,
KoColorConversionTransformation::internalRenderingIntent(),
KoColorConversionTransformation::internalConversionFlags());
while (nPixels--) {
t->transform(src, reinterpret_cast<quint8 *>(m_rgba), 1);
m_fromConversion->transform(src, reinterpret_cast<quint8 *>(m_rgba), 1);
m_mod[0] = m_rgba[0] % m_step;
m_mod[1] = m_rgba[1] % m_step;
......@@ -114,7 +119,7 @@ void KisPosterizeColorTransformation::transform(const quint8* src, quint8* dst,
m_rgba[2] = m_rgba[2] + (m_mod[2] > m_halfStep ? m_step - m_mod[2] : -m_mod[2]);
m_rgba[3] = m_rgba[3] + (m_mod[3] > m_halfStep ? m_step - m_mod[3] : -m_mod[3]);
b->transform(reinterpret_cast<quint8 *>(m_rgba), dst, 1);
m_toConversion->transform(reinterpret_cast<quint8 *>(m_rgba), dst, 1);
src += m_psize;
dst += m_psize;
}
......
......@@ -50,12 +50,15 @@ class KisPosterizeColorTransformation : public KoColorTransformation
{
public:
KisPosterizeColorTransformation(int steps, const KoColorSpace* cs);
~KisPosterizeColorTransformation() override;
void transform(const quint8* src, quint8* dst, qint32 nPixels) const override;
private:
const KoColorSpace* m_colorSpace;
quint32 m_psize;
quint16 m_step;
quint16 m_halfStep;
KoColorConversionTransformation* m_fromConversion;
KoColorConversionTransformation* m_toConversion;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment