예제 #1
0
KisDlgOptionsTIFF::KisDlgOptionsTIFF(QWidget *parent)
        : KDialog(parent), wdg(new QWidget)
{
    setWindowTitle(i18n("TIFF Export Options"));
    setButtons(KDialog::Ok | KDialog::Cancel);
    optionswdg = new Ui_KisWdgOptionsTIFF();
    optionswdg->setupUi(wdg);
    activated(0);
    connect(optionswdg->kComboBoxCompressionType, SIGNAL(activated(int)), this, SLOT(activated(int)));
    connect(optionswdg->flatten, SIGNAL(toggled(bool)), this, SLOT(flattenToggled(bool)));
    setMainWidget(wdg);
    qApp->restoreOverrideCursor();
    setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));

    QString filterConfig = KisConfig().exportConfiguration("TIFF");
    KisPropertiesConfiguration cfg;
    cfg.fromXML(filterConfig);

    optionswdg->kComboBoxCompressionType->setCurrentIndex(cfg.getInt("compressiontype", 0));
    activated(optionswdg->kComboBoxCompressionType->currentIndex());
    optionswdg->kComboBoxPredictor->setCurrentIndex(cfg.getInt("predictor", 0));
    optionswdg->alpha->setChecked(cfg.getBool("alpha", true));
    optionswdg->flatten->setChecked(cfg.getBool("flatten", true));
    flattenToggled(optionswdg->flatten->isChecked());
    optionswdg->qualityLevel->setValue(cfg.getInt("quality", 80));
    optionswdg->compressionLevelDeflate->setValue(cfg.getInt("deflate", 6));
    optionswdg->kComboBoxFaxMode->setCurrentIndex(cfg.getInt("faxmode", 0));
    optionswdg->compressionLevelPixarLog->setValue(cfg.getInt("pixarlog", 6));
}
void KisPropertiesConfigurationTest::testSerialization()
{
    KisPropertiesConfiguration* config = createConfig();
    QString xml = config->toXML();
    KisPropertiesConfiguration* decodedConfig = new KisPropertiesConfiguration();
    decodedConfig->fromXML(xml);
    testConfig(decodedConfig);
    delete config;
    delete decodedConfig;
}
void KisPropertiesConfigurationTest::testNotSavedValues()
{
    KisPropertiesConfiguration* config = createConfig();
    config->setPropertyNotSaved("v3");
    testConfig(config);
    QString s = config->toXML();
    delete config;
    config = new KisPropertiesConfiguration();
    config->fromXML(s);
    QVERIFY(config->getInt("v1", 0) == v1);
    QVERIFY(config->getString("v2", "") == v2);
    QVERIFY(config->hasProperty("v3") == false);
    QVERIFY(config->getBool("v4", !v4) == v4);
    QVERIFY(config->getCubicCurve("v5") == v5);
    delete config;   
}
예제 #4
0
KisImportExportFilter::ConversionStatus KisHeightMapExport::convert(const QByteArray& from, const QByteArray& to)
{
    dbgFile << "HeightMap export! From:" << from << ", To:" << to;

    if (from != "application/x-krita")
        return KisImportExportFilter::NotImplemented;

    KisDocument *inputDoc = inputDocument();
    QString filename = outputFile();

    if (!inputDoc)
        return KisImportExportFilter::NoDocumentCreated;

    if (filename.isEmpty()) return KisImportExportFilter::FileNotFound;

    KisImageWSP image = inputDoc->image();
    Q_CHECK_PTR(image);

    if (inputDoc->image()->width() != inputDoc->image()->height()) {
        inputDoc->setErrorMessage(i18n("Cannot export this image to a heightmap: it is not square"));
        return KisImportExportFilter::WrongFormat;
    }

    if (inputDoc->image()->colorSpace()->colorModelId() != GrayAColorModelID) {
        inputDoc->setErrorMessage(i18n("Cannot export this image to a heightmap: it is not grayscale"));
        return KisImportExportFilter::WrongFormat;
    }

    KoDialog* kdb = new KoDialog(0);
    kdb->setWindowTitle(i18n("HeightMap Export Options"));
    kdb->setButtons(KoDialog::Ok | KoDialog::Cancel);

    Ui::WdgOptionsHeightMap optionsHeightMap;

    QWidget* wdg = new QWidget(kdb);
    optionsHeightMap.setupUi(wdg);

    kdb->setMainWidget(wdg);
    QApplication::restoreOverrideCursor();

    QString filterConfig = KisConfig().exportConfiguration("HeightMap");
    KisPropertiesConfiguration cfg;
    cfg.fromXML(filterConfig);

    optionsHeightMap.intSize->setValue(image->width());

    int endianness = cfg.getInt("endianness", 0);
    QDataStream::ByteOrder bo = QDataStream::LittleEndian;
    optionsHeightMap.radioPC->setChecked(true);

    if (endianness == 0) {
        bo = QDataStream::BigEndian;
        optionsHeightMap.radioMac->setChecked(true);
    }

    if (!getBatchMode()) {
        if (kdb->exec() == QDialog::Rejected) {
            return KisImportExportFilter::UserCancelled;
        }
    }

    if (optionsHeightMap.radioMac->isChecked()) {
        cfg.setProperty("endianness", 0);
        bo = QDataStream::BigEndian;
    }
    else {
        cfg.setProperty("endianness", 1);
        bo = QDataStream::LittleEndian;
    }
    KisConfig().setExportConfiguration("HeightMap", cfg);

    bool downscale = false;
    if (to == "image/x-r8" && image->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) {

        downscale = (QMessageBox::question(0,
                                           i18nc("@title:window", "Downscale Image"),
                                           i18n("You specified the .r8 extension for a 16 bit/channel image. Do you want to save as 8 bit? Your image data will not be changed."),
                                           QMessageBox::Yes | QMessageBox::No)
                          == QMessageBox::Yes);
    }


    // the image must be locked at the higher levels
    KIS_SAFE_ASSERT_RECOVER_NOOP(image->locked());
    KisPaintDeviceSP pd = new KisPaintDevice(*image->projection());

    QFile f(filename);
    f.open(QIODevice::WriteOnly);
    QDataStream s(&f);
    s.setByteOrder(bo);

    KisRandomConstAccessorSP it = pd->createRandomConstAccessorNG(0, 0);
    bool r16 = ((image->colorSpace()->colorDepthId() == Integer16BitsColorDepthID) && !downscale);
    for (int i = 0; i < image->height(); ++i) {
        for (int j = 0; j < image->width(); ++j) {
            it->moveTo(i, j);
            if (r16) {
                s << KoGrayU16Traits::gray(const_cast<quint8*>(it->rawDataConst()));
            }
            else {
                s << KoGrayU8Traits::gray(const_cast<quint8*>(it->rawDataConst()));
            }
        }
    }

    f.close();
    return KisImportExportFilter::OK;
}