Esempio n. 1
0
bool AssignTemplate::toolOperations()
{
    DMetadata meta;

    if (image().isNull())
    {
        if (!meta.load(inputUrl().toLocalFile()))
        {
            return false;
        }
    }
    else
    {
        meta.setData(image().getMetadata());
    }

    QString title = settings()[QLatin1String("TemplateTitle")].toString();

    if (title == Template::removeTemplateTitle())
    {
        meta.removeMetadataTemplate();
    }
    else if (title.isEmpty())
    {
        // Nothing to do.
    }
    else
    {
        Template t = TemplateManager::defaultManager()->findByTitle(title);
        meta.removeMetadataTemplate();
        meta.setMetadataTemplate(t);
    }

    bool ret = true;

    if (image().isNull())
    {
        QFile::remove(outputUrl().toLocalFile());
        ret = QFile::copy(inputUrl().toLocalFile(), outputUrl().toLocalFile());

        if (ret && !title.isEmpty())
        {
            ret = meta.save(outputUrl().toLocalFile());
        }
    }
    else
    {
        if (!title.isEmpty())
        {
            image().setMetadata(meta.data());
        }

        ret = savefromDImg();
    }

    return ret;
}
Esempio n. 2
0
OvenCLIApplication::OvenCLIApplication(int argc, char* argv[]) :
    QCoreApplication(argc, argv)
{
    // parse the command line parameters
    QCommandLineParser parser;

    parser.addOptions({
        { CLI_INPUT_PARAMETER, "Path to file that you would like to bake.", "input" },
        { CLI_OUTPUT_PARAMETER, "Path to folder that will be used as output.", "output" },
        { CLI_TYPE_PARAMETER, "Type of asset.", "type" },
        { CLI_DISABLE_TEXTURE_COMPRESSION_PARAMETER, "Disable texture compression." }
    });

    parser.addHelpOption();
    parser.process(*this);

    if (parser.isSet(CLI_INPUT_PARAMETER) && parser.isSet(CLI_OUTPUT_PARAMETER)) {
        BakerCLI* cli = new BakerCLI(this);
        QUrl inputUrl(QDir::fromNativeSeparators(parser.value(CLI_INPUT_PARAMETER)));
        QUrl outputUrl(QDir::fromNativeSeparators(parser.value(CLI_OUTPUT_PARAMETER)));
        QString type = parser.isSet(CLI_TYPE_PARAMETER) ? parser.value(CLI_TYPE_PARAMETER) : QString::null;

        if (parser.isSet(CLI_DISABLE_TEXTURE_COMPRESSION_PARAMETER)) {
            qDebug() << "Disabling texture compression";
            TextureBaker::setCompressionEnabled(false);
        }

        QMetaObject::invokeMethod(cli, "bakeFile", Qt::QueuedConnection, Q_ARG(QUrl, inputUrl),
                                    Q_ARG(QString, outputUrl.toString()), Q_ARG(QString, type));
    } else {
        parser.showHelp();
        QCoreApplication::quit();
    }

}
Esempio n. 3
0
bool Flip::toolOperations()
{
    DImg::FLIP flip = (DImg::FLIP)(settings()[QLatin1String("Flip")].toInt());

    if (JPEGUtils::isJpegImage(inputUrl().toLocalFile()) && image().isNull())
    {
        JPEGUtils::JpegRotator rotator(inputUrl().toLocalFile());
        rotator.setDestinationFile(outputUrl().toLocalFile());

        switch (flip)
        {
            case DImg::HORIZONTAL:
                return rotator.exifTransform(MetaEngineRotation::FlipHorizontal);
                break;

            case DImg::VERTICAL:
                return rotator.exifTransform(MetaEngineRotation::FlipVertical);
                break;

            default:
                qCDebug(DIGIKAM_DPLUGIN_BQM_LOG) << "Unknown flip action";
                return false;
                break;
        }
    }

    if (!loadToDImg())
    {
        return false;
    }

    DImgBuiltinFilter filter;
    switch (flip)
    {
        case DImg::HORIZONTAL:
            filter = DImgBuiltinFilter(DImgBuiltinFilter::FlipHorizontally);
            break;
        case DImg::VERTICAL:
            filter = DImgBuiltinFilter(DImgBuiltinFilter::FlipVertically);
            break;
    }
    applyFilter(&filter);

    return (savefromDImg());
}
Esempio n. 4
0
bool UserScript::toolOperations()
{
    QString script = settings()[QLatin1String("Script")].toString();

    if (script.isEmpty())
    {
        setErrorDescription(i18n("User Script: No script."));
        return false;
    }

    // Replace all occurences of $INPUT and $OUTPUT in script to file names. Case sensitive.
    script.replace(QLatin1String("$INPUT"),  QLatin1Char('"') + inputUrl().toLocalFile()  + QLatin1Char('"'));
    script.replace(QLatin1String("$OUTPUT"), QLatin1Char('"') + outputUrl().toLocalFile() + QLatin1Char('"'));

    QString shellScript;

#ifndef WIN32
    QString envCmd  = QLatin1String("export ");
#else
    QString envCmd  = QLatin1String("set ");
#endif // WIN32

    QString tagPath = TagsCache::instance()->tagPaths(imageInfo().tagIds(), TagsCache::NoLeadingSlash,
                                                      TagsCache::NoHiddenTags).join(QLatin1Char(';'));

    // Populate env variables from metadata
    shellScript.append(envCmd + QString::fromUtf8("COLORLABEL=\"%1\"\n").arg(imageInfo().colorLabel()));
    shellScript.append(envCmd + QString::fromUtf8("PICKLABEL=\"%1\"\n") .arg(imageInfo().pickLabel()));
    shellScript.append(envCmd + QString::fromUtf8("COMMENTS=\"%1\"\n")  .arg(imageInfo().comment()));
    shellScript.append(envCmd + QString::fromUtf8("RATING=\"%1\"\n")    .arg(imageInfo().rating()));
    shellScript.append(envCmd + QString::fromUtf8("TITLE=\"%1\"\n")     .arg(imageInfo().title()));
    shellScript.append(envCmd + QString::fromUtf8("TAGSPATH=\"%1\"\n")  .arg(tagPath));
    shellScript.append(script);

    // Empties d->image, not to pass it to the next tool in chain
    setImageData(DImg());

    QProcess process(this);

    // call the shell script
#ifndef WIN32
    int returncode = process.execute(QLatin1String("/bin/sh"), QStringList() << QLatin1String("-c") << shellScript);
#else
    int returncode = process.execute(QLatin1String("cmd.exe"), QStringList() << QLatin1String("/c") << shellScript);
#endif // WIN32

    if (returncode == -2)
    {
        setErrorDescription(i18n("User Script: Failed to start script."));
        return false;
    }

    if (returncode == -1)
    {
        setErrorDescription(i18n("User Script: Script process crashed."));
        return false;
    }

    if (returncode == 127)
    {
        setErrorDescription(i18n("User Script: Command not found."));
        return false;
    }

    return true;
}