colorspaceconversion.cc 5.79 KB
Newer Older
1 2 3 4 5
/*
 * colorspaceconversion.cc -- Part of Krita
 *
 * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org)
 *
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
 */
Halla Rempt's avatar
Halla Rempt committed
20 21

#include "colorspaceconversion.h"
22 23
#include <stdlib.h>

24
#include <QRadioButton>
25 26 27
#include <QCheckBox>
#include <QLabel>
#include <QComboBox>
28 29
#include <QApplication>
#include <QCursor>
30

31
#include <klocale.h>
32
#include <kcomponentdata.h>
33 34
#include <kmessagebox.h>
#include <kstandarddirs.h>
35
#include <kis_debug.h>
36
#include <kpluginfactory.h>
37
#include <kactioncollection.h>
38

Halla Rempt's avatar
Halla Rempt committed
39
#include <KoColorSpace.h>
40 41
#include <KoColorSpaceRegistry.h>

Halla Rempt's avatar
Halla Rempt committed
42 43 44 45 46 47 48 49 50 51
#include <kis_undo_adapter.h>
#include <kis_transaction.h>
#include <kis_annotation.h>
#include <kis_config.h>
#include <kis_cursor.h>
#include <kis_global.h>
#include <kis_image.h>
#include <kis_node_manager.h>
#include <kis_layer.h>
#include <kis_types.h>
Halla Rempt's avatar
Halla Rempt committed
52
#include <kis_colorspace_convert_visitor.h>
Halla Rempt's avatar
Halla Rempt committed
53 54 55 56 57 58

#include <kis_view2.h>
#include <kis_paint_device.h>
#include <widgets/kis_cmb_idlist.h>
#include <widgets/squeezedcombobox.h>
#include <kis_group_layer.h>
Halla Rempt's avatar
Halla Rempt committed
59

60 61
#include "dlg_colorspaceconversion.h"

62 63
K_PLUGIN_FACTORY(ColorSpaceConversionFactory, registerPlugin<ColorSpaceConversion>();)
K_EXPORT_PLUGIN(ColorSpaceConversionFactory("krita"))
64 65


66
ColorSpaceConversion::ColorSpaceConversion(QObject *parent, const QVariantList &)
Halla Rempt's avatar
Halla Rempt committed
67
        : KParts::Plugin(parent)
68
{
Halla Rempt's avatar
Halla Rempt committed
69
    if (parent->inherits("KisView2")) {
70
        m_view = (KisView2*) parent;
Halla Rempt's avatar
Halla Rempt committed
71 72
        setXMLFile(KStandardDirs::locate("data", "kritaplugins/colorspaceconversion.rc"),
                   true);
73

74
        KAction *action  = new KAction(i18n("&Convert Image Type..."), this);
Halla Rempt's avatar
Halla Rempt committed
75 76
        actionCollection()->addAction("imagecolorspaceconversion", action);
        connect(action, SIGNAL(triggered()), this, SLOT(slotImageColorSpaceConversion()));
77
        action  = new KAction(i18n("&Convert Layer Type..."), this);
Halla Rempt's avatar
Halla Rempt committed
78
        actionCollection()->addAction("layercolorspaceconversion", action);
Adrian Page's avatar
Adrian Page committed
79
        connect(action, SIGNAL(triggered()), this, SLOT(slotLayerColorSpaceConversion()));
80
    }
81 82
}

83
ColorSpaceConversion::~ColorSpaceConversion()
84
{
85
    m_view = 0;
86 87
}

Halla Rempt's avatar
Halla Rempt committed
88
void ColorSpaceConversion::slotImageColorSpaceConversion()
89
{
90
    KisImageWSP image = m_view->image();
91

92
    if (!image) return;
93

94

95
    DlgColorSpaceConversion * dlgColorSpaceConversion = new DlgColorSpaceConversion(m_view, "ColorSpaceConversion");
96 97
    bool allowLCMSOptimization = KisConfig().allowLCMSOptimization();
    dlgColorSpaceConversion->m_page->chkAllowLCMSOptimization->setChecked(allowLCMSOptimization);
98
    Q_CHECK_PTR(dlgColorSpaceConversion);
Halla Rempt's avatar
Halla Rempt committed
99

100
    dlgColorSpaceConversion->setCaption(i18n("Convert All Layers From ") + image->colorSpace()->name());
101

102
    if (dlgColorSpaceConversion->exec() == QDialog::Accepted) {
Halla Rempt's avatar
Halla Rempt committed
103

Cyrille Berger's avatar
Cyrille Berger committed
104
        const KoColorSpace * cs = dlgColorSpaceConversion->m_page->colorSpaceSelector->currentColorSpace();
105

106
        QApplication::setOverrideCursor(KisCursor::waitCursor());
107
        KoColorConversionTransformation::ConversionFlags conversionFlags = KoColorConversionTransformation::HighQuality;
108
        if (dlgColorSpaceConversion->m_page->chkBlackpointCompensation->isChecked()) conversionFlags |= KoColorConversionTransformation::BlackpointCompensation;
109
        if (!dlgColorSpaceConversion->m_page->chkAllowLCMSOptimization->isChecked()) conversionFlags |= KoColorConversionTransformation::NoOptimization;
110
        image->convertImageColorSpace(cs, (KoColorConversionTransformation::Intent)dlgColorSpaceConversion->m_intentButtonGroup.checkedId(), conversionFlags);
111
        QApplication::restoreOverrideCursor();
112 113
    }
    delete dlgColorSpaceConversion;
114 115
}

116
void ColorSpaceConversion::slotLayerColorSpaceConversion()
117
{
118

119
    KisImageWSP image = m_view->image();
120 121
    if (!image) return;

Halla Rempt's avatar
Halla Rempt committed
122 123
    KisLayerSP layer = m_view->activeLayer();
    if (!layer) return;
124 125 126 127

    DlgColorSpaceConversion * dlgColorSpaceConversion = new DlgColorSpaceConversion(m_view, "ColorSpaceConversion");
    Q_CHECK_PTR(dlgColorSpaceConversion);

Halla Rempt's avatar
Halla Rempt committed
128
    dlgColorSpaceConversion->setCaption(i18n("Convert Current Layer From") + layer->colorSpace()->name());
129

130
    if (dlgColorSpaceConversion->exec() == QDialog::Accepted) {
Halla Rempt's avatar
Halla Rempt committed
131

Halla Rempt's avatar
Halla Rempt committed
132
        QApplication::setOverrideCursor(KisCursor::waitCursor());
Halla Rempt's avatar
Halla Rempt committed
133

Cyrille Berger's avatar
Cyrille Berger committed
134
        const KoColorSpace * cs = dlgColorSpaceConversion->m_page->colorSpaceSelector->currentColorSpace();
135

136
        image->undoAdapter()->beginMacro(i18n("Convert Layer Type"));
Halla Rempt's avatar
Halla Rempt committed
137

138
        KoColorConversionTransformation::ConversionFlags conversionFlags = KoColorConversionTransformation::HighQuality;
139
        if (dlgColorSpaceConversion->m_page->chkBlackpointCompensation->isChecked()) conversionFlags |= KoColorConversionTransformation::BlackpointCompensation;
140
        if (!dlgColorSpaceConversion->m_page->chkAllowLCMSOptimization->isChecked()) conversionFlags |= KoColorConversionTransformation::NoOptimization;
141
        KisColorSpaceConvertVisitor visitor(image, layer->colorSpace(), cs, (KoColorConversionTransformation::Intent)dlgColorSpaceConversion->m_intentButtonGroup.checkedId(), conversionFlags);
Halla Rempt's avatar
Halla Rempt committed
142 143
        layer->accept(visitor);

144
        image->undoAdapter()->endMacro();
Halla Rempt's avatar
Halla Rempt committed
145

146
        QApplication::restoreOverrideCursor();
147
        m_view->nodeManager()->nodesUpdated();
148 149
    }
    delete dlgColorSpaceConversion;
150 151 152
}

#include "colorspaceconversion.moc"