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 <KoColorSpace.h> | ||||
26 | #include <KoChannelInfo.h> | ||||
27 | #include <KoColor.h> | ||||
28 | #include <kis_painter.h> | ||||
29 | #include <kis_paint_device.h> | ||||
30 | #include <kis_paint_layer.h> | ||||
31 | #include <kis_group_layer.h> | ||||
32 | #include <KoCompositeOps.h> | ||||
33 | | ||||
34 | #include <kis_mask_generator.h> | ||||
35 | #include <kis_gaussian_kernel.h> | ||||
36 | #include <filter/kis_filter_category_ids.h> | ||||
37 | #include <filter/kis_filter_configuration.h> | ||||
38 | #include <kis_processing_information.h> | ||||
39 | #include <KoProgressUpdater.h> | ||||
40 | #include <KoUpdater.h> | ||||
41 | #include <KoMixColorsOp.h> | ||||
42 | #include <kis_paint_device.h> | ||||
43 | #include "kis_lod_transform.h" | ||||
44 | | ||||
45 | #include "wdg_guassianhighpass.h" | ||||
46 | #include "ui_wdgguassianhighpass.h" | ||||
47 | #include "KoColorSpaceTraits.h" | ||||
48 | #include <KisSequentialIteratorProgress.h> | ||||
49 | | ||||
50 | | ||||
51 | KisGuassianHighPassFilter::KisGuassianHighPassFilter() : KisFilter(id(), FiltersCategoryEdgeDetectionId, i18n("&Guassian High Pass...")) | ||||
52 | { | ||||
53 | setSupportsPainting(true); | ||||
54 | setSupportsAdjustmentLayers(true); | ||||
55 | setSupportsThreading(true); | ||||
56 | setSupportsLevelOfDetail(false); | ||||
57 | setColorSpaceIndependence(FULLY_INDEPENDENT); | ||||
58 | } | ||||
59 | | ||||
60 | KisConfigWidget * KisGuassianHighPassFilter::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP) const | ||||
61 | { | ||||
62 | return new KisWdgGuassianHighPass(parent); | ||||
63 | } | ||||
64 | | ||||
65 | KisFilterConfigurationSP KisGuassianHighPassFilter::factoryConfiguration() const | ||||
66 | { | ||||
67 | KisFilterConfigurationSP config = new KisFilterConfiguration(id().id(), 1); | ||||
68 | config->setProperty("blurAmount", 1); | ||||
69 | return config; | ||||
70 | } | ||||
71 | | ||||
72 | void KisGuassianHighPassFilter::processImpl(KisPaintDeviceSP device, | ||||
73 | const QRect& applyRect, | ||||
74 | const KisFilterConfigurationSP _config, | ||||
75 | KoUpdater * | ||||
76 | ) const | ||||
77 | { | ||||
78 | QPointer<KoUpdater> filterUpdater = 0; | ||||
79 | QPointer<KoUpdater> convolutionUpdater = 0; | ||||
80 | const QRect deviceBounds = device->defaultBounds()->bounds(); | ||||
81 | | ||||
82 | KisFilterConfigurationSP config = _config ? _config : new KisFilterConfiguration(id().id(), 1); | ||||
83 | | ||||
84 | QVariant value; | ||||
85 | KisLodTransformScalar t(device); | ||||
86 | const qreal blurAmount = t.scale(config->getProperty("blurAmount", value) ? value.toDouble() : 1.0); | ||||
87 | QBitArray channelFlags = config->channelFlags(); | ||||
88 | KisPaintDeviceSP blur = new KisPaintDevice(*device); | ||||
89 | KisGaussianKernel::applyGaussian(blur, applyRect, | ||||
90 | blurAmount, blurAmount, | ||||
91 | channelFlags, | ||||
92 | convolutionUpdater); | ||||
93 | | ||||
94 | KisPainter painter(device); | ||||
95 | painter.setCompositeOp(blur->colorSpace()->compositeOp(COMPOSITE_GRAIN_EXTRACT)); | ||||
96 | painter.bitBlt(0, 0, blur, 0, 0, deviceBounds.width(), deviceBounds.height()); | ||||
97 | painter.end(); | ||||
98 | } | ||||
99 | | ||||
100 | | ||||
101 | QRect KisGuassianHighPassFilter::neededRect(const QRect & rect, const KisFilterConfigurationSP config, int lod) const | ||||
102 | { | ||||
103 | KisLodTransformScalar t(lod); | ||||
104 | | ||||
105 | QVariant value; | ||||
106 | const qreal blurAmount = t.scale(config->getProperty("blurAmount", value) ? value.toDouble() : 1.0); | ||||
107 | | ||||
108 | return rect.adjusted(-blurAmount * 2, -blurAmount * 2, blurAmount * 2, blurAmount * 2); | ||||
109 | } | ||||
110 | | ||||
111 | QRect KisGuassianHighPassFilter::changedRect(const QRect & rect, const KisFilterConfigurationSP config, int lod) const | ||||
112 | { | ||||
113 | KisLodTransformScalar t(lod); | ||||
114 | | ||||
115 | QVariant value; | ||||
116 | const qreal blurAmount = t.scale(config->getProperty("blurAmount", value) ? value.toDouble() : 1.0); | ||||
117 | | ||||
118 | return rect.adjusted( -blurAmount, -blurAmount, blurAmount, blurAmount); | ||||
119 | } |