コード例 #1
0
ファイル: bwconvert.cpp プロジェクト: KDE/digikam
bool BWConvert::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    BWSepiaContainer prm;

    prm.filmType                     = settings()[QLatin1String("filmType")].toInt();
    prm.filterType                   = settings()[QLatin1String("filterType")].toInt();
    prm.toneType                     = settings()[QLatin1String("toneType")].toInt();
    prm.bcgPrm.contrast              = settings()[QLatin1String("contrast")].toDouble();
    prm.strength                     = settings()[QLatin1String("strength")].toDouble();

    CurvesContainer curves((ImageCurves::CurveType)settings()[QLatin1String("curvesType")].toInt(), true);
    curves.initialize();
    curves.values[LuminosityChannel] = settings()[QLatin1String("curves")].value<QPolygon>();
    prm.curvesPrm                    = curves;

    BWSepiaFilter bw(&image(), 0L, prm);
    applyFilter(&bw);

    return (savefromDImg());
}
コード例 #2
0
ファイル: filmgrain.cpp プロジェクト: rickysarraf/digikam
bool FilmGrain::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    FilmGrainContainer prm;
    prm.grainSize               = settings()["grainSize"].toInt();
    prm.photoDistribution       = settings()["photoDistribution"].toBool();
    prm.addLuminanceNoise       = settings()["addLuminanceNoise"].toBool();
    prm.lumaIntensity           = settings()["lumaIntensity"].toInt();
    prm.lumaShadows             = settings()["lumaShadows"].toInt();
    prm.lumaMidtones            = settings()["lumaMidtones"].toInt();
    prm.lumaHighlights          = settings()["lumaHighlights"].toInt();
    prm.addChrominanceBlueNoise = settings()["addChrominanceBlueNoise"].toBool();
    prm.chromaBlueIntensity     = settings()["chromaBlueIntensity"].toInt();
    prm.chromaBlueShadows       = settings()["chromaBlueShadows"].toInt();
    prm.chromaBlueMidtones      = settings()["chromaBlueMidtones"].toInt();
    prm.chromaBlueHighlights    = settings()["chromaBlueHighlights"].toInt();
    prm.addChrominanceRedNoise  = settings()["addChrominanceRedNoise"].toBool();
    prm.chromaRedIntensity      = settings()["chromaRedIntensity"].toInt();
    prm.chromaRedShadows        = settings()["chromaRedShadows"].toInt();
    prm.chromaRedMidtones       = settings()["chromaRedMidtones"].toInt();
    prm.chromaRedHighlights     = settings()["chromaRedHighlights"].toInt();

    FilmGrainFilter fg(&image(), 0L, prm);
    applyFilter(&fg);

    return savefromDImg();
}
コード例 #3
0
ファイル: sharpen.cpp プロジェクト: UIKit0/digikam
bool Sharpen::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    int filterType  = settings()["SharpenFilterType"].toInt();

    switch (filterType)
    {
        case SharpContainer::SimpleSharp:
        {
            double radius = settings()["SimpleSharpRadius"].toInt() / 10.0;
            double sigma;

            if (radius < 1.0)
            {
                sigma = radius;
            }
            else
            {
                sigma = sqrt(radius);
            }

            SharpenFilter filter(&image(), 0L, radius, sigma);
            filter.startFilterDirectly();
            image().putImageData(filter.getTargetImage().bits());
            break;
        }

        case SharpContainer::UnsharpMask:
        {
            int r     = (int)settings()["UnsharpMaskRadius"].toDouble();
            double a  = settings()["UnsharpMaskAmount"].toDouble();
            double th = settings()["UnsharpMaskThreshold"].toDouble();

            UnsharpMaskFilter filter(&image(), 0L, r, a, th);
            filter.startFilterDirectly();
            image().putImageData(filter.getTargetImage().bits());
            break;
        }

        case SharpContainer::Refocus:
        {
            double radius      = settings()["RefocusRadius"].toDouble();
            double correlation = settings()["RefocusCorrelation"].toDouble();
            double noise       = settings()["RefocusNoise"].toDouble();
            double gauss       = settings()["RefocusGauss"].toDouble();
            int matrixSize     = settings()["RefocusMatrixSize"].toInt();

            RefocusFilter filter(&image(), 0L, matrixSize, radius, gauss, correlation, noise);
            filter.startFilterDirectly();
            image().putImageData(filter.getTargetImage().bits());
            break;
        }
    }

    return savefromDImg();
}
コード例 #4
0
ファイル: channelmixer.cpp プロジェクト: UIKit0/digikam
bool ChannelMixer::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    MixerContainer prm;

    prm.bPreserveLum   = settings()["bPreserveLum"].toBool();
    prm.bMonochrome    = settings()["bMonochrome"].toBool();

    // Standard settings.
    prm.redRedGain     = settings()["redRedGain"].toDouble();
    prm.redGreenGain   = settings()["redGreenGain"].toDouble();
    prm.redBlueGain    = settings()["redBlueGain"].toDouble();
    prm.greenRedGain   = settings()["greenRedGain"].toDouble();
    prm.greenGreenGain = settings()["greenGreenGain"].toDouble();
    prm.greenBlueGain  = settings()["greenBlueGain"].toDouble();
    prm.blueRedGain    = settings()["blueRedGain"].toDouble();
    prm.blueGreenGain  = settings()["blueGreenGain"].toDouble();
    prm.blueBlueGain   = settings()["blueBlueGain"].toDouble();

    // Monochrome settings.
    prm.blackRedGain   = settings()["blackRedGain"].toDouble();
    prm.blackGreenGain = settings()["blackGreenGain"].toDouble();
    prm.blackBlueGain  = settings()["blackBlueGain"].toDouble();

    MixerFilter mixer(&image(), 0L, prm);
    mixer.startFilterDirectly();
    image().putImageData(mixer.getTargetImage().bits());

    return (savefromDImg());
}
コード例 #5
0
ファイル: border.cpp プロジェクト: KDE/digikam
bool Border::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    BorderContainer prm;
    prm.preserveAspectRatio   = settings()[QLatin1String("preserveAspectRatio")].toBool();
    prm.borderType            = settings()[QLatin1String("borderType")].toInt();
    prm.borderWidth1          = settings()[QLatin1String("borderWidth1")].toInt();
    prm.borderWidth2          = settings()[QLatin1String("borderWidth2")].toInt();
    prm.borderWidth3          = settings()[QLatin1String("borderWidth3")].toInt();
    prm.borderWidth4          = settings()[QLatin1String("borderWidth4")].toInt();
    prm.borderPercent         = settings()[QLatin1String("borderPercent")].toDouble();
    prm.borderPath            = settings()[QLatin1String("borderPath")].toString();
    prm.solidColor            = settings()[QLatin1String("solidColor")].value<QColor>();
    prm.niepceBorderColor     = settings()[QLatin1String("niepceBorderColor")].value<QColor>();
    prm.niepceLineColor       = settings()[QLatin1String("niepceLineColor")].value<QColor>();
    prm.bevelUpperLeftColor   = settings()[QLatin1String("bevelUpperLeftColor")].value<QColor>();
    prm.bevelLowerRightColor  = settings()[QLatin1String("bevelLowerRightColor")].value<QColor>();
    prm.decorativeFirstColor  = settings()[QLatin1String("decorativeFirstColor")].value<QColor>();
    prm.decorativeSecondColor = settings()[QLatin1String("decorativeSecondColor")].value<QColor>();
    prm.orgWidth              = image().width();
    prm.orgHeight             = image().height();

    BorderFilter bd(&image(), 0L, prm);
    applyFilterChangedProperties(&bd);

    return (savefromDImg());
}
コード例 #6
0
bool AssignTemplate::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

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

    DMetadata meta(image().getMetadata());

    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);
    }

    image().setMetadata(meta.data());

    return (savefromDImg());
}
コード例 #7
0
ファイル: sharpen.cpp プロジェクト: rickysarraf/digikam
bool Sharpen::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    int filterType  = settings()["SharpenFilterType"].toInt();

    switch (filterType)
    {
        case SharpContainer::SimpleSharp:
        {
            double radius = settings()["SimpleSharpRadius"].toInt() / 10.0;
            double sigma;

            if (radius < 1.0)
            {
                sigma = radius;
            }
            else
            {
                sigma = sqrt(radius);
            }

            SharpenFilter filter(&image(), 0L, radius, sigma);
            applyFilter(&filter);
            break;
        }

        case SharpContainer::UnsharpMask:
        {
            double r     = settings()["UnsharpMaskRadius"].toDouble();
            double a  = settings()["UnsharpMaskAmount"].toDouble();
            double th = settings()["UnsharpMaskThreshold"].toDouble();

            UnsharpMaskFilter filter(&image(), 0L, r, a, th);
            applyFilter(&filter);
            break;
        }

        case SharpContainer::Refocus:
        {
#ifdef HAVE_EIGEN3
            double radius      = settings()["RefocusRadius"].toDouble();
            double correlation = settings()["RefocusCorrelation"].toDouble();
            double noise       = settings()["RefocusNoise"].toDouble();
            double gauss       = settings()["RefocusGauss"].toDouble();
            int matrixSize     = settings()["RefocusMatrixSize"].toInt();

            RefocusFilter filter(&image(), 0L, matrixSize, radius, gauss, correlation, noise);
            applyFilter(&filter);
#endif // HAVE_EIGEN3
            break;
        }
    }

    return savefromDImg();
}
コード例 #8
0
ファイル: convert2tiff.cpp プロジェクト: KDE/digikam
bool Convert2TIFF::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    image().setAttribute(QLatin1String("compress"), settings()[QLatin1String("compress")].toBool());

    return (savefromDImg());
}
コード例 #9
0
ファイル: convert8to16.cpp プロジェクト: Match-Yang/digikam
bool Convert8to16::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    DImgBuiltinFilter filter(DImgBuiltinFilter::ConvertTo16Bit);
    applyFilter(&filter);

    return (savefromDImg());
}
コード例 #10
0
ファイル: lensautofix.cpp プロジェクト: swatilodha/digikam
bool LensAutoFix::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    LensFunContainer prm;

    bool useMeta = settings()[QLatin1String("UseMetadata")].toBool();

    if (useMeta)
    {
        LensFunIface iface;
        DMetadata    meta(image().getMetadata());
        LensFunIface::MetadataMatch ret = iface.findFromMetadata(meta);
        prm                             = iface.settings();

        if (ret != LensFunIface::MetadataExactMatch)
        {
            setErrorDescription(i18n("Cannot find all lens information to process lens auto-corrections"));
            return false;
        }
    }
    else
    {
        prm.filterCCA       = settings()[QLatin1String("filterCCA")].toBool();
        prm.filterVIG       = settings()[QLatin1String("filterVIG")].toBool();
        prm.filterDST       = settings()[QLatin1String("filterDST")].toBool();
        prm.filterGEO       = settings()[QLatin1String("filterGEO")].toBool();

        prm.cropFactor      = settings()[QLatin1String("cropFactor")].toDouble();
        prm.focalLength     = settings()[QLatin1String("focalLength")].toDouble();
        prm.aperture        = settings()[QLatin1String("aperture")].toDouble();
        prm.subjectDistance = settings()[QLatin1String("subjectDistance")].toDouble();

        QString cameraMake  = settings()[QLatin1String("cameraMake")].toString();
        QString cameraModel = settings()[QLatin1String("cameraModel")].toString();
        QString lensModel   = settings()[QLatin1String("lensModel")].toString();
    }

    LensFunFilter filter(&image(), 0L, prm);
    applyFilter(&filter);

    MetaEngineData data = image().getMetadata();
    filter.registerSettingsToXmp(data);
    image().setMetadata(data);

    return savefromDImg();
}
コード例 #11
0
ファイル: autocorrection.cpp プロジェクト: UIKit0/digikam
bool AutoCorrection::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    int type = settings()["AutoCorrectionFilter"].toInt();

    switch (type)
    {
        case AutoLevelsCorrection:
        {
            AutoLevelsFilter autolevels(&image(), &image());
            autolevels.startFilterDirectly();
            image().putImageData(autolevels.getTargetImage().bits());
            break;
        }
        case NormalizeCorrection:
        {
            NormalizeFilter normalize(&image(), &image());
            normalize.startFilterDirectly();
            image().putImageData(normalize.getTargetImage().bits());
            break;
        }
        case EqualizeCorrection:
        {
            EqualizeFilter equalize(&image(), &image());
            equalize.startFilterDirectly();
            image().putImageData(equalize.getTargetImage().bits());
            break;
        }
        case StretchContrastCorrection:
        {
            StretchFilter stretch(&image(), &image());
            stretch.startFilterDirectly();
            image().putImageData(stretch.getTargetImage().bits());
            break;
        }
        case AutoExposureCorrection:
        {
            AutoExpoFilter expo(&image(), &image());
            expo.startFilterDirectly();
            image().putImageData(expo.getTargetImage().bits());
            break;
        }
    }

    return (savefromDImg());
}
コード例 #12
0
ファイル: colorfx.cpp プロジェクト: rickysarraf/digikam
bool ColorFX::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    ColorFXContainer prm;
    prm.colorFXType = settings()["colorFXType"].toInt();
    prm.level       = settings()["level"].toInt();
    prm.iterations  = settings()["iterations"].toInt();

    ColorFXFilter fg(&image(), 0L, prm);
    applyFilter(&fg);

    return savefromDImg();
}
コード例 #13
0
ファイル: flip.cpp プロジェクト: rompe/digikam
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());
}
コード例 #14
0
ファイル: colorbalance.cpp プロジェクト: UIKit0/digikam
bool ColorBalance::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    CBContainer prm;
    prm.red   = settings()["Red"].toDouble();
    prm.green = settings()["Green"].toDouble();
    prm.blue  = settings()["Blue"].toDouble();

    CBFilter cb(&image(), 0L, prm);
    cb.startFilterDirectly();
    image().putImageData(cb.getTargetImage().bits());

    return (savefromDImg());
}
コード例 #15
0
ファイル: redeyecorrection.cpp プロジェクト: KDE/digikam
bool RedEyeCorrection::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    RedEyeCorrectionContainer prm;
    prm.m_redToAvgRatio = settings()[QLatin1String("redtoavgratio")].toDouble();

    m_redEyeCFilter = new RedEyeCorrectionFilter(&image(), 0L, prm);
    applyFilter(m_redEyeCFilter);

    delete m_redEyeCFilter;
    m_redEyeCFilter = 0;

    return (savefromDImg());
}
コード例 #16
0
ファイル: bwconvert.cpp プロジェクト: UIKit0/digikam
bool BWConvert::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    BWSepiaContainer prm;

    prm.filmType               = settings()["filmType"].toInt();
    prm.filterType             = settings()["filterType"].toInt();
    prm.toneType               = settings()["toneType"].toInt();
    prm.bcgPrm.contrast        = settings()["contrast"].toDouble();
    prm.strength               = settings()["strength"].toDouble();
    prm.curvesPrm.values[LuminosityChannel] = settings()["curves"].value<QPolygon>();

    BWSepiaFilter bw(&image(), 0L, prm);
    bw.startFilterDirectly();
    image().putImageData(bw.getTargetImage().bits());

    return (savefromDImg());
}
コード例 #17
0
ファイル: watermark.cpp プロジェクト: KDE/digikam
bool WaterMark::toolOperations()
{

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

    QString fileName        = settings()[QLatin1String("Watermark image")].toString();
    int placement           = settings()[QLatin1String("Placement")].toInt();
    int size                = settings()[QLatin1String("Watermark size")].toInt();
    int xMargin             = settings()[QLatin1String("X margin")].toInt();
    int yMargin             = settings()[QLatin1String("Y margin")].toInt();
    bool useImage           = settings()[QLatin1String("Use image")].toBool();

    QString text            = settings()[QLatin1String("Text")].toString();
    QFont font              = settings()[QLatin1String("Font")].toString();
    QColor fontColor        = settings()[QLatin1String("Color")].toString();
    int textOpacity         = settings()[QLatin1String("Text opacity")].toInt();
    bool useBackground      = settings()[QLatin1String("Use background")].toBool();
    QColor backgroundColor  = settings()[QLatin1String("Background color")].toString();
    int backgroundOpacity   = settings()[QLatin1String("Background opacity")].toInt();


    DImg watermarkImage;
    DColorComposer* composer = DColorComposer::getComposer(DColorComposer::PorterDuffNone);
    int marginW              = lround(image().width()  * (xMargin / 100.0));
    int marginH              = lround(image().height() * (yMargin / 100.0));

    if (useImage)
    {
        watermarkImage = DImg(fileName);

        if (watermarkImage.isNull())
        {
            return false;
        }

        DImg tempImage = watermarkImage.smoothScale(image().width() * size / 100, image().height() * size / 100, Qt::KeepAspectRatio);
        watermarkImage = tempImage;
    }
    else
    {
        int alignMode;
        const int radius = 10;

        if (text.isEmpty())
        {
            return false;
        }

        int fontSize = queryFontSize(text, font, size);

        if (fontSize == 0)
        {
            return false;
        }

        switch (placement)
        {
            case Private::TopLeft:
                alignMode = Qt::AlignLeft;
                break;

            case Private::TopRight:
                alignMode = Qt::AlignRight;
                break;

            case Private::BottomLeft:
                alignMode = Qt::AlignLeft;
                break;

            case Private::Center:
                alignMode = Qt::AlignCenter;
                break;

            default :    // BottomRight
                alignMode = Qt::AlignRight;
                break;
        }

        font.setPointSizeF(fontSize);
        QFontMetrics fontMt(font);
        QRect fontRect = fontMt.boundingRect(radius, radius, image().width(), image().height(), 0, text);

        // Add a transparent layer.
        QRect backgroundRect(fontRect.x() - radius, fontRect.y() - radius,
                             fontRect.width() + 2 * radius, fontRect.height() + 2 * radius);
        DImg backgroundLayer(backgroundRect.width(), backgroundRect.height(), image().sixteenBit(), true);
        DColor transparent(QColor(0, 0, 0));
        transparent.setAlpha(0);

        if (image().sixteenBit())
        {
            transparent.convertToSixteenBit();
        }

        backgroundLayer.fill(transparent);

        DImg grayTransLayer(fontRect.width(), fontRect.height(), image().sixteenBit(), true);

        if (useBackground)
        {
            DColor grayTrans(backgroundColor);
            grayTrans.setAlpha(backgroundOpacity * 255 / 100);

            if (image().sixteenBit())
            {
                grayTrans.convertToSixteenBit();
            }

            grayTransLayer.fill(grayTrans);
            backgroundLayer.bitBlendImage(composer, &grayTransLayer, 0, 0,
                                          grayTransLayer.width(), grayTransLayer.height(),
                                          radius, radius);
        }

        BlurFilter blur(&backgroundLayer, 0L, radius);
        blur.startFilterDirectly();
        backgroundLayer.putImageData(blur.getTargetImage().bits());

        // Draw text
        QImage img = backgroundLayer.copyQImage(fontRect);
        QPainter p(&img);
        fontColor.setAlpha(textOpacity * 255 / 100);
        p.setPen(QPen(fontColor, 1));
        p.setFont(font);
        p.save();
        p.drawText(0, 0, fontRect.width(), fontRect.height(), alignMode, text);
        p.restore();
        p.end();

        watermarkImage = DImg(img);
    }

    watermarkImage.convertToDepthOfImage(&image());

    QRect watermarkRect(0, 0, watermarkImage.width(), watermarkImage.height());

    switch (placement)
    {
        case Private::TopLeft:
            watermarkRect.moveTopLeft(QPoint(marginW, marginH));
            break;

        case Private::TopRight:
            watermarkRect.moveTopRight(QPoint(image().width() - marginW, marginH));
            break;

        case Private::BottomLeft:
            watermarkRect.moveBottomLeft(QPoint(marginW, image().height() - marginH));
            break;

        case Private::Center:
            watermarkRect.moveCenter(QPoint((int)(image().width() / 2), (int)(image().height() / 2)));
            break;

        default :    // BottomRight
            watermarkRect.moveBottomRight(QPoint(image().width() - marginW, image().height() - marginH));
            break;
    }

    // TODO: Create watermark filter, move code there, implement FilterAction

    image().bitBlendImage(composer, &watermarkImage, 0, 0, watermarkImage.width(), watermarkImage.height(),
                          watermarkRect.left(), watermarkRect.top());

    delete composer;

    return (savefromDImg());
}