File indexing completed on 2025-01-26 04:10:37

0001 /*
0002  * This file is part of the KDE project
0003  *
0004  * SPDX-FileCopyrightText: 2004 Cyrille Berger <cberger@cberger.net>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #include "convolutionfilters.h"
0010 
0011 #include <stdlib.h>
0012 
0013 #include <klocalizedstring.h>
0014 
0015 #include <kpluginfactory.h>
0016 
0017 #include <kis_convolution_kernel.h>
0018 #include <kis_convolution_painter.h>
0019 
0020 #include <filter/kis_filter_category_ids.h>
0021 #include <filter/kis_filter_configuration.h>
0022 #include <kis_selection.h>
0023 #include <kis_paint_device.h>
0024 #include <kis_processing_information.h>
0025 
0026 #include <Eigen/Core>
0027 
0028 K_PLUGIN_FACTORY_WITH_JSON(KritaConvolutionFiltersFactory, "kritaconvolutionfilters.json", registerPlugin<KritaConvolutionFilters>();)
0029 
0030 KritaConvolutionFilters::KritaConvolutionFilters(QObject *parent, const QVariantList &)
0031         : QObject(parent)
0032 {
0033     KisFilterRegistry * manager = KisFilterRegistry::instance();
0034     manager->add(new KisSharpenFilter());
0035     manager->add(new KisMeanRemovalFilter());
0036     manager->add(new KisEmbossLaplascianFilter());
0037     manager->add(new KisEmbossInAllDirectionsFilter());
0038     manager->add(new KisEmbossHorizontalVerticalFilter());
0039     manager->add(new KisEmbossVerticalFilter());
0040     manager->add(new KisEmbossHorizontalFilter());
0041 }
0042 
0043 KritaConvolutionFilters::~KritaConvolutionFilters()
0044 {
0045 }
0046 
0047 KisSharpenFilter::KisSharpenFilter()
0048         : KisConvolutionFilter(id(), FiltersCategoryEnhanceId, i18n("&Sharpen"))
0049 {
0050     setSupportsPainting(true);
0051     setShowConfigurationWidget(false);
0052 
0053     Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
0054     kernelMatrix <<  0, -2,   0,
0055                     -2,  11, -2,
0056                      0, -2,   0;
0057 
0058     m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0, 3);
0059 }
0060 
0061 KisMeanRemovalFilter::KisMeanRemovalFilter()
0062         : KisConvolutionFilter(id(), FiltersCategoryEnhanceId, i18n("&Mean Removal"))
0063 {
0064     setSupportsPainting(false);
0065     setShowConfigurationWidget(false);
0066 
0067     Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
0068     kernelMatrix << -1, -1, -1,
0069                     -1,  9, -1,
0070                     -1, -1, -1;
0071 
0072     m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0, 1);
0073 }
0074 
0075 KisEmbossLaplascianFilter::KisEmbossLaplascianFilter()
0076         : KisConvolutionFilter(id(), FiltersCategoryEmbossId, i18n("Emboss (Laplacian)"))
0077 {
0078     setSupportsPainting(false);
0079     setShowConfigurationWidget(false);
0080 
0081     Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
0082     kernelMatrix << -1, 0, -1,
0083                      0, 4,  0,
0084                     -1, 0, -1;
0085 
0086     m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0.5, 1);
0087     setIgnoreAlpha(true);
0088 }
0089 
0090 KisEmbossInAllDirectionsFilter::KisEmbossInAllDirectionsFilter()
0091         : KisConvolutionFilter(id(), FiltersCategoryEmbossId, i18n("Emboss in All Directions"))
0092 {
0093     setSupportsPainting(false);
0094     setShowConfigurationWidget(false);
0095 
0096     Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
0097     kernelMatrix << -1, -1, -1,
0098                     -1,  8, -1,
0099                     -1, -1, -1;
0100 
0101     m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0.5, 1);
0102     setIgnoreAlpha(true);
0103 }
0104 
0105 KisEmbossHorizontalVerticalFilter::KisEmbossHorizontalVerticalFilter()
0106         : KisConvolutionFilter(id(), FiltersCategoryEmbossId, i18n("Emboss Horizontal && Vertical"))
0107 {
0108     setSupportsPainting(false);
0109     setShowConfigurationWidget(false);
0110 
0111     Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
0112     kernelMatrix <<  0, -1,  0,
0113                     -1,  4, -1,
0114                      0, -1,  0;
0115 
0116     m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0.5, 1);
0117     setIgnoreAlpha(true);
0118 }
0119 
0120 KisEmbossVerticalFilter::KisEmbossVerticalFilter()
0121         : KisConvolutionFilter(id(), FiltersCategoryEmbossId, i18n("Emboss Vertical Only"))
0122 {
0123     setSupportsPainting(false);
0124     setShowConfigurationWidget(false);
0125 
0126     Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
0127     kernelMatrix << 0, -1, 0,
0128                     0,  2, 0,
0129                     0, -1, 0;
0130 
0131     m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0.5, 1);
0132     setIgnoreAlpha(true);
0133 }
0134 
0135 KisEmbossHorizontalFilter::KisEmbossHorizontalFilter() :
0136         KisConvolutionFilter(id(), FiltersCategoryEmbossId, i18n("Emboss Horizontal Only"))
0137 {
0138     setSupportsPainting(false);
0139     setShowConfigurationWidget(false);
0140 
0141     Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
0142     kernelMatrix <<  0, 0,  0,
0143                     -1, 2, -1,
0144                      0, 0,  0;
0145 
0146     m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0.5, 1);
0147     setIgnoreAlpha(true);
0148 }
0149 
0150 KisEmbossDiagonalFilter::KisEmbossDiagonalFilter()
0151         : KisConvolutionFilter(id(), FiltersCategoryEdgeDetectionId, i18n("Top Edge Detection"))
0152 {
0153     setSupportsPainting(false);
0154     setShowConfigurationWidget(false);
0155 
0156     Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> kernelMatrix(3, 3);
0157     kernelMatrix << -1, 0, -1,
0158                      0, 4,  0,
0159                     -1, 0, -1;
0160 
0161     m_matrix = KisConvolutionKernel::fromMatrix(kernelMatrix, 0.5, 1);
0162     setIgnoreAlpha(true);
0163 }
0164 
0165 #include "convolutionfilters.moc"