1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2010-02-23
 * Description : Black and White conversion batch tool.
 *
 * SPDX-FileCopyrightText: 2010-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#include "bwconvert.h"

// Qt includes

#include <QWidget>

// KDE includes

#include <klocalizedstring.h>

// Local includes

#include "dimg.h"
#include "bwsepiafilter.h"

namespace DigikamBqmBWConvertPlugin
{

BWConvert::BWConvert(QObject* const parent)
    : BatchTool(QLatin1String("BWConvert"), ColorTool, parent)
{
}

BatchTool* BWConvert::clone(QObject* const parent) const
{
    return new BWConvert(parent);
}

void BWConvert::registerSettingsWidget()
{
    m_settingsWidget = new QWidget;
    m_settingsView   = new BWSepiaSettings(m_settingsWidget, &m_preview);
    m_settingsView->startPreviewFilters();

    connect(m_settingsView, SIGNAL(signalSettingsChanged()),
            this, SLOT(slotSettingsChanged()));

    BatchTool::registerSettingsWidget();
}

void BWConvert::slotResetSettingsToDefault()<--- Derived function 'BWConvert::slotResetSettingsToDefault'
{
    // We need to call this method there to reset all curves points.
    // Curves values are cleaned with default settings passed after.

    m_settingsView->resetToDefault();
    BatchTool::slotResetSettingsToDefault();
}

BatchToolSettings BWConvert::defaultSettings()
{
    BatchToolSettings prm;
    BWSepiaContainer defaultPrm = m_settingsView->defaultSettings();

    prm.insert(QLatin1String("filmType"),   (int)defaultPrm.filmType);
    prm.insert(QLatin1String("filterType"), (int)defaultPrm.filterType);
    prm.insert(QLatin1String("toneType"),   (int)defaultPrm.toneType);
    prm.insert(QLatin1String("contrast"),   (double)defaultPrm.bcgPrm.contrast);
    prm.insert(QLatin1String("strength"),   (double)defaultPrm.strength);
    prm.insert(QLatin1String("curvesType"), defaultPrm.curvesPrm.curvesType);
    prm.insert(QLatin1String("curves"),     defaultPrm.curvesPrm.values[LuminosityChannel]);

    return prm;
}

void BWConvert::slotAssignSettings2Widget()
{
    BWSepiaContainer prm;

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

    m_settingsView->setSettings(prm);
}

void BWConvert::slotSettingsChanged()
{
    BatchToolSettings prm;
    BWSepiaContainer currentPrm = m_settingsView->settings();

    prm.insert(QLatin1String("filmType"),   (int)currentPrm.filmType);
    prm.insert(QLatin1String("filterType"), (int)currentPrm.filterType);
    prm.insert(QLatin1String("toneType"),   (int)currentPrm.toneType);
    prm.insert(QLatin1String("contrast"),   (double)currentPrm.bcgPrm.contrast);
    prm.insert(QLatin1String("strength"),   (double)currentPrm.strength);
    prm.insert(QLatin1String("curvesType"), (int)currentPrm.curvesPrm.curvesType);
    prm.insert(QLatin1String("curves"),     currentPrm.curvesPrm.values[LuminosityChannel]);

    BatchTool::slotSettingsChanged(prm);
}

bool BWConvert::toolOperations()
{
    if (!loadToDImg())
    {
        return false;
    }

    BWSepiaContainer prm;

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

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

    BWSepiaFilter bw(&image(), nullptr, prm);
    applyFilter(&bw);

    return (savefromDImg());
}

} // namespace DigikamBqmBWConvertPlugin

#include "moc_bwconvert.cpp"