summaryrefslogtreecommitdiffstats
path: root/chalk/plugins/filters/convolutionfilters/kis_custom_convolution_filter.cpp
blob: dc73f197b063bc6e62e48d66a8007a9d3347bf13 (plain)
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
/*
 * This file is part of the KDE project
 *
 * Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
 *
 *  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 <kdebug.h>

#include "kis_custom_convolution_filter.h"

#include <tqspinbox.h>

#include "kis_convolution_painter.h"
#include "kis_custom_convolution_filter_configuration_widget.h"
#include "kis_custom_convolution_filter_configuration_base_widget.h"
#include "kis_matrix_widget.h"


KisFilterConfigWidget * KisCustomConvolutionFilter::createConfigurationWidget(TQWidget* parent, KisPaintDeviceSP)
{
    KisCustomConvolutionFilterConfigurationWidget* ccfcw = new KisCustomConvolutionFilterConfigurationWidget(this,parent, "custom convolution config widget");
    TQ_CHECK_PTR(ccfcw);
    return ccfcw;
}

KisFilterConfiguration * KisCustomConvolutionFilter::configuration(TQWidget* nwidget)
{
    KisCustomConvolutionFilterConfigurationWidget* widget = (KisCustomConvolutionFilterConfigurationWidget*) nwidget;

    if ( widget == 0 )
    {
        // Create the identity matrix:
        KisKernelSP kernel = new KisKernel();
        kernel->width = 3;
        kernel->height = 3;

        kernel->factor = 1;
        kernel->offset = 127;

        kernel->data = new TQ_INT32[9];
        kernel->data[0] = 0;
        kernel->data[1] = 0;
        kernel->data[2] = 0;
        kernel->data[3] = 0;
        kernel->data[4] = 1;
        kernel->data[5] = 0;
        kernel->data[6] = 0;
        kernel->data[7] = 0;
        kernel->data[8] = 0;

        return new KisConvolutionConfiguration( "custom convolution", kernel );
        
    } else {

        // Create the identity matrices:
        KisKernelSP kernel = new KisKernel();
        kernel->width = 3;
        kernel->height = 3;

        kernel->data = new TQ_INT32[9];

        KisCustomConvolutionFilterConfigurationBaseWidget* mw = widget->matrixWidget();

        kernel->data[0] = mw->matrixWidget->m11->value();
        kernel->data[1] = mw->matrixWidget->m21->value();
        kernel->data[2] = mw->matrixWidget->m31->value();
        kernel->data[3] = mw->matrixWidget->m12->value();
        kernel->data[4] = mw->matrixWidget->m22->value();
        kernel->data[5] = mw->matrixWidget->m32->value();
        kernel->data[6] = mw->matrixWidget->m13->value();
        kernel->data[7] = mw->matrixWidget->m23->value();
        kernel->data[8] = mw->matrixWidget->m33->value();

        kernel->factor = mw->spinBoxFactor->value();
        kernel->offset = mw->spinBoxOffset->value();

        return new KisConvolutionConfiguration( "custom convolution",  kernel );
    }
}