File indexing completed on 2024-06-09 04:26:46
0001 /* 0002 * SPDX-FileCopyrightText: 2004 Boudewijn Rempt <boud@valdyas.org> 0003 * SPDX-FileCopyrightText: 2021 L. E. Segovia <amy@amyspark.me> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "lutdocker_dock.h" 0009 #include <config-hdr.h> 0010 0011 #include <sstream> 0012 0013 #include <QLayout> 0014 #include <QLabel> 0015 #include <QPixmap> 0016 #include <QPainter> 0017 #include <QImage> 0018 #include <QFormLayout> 0019 #include <QCheckBox> 0020 #include <QApplication> 0021 #include <QDesktopWidget> 0022 #include <QToolButton> 0023 #include <QDir> 0024 0025 0026 #include <klocalizedstring.h> 0027 0028 #include <KisMainWindow.h> 0029 #include <KoFileDialog.h> 0030 #include <KoChannelInfo.h> 0031 #include <KoColorSpace.h> 0032 #include <KoColorSpaceFactory.h> 0033 #include <KoColorProfile.h> 0034 #include <KoColorModelStandardIds.h> 0035 0036 #include "kis_icon_utils.h" 0037 #include <KisViewManager.h> 0038 #include <KisDocument.h> 0039 #include <kis_config.h> 0040 #include <kis_canvas2.h> 0041 #include <kis_canvas_resource_provider.h> 0042 #include <kis_config_notifier.h> 0043 #include <kis_image.h> 0044 #include <KisSqueezedComboBox.h> 0045 #include "kis_signals_blocker.h" 0046 #include "krita_utils.h" 0047 #include <KisOcioConfiguration.h> 0048 0049 #include <opengl/KisOpenGLModeProber.h> 0050 0051 #include "black_white_point_chooser.h" 0052 0053 0054 OCIO::ConstConfigRcPtr defaultRawProfile() 0055 { 0056 /** 0057 * Copied from OCIO, just a noop profile 0058 */ 0059 const char * INTERNAL_RAW_PROFILE = 0060 "ocio_profile_version: 1\n" 0061 "strictparsing: false\n" 0062 "roles:\n" 0063 " default: raw\n" 0064 "displays:\n" 0065 " sRGB:\n" 0066 " - !<View> {name: Raw, colorspace: raw}\n" 0067 "colorspaces:\n" 0068 " - !<ColorSpace>\n" 0069 " name: raw\n" 0070 " family: raw\n" 0071 " equalitygroup:\n" 0072 " bitdepth: 32f\n" 0073 " isdata: true\n" 0074 " allocation: uniform\n" 0075 " description: 'A raw color space. Conversions to and from this space are no-ops.'\n"; 0076 0077 0078 std::istringstream istream; 0079 istream.str(INTERNAL_RAW_PROFILE); 0080 return OCIO::Config::CreateFromStream(istream); 0081 } 0082 0083 LutDockerDock::LutDockerDock() 0084 : QDockWidget(i18n("LUT Management")) 0085 , m_canvas(0) 0086 { 0087 using namespace std::placeholders; // For _1 0088 m_exposureCompressor.reset( 0089 new KisSignalCompressorWithParam<qreal>(40, std::bind(&LutDockerDock::exposureValueChanged, this, _1))); 0090 m_gammaCompressor.reset( 0091 new KisSignalCompressorWithParam<qreal>(40, std::bind(&LutDockerDock::gammaValueChanged, this, _1))); 0092 0093 m_page = new QWidget(this); 0094 setupUi(m_page); 0095 setWidget(m_page); 0096 0097 KisConfig cfg(true); 0098 m_chkUseOcio->setChecked(cfg.useOcio()); 0099 connect(m_chkUseOcio, SIGNAL(toggled(bool)), SLOT(updateDisplaySettings())); 0100 connect(m_colorManagement, SIGNAL(currentIndexChanged(int)), SLOT(slotColorManagementModeChanged())); 0101 0102 m_bnSelectConfigurationFile->setToolTip(i18n("Select custom configuration file.")); 0103 connect(m_bnSelectConfigurationFile,SIGNAL(clicked()), SLOT(selectOcioConfiguration())); 0104 0105 KisOcioConfiguration ocioOptions = cfg.ocioConfiguration(); 0106 m_txtConfigurationPath->setText(ocioOptions.configurationPath); 0107 m_txtLut->setText(ocioOptions.lutPath); 0108 0109 m_bnSelectLut->setToolTip(i18n("Select LUT file")); 0110 connect(m_bnSelectLut, SIGNAL(clicked()), SLOT(selectLut())); 0111 connect(m_bnClearLut, SIGNAL(clicked()), SLOT(clearLut())); 0112 0113 // See https://groups.google.com/group/ocio-dev/browse_thread/thread/ec95c5f54a74af65 -- maybe need to be reinstated 0114 // when people ask for it. 0115 m_lblLut->hide(); 0116 m_txtLut->hide(); 0117 m_bnSelectLut->hide(); 0118 m_bnClearLut->hide(); 0119 0120 connect(m_cmbDisplayDevice, SIGNAL(currentIndexChanged(int)), SLOT(refillViewCombobox())); 0121 0122 m_exposureDoubleWidget->setToolTip(i18n("Select the exposure (stops) for HDR images.")); 0123 m_exposureDoubleWidget->setRange(-10.0, 10.0, 2); 0124 m_exposureDoubleWidget->setValue(0.0); 0125 m_exposureDoubleWidget->setSingleStep(0.25); 0126 0127 connect(m_exposureDoubleWidget, QOverload<double>::of(&KisDoubleSliderSpinBox::valueChanged), 0128 [this](double value){ m_exposureCompressor->start(value); }); 0129 0130 // Gamma needs to be exponential (gamma *= 1.1f, gamma /= 1.1f as steps) 0131 0132 m_gammaDoubleWidget->setToolTip(i18n("Select the amount of gamma modification for display. This does not affect the pixels of your image.")); 0133 m_gammaDoubleWidget->setRange(0.1, 5.0, 2); 0134 m_gammaDoubleWidget->setValue(1.0); 0135 m_gammaDoubleWidget->setSingleStep(0.1); 0136 0137 connect(m_gammaDoubleWidget, QOverload<double>::of(&KisDoubleSliderSpinBox::valueChanged), 0138 [this](double value){ m_gammaCompressor->start(value); }); 0139 0140 m_bwPointChooser = new BlackWhitePointChooser(this); 0141 0142 connect(m_bwPointChooser, SIGNAL(sigBlackPointChanged(qreal)), SLOT(updateDisplaySettings())); 0143 connect(m_bwPointChooser, SIGNAL(sigWhitePointChanged(qreal)), SLOT(updateDisplaySettings())); 0144 0145 connect(m_btnConvertCurrentColor, SIGNAL(toggled(bool)), SLOT(updateDisplaySettings())); 0146 connect(m_btmShowBWConfiguration, SIGNAL(clicked()), SLOT(slotShowBWConfiguration())); 0147 slotUpdateIcons(); 0148 0149 connect(m_cmbInputColorSpace, SIGNAL(currentIndexChanged(int)), SLOT(updateDisplaySettings())); 0150 connect(m_cmbDisplayDevice, SIGNAL(currentIndexChanged(int)), SLOT(updateDisplaySettings())); 0151 connect(m_cmbView, SIGNAL(currentIndexChanged(int)), SLOT(updateDisplaySettings())); 0152 connect(m_cmbLook, SIGNAL(currentIndexChanged(int)), SLOT(updateDisplaySettings())); 0153 connect(m_cmbComponents, SIGNAL(currentIndexChanged(int)), SLOT(updateDisplaySettings())); 0154 0155 connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(resetOcioConfiguration())); 0156 0157 resetOcioConfiguration(); 0158 } 0159 0160 LutDockerDock::~LutDockerDock() 0161 { 0162 } 0163 0164 void LutDockerDock::setCanvas(KoCanvasBase* _canvas) 0165 { 0166 if (m_canvas) { 0167 m_canvas->disconnect(this); 0168 } 0169 0170 setEnabled(_canvas != 0); 0171 0172 if (KisCanvas2* canvas = dynamic_cast<KisCanvas2*>(_canvas)) { 0173 m_canvas = canvas; 0174 if (m_canvas) { 0175 if (!m_canvas->displayFilter()) { 0176 resetOcioConfiguration(); 0177 updateDisplaySettings(); 0178 } 0179 else { 0180 m_displayFilter = m_canvas->displayFilter(); 0181 OcioDisplayFilter *displayFilter = qobject_cast<OcioDisplayFilter*>(m_displayFilter.data()); 0182 Q_ASSERT(displayFilter); 0183 m_ocioConfig = displayFilter->config; 0184 KisSignalsBlocker exposureBlocker(m_exposureDoubleWidget); 0185 m_exposureDoubleWidget->setValue(displayFilter->exposure); 0186 KisSignalsBlocker gammaBlocker(m_gammaDoubleWidget); 0187 m_gammaDoubleWidget->setValue(displayFilter->gamma); 0188 KisSignalsBlocker componentsBlocker(m_cmbComponents); 0189 m_cmbComponents->setCurrentIndex((int)displayFilter->swizzle); 0190 KisSignalsBlocker bwBlocker(m_bwPointChooser); 0191 m_bwPointChooser->setBlackPoint(displayFilter->blackPoint); 0192 m_bwPointChooser->setWhitePoint(displayFilter->whitePoint); 0193 } 0194 0195 connect(m_canvas->image(), SIGNAL(sigColorSpaceChanged(const KoColorSpace*)), SLOT(slotImageColorSpaceChanged()), Qt::UniqueConnection); 0196 connect(m_canvas->viewManager()->mainWindow(), SIGNAL(themeChanged()), SLOT(slotUpdateIcons()), Qt::UniqueConnection); 0197 0198 } 0199 } 0200 } 0201 0202 void LutDockerDock::unsetCanvas() 0203 { 0204 m_canvas = 0; 0205 setEnabled(false); 0206 m_displayFilter = QSharedPointer<KisDisplayFilter>(0); 0207 } 0208 0209 void LutDockerDock::slotUpdateIcons() 0210 { 0211 m_btnConvertCurrentColor->setIcon(KisIconUtils::loadIcon("krita_tool_freehand")); 0212 m_btmShowBWConfiguration->setIcon(KisIconUtils::loadIcon("settings-button")); 0213 m_lblOcioVersion->setText(QString("OCIO: %1 | %2").arg(OCIO_VERSION_FULL_STR, KisOpenGL::currentDriver())); 0214 m_lblOcioVersion->setWordWrap(true); 0215 m_lblOcioVersion->setEnabled(false); 0216 } 0217 0218 void LutDockerDock::slotShowBWConfiguration() 0219 { 0220 m_bwPointChooser->showPopup(m_btmShowBWConfiguration->mapToGlobal(QPoint())); 0221 } 0222 0223 bool LutDockerDock::canChangeExposureAndGamma() const 0224 { 0225 if (!m_chkUseOcio->isChecked() || !m_ocioConfig) return false; 0226 0227 const bool externalColorManagementEnabled = 0228 m_colorManagement->currentIndex() != (int)KisOcioConfiguration::INTERNAL; 0229 0230 0231 #ifdef HAVE_HDR 0232 #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) 0233 KisSurfaceColorSpace currentColorSpace = KisOpenGLModeProber::instance()->surfaceformatInUse().colorSpace(); 0234 #else 0235 KisSurfaceColorSpace currentColorSpace = KisSurfaceColorSpace::DefaultColorSpace; 0236 #endif 0237 #endif 0238 0239 const bool exposureManagementEnabled = 0240 externalColorManagementEnabled 0241 #ifdef HAVE_HDR 0242 || currentColorSpace == KisSurfaceColorSpace::scRGBColorSpace 0243 #endif 0244 ; 0245 0246 return exposureManagementEnabled; 0247 } 0248 0249 qreal LutDockerDock::currentExposure() const 0250 { 0251 if (!m_displayFilter) return 0.0; 0252 OcioDisplayFilter *displayFilter = qobject_cast<OcioDisplayFilter*>(m_displayFilter.data()); 0253 return canChangeExposureAndGamma() ? displayFilter->exposure : 0.0; 0254 } 0255 0256 void LutDockerDock::setCurrentExposure(qreal value) 0257 { 0258 if (!canChangeExposureAndGamma()) return; 0259 m_exposureDoubleWidget->setValue(value); 0260 if(m_canvas) { 0261 m_canvas->viewManager()->showFloatingMessage( 0262 i18nc("floating message about exposure", "Exposure: %1", 0263 KritaUtils::prettyFormatReal(m_exposureDoubleWidget->value())), 0264 QIcon(), 500, KisFloatingMessage::Low); 0265 } 0266 } 0267 0268 qreal LutDockerDock::currentGamma() const 0269 { 0270 if (!m_displayFilter) return 1.0; 0271 OcioDisplayFilter *displayFilter = qobject_cast<OcioDisplayFilter*>(m_displayFilter.data()); 0272 return canChangeExposureAndGamma() ? displayFilter->gamma : 1.0; 0273 } 0274 0275 void LutDockerDock::setCurrentGamma(qreal value) 0276 { 0277 if (!canChangeExposureAndGamma()) return; 0278 m_gammaDoubleWidget->setValue(value); 0279 if (m_canvas) { 0280 m_canvas->viewManager()->showFloatingMessage( 0281 i18nc("floating message about gamma", "Gamma: %1", 0282 KritaUtils::prettyFormatReal(m_gammaDoubleWidget->value())), 0283 QIcon(), 500, KisFloatingMessage::Low); 0284 } 0285 } 0286 0287 void LutDockerDock::slotImageColorSpaceChanged() 0288 { 0289 enableControls(); 0290 writeControls(); 0291 resetOcioConfiguration(); 0292 } 0293 0294 void LutDockerDock::exposureValueChanged(double exposure) 0295 { 0296 if (m_canvas) { 0297 m_canvas->viewManager()->canvasResourceProvider()->setHDRExposure(exposure); 0298 updateDisplaySettings(); 0299 } 0300 } 0301 0302 void LutDockerDock::gammaValueChanged(double gamma) 0303 { 0304 if (m_canvas) { 0305 m_canvas->viewManager()->canvasResourceProvider()->setHDRGamma(gamma); 0306 updateDisplaySettings(); 0307 } 0308 } 0309 0310 void LutDockerDock::enableControls() 0311 { 0312 bool canDoExternalColorCorrection = false; 0313 0314 if (m_canvas) { 0315 KisImageSP image = m_canvas->viewManager()->image(); 0316 canDoExternalColorCorrection = 0317 image->colorSpace()->colorModelId() == RGBAColorModelID; 0318 } 0319 0320 if (!canDoExternalColorCorrection) { 0321 KisSignalsBlocker colorManagementBlocker(m_colorManagement); 0322 Q_UNUSED(colorManagementBlocker); 0323 m_colorManagement->setCurrentIndex((int) KisOcioConfiguration::INTERNAL); 0324 } 0325 0326 const bool ocioEnabled = m_chkUseOcio->isChecked(); 0327 m_colorManagement->setEnabled(ocioEnabled && canDoExternalColorCorrection); 0328 0329 const bool externalColorManagementEnabled = 0330 m_colorManagement->currentIndex() != (int)KisOcioConfiguration::INTERNAL; 0331 0332 m_lblInputColorSpace->setEnabled(ocioEnabled && externalColorManagementEnabled); 0333 m_cmbInputColorSpace->setEnabled(ocioEnabled && externalColorManagementEnabled); 0334 m_lblDisplayDevice->setEnabled(ocioEnabled && externalColorManagementEnabled); 0335 m_cmbDisplayDevice->setEnabled(ocioEnabled && externalColorManagementEnabled); 0336 m_lblView->setEnabled(ocioEnabled && externalColorManagementEnabled); 0337 m_cmbView->setEnabled(ocioEnabled && externalColorManagementEnabled); 0338 m_lblLook->setEnabled(ocioEnabled && externalColorManagementEnabled); 0339 m_cmbLook->setEnabled(ocioEnabled && externalColorManagementEnabled); 0340 0341 const bool exposureManagementEnabled = canChangeExposureAndGamma(); 0342 0343 m_exposureDoubleWidget->setEnabled(exposureManagementEnabled); 0344 m_gammaDoubleWidget->setEnabled(exposureManagementEnabled); 0345 m_lblExposure->setEnabled(exposureManagementEnabled); 0346 m_lblGamma->setEnabled(exposureManagementEnabled); 0347 0348 QString exposureToolTip; 0349 0350 if (!exposureManagementEnabled) { 0351 exposureToolTip = i18nc("@info:tooltip", "Exposure and Gamma corrections are disabled in Internal mode. Switch to OCIO mode to use them"); 0352 } 0353 m_exposureDoubleWidget->setToolTip(exposureToolTip); 0354 m_gammaDoubleWidget->setToolTip(exposureToolTip); 0355 m_lblExposure->setToolTip(exposureToolTip); 0356 m_lblGamma->setToolTip(exposureToolTip); 0357 0358 bool enableConfigPath = m_colorManagement->currentIndex() == (int) KisOcioConfiguration::OCIO_CONFIG; 0359 0360 lblConfig->setEnabled(ocioEnabled && enableConfigPath); 0361 m_txtConfigurationPath->setEnabled(ocioEnabled && enableConfigPath); 0362 m_bnSelectConfigurationFile->setEnabled(ocioEnabled && enableConfigPath); 0363 } 0364 0365 void LutDockerDock::updateDisplaySettings() 0366 { 0367 if (!m_canvas || !m_canvas->viewManager() || !m_canvas->viewManager()->image()) { 0368 return; 0369 } 0370 0371 enableControls(); 0372 writeControls(); 0373 0374 if (m_chkUseOcio->isChecked() && m_ocioConfig) { 0375 KIS_SAFE_ASSERT_RECOVER_NOOP(!m_canvas->displayFilter() || 0376 m_canvas->displayFilter() == m_displayFilter); 0377 0378 if (!m_displayFilter) { 0379 m_displayFilter = 0380 m_canvas->displayFilter() ? 0381 m_canvas->displayFilter() : 0382 QSharedPointer<KisDisplayFilter>(new OcioDisplayFilter(this)); 0383 } 0384 0385 OcioDisplayFilter *displayFilter = qobject_cast<OcioDisplayFilter*>(m_displayFilter.data()); 0386 displayFilter->config = m_ocioConfig; 0387 displayFilter->inputColorSpaceName = m_ocioConfig->getColorSpaceNameByIndex(m_cmbInputColorSpace->currentIndex()); 0388 displayFilter->displayDevice = m_ocioConfig->getDisplay(m_cmbDisplayDevice->currentIndex()); 0389 displayFilter->view = m_ocioConfig->getView(displayFilter->displayDevice, m_cmbView->currentIndex()); 0390 displayFilter->look = m_ocioConfig->getLookNameByIndex(m_cmbLook->currentIndex()); 0391 displayFilter->gamma = m_gammaDoubleWidget->isEnabled() ? m_gammaDoubleWidget->value() : 1.0; 0392 displayFilter->exposure = m_exposureDoubleWidget->isEnabled() ? m_exposureDoubleWidget->value() : 0.0; 0393 displayFilter->swizzle = (OCIO_CHANNEL_SWIZZLE)m_cmbComponents->currentIndex(); 0394 0395 displayFilter->blackPoint = m_bwPointChooser->blackPoint(); 0396 displayFilter->whitePoint = m_bwPointChooser->whitePoint(); 0397 0398 displayFilter->forceInternalColorManagement = 0399 m_colorManagement->currentIndex() == (int)KisOcioConfiguration::INTERNAL; 0400 0401 displayFilter->setLockCurrentColorVisualRepresentation(m_btnConvertCurrentColor->isChecked()); 0402 0403 displayFilter->updateProcessor(); 0404 m_canvas->setDisplayFilter(m_displayFilter); 0405 } 0406 else { 0407 m_canvas->setDisplayFilter(QSharedPointer<KisDisplayFilter>(0)); 0408 } 0409 m_canvas->updateCanvas(); 0410 } 0411 0412 void LutDockerDock::writeControls() 0413 { 0414 KisOcioConfiguration ocioOptions; 0415 ocioOptions.mode = (KisOcioConfiguration::Mode)m_colorManagement->currentIndex(); 0416 ocioOptions.configurationPath = m_txtConfigurationPath->text(); 0417 ocioOptions.lutPath = m_txtLut->text(); 0418 ocioOptions.inputColorSpace = m_cmbInputColorSpace->currentUnsqueezedText(); 0419 ocioOptions.displayDevice = m_cmbDisplayDevice->currentUnsqueezedText(); 0420 ocioOptions.displayView = m_cmbView->currentUnsqueezedText(); 0421 ocioOptions.look = m_cmbLook->currentUnsqueezedText(); 0422 0423 KisConfig cfg(false); 0424 cfg.setUseOcio(m_chkUseOcio->isChecked()); 0425 cfg.setOcioConfiguration(ocioOptions); 0426 cfg.setOcioLockColorVisualRepresentation(m_btnConvertCurrentColor->isChecked()); 0427 } 0428 0429 void LutDockerDock::slotColorManagementModeChanged() 0430 { 0431 enableControls(); 0432 writeControls(); 0433 resetOcioConfiguration(); 0434 } 0435 0436 void LutDockerDock::selectOcioConfiguration() 0437 { 0438 QString filename = m_txtConfigurationPath->text(); 0439 0440 KoFileDialog dialog(this, KoFileDialog::OpenFile, "lutdocker"); 0441 dialog.setCaption(i18n("Select OpenColorIO Configuration")); 0442 dialog.setDefaultDir(QDir::cleanPath(filename.isEmpty() ? QDir::homePath() : filename)); 0443 dialog.setMimeTypeFilters(QStringList() << "application/x-opencolorio-configuration"); 0444 filename = dialog.filename(); 0445 QFile f(filename); 0446 if (f.exists()) { 0447 m_txtConfigurationPath->setText(filename); 0448 writeControls(); 0449 resetOcioConfiguration(); 0450 } 0451 } 0452 0453 void LutDockerDock::resetOcioConfiguration() 0454 { 0455 KisConfig cfg(true); 0456 KisOcioConfiguration ocioOptions = cfg.ocioConfiguration(); 0457 m_ocioConfig.reset(); 0458 0459 try { 0460 if (ocioOptions.mode == KisOcioConfiguration::INTERNAL) { 0461 m_ocioConfig = defaultRawProfile(); 0462 } else if (ocioOptions.mode == KisOcioConfiguration::OCIO_ENVIRONMENT) { 0463 m_ocioConfig = OCIO::Config::CreateFromEnv(); 0464 } 0465 else if (ocioOptions.mode == KisOcioConfiguration::OCIO_CONFIG) { 0466 QString configFile = ocioOptions.configurationPath; 0467 0468 if (QFile::exists(configFile)) { 0469 m_ocioConfig = OCIO::Config::CreateFromFile(configFile.toUtf8()); 0470 } else { 0471 m_ocioConfig = defaultRawProfile(); 0472 } 0473 } 0474 if (m_ocioConfig) { 0475 OCIO::SetCurrentConfig(m_ocioConfig); 0476 } 0477 } catch (OCIO::Exception &exception) { 0478 errKrita << "OpenColorIO Error:" << exception.what() << "Cannot create the LUT docker"; 0479 } 0480 0481 0482 if (m_ocioConfig) { 0483 refillControls(); 0484 } 0485 } 0486 0487 void LutDockerDock::refillControls() 0488 { 0489 if (!m_canvas) return; 0490 if (!m_canvas->viewManager()) return; 0491 if (!m_canvas->viewManager()->canvasResourceProvider()) return; 0492 if (!m_canvas->viewManager()->image()) return; 0493 0494 KIS_ASSERT_RECOVER_RETURN(m_ocioConfig); 0495 0496 KisConfig cfg(true); 0497 KisOcioConfiguration ocioOptions = cfg.ocioConfiguration(); 0498 0499 { // Color Management Mode 0500 KisSignalsBlocker modeBlocker(m_colorManagement); 0501 m_colorManagement->setCurrentIndex((int) ocioOptions.mode); 0502 } 0503 0504 { // Exposure 0505 KisSignalsBlocker exposureBlocker(m_exposureDoubleWidget); 0506 m_exposureDoubleWidget->setValue(m_canvas->viewManager()->canvasResourceProvider()->HDRExposure()); 0507 } 0508 0509 { // Gamma 0510 KisSignalsBlocker gammaBlocker(m_gammaDoubleWidget); 0511 m_gammaDoubleWidget->setValue(m_canvas->viewManager()->canvasResourceProvider()->HDRGamma()); 0512 } 0513 0514 { // Components 0515 const KoColorSpace *cs = m_canvas->viewManager()->image()->colorSpace(); 0516 0517 QStringList itemsList; 0518 itemsList << i18n("Luminance"); 0519 itemsList << i18n("All Channels"); 0520 Q_FOREACH (KoChannelInfo *channel, KoChannelInfo::displayOrderSorted(cs->channels())) { 0521 itemsList << channel->name(); 0522 } 0523 0524 if (m_cmbComponents->originalTexts() != itemsList) { 0525 KisSignalsBlocker componentsBlocker(m_cmbComponents); 0526 m_cmbComponents->resetOriginalTexts(itemsList); 0527 m_cmbComponents->setCurrentIndex(1); // All Channels... 0528 } 0529 } 0530 0531 { // Input Color Space 0532 QStringList itemsList; 0533 int numOcioColorSpaces = m_ocioConfig->getNumColorSpaces(); 0534 for(int i = 0; i < numOcioColorSpaces; ++i) { 0535 const char *cs = m_ocioConfig->getColorSpaceNameByIndex(i); 0536 OCIO::ConstColorSpaceRcPtr colorSpace = m_ocioConfig->getColorSpace(cs); 0537 itemsList << QString::fromUtf8(colorSpace->getName()); 0538 } 0539 0540 KisSignalsBlocker inputCSBlocker(m_cmbInputColorSpace); 0541 0542 if (itemsList != m_cmbInputColorSpace->originalTexts()) { 0543 m_cmbInputColorSpace->resetOriginalTexts(itemsList); 0544 } 0545 0546 m_cmbInputColorSpace->setCurrent(ocioOptions.inputColorSpace); 0547 } 0548 0549 { // Display Device 0550 QStringList itemsList; 0551 int numDisplays = m_ocioConfig->getNumDisplays(); 0552 for (int i = 0; i < numDisplays; ++i) { 0553 itemsList << QString::fromUtf8(m_ocioConfig->getDisplay(i)); 0554 } 0555 0556 KisSignalsBlocker displayDeviceLocker(m_cmbDisplayDevice); 0557 0558 if (itemsList != m_cmbDisplayDevice->originalTexts()) { 0559 m_cmbDisplayDevice->resetOriginalTexts(itemsList); 0560 } 0561 0562 m_cmbDisplayDevice->setCurrent(ocioOptions.displayDevice); 0563 } 0564 0565 { // Lock Current Color 0566 KisSignalsBlocker locker(m_btnConvertCurrentColor); 0567 m_btnConvertCurrentColor->setChecked(cfg.ocioLockColorVisualRepresentation()); 0568 } 0569 0570 refillViewCombobox(); 0571 0572 { 0573 QStringList itemsList; 0574 int numLooks = m_ocioConfig->getNumLooks(); 0575 for (int k = 0; k < numLooks; k++) { 0576 itemsList << QString::fromUtf8(m_ocioConfig->getLookNameByIndex(k)); 0577 } 0578 itemsList << i18nc("Item to indicate no look transform being selected","None"); 0579 0580 KisSignalsBlocker LookComboLocker(m_cmbLook); 0581 0582 if (itemsList != m_cmbLook->originalTexts()) { 0583 m_cmbLook->resetOriginalTexts(itemsList); 0584 } 0585 0586 m_cmbLook->setCurrent(ocioOptions.look); 0587 } 0588 updateDisplaySettings(); 0589 } 0590 0591 void LutDockerDock::refillViewCombobox() 0592 { 0593 KisSignalsBlocker viewComboLocker(m_cmbView); 0594 m_cmbView->clear(); 0595 0596 if (!m_canvas || !m_ocioConfig) return; 0597 0598 const char *display = m_ocioConfig->getDisplay(m_cmbDisplayDevice->currentIndex()); 0599 int numViews = m_ocioConfig->getNumViews(display); 0600 0601 for (int j = 0; j < numViews; ++j) { 0602 m_cmbView->addSqueezedItem(QString::fromUtf8(m_ocioConfig->getView(display, j))); 0603 } 0604 0605 KisConfig cfg(true); 0606 KisOcioConfiguration ocioOptions = cfg.ocioConfiguration(); 0607 m_cmbView->setCurrent(ocioOptions.displayView); 0608 } 0609 0610 void LutDockerDock::selectLut() 0611 { 0612 QString filename = m_txtLut->text(); 0613 0614 KoFileDialog dialog(this, KoFileDialog::OpenFile, "lutdocker"); 0615 dialog.setCaption(i18n("Select LUT file")); 0616 dialog.setDefaultDir(QDir::cleanPath(filename)); 0617 dialog.setMimeTypeFilters(QStringList() << "application/octet-stream", "application/octet-stream"); 0618 filename = dialog.filename(); 0619 0620 QFile f(filename); 0621 if (f.exists() && filename != m_txtLut->text()) { 0622 m_txtLut->setText(filename); 0623 writeControls(); 0624 updateDisplaySettings(); 0625 } 0626 } 0627 0628 void LutDockerDock::clearLut() 0629 { 0630 m_txtLut->clear(); 0631 updateDisplaySettings(); 0632 } 0633