Commit 59425a04 authored by Halla Rempt's avatar Halla Rempt
Browse files

Add an option to convert to 8 bit/channel when exporting to PNG

CCBUG:459415
parent 2527124a
Pipeline #234915 canceled with stage
in 28 minutes and 59 seconds
......@@ -872,6 +872,7 @@ bool KisPNGConverter::saveDeviceToStore(const QString &filename, const QRect &im
options.tryToSaveAsIndexed = false;
options.alpha = true;
options.saveSRGBProfile = false;
options.downsample = false;
if (dev->colorSpace()->id() != "RGBA") {
dev = new KisPaintDevice(*dev.data());
......@@ -930,12 +931,13 @@ KisImportExportErrorCode KisPNGConverter::buildFile(QIODevice* iodevice, const Q
if (device->colorSpace()->colorDepthId() == Float16BitsColorDepthID
|| device->colorSpace()->colorDepthId() == Float32BitsColorDepthID
|| device->colorSpace()->colorDepthId() == Float64BitsColorDepthID
|| options.saveAsHDR) {
|| options.saveAsHDR
|| (device->colorSpace()->colorDepthId() != Integer8BitsColorDepthID && options.downsample)) {
const KoColorSpace *dstCS =
KoColorSpaceRegistry::instance()->colorSpace(
device->colorSpace()->colorModelId().id(),
Integer16BitsColorDepthID.id(),
options.downsample ? Integer8BitsColorDepthID.id() : Integer16BitsColorDepthID.id(),
device->colorSpace()->profile());
if (options.saveAsHDR) {
......@@ -951,7 +953,6 @@ KisImportExportErrorCode KisPNGConverter::buildFile(QIODevice* iodevice, const Q
tmp->convertTo(dstCS);
device = tmp;
}
KIS_SAFE_ASSERT_RECOVER(!options.saveAsHDR || !options.forceSRGB) {
......@@ -964,7 +965,7 @@ KisImportExportErrorCode KisPNGConverter::buildFile(QIODevice* iodevice, const Q
QStringList colormodels = QStringList() << RGBAColorModelID.id() << GrayAColorModelID.id();
if (options.forceSRGB || !colormodels.contains(device->colorSpace()->colorModelId().id())) {
const KoColorSpace* cs = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), device->colorSpace()->colorDepthId().id(), "sRGB built-in - (lcms internal)");
const KoColorSpace* cs = KoColorSpaceRegistry::instance()->colorSpace(RGBAColorModelID.id(), options.downsample ? Integer8BitsColorDepthID.id() : device->colorSpace()->colorDepthId().id(), "sRGB built-in - (lcms internal)");
device = new KisPaintDevice(*device);
device->convertTo(cs);
}
......
......@@ -44,6 +44,7 @@ struct KisPNGOptions {
, storeAuthor(false)
, saveAsHDR(false)
, transparencyFillColor(Qt::white)
, downsample(false)
{}
int compression;
......@@ -60,7 +61,7 @@ struct KisPNGOptions {
bool saveAsHDR;
QList<const KisMetaData::Filter*> filters;
QColor transparencyFillColor;
bool downsample; // Converts to 8 bit on export
};
/**
......
......@@ -62,6 +62,7 @@ KisImportExportErrorCode KisPNGExport::convert(KisDocument *document, QIODevice
options.storeAuthor = configuration->getBool("storeAuthor", false);
options.storeMetaData = configuration->getBool("storeMetaData", false);
options.saveAsHDR = configuration->getBool("saveAsHDR", false);
options.downsample = configuration->getBool("downsample", false);
vKisAnnotationSP_it beginIt = image->beginAnnotations();
vKisAnnotationSP_it endIt = image->endAnnotations();
......@@ -105,7 +106,7 @@ KisPropertiesConfigurationSP KisPNGExport::defaultConfiguration(const QByteArray
cfg->setProperty("saveAsHDR", false);
cfg->setProperty("storeMetaData", false);
cfg->setProperty("storeAuthor", false);
cfg->setProperty("downsample", false);
return cfg;
}
......@@ -183,6 +184,8 @@ void KisWdgOptionsPNG::setConfiguration(const KisPropertiesConfigurationSP cfg)
background.fromQColor(Qt::white);
bnTransparencyFillColor->setDefaultColor(background);
bnTransparencyFillColor->setColor(cfg->getColor("transparencyFillcolor", background));
chkDownsample->setChecked(cfg->getBool("downsample", false));
}
KisPropertiesConfigurationSP KisWdgOptionsPNG::configuration() const
......@@ -199,6 +202,7 @@ KisPropertiesConfigurationSP KisWdgOptionsPNG::configuration() const
bool forceSRGB = !saveAsHDR && chkForceSRGB->isChecked();
bool storeAuthor = chkAuthor->isChecked();
bool storeMetaData = chkMetaData->isChecked();
bool downsample = chkDownsample->isChecked();
QVariant transparencyFillcolor;
......@@ -214,7 +218,7 @@ KisPropertiesConfigurationSP KisWdgOptionsPNG::configuration() const
cfg->setProperty("forceSRGB", forceSRGB);
cfg->setProperty("storeAuthor", storeAuthor);
cfg->setProperty("storeMetaData", storeMetaData);
cfg->setProperty("downsample", downsample);
return cfg;
}
......
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author>
SPDX-FileCopyrightText: none
......@@ -10,15 +10,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>561</width>
<height>266</height>
<width>592</width>
<height>381</height>
</rect>
</property>
<property name="windowTitle">
<string>PNG Options</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item column="0" row="0">
<item row="0" column="0">
<layout class="QGridLayout">
<property name="leftMargin">
<number>0</number>
......@@ -38,17 +38,28 @@
<property name="verticalSpacing">
<number>6</number>
</property>
<item column="1" row="6">
<widget class="QCheckBox" name="chkSRGB">
<item row="12" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Transparent color: </string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="KisDoubleSliderSpinBox" name="compressionLevel" native="true">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;PNG&lt;/span&gt; files have &lt;span style=&quot; font-style:italic;&quot;&gt;two&lt;/span&gt; options to save &lt;span style=&quot; font-weight:600;&quot;&gt;sRGB&lt;/span&gt; information: as a tag or as an explicit profile. For use with in websites, &lt;span style=&quot; font-style:italic;&quot;&gt;disable&lt;/span&gt; this option. For interchange with other applications, &lt;span style=&quot; font-style:italic;&quot;&gt;enable&lt;/span&gt; this option.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Note: the compression level does not change the quality of the result</string>
</property>
<property name="text">
<string>Embed sRGB profile</string>
<property name="whatsThis">
<string>&lt;p&gt;Adjust the compression time. Better compression takes longer.
&lt;br&gt;Note: the compression level does not change the quality of the result.&lt;/p&gt;</string>
</property>
</widget>
</item>
<item column="1" row="11">
<item row="12" column="1">
<widget class="KisColorButton" name="bnTransparencyFillColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
......@@ -67,41 +78,62 @@
</property>
</widget>
</item>
<item column="1" row="8">
<widget class="QCheckBox" name="alpha">
<item row="9" column="1">
<widget class="QCheckBox" name="chkMetaData">
<property name="toolTip">
<string>Disable to get smaller files if your image has no transparency</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Store information like keywords, title and subject and license, if possible.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Store Metadata</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="textLabel3">
<property name="whatsThis">
<string>&lt;p&gt;The Portable Network Graphics (PNG) file format allows transparency in your image to be stored by saving an alpha channel.
You can uncheck the box if you are not using transparency and you want to make the resulting file smaller .&lt;br&gt;Always saving the alpha channel is recommended.&lt;/p&gt;</string>
<string>&lt;p&gt;Adjust the compression time. Better compression takes longer.
&lt;br&gt;Note: the compression level does not change the quality of the result.&lt;/p&gt;</string>
</property>
<property name="text">
<string>Store alpha channel (transparency)</string>
<string comment="The file will save fast but will not be compressed a lot">Large file size</string>
</property>
<property name="checked">
<bool>true</bool>
</widget>
</item>
<item row="7" column="1">
<widget class="QCheckBox" name="chkForceSRGB">
<property name="text">
<string>Force convert to sRGB</string>
</property>
</widget>
</item>
<item column="1" row="10">
<widget class="QCheckBox" name="chkAuthor">
<item row="3" column="1">
<widget class="QCheckBox" name="tryToSaveAsIndexed">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save author nickname and the first contact information of the author profile into the png, if possible.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Indexed PNG images are smaller. If you enabled this option, your image will be analyzed to see whether it is possible to save as an indexed PNG.</string>
</property>
<property name="text">
<string>Sign with author data</string>
<string>Save as indexed PNG, if possible</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item column="1" row="7">
<widget class="QCheckBox" name="chkForceSRGB">
<item row="4" column="1">
<widget class="QCheckBox" name="interlacing">
<property name="toolTip">
<string>Use interlacing when publishing on the Internet.</string>
</property>
<property name="whatsThis">
<string>&lt;p&gt;Interlacing is useful if you intend to publish your image on the Internet.&lt;br&gt;
Enabling interlacing will cause the image to be displayed by the browser even while downloading.&lt;/p&gt;</string>
</property>
<property name="text">
<string>Force convert to sRGB</string>
<string>Interlacing</string>
</property>
</widget>
</item>
<item column="2" row="0">
<item row="0" column="2">
<widget class="QLabel" name="textLabel4_2">
<property name="whatsThis">
<string>&lt;p&gt;Adjust the compression time. Better compression takes longer.
......@@ -115,30 +147,14 @@ You can uncheck the box if you are not using transparency and you want to make t
</property>
</widget>
</item>
<item column="1" row="9">
<widget class="QCheckBox" name="chkMetaData">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Store information like keywords, title and subject and license, if possible.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Store Metadata</string>
</property>
</widget>
</item>
<item column="1" row="3">
<widget class="QCheckBox" name="tryToSaveAsIndexed">
<property name="toolTip">
<string>Indexed PNG images are smaller. If you enabled this option, your image will be analyzed to see whether it is possible to save as an indexed PNG.</string>
</property>
<item row="5" column="1">
<widget class="QCheckBox" name="chkSaveAsHDR">
<property name="text">
<string>Save as indexed PNG, if possible</string>
</property>
<property name="checked">
<bool>true</bool>
<string>Save as HDR image (Rec. 2020 PQ)</string>
</property>
</widget>
</item>
<item column="0" row="1" rowspan="2">
<item row="1" column="0" rowspan="2">
<widget class="QLabel" name="textLabel1">
<property name="toolTip">
<string>Note: the compression level does not change the quality of the result</string>
......@@ -155,62 +171,53 @@ You can uncheck the box if you are not using transparency and you want to make t
</property>
</widget>
</item>
<item column="0" row="11">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Transparent color: </string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<item row="8" column="1">
<widget class="QCheckBox" name="alpha">
<property name="toolTip">
<string>Disable to get smaller files if your image has no transparency</string>
</property>
</widget>
</item>
<item column="1" row="0">
<widget class="QLabel" name="textLabel3">
<property name="whatsThis">
<string>&lt;p&gt;Adjust the compression time. Better compression takes longer.
&lt;br&gt;Note: the compression level does not change the quality of the result.&lt;/p&gt;</string>
<string>&lt;p&gt;The Portable Network Graphics (PNG) file format allows transparency in your image to be stored by saving an alpha channel.
You can uncheck the box if you are not using transparency and you want to make the resulting file smaller .&lt;br&gt;Always saving the alpha channel is recommended.&lt;/p&gt;</string>
</property>
<property name="text">
<string comment="The file will save fast but will not be compressed a lot">Large file size</string>
<string>Store alpha channel (transparency)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item colspan="2" column="1" row="1">
<widget class="KisDoubleSliderSpinBox" name="compressionLevel" native="true">
<item row="6" column="1">
<widget class="QCheckBox" name="chkSRGB">
<property name="toolTip">
<string>Note: the compression level does not change the quality of the result</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;PNG&lt;/span&gt; files have &lt;span style=&quot; font-style:italic;&quot;&gt;two&lt;/span&gt; options to save &lt;span style=&quot; font-weight:600;&quot;&gt;sRGB&lt;/span&gt; information: as a tag or as an explicit profile. For use with in websites, &lt;span style=&quot; font-style:italic;&quot;&gt;disable&lt;/span&gt; this option. For interchange with other applications, &lt;span style=&quot; font-style:italic;&quot;&gt;enable&lt;/span&gt; this option.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="whatsThis">
<string>&lt;p&gt;Adjust the compression time. Better compression takes longer.
&lt;br&gt;Note: the compression level does not change the quality of the result.&lt;/p&gt;</string>
<property name="text">
<string>Embed sRGB profile</string>
</property>
</widget>
</item>
<item column="1" row="4">
<widget class="QCheckBox" name="interlacing">
<item row="10" column="1">
<widget class="QCheckBox" name="chkAuthor">
<property name="toolTip">
<string>Use interlacing when publishing on the Internet.</string>
</property>
<property name="whatsThis">
<string>&lt;p&gt;Interlacing is useful if you intend to publish your image on the Internet.&lt;br&gt;
Enabling interlacing will cause the image to be displayed by the browser even while downloading.&lt;/p&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save author nickname and the first contact information of the author profile into the png, if possible.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Interlacing</string>
<string>Sign with author data</string>
</property>
</widget>
</item>
<item column="1" row="5">
<widget class="QCheckBox" name="chkSaveAsHDR">
<item row="11" column="1">
<widget class="QCheckBox" name="chkDownsample">
<property name="text">
<string>Save as HDR image (Rec. 2020 PQ)</string>
<string>Force convert to 8 bits/channel</string>
</property>
</widget>
</item>
</layout>
</item>
<item column="0" row="6">
<item row="6" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -243,4 +250,4 @@ Enabling interlacing will cause the image to be displayed by the browser even wh
</customwidgets>
<resources/>
<connections/>
</ui>
\ No newline at end of file
</ui>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment