convolutionfilters.cpp 5.75 KB
Newer Older
1 2 3 4 5
/*
 * This file is part of the KDE project
 *
 * Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
 *
6 7 8 9
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
10
 *
11 12 13 14
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
15
 *
16 17
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 20
 */

Boudewijn Rempt's avatar
Boudewijn Rempt committed
21 22
#include "convolutionfilters.h"

23 24
#include <stdlib.h>

25
#include <klocalizedstring.h>
26

27
#include <kpluginfactory.h>
28

29
#include <kis_convolution_kernel.h>
30
#include <kis_convolution_painter.h>
Boudewijn Rempt's avatar
Boudewijn Rempt committed
31

32
#include <filter/kis_filter_category_ids.h>
33
#include <filter/kis_filter_configuration.h>
34 35
#include <kis_selection.h>
#include <kis_paint_device.h>
36
#include <kis_processing_information.h>
37

38 39
#include <Eigen/Core>

40
K_PLUGIN_FACTORY_WITH_JSON(KritaConvolutionFiltersFactory, "kritaconvolutionfilters.json", registerPlugin<KritaConvolutionFilters>();)
41

42
KritaConvolutionFilters::KritaConvolutionFilters(QObject *parent, const QVariantList &)
43
        : QObject(parent)
44
{
45 46 47 48 49 50 51 52
    KisFilterRegistry * manager = KisFilterRegistry::instance();
    manager->add(new KisSharpenFilter());
    manager->add(new KisMeanRemovalFilter());
    manager->add(new KisEmbossLaplascianFilter());
    manager->add(new KisEmbossInAllDirectionsFilter());
    manager->add(new KisEmbossHorizontalVerticalFilter());
    manager->add(new KisEmbossVerticalFilter());
    manager->add(new KisEmbossHorizontalFilter());
53 54 55 56 57 58
}

KritaConvolutionFilters::~KritaConvolutionFilters()
{
}

59
KisSharpenFilter::KisSharpenFilter()
60
        : KisConvolutionFilter(id(), FiltersCategoryEnhanceId, i18n("&Sharpen"))
61
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
62
    setSupportsPainting(true);
63
    setShowConfigurationWidget(false);
64

65
    Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
66 67 68 69 70
    kernelMatrix <<  0, -2,   0,
                    -2,  11, -2,
                     0, -2,   0;

    m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0, 3);
71 72
}

73
KisMeanRemovalFilter::KisMeanRemovalFilter()
74
        : KisConvolutionFilter(id(), FiltersCategoryEnhanceId, i18n("&Mean Removal"))
75
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
76
    setSupportsPainting(false);
77
    setShowConfigurationWidget(false);
78

79
    Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
80 81 82 83 84
    kernelMatrix << -1, -1, -1,
                    -1,  9, -1,
                    -1, -1, -1;

    m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0, 1);
85 86
}

87
KisEmbossLaplascianFilter::KisEmbossLaplascianFilter()
88
        : KisConvolutionFilter(id(), FiltersCategoryEmbossId, i18n("Emboss (Laplacian)"))
89
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
90
    setSupportsPainting(false);
91
    setShowConfigurationWidget(false);
92

93
    Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
94 95 96 97
    kernelMatrix << -1, 0, -1,
                     0, 4,  0,
                    -1, 0, -1;

98 99
    m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0.5, 1);
    setIgnoreAlpha(true);
100 101
}

102
KisEmbossInAllDirectionsFilter::KisEmbossInAllDirectionsFilter()
103
        : KisConvolutionFilter(id(), FiltersCategoryEmbossId, i18n("Emboss in All Directions"))
104
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
105
    setSupportsPainting(false);
106
    setShowConfigurationWidget(false);
107

108
    Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
109 110 111 112
    kernelMatrix << -1, -1, -1,
                    -1,  8, -1,
                    -1, -1, -1;

113 114
    m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0.5, 1);
    setIgnoreAlpha(true);
115 116
}

117
KisEmbossHorizontalVerticalFilter::KisEmbossHorizontalVerticalFilter()
118
        : KisConvolutionFilter(id(), FiltersCategoryEmbossId, i18n("Emboss Horizontal && Vertical"))
119
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
120
    setSupportsPainting(false);
121
    setShowConfigurationWidget(false);
122

123
    Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
124 125 126 127
    kernelMatrix <<  0, -1,  0,
                    -1,  4, -1,
                     0, -1,  0;

128 129
    m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0.5, 1);
    setIgnoreAlpha(true);
130 131
}

132
KisEmbossVerticalFilter::KisEmbossVerticalFilter()
133
        : KisConvolutionFilter(id(), FiltersCategoryEmbossId, i18n("Emboss Vertical Only"))
134
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
135
    setSupportsPainting(false);
136
    setShowConfigurationWidget(false);
137

138
    Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
139 140 141 142
    kernelMatrix << 0, -1, 0,
                    0,  2, 0,
                    0, -1, 0;

143 144
    m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0.5, 1);
    setIgnoreAlpha(true);
145 146
}

147
KisEmbossHorizontalFilter::KisEmbossHorizontalFilter() :
148
        KisConvolutionFilter(id(), FiltersCategoryEmbossId, i18n("Emboss Horizontal Only"))
149
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
150
    setSupportsPainting(false);
151
    setShowConfigurationWidget(false);
152

153
    Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
154
    kernelMatrix <<  0, 0,  0,
155
                    -1, 2, -1,
156 157
                     0, 0,  0;

158 159
    m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0.5, 1);
    setIgnoreAlpha(true);
160 161
}

162
KisEmbossDiagonalFilter::KisEmbossDiagonalFilter()
163
        : KisConvolutionFilter(id(), FiltersCategoryEdgeDetectionId, i18n("Top Edge Detection"))
164
{
Boudewijn Rempt's avatar
Boudewijn Rempt committed
165
    setSupportsPainting(false);
166
    setShowConfigurationWidget(false);
167

168
    Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
169 170 171 172
    kernelMatrix << -1, 0, -1,
                     0, 4,  0,
                    -1, 0, -1;

173 174
    m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0.5, 1);
    setIgnoreAlpha(true);
175 176
}

177
#include "convolutionfilters.moc"