File indexing completed on 2024-12-22 04:15:05
0001 /* 0002 * colorspaceconversion.cc -- Part of Krita 0003 * 0004 * SPDX-FileCopyrightText: 2004 Boudewijn Rempt (boud@valdyas.org) 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "colorspaceconversion.h" 0010 0011 #include <QApplication> 0012 0013 #include <klocalizedstring.h> 0014 #include <kis_debug.h> 0015 #include <kpluginfactory.h> 0016 0017 #include <KoColorSpace.h> 0018 0019 #include <kis_undo_adapter.h> 0020 #include <kis_transaction.h> 0021 #include <kis_annotation.h> 0022 #include <kis_config.h> 0023 #include <kis_global.h> 0024 #include <kis_image.h> 0025 #include <kis_node_manager.h> 0026 #include <kis_layer.h> 0027 #include <kis_types.h> 0028 0029 #include <KisViewManager.h> 0030 #include <kis_paint_device.h> 0031 #include <kis_action.h> 0032 #include <kis_group_layer.h> 0033 0034 #include <dialogs/KisColorSpaceConversionDialog.h> 0035 #include "kis_action_manager.h" 0036 0037 K_PLUGIN_FACTORY_WITH_JSON(ColorSpaceConversionFactory, "kritacolorspaceconversion.json", registerPlugin<ColorSpaceConversion>();) 0038 0039 0040 ColorSpaceConversion::ColorSpaceConversion(QObject *parent, const QVariantList &) 0041 : KisActionPlugin(parent) 0042 { 0043 KisAction *action = viewManager()->actionManager()->createAction("imagecolorspaceconversion"); 0044 connect(action, SIGNAL(triggered()), this, SLOT(slotImageColorSpaceConversion())); 0045 0046 action = viewManager()->actionManager()->createAction("layercolorspaceconversion"); 0047 connect(action, SIGNAL(triggered()), this, SLOT(slotLayerColorSpaceConversion())); 0048 } 0049 0050 ColorSpaceConversion::~ColorSpaceConversion() 0051 { 0052 } 0053 0054 void ColorSpaceConversion::slotImageColorSpaceConversion() 0055 { 0056 KisImageSP image = viewManager()->image().toStrongRef(); 0057 if (!image) return; 0058 0059 KisColorSpaceConversionDialog * dlgColorSpaceConversion = new KisColorSpaceConversionDialog(viewManager()->mainWindowAsQWidget(), "ColorSpaceConversion"); 0060 bool allowLCMSOptimization = KisConfig(true).allowLCMSOptimization(); 0061 dlgColorSpaceConversion->m_page->chkAllowLCMSOptimization->setChecked(allowLCMSOptimization); 0062 Q_CHECK_PTR(dlgColorSpaceConversion); 0063 0064 dlgColorSpaceConversion->setCaption(i18n("Convert All Layers From %1", image->colorSpace()->name())); 0065 dlgColorSpaceConversion->setInitialColorSpace(image->colorSpace(), image); 0066 0067 if (dlgColorSpaceConversion->exec() == QDialog::Accepted) { 0068 0069 const KoColorSpace * cs = dlgColorSpaceConversion->colorSpace(); 0070 if (cs) { 0071 image->convertImageColorSpace(cs, 0072 dlgColorSpaceConversion->conversionIntent(), 0073 dlgColorSpaceConversion->conversionFlags()); 0074 } 0075 } 0076 delete dlgColorSpaceConversion; 0077 } 0078 0079 void ColorSpaceConversion::slotLayerColorSpaceConversion() 0080 { 0081 KisImageSP image = viewManager()->image().toStrongRef(); 0082 if (!image) return; 0083 0084 KisLayerSP layer = viewManager()->activeLayer(); 0085 if (!layer) return; 0086 0087 KisColorSpaceConversionDialog * dlgColorSpaceConversion = new KisColorSpaceConversionDialog(viewManager()->mainWindowAsQWidget(), "ColorSpaceConversion"); 0088 Q_CHECK_PTR(dlgColorSpaceConversion); 0089 0090 dlgColorSpaceConversion->setCaption(i18n("Convert Current Layer From %1", layer->colorSpace()->name())); 0091 dlgColorSpaceConversion->setInitialColorSpace(layer->colorSpace(), 0); 0092 0093 if (dlgColorSpaceConversion->exec() == QDialog::Accepted) { 0094 const KoColorSpace * cs = dlgColorSpaceConversion->m_page->colorSpaceSelector->currentColorSpace(); 0095 if (cs) { 0096 KoColorConversionTransformation::ConversionFlags conversionFlags = KoColorConversionTransformation::HighQuality; 0097 if (dlgColorSpaceConversion->m_page->chkBlackpointCompensation->isChecked()) conversionFlags |= KoColorConversionTransformation::BlackpointCompensation; 0098 if (!dlgColorSpaceConversion->m_page->chkAllowLCMSOptimization->isChecked()) conversionFlags |= KoColorConversionTransformation::NoOptimization; 0099 image->convertLayerColorSpace(layer, cs, (KoColorConversionTransformation::Intent)dlgColorSpaceConversion->m_intentButtonGroup.checkedId(), conversionFlags); 0100 } 0101 } 0102 delete dlgColorSpaceConversion; 0103 } 0104 0105 #include "colorspaceconversion.moc"