Changeset View
Changeset View
Standalone View
Standalone View
plugins/filters/guassianhighpass/guassianhighpass_filter.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * This file is part of Krita | ||||
3 | * | ||||
4 | * Copyright (c) 2019 Miguel Lopez <reptillia39@live.com> | ||||
5 | * | ||||
6 | * This program is free software; you can redistribute it and/or modify | ||||
7 | * it under the terms of the GNU General Public License as published by | ||||
8 | * the Free Software Foundation; either version 2 of the License, or | ||||
9 | * (at your option) any later version. | ||||
10 | * | ||||
11 | * This program is distributed in the hope that it will be useful, | ||||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
14 | * GNU General Public License for more details. | ||||
15 | * | ||||
16 | * You should have received a copy of the GNU General Public License | ||||
17 | * 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 | | ||||
21 | #include <compositeops/KoVcMultiArchBuildSupport.h> //MSVC requires that Vc come first | ||||
22 | #include "guassianhighpass_filter.h" | ||||
23 | #include <QBitArray> | ||||
24 | | ||||
25 | #include <kis_mask_generator.h> | ||||
26 | #include <kis_convolution_kernel.h> | ||||
27 | #include <kis_convolution_painter.h> | ||||
28 | #include <kis_gaussian_kernel.h> | ||||
29 | #include <filter/kis_filter_category_ids.h> | ||||
30 | #include <filter/kis_filter_configuration.h> | ||||
31 | #include <kis_processing_information.h> | ||||
32 | #include <KoProgressUpdater.h> | ||||
33 | #include <KoUpdater.h> | ||||
34 | #include <KoConvolutionOp.h> | ||||
35 | #include <KoMixColorsOp.h> | ||||
36 | #include <kis_paint_device.h> | ||||
37 | #include "kis_lod_transform.h" | ||||
38 | | ||||
39 | #include "wdg_guassianhighpass.h" | ||||
40 | #include "ui_wdgguassianhighpass.h" | ||||
41 | #include "KoColorSpaceTraits.h" | ||||
42 | #include <KisSequentialIteratorProgress.h> | ||||
43 | | ||||
44 | | ||||
45 | KisGuassianHighPassFilter::KisGuassianHighPassFilter() : KisFilter(id(), FiltersCategoryEdgeDetectionId, i18n("&Guassian High Pass...")) | ||||
46 | { | ||||
47 | setSupportsPainting(true); | ||||
48 | setSupportsAdjustmentLayers(true); | ||||
49 | setSupportsThreading(true); | ||||
50 | setSupportsLevelOfDetail(false); | ||||
51 | setColorSpaceIndependence(FULLY_INDEPENDENT); | ||||
52 | } | ||||
53 | | ||||
54 | KisConfigWidget * KisGuassianHighPassFilter::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP) const | ||||
55 | { | ||||
56 | return new KisWdgGuassianHighPass(parent); | ||||
57 | } | ||||
58 | | ||||
59 | KisFilterConfigurationSP KisGuassianHighPassFilter::factoryConfiguration() const | ||||
60 | { | ||||
61 | KisFilterConfigurationSP config = new KisFilterConfiguration(id().id(), 1); | ||||
62 | config->setProperty("blurAmount", 1); | ||||
63 | return config; | ||||
64 | } | ||||
65 | | ||||
66 | void KisGuassianHighPassFilter::processImpl(KisPaintDeviceSP device, | ||||
67 | const QRect& applyRect, | ||||
68 | const KisFilterConfigurationSP _config, | ||||
69 | KoUpdater* progressUpdater | ||||
70 | ) const | ||||
71 | { | ||||
72 | | ||||
73 | QPointer<KoUpdater> filterUpdater = 0; | ||||
74 | QPointer<KoUpdater> convolutionUpdater = 0; | ||||
75 | QScopedPointer<KoProgressUpdater> updater; | ||||
76 | | ||||
77 | if (progressUpdater) { | ||||
78 | updater.reset(new KoProgressUpdater(progressUpdater)); | ||||
79 | updater->start(100, i18n("Guassian High Pass")); | ||||
80 | // Two sub-sub tasks that each go from 0 to 100. | ||||
81 | convolutionUpdater = updater->startSubtask(); | ||||
82 | filterUpdater = updater->startSubtask(); | ||||
83 | } | ||||
84 | | ||||
85 | KisFilterConfigurationSP config = _config ? _config : new KisFilterConfiguration(id().id(), 1); | ||||
86 | | ||||
87 | QVariant value; | ||||
88 | | ||||
89 | KisLodTransformScalar t(device); | ||||
90 | | ||||
91 | const qreal blurAmount = t.scale(config->getProperty("blurAmount", value) ? value.toDouble() : 1.0); | ||||
92 | | ||||
93 | QBitArray channelFlags = config->channelFlags(); | ||||
94 | KisGaussianKernel::applyGaussian(device, applyRect, | ||||
95 | blurAmount, blurAmount, | ||||
96 | channelFlags, | ||||
97 | convolutionUpdater); | ||||
98 | | ||||
99 | qreal weights[2]; | ||||
100 | qreal factor = 128; | ||||
101 | | ||||
102 | weights[0] = -factor; | ||||
103 | weights[1] = 128; | ||||
104 | | ||||
105 | { | ||||
106 | processRaw(device, applyRect, weights, factor, channelFlags, filterUpdater); | ||||
107 | } | ||||
108 | } | ||||
109 | | ||||
110 | void KisGuassianHighPassFilter::processRaw(KisPaintDeviceSP device, | ||||
111 | const QRect &rect, | ||||
112 | qreal weights[2], | ||||
113 | qreal factor, | ||||
114 | const QBitArray &channelFlags, | ||||
115 | KoUpdater *progressUpdater) const | ||||
116 | { | ||||
117 | const KoColorSpace *cs = device->colorSpace(); | ||||
118 | const int pixelSize = cs->pixelSize(); | ||||
119 | KoConvolutionOp * convolutionOp = cs->convolutionOp(); | ||||
120 | KoColorTransformation * createInvertTransformation = cs->createInvertTransformation(); | ||||
121 | KoMixColorsOp * mixColorsOp = cs->mixColorsOp(); | ||||
122 | | ||||
123 | quint8 *colors[2]; | ||||
124 | colors[0] = new quint8[pixelSize]; | ||||
125 | colors[1] = new quint8[pixelSize]; | ||||
126 | | ||||
127 | KisSequentialIteratorProgress dstIt(device, rect, progressUpdater); | ||||
128 | | ||||
129 | while (dstIt.nextPixel()) { | ||||
130 | { | ||||
131 | memcpy(colors[0], dstIt.oldRawData(), pixelSize); | ||||
132 | memcpy(colors[1], dstIt.rawDataConst(), pixelSize); | ||||
133 | convolutionOp->convolveColors(colors, weights, dstIt.rawData(), factor, 0, 2, channelFlags); | ||||
134 | createInvertTransformation->transform(dstIt.rawDataConst(), dstIt.rawData(),1); | ||||
135 | } | ||||
136 | } | ||||
137 | | ||||
138 | delete[] colors[0]; | ||||
139 | delete[] colors[1]; | ||||
140 | } | ||||
141 | | ||||
142 | QRect KisGuassianHighPassFilter::neededRect(const QRect & rect, const KisFilterConfigurationSP config, int lod) const | ||||
143 | { | ||||
144 | KisLodTransformScalar t(lod); | ||||
145 | | ||||
146 | QVariant value; | ||||
147 | const qreal blurAmount = t.scale(config->getProperty("blurAmount", value) ? value.toDouble() : 1.0); | ||||
148 | | ||||
149 | return rect.adjusted(-blurAmount * 2, -blurAmount * 2, blurAmount * 2, blurAmount * 2); | ||||
150 | } | ||||
151 | | ||||
152 | QRect KisGuassianHighPassFilter::changedRect(const QRect & rect, const KisFilterConfigurationSP config, int lod) const | ||||
153 | { | ||||
154 | KisLodTransformScalar t(lod); | ||||
155 | | ||||
156 | QVariant value; | ||||
157 | const qreal blurAmount = t.scale(config->getProperty("blurAmount", value) ? value.toDouble() : 1.0); | ||||
158 | | ||||
159 | return rect.adjusted( -blurAmount, -blurAmount, blurAmount, blurAmount); | ||||
160 | } |