Changeset View
Changeset View
Standalone View
Standalone View
plugins/filters/colors/kis_luminositytoalpha_filter.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * This file is part of Krita | ||||
3 | * | ||||
4 | * Copyright (c) 2004 Cyrille Berger <cberger@cberger.net> | ||||
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 "kis_luminositytoalpha_filter.h" | ||||
22 | | ||||
23 | | ||||
24 | #include <math.h> | ||||
25 | | ||||
26 | #include <stdlib.h> | ||||
27 | #include <string.h> | ||||
28 | | ||||
29 | #include <QSlider> | ||||
30 | #include <QPoint> | ||||
31 | #include <QColor> | ||||
32 | #include <QButtonGroup> | ||||
33 | | ||||
34 | #include <klocalizedstring.h> | ||||
35 | | ||||
36 | #include <kis_debug.h> | ||||
37 | #include <kpluginfactory.h> | ||||
38 | | ||||
39 | #include "KoBasicHistogramProducers.h" | ||||
40 | #include <KoColorSpace.h> | ||||
41 | #include <KoColorTransformation.h> | ||||
42 | #include <filter/kis_filter_category_ids.h> | ||||
43 | #include <filter/kis_color_transformation_configuration.h> | ||||
44 | #include <kis_paint_device.h> | ||||
45 | #include <kis_processing_information.h> | ||||
46 | #include <KisDocument.h> | ||||
47 | #include <kis_image.h> | ||||
48 | #include <kis_layer.h> | ||||
49 | #include <kis_global.h> | ||||
50 | #include <kis_types.h> | ||||
51 | #include <kis_selection.h> | ||||
52 | #include "filter/kis_filter_registry.h" | ||||
53 | #include <kis_painter.h> | ||||
54 | #include <KoColorSpaceConstants.h> | ||||
55 | #include <KoCompositeOp.h> | ||||
56 | #include <kis_iterator_ng.h> | ||||
57 | | ||||
58 | KisLuminosityToAlphaFilter::KisLuminosityToAlphaFilter() | ||||
59 | : KisColorTransformationFilter(id(), FiltersCategoryColorId, i18n("&Luminosity To Alpha...")) | ||||
60 | { | ||||
61 | setSupportsPainting(true); | ||||
62 | } | ||||
63 | | ||||
64 | KisLuminosityToAlphaFilter::~KisLuminosityToAlphaFilter() | ||||
65 | { | ||||
66 | } | ||||
67 | | ||||
68 | KisConfigWidget *KisLuminosityToAlphaFilter::createConfigurationWidget(QWidget *parent, const KisPaintDeviceSP dev) const | ||||
69 | { | ||||
70 | Q_UNUSED(dev); | ||||
71 | return new KisLuminosityToAlphaConfigWidget(parent); | ||||
72 | } | ||||
73 | | ||||
74 | | ||||
75 | KoColorTransformation* KisLuminosityToAlphaFilter::createTransformation(const KoColorSpace* cs, const KisFilterConfigurationSP config) const | ||||
76 | { | ||||
77 | QHash<QString, QVariant> params; | ||||
78 | if (config) { | ||||
79 | params["type"] = config->getInt("type", 0); | ||||
80 | } | ||||
81 | return cs->createColorTransformation("luminositytoalpha_adjustment", params); | ||||
82 | } | ||||
83 | | ||||
84 | KisFilterConfigurationSP KisLuminosityToAlphaFilter::factoryConfiguration() const | ||||
85 | { | ||||
86 | KisColorTransformationConfigurationSP config = new KisColorTransformationConfiguration(id().id(), 1); | ||||
87 | config->setProperty("type", 0); | ||||
88 | return config; | ||||
89 | } | ||||
90 | | ||||
91 | KisLuminosityToAlphaConfigWidget::KisLuminosityToAlphaConfigWidget(QWidget * parent, Qt::WindowFlags f) : KisConfigWidget(parent, f) | ||||
92 | { | ||||
93 | m_page = new Ui_WdgLuminosityToAlpha(); | ||||
94 | m_page->setupUi(this); | ||||
95 | m_group = new QButtonGroup(this); | ||||
96 | m_group->addButton(m_page->LLL, 0); | ||||
97 | m_group->addButton(m_page->LL, 1); | ||||
98 | m_group->addButton(m_page->L, 2); | ||||
99 | m_group->addButton(m_page->M, 3); | ||||
100 | m_group->addButton(m_page->MM, 4); | ||||
101 | m_group->addButton(m_page->MMM, 5); | ||||
102 | m_group->addButton(m_page->D, 6); | ||||
103 | m_group->addButton(m_page->DD, 7); | ||||
104 | m_group->addButton(m_page->DDD, 8); | ||||
105 | m_group->setExclusive(true); | ||||
106 | connect(m_group, SIGNAL(buttonClicked(int)), SIGNAL(sigConfigurationItemChanged())); | ||||
107 | } | ||||
108 | | ||||
109 | KisLuminosityToAlphaConfigWidget::~KisLuminosityToAlphaConfigWidget() | ||||
110 | { | ||||
111 | delete m_page; | ||||
112 | } | ||||
113 | | ||||
114 | KisPropertiesConfigurationSP KisLuminosityToAlphaConfigWidget::configuration() const | ||||
115 | { | ||||
116 | KisColorTransformationConfigurationSP c = new KisColorTransformationConfiguration(KisLuminosityToAlphaFilter::id().id(), 0); | ||||
117 | c->setProperty("type", m_group->checkedId()); | ||||
118 | return c; | ||||
119 | } | ||||
120 | | ||||
121 | void KisLuminosityToAlphaConfigWidget::setConfiguration(const KisPropertiesConfigurationSP config) | ||||
122 | { | ||||
123 | m_group->button(config->getInt("type", 0))->setChecked(true); | ||||
124 | emit sigConfigurationItemChanged(); | ||||
125 | } |