Commit 6fbfe1de authored by Halla Rempt's avatar Halla Rempt
Browse files

Add an option to the png export dialog to choose between srgb and icc

We cannot save both the srgb tag and the icc profile if the icc profile
is sRGB(-like), so give the user a choice depending on their needs.

CCMAIL:l.elle.stone@gmail.com
parent 93aaad38
......@@ -29,6 +29,7 @@
#include <KoColorSpace.h>
#include <KoFilterChain.h>
#include <KoFilterManager.h>
#include <KoColorProfile.h>
#include <kis_paint_device.h>
#include <kis_doc2.h>
......@@ -106,6 +107,8 @@ KoFilter::ConversionStatus KisPNGExport::convert(const QByteArray& from, const Q
}
} while (it->nextPixel());
bool sRGB = cs->profile()->name().toLower().contains("srgb");
KisWdgOptionsPNG* wdg = new KisWdgOptionsPNG(kdb);
QString filterConfig = KisConfig().exportConfiguration("PNG");
......@@ -127,6 +130,9 @@ KoFilter::ConversionStatus KisPNGExport::convert(const QByteArray& from, const Q
wdg->bnTransparencyFillColor->setEnabled(!wdg->alpha->isChecked());
wdg->chkSRGB->setVisible(sRGB);
wdg->chkSRGB->setChecked(cfg.getBool("saveSRGBProfile", true));
QStringList rgb = cfg.getString("transparencyFillcolor", "255,255,255").split(",");
wdg->bnTransparencyFillColor->setDefaultColor(Qt::white);
wdg->bnTransparencyFillColor->setColor(QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt()));
......@@ -147,13 +153,14 @@ KoFilter::ConversionStatus KisPNGExport::convert(const QByteArray& from, const Q
int compression = wdg->compressionLevel->value();
bool tryToSaveAsIndexed = wdg->tryToSaveAsIndexed->isChecked();
QColor c = wdg->bnTransparencyFillColor->color();
bool saveSRGB = wdg->chkSRGB->isChecked();
cfg.setProperty("alpha", alpha);
cfg.setProperty("indexed", tryToSaveAsIndexed);
cfg.setProperty("compression", compression);
cfg.setProperty("interlaced", interlace);
cfg.setProperty("transparencyFillcolor", QString("%1,%2,%3").arg(c.red()).arg(c.green()).arg(c.blue()));
cfg.setProperty("saveSRGBProfile", saveSRGB);
KisConfig().setExportConfiguration("PNG", cfg);
delete kdb;
......@@ -172,6 +179,8 @@ KoFilter::ConversionStatus KisPNGExport::convert(const QByteArray& from, const Q
options.compression = compression;
options.tryToSaveAsIndexed = tryToSaveAsIndexed;
options.transparencyFillColor = c;
options.saveSRGBProfile = saveSRGB;
KisExifInfoVisitor eIV;
eIV.visit(image->rootLayer().data());
KisMetaData::Store* eI = 0;
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>170</height>
<width>432</width>
<height>189</height>
</rect>
</property>
<property name="windowTitle">
......@@ -148,7 +148,7 @@ You can uncheck the box if you are not using transparency and you want to make t
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<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>
......@@ -161,7 +161,7 @@ You can uncheck the box if you are not using transparency and you want to make t
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_4">
......@@ -179,7 +179,7 @@ You can uncheck the box if you are not using transparency and you want to make t
</item>
</layout>
</item>
<item row="5" column="0">
<item row="6" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -195,6 +195,16 @@ You can uncheck the box if you are not using transparency and you want to make t
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="chkSRGB">
<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>
</property>
<property name="text">
<string>save sRGB profile</string>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
......
......@@ -518,7 +518,7 @@ KisImageBuilder_Result KisPNGConverter::buildImage(QIODevice* iod)
} else {
dbgFile << "no embedded profile, will use the default profile";
}
// Check that the profile is used by the color space
if (profile && !KoColorSpaceRegistry::instance()->colorSpaceFactory(
KoColorSpaceRegistry::instance()->colorSpaceId(
......@@ -922,7 +922,7 @@ KisImageBuilder_Result KisPNGConverter::buildFile(QIODevice* iodevice, KisImageW
// set sRGB only if the profile is sRGB -- http://www.w3.org/TR/PNG/#11sRGB says sRGB and iCCP should not both be present
bool sRGB = device->colorSpace()->profile()->name().toLower().contains("srgb");
if (sRGB) {
if (!options.saveSRGBProfile && sRGB) {
png_set_sRGB(png_ptr, info_ptr, PNG_sRGB_INTENT_ABSOLUTE);
}
// set the palette
......@@ -934,7 +934,7 @@ KisImageBuilder_Result KisPNGConverter::buildFile(QIODevice* iodevice, KisImageW
while (it != annotationsEnd) {
if (!(*it) || (*it)->type().isEmpty()) {
dbgFile << "Warning: empty annotation";
continue;
}
......@@ -949,23 +949,23 @@ KisImageBuilder_Result KisPNGConverter::buildFile(QIODevice* iodevice, KisImageW
} else if ((*it)->type() == "kpp_version" || (*it)->type() == "kpp_preset" ) {
dbgFile << "Saving preset information " << (*it)->description();
png_textp text = (png_textp) png_malloc(png_ptr, (png_uint_32) sizeof(png_text));
QByteArray keyData = (*it)->description().toLatin1();
text[0].key = keyData.data();
text[0].text = (*it)->annotation().data();
text[0].text_length = (*it)->annotation().size();
text[0].compression = -1;
png_set_text(png_ptr, info_ptr, text, 1);
png_free(png_ptr, text);
}
}
// Save the color profile
const KoColorProfile* colorProfile = device->colorSpace()->profile();
QByteArray colorProfileData = colorProfile->rawData();
if (!sRGB) {
if (!sRGB || options.saveSRGBProfile) {
#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 5
png_set_iCCP(png_ptr, info_ptr, "icc", PNG_COMPRESSION_TYPE_BASE, (const png_bytep)colorProfileData.data(), colorProfileData . size());
#else
......
......@@ -52,6 +52,7 @@ struct KisPNGOptions {
, xmp(true)
, tryToSaveAsIndexed(true)
, transparencyFillColor(Qt::white)
, saveSRGBProfile(false)
{}
int compression;
......@@ -61,6 +62,7 @@ struct KisPNGOptions {
bool iptc;
bool xmp;
bool tryToSaveAsIndexed;
bool saveSRGBProfile;
QList<const KisMetaData::Filter*> filters;
QColor transparencyFillColor;
......
Markdown is supported
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