File indexing completed on 2024-12-22 04:15:56
0001 /* 0002 * SPDX-FileCopyrightText: 2005 Cyrille Berger <cberger@cberger.net> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_dlg_options_tiff.h" 0008 0009 #include <QCheckBox> 0010 #include <QGroupBox> 0011 #include <QSlider> 0012 #include <QStackedWidget> 0013 #include <QApplication> 0014 0015 #include <kcombobox.h> 0016 #include <klocalizedstring.h> 0017 0018 #include <KisImportExportFilter.h> 0019 #include <KoChannelInfo.h> 0020 #include <KoColorModelStandardIds.h> 0021 #include <KoColorSpace.h> 0022 #include <kis_config.h> 0023 #include <kis_properties_configuration.h> 0024 0025 #include <config-tiff.h> 0026 0027 KisTIFFOptionsWidget::KisTIFFOptionsWidget(QWidget *parent) 0028 : KisConfigWidget(parent) 0029 { 0030 setupUi(this); 0031 activated(0); 0032 connect(kComboBoxCompressionType, SIGNAL(activated(int)), this, SLOT(activated(int))); 0033 connect(flatten, SIGNAL(toggled(bool)), this, SLOT(flattenToggled(bool))); 0034 setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); 0035 0036 // See KisTIFFOptions::fromProperties 0037 kComboBoxCompressionType->addItem(i18nc("TIFF options", "None"), 0); 0038 kComboBoxCompressionType->addItem( 0039 i18nc("TIFF options", "JPEG DCT compression"), 0040 1); 0041 kComboBoxCompressionType->addItem(i18nc("TIFF options", "Deflate (ZIP)"), 0042 2); 0043 kComboBoxCompressionType->addItem( 0044 i18nc("TIFF options", "Lempel-Ziv & Welch"), 0045 3); 0046 kComboBoxCompressionType->addItem(i18nc("TIFF options", "Pixar Log"), 4); 0047 0048 connect(kComboBoxCompressionType, 0049 QOverload<int>::of(&QComboBox::currentIndexChanged), 0050 [&](int index) { 0051 const int deflate = kComboBoxCompressionType->findData(2); 0052 const int lzw = kComboBoxCompressionType->findData(3); 0053 kComboBoxPredictor->setEnabled(index == deflate 0054 || index == lzw); 0055 }); 0056 0057 kComboBoxPredictor->addItem(i18nc("TIFF options", "None"), 0); 0058 kComboBoxPredictor->addItem( 0059 i18nc("TIFF options", "Horizontal Differencing"), 0060 1); 0061 kComboBoxPredictor->addItem( 0062 i18nc("TIFF options", "Floating Point Horizontal Differencing"), 0063 2); 0064 } 0065 0066 void KisTIFFOptionsWidget::setConfiguration(const KisPropertiesConfigurationSP cfg) 0067 { 0068 kComboBoxCompressionType->setCurrentIndex(cfg->getInt("compressiontype", 0)); 0069 activated(kComboBoxCompressionType->currentIndex()); 0070 kComboBoxPredictor->setCurrentIndex(cfg->getInt("predictor", 0)); 0071 alpha->setChecked(cfg->getBool("alpha", true)); 0072 #ifdef TIFF_CAN_WRITE_PSD_TAGS 0073 chkPhotoshop->setEnabled(true); 0074 chkPhotoshop->setChecked(cfg->getBool("saveAsPhotoshop", false)); 0075 kComboBoxPSDCompressionType->setCurrentIndex(cfg->getInt("psdCompressionType", 0)); 0076 #else 0077 chkPhotoshop->setEnabled(false); 0078 chkPhotoshop->setChecked(false); 0079 #endif 0080 flatten->setChecked(cfg->getBool("flatten", true)); 0081 flattenToggled(flatten->isChecked()); 0082 qualityLevel->setValue(cfg->getInt("quality", 80)); 0083 compressionLevelDeflate->setValue(cfg->getInt("deflate", 6)); 0084 compressionLevelPixarLog->setValue(cfg->getInt("pixarlog", 6)); 0085 chkSaveProfile->setChecked(cfg->getBool("saveProfile", true)); 0086 0087 { 0088 const QString colorDepthId = 0089 cfg->getString(KisImportExportFilter::ColorDepthIDTag); 0090 0091 if (colorDepthId == Float16BitsColorDepthID.id() 0092 || colorDepthId == Float32BitsColorDepthID.id() 0093 || colorDepthId == Float64BitsColorDepthID.id()) { 0094 kComboBoxPredictor->removeItem(1); 0095 } else { 0096 kComboBoxPredictor->removeItem(2); 0097 } 0098 0099 if (colorDepthId != Integer8BitsColorDepthID.id()) { 0100 kComboBoxCompressionType->removeItem( 0101 kComboBoxCompressionType->findData(1)); 0102 } 0103 } 0104 0105 { 0106 const QString colorModelId = 0107 cfg->getString(KisImportExportFilter::ColorModelIDTag); 0108 0109 if (colorModelId == YCbCrAColorModelID.id()) { 0110 alpha->setChecked(false); 0111 alpha->setEnabled(false); 0112 } 0113 } 0114 } 0115 0116 KisPropertiesConfigurationSP KisTIFFOptionsWidget::configuration() const 0117 { 0118 KisPropertiesConfigurationSP cfg(new KisPropertiesConfiguration()); 0119 cfg->setProperty("compressiontype", 0120 kComboBoxCompressionType->currentData()); 0121 cfg->setProperty("predictor", kComboBoxPredictor->currentData()); 0122 cfg->setProperty("alpha", alpha->isChecked()); 0123 cfg->setProperty("saveAsPhotoshop", chkPhotoshop->isChecked()); 0124 cfg->setProperty("psdCompressionType", kComboBoxPSDCompressionType->currentIndex()); 0125 cfg->setProperty("flatten", flatten->isChecked()); 0126 cfg->setProperty("quality", qualityLevel->value()); 0127 cfg->setProperty("deflate", compressionLevelDeflate->value()); 0128 cfg->setProperty("pixarlog", compressionLevelPixarLog->value()); 0129 cfg->setProperty("saveProfile", chkSaveProfile->isChecked()); 0130 0131 return cfg; 0132 } 0133 0134 void KisTIFFOptionsWidget::activated(int index) 0135 { 0136 const int data = kComboBoxCompressionType->itemData(index).value<int>(); 0137 switch (data) { 0138 case 1: // JPEG 0139 codecsOptionsStack->setCurrentIndex(1); 0140 break; 0141 case 2: // Deflate 0142 codecsOptionsStack->setCurrentIndex(2); 0143 break; 0144 case 4: // Pixar Log 0145 codecsOptionsStack->setCurrentIndex(3); 0146 break; 0147 default: 0148 codecsOptionsStack->setCurrentIndex(0); 0149 } 0150 } 0151 0152 void KisTIFFOptionsWidget::flattenToggled(bool t) 0153 { 0154 alpha->setEnabled(t); 0155 if (!t) { 0156 alpha->setChecked(true); 0157 } 0158 #ifdef TIFF_CAN_WRITE_PSD_TAGS 0159 chkPhotoshop->setEnabled(!t); 0160 if (t) { 0161 chkPhotoshop->setChecked(false); 0162 } 0163 #endif 0164 } 0165