File indexing completed on 2025-01-26 04:08:07

0001 /*
0002  *  KisColorSpaceConversionDialog.cpp - part of KimageShop^WKrayon^WKrita
0003  *
0004  *  SPDX-FileCopyrightText: 2004 Boudewijn Rempt <boud@valdyas.org>
0005  *
0006  *  SPDX-License-Identifier: GPL-2.0-or-later
0007  */
0008 
0009 #include "KisColorSpaceConversionDialog.h"
0010 
0011 #include <QRadioButton>
0012 #include <QCheckBox>
0013 #include <QLabel>
0014 #include <QComboBox>
0015 #include <QList>
0016 
0017 #include <klocalizedstring.h>
0018 #include <kis_debug.h>
0019 
0020 #include "KoColorProfile.h"
0021 #include "KoColorSpace.h"
0022 #include "KoID.h"
0023 
0024 #include "widgets/kis_cmb_idlist.h"
0025 #include <KisSqueezedComboBox.h>
0026 
0027 #include "kis_image.h"
0028 #include "kis_layer_utils.h"
0029 
0030 KisColorSpaceConversionDialog::KisColorSpaceConversionDialog(QWidget *  parent,
0031         const char * name)
0032         : KoDialog(parent)
0033 {
0034     setButtons(Ok | Cancel);
0035     setDefaultButton(Ok);
0036     setObjectName(name);
0037     m_page = new WdgConvertColorSpace(this);
0038     Q_CHECK_PTR(m_page);
0039     m_page->setObjectName("colorspace_conversion");
0040 
0041     // the warning label is hidden by default!
0042     m_page->lblHeadlineWarning->setVisible(false);
0043 
0044     setMainWidget(m_page);
0045     resize(m_page->sizeHint());
0046 
0047     m_intentButtonGroup.addButton(m_page->radioAbsoluteColorimetric, KoColorConversionTransformation::IntentAbsoluteColorimetric);
0048     m_intentButtonGroup.addButton(m_page->radioPerceptual, KoColorConversionTransformation::IntentPerceptual);
0049     m_intentButtonGroup.addButton(m_page->radioRelativeColorimetric, KoColorConversionTransformation::IntentRelativeColorimetric);
0050     m_intentButtonGroup.addButton(m_page->radioSaturation, KoColorConversionTransformation::IntentSaturation);
0051 
0052     connect(this, SIGNAL(okClicked()),
0053             this, SLOT(okClicked()));
0054 
0055 
0056     connect(m_page->colorSpaceSelector, SIGNAL(selectionChanged(bool)), this, SLOT(selectionChanged(bool)));
0057     connect(m_page->colorSpaceSelector, SIGNAL(colorSpaceChanged(const KoColorSpace*)), this, SLOT(slotColorSpaceChanged(const KoColorSpace*)));
0058 
0059 }
0060 
0061 
0062 
0063 KisColorSpaceConversionDialog::~KisColorSpaceConversionDialog()
0064 {
0065     delete m_page;
0066 }
0067 
0068 void KisColorSpaceConversionDialog::setInitialColorSpace(const KoColorSpace *cs, KisImageSP entireImage)
0069 {
0070     if (!cs) {
0071         return;
0072     }
0073 
0074     if (cs->profile()->getEstimatedTRC()[0]==1.0) {
0075     //this tries to automatically determine whether optimizations ought to be checked or not.
0076     //if the space you're converting from is linear TRC, uncheck.
0077         m_page->chkAllowLCMSOptimization->setCheckState(Qt::Unchecked);
0078     } else {
0079         m_page->chkAllowLCMSOptimization->setCheckState(Qt::Checked);
0080     }
0081     m_page->colorSpaceSelector->setCurrentColorSpace(cs);
0082 
0083     m_image = entireImage;
0084 }
0085 
0086 const KoColorSpace *KisColorSpaceConversionDialog::colorSpace() const
0087 {
0088     return m_page->colorSpaceSelector->currentColorSpace();
0089 }
0090 
0091 KoColorConversionTransformation::Intent KisColorSpaceConversionDialog::conversionIntent() const
0092 {
0093     return static_cast<KoColorConversionTransformation::Intent>(m_intentButtonGroup.checkedId());
0094 }
0095 
0096 KoColorConversionTransformation::ConversionFlags KisColorSpaceConversionDialog::conversionFlags() const
0097 {
0098     KoColorConversionTransformation::ConversionFlags flags = KoColorConversionTransformation::HighQuality;
0099 
0100     if (m_page->chkBlackpointCompensation->isChecked()) flags |= KoColorConversionTransformation::BlackpointCompensation;
0101     if (!m_page->chkAllowLCMSOptimization->isChecked()) flags |= KoColorConversionTransformation::NoOptimization;
0102 
0103     return flags;
0104 }
0105 
0106 void KisColorSpaceConversionDialog::selectionChanged(bool valid)
0107 {
0108     //TODO: Figure out how to uncheck when moving TO a linear TRC.
0109     Q_UNUSED(valid);
0110     enableButtonOk(m_page->colorSpaceSelector->currentColorSpace());
0111 }
0112 
0113 // SLOTS
0114 
0115 void KisColorSpaceConversionDialog::okClicked()
0116 {
0117     accept();
0118 }
0119 
0120 void KisColorSpaceConversionDialog::slotColorSpaceChanged(const KoColorSpace *cs)
0121 {
0122     if (m_image &&
0123         *m_image->profile() != *cs->profile() &&
0124         !KisLayerUtils::canChangeImageProfileInvisibly(m_image)) {
0125 
0126         m_page->wdgWarningNotice->setVisible(true);
0127         m_page->wdgWarningNotice->setText(
0128                     m_page->wdgWarningNotice->changeImageProfileWarningText());
0129     } else {
0130         m_page->wdgWarningNotice->setVisible(false);
0131     }
0132 }
0133