diff --git a/plugins/impex/png/kis_png_export.cc b/plugins/impex/png/kis_png_export.cc index 87837ccbc4..9dc03fb6e6 100644 --- a/plugins/impex/png/kis_png_export.cc +++ b/plugins/impex/png/kis_png_export.cc @@ -1,248 +1,252 @@ /* * Copyright (c) 2005 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kis_png_export.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kis_png_converter.h" #include K_PLUGIN_FACTORY_WITH_JSON(KisPNGExportFactory, "krita_png_export.json", registerPlugin();) KisPNGExport::KisPNGExport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent) { } KisPNGExport::~KisPNGExport() { } bool hasVisibleWidgets() { QWidgetList wl = QApplication::allWidgets(); Q_FOREACH (QWidget* w, wl) { if (w->isVisible() && strcmp(w->metaObject()->className(), "QDesktopWidget")) { dbgFile << "Widget " << w << " " << w->objectName() << " " << w->metaObject()->className() << " is visible"; return true; } } return false; } KisImportExportFilter::ConversionStatus KisPNGExport::convert(const QByteArray& from, const QByteArray& to) { dbgFile << "Png export! From:" << from << ", To:" << to << ""; KisDocument *input = inputDocument(); QString filename = outputFile(); if (!input) return KisImportExportFilter::NoDocumentCreated; if (filename.isEmpty()) return KisImportExportFilter::FileNotFound; if (from != "application/x-krita") return KisImportExportFilter::NotImplemented; KoDialog* kdb = new KoDialog(0); kdb->setCaption(i18n("PNG Export Options")); kdb->setModal(false); kdb->setButtons(KoDialog::Ok | KoDialog::Cancel); KisImageWSP image = input->image(); // the image must be locked at the higher levels KIS_SAFE_ASSERT_RECOVER_NOOP(image->locked()); KisPaintDeviceSP pd; pd = new KisPaintDevice(*image->projection()); KisPaintLayerSP l = new KisPaintLayer(image, "projection", OPACITY_OPAQUE_U8, pd); if (!KisPNGConverter::isColorSpaceSupported(pd->colorSpace())) { if (!getBatchMode()) { QMessageBox::critical(0, i18nc("@title:window", "Krita PNG Export"), i18n("You can only save grayscale and RGB images to PNG. Convert your image before exporting to PNG.")); } return KisImportExportFilter::UsageError; } KisSequentialConstIterator it(l->paintDevice(), image->bounds()); const KoColorSpace* cs = l->paintDevice()->colorSpace(); KisPNGOptions options; bool isThereAlpha = false; do { if (cs->opacityU8(it.oldRawData()) != OPACITY_OPAQUE_U8) { isThereAlpha = true; break; } } while (it.nextPixel()); if (!qApp->applicationName().toLower().contains("test")) { bool sRGB = (cs->profile()->name().contains(QLatin1String("srgb"), Qt::CaseInsensitive) && !cs->profile()->name().contains(QLatin1String("g10"))); KisWdgOptionsPNG* wdg = new KisWdgOptionsPNG(kdb); QString filterConfig = KisConfig().exportConfiguration("PNG"); KisPropertiesConfiguration cfg; cfg.fromXML(filterConfig); wdg->alpha->setChecked(cfg.getBool("alpha", isThereAlpha)); if (cs->colorModelId() == RGBAColorModelID) { wdg->tryToSaveAsIndexed->setVisible(true); if (wdg->alpha->isChecked()) { wdg->tryToSaveAsIndexed->setChecked(false); } else { wdg->tryToSaveAsIndexed->setChecked(cfg.getBool("indexed", false)); } } else { wdg->tryToSaveAsIndexed->setVisible(false); } wdg->interlacing->setChecked(cfg.getBool("interlaced", false)); wdg->compressionLevel->setValue(cfg.getInt("compression", 9)); wdg->compressionLevel->setRange(1, 9 , 0); wdg->alpha->setEnabled(isThereAlpha); wdg->tryToSaveAsIndexed->setVisible(!isThereAlpha); wdg->bnTransparencyFillColor->setEnabled(!wdg->alpha->isChecked()); - wdg->chkSRGB->setEnabled(sRGB); + //This used to be 'setEnabled(sRGB)' but firefox and ColorD are incredibly awkward about sRGB management + //on Linux devices, as indicated by the same distorted colours with using the sRGB chunk, meaning it's unrelated to the profile. + //We can somewhat assume sRGB is the default color space for the web, but it's still a darn pity we cannot rely on firefox and colord + //to manage sRGB-marked images properly. + wdg->chkSRGB->setEnabled(!sRGB); wdg->chkSRGB->setChecked(cfg.getBool("saveSRGBProfile", true)); wdg->chkForceSRGB->setEnabled(!sRGB); wdg->chkForceSRGB->setChecked(cfg.getBool("forceSRGB", false)); QStringList rgb = cfg.getString("transparencyFillcolor", "0,0,0").split(','); wdg->bnTransparencyFillColor->setDefaultColor(Qt::white); wdg->bnTransparencyFillColor->setColor(QColor(rgb[0].toInt(), rgb[1].toInt(), rgb[2].toInt())); kdb->setMainWidget(wdg); QApplication::restoreOverrideCursor(); if (hasVisibleWidgets()) { if (!getBatchMode()) { if (kdb->exec() == QDialog::Rejected) { return KisImportExportFilter::UserCancelled; } } } bool alpha = wdg->alpha->isChecked(); bool interlace = wdg->interlacing->isChecked(); int compression = (int)wdg->compressionLevel->value(); bool tryToSaveAsIndexed = wdg->tryToSaveAsIndexed->isChecked(); QColor c = wdg->bnTransparencyFillColor->color(); bool saveSRGB = wdg->chkSRGB->isChecked(); bool forceSRGB = wdg->chkForceSRGB->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); cfg.setProperty("forceSRGB", forceSRGB); KisConfig().setExportConfiguration("PNG", cfg); options.alpha = alpha; options.interlace = interlace; options.compression = compression; options.tryToSaveAsIndexed = tryToSaveAsIndexed; options.transparencyFillColor = c; options.saveSRGBProfile = saveSRGB; options.forceSRGB = forceSRGB; } else { options.alpha = true; options.interlace = false; options.compression = 9; options.tryToSaveAsIndexed = false; options.transparencyFillColor = QColor(0,0,0); options.saveSRGBProfile = false; options.forceSRGB = false; } delete kdb; KisPNGConverter kpc(input); vKisAnnotationSP_it beginIt = image->beginAnnotations(); vKisAnnotationSP_it endIt = image->endAnnotations(); KisImageBuilder_Result res; KisExifInfoVisitor eIV; eIV.visit(image->rootLayer().data()); KisMetaData::Store* eI = 0; if (eIV.countPaintLayer() == 1) eI = eIV.exifInfo(); if (eI) { KisMetaData::Store* copy = new KisMetaData::Store(*eI); eI = copy; } if ((res = kpc.buildFile(filename, image->bounds(), image->xRes(), image->yRes(), l->paintDevice(), beginIt, endIt, options, eI)) == KisImageBuilder_RESULT_OK) { dbgFile << "success !"; delete eI; return KisImportExportFilter::OK; } delete eI; dbgFile << " Result =" << res; return KisImportExportFilter::InternalError; } #include "kis_png_export.moc" void KisWdgOptionsPNG::on_alpha_toggled(bool checked) { bnTransparencyFillColor->setEnabled(!checked); }