summaryrefslogtreecommitdiffstats
path: root/chalk/plugins/viewplugins/scripting/chalkcore/krs_wavelet.cpp
blob: 21ab7646465e98ff7d5093d056192dc846638db3 (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 *  This file is part of the KDE project
 *
 *  Copyright (c) 2006 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 "krs_wavelet.h"

#include <tdelocale.h>

#include <kis_math_toolbox.h>

namespace Kross {

namespace ChalkCore {

Wavelet::Wavelet(KisMathToolbox::KisWavelet* kwl)
    : Kross::Api::Class<Wavelet>("ChalkWavelet"), m_wavelet(kwl)
{
    addFunction("getNCoeff", &Wavelet::getNCoeff);
    addFunction("setNCoeff", &Wavelet::setNCoeff);
    addFunction("getXYCoeff", &Wavelet::getXYCoeff);
    addFunction("setXYCoeff", &Wavelet::setXYCoeff);
    addFunction("getDepth", &Wavelet::getDepth);
    addFunction("getSize", &Wavelet::getSize);
    addFunction("getNumCoeffs", &Wavelet::getNumCoeffs);
    m_numCoeff = m_wavelet->size*m_wavelet->size*m_wavelet->depth;
}


Wavelet::~Wavelet()
{
}


Kross::Api::Object::Ptr Wavelet::getNCoeff(Kross::Api::List::Ptr args)
{
    TQ_UINT32 n = Kross::Api::Variant::toUInt(args->item(0));
    if( n > m_numCoeff)
    {
        throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("An error has occured in %1").arg("getNCoeff") + "\n" + i18n("Index out of bound") ) );
    }
    return new Kross::Api::Variant(*(m_wavelet->coeffs + n ));
}

Kross::Api::Object::Ptr Wavelet::setNCoeff(Kross::Api::List::Ptr args)
{
    TQ_UINT32 n = Kross::Api::Variant::toUInt(args->item(0));
    double v = Kross::Api::Variant::toDouble(args->item(1));
    if( n > m_numCoeff)
    {
        throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("An error has occured in %1").arg("setNCoeff") + "\n" + i18n("Index out of bound") ) );
    }
    *(m_wavelet->coeffs + n ) = v;
    return 0;
}

Kross::Api::Object::Ptr Wavelet::getXYCoeff(Kross::Api::List::Ptr args)
{
    TQ_UINT32 x = Kross::Api::Variant::toUInt(args->item(0));
    TQ_UINT32 y = Kross::Api::Variant::toUInt(args->item(1));
    if( x > m_wavelet->size && y > m_wavelet->size)
    {
        throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("An error has occured in %1").arg("getXYCoeff") + "\n" + i18n("Index out of bound") ) );
    }
    return new Kross::Api::Variant(*(m_wavelet->coeffs  + (x + y * m_wavelet->size ) * m_wavelet->depth ));
}

Kross::Api::Object::Ptr Wavelet::setXYCoeff(Kross::Api::List::Ptr args)
{
    TQ_UINT32 x = Kross::Api::Variant::toUInt(args->item(0));
    TQ_UINT32 y = Kross::Api::Variant::toUInt(args->item(1));
    double v = Kross::Api::Variant::toDouble(args->item(2));
    if( x > m_wavelet->size && y > m_wavelet->size)
    {
        throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("An error has occured in %1").arg("setXYCoeff") + "\n" + i18n("Index out of bound") ));
    }
    *(m_wavelet->coeffs + (x + y * m_wavelet->size ) * m_wavelet->depth ) = v;
    return 0;
}

Kross::Api::Object::Ptr Wavelet::getDepth(Kross::Api::List::Ptr /*args*/)
{
    return new Kross::Api::Variant(m_wavelet->depth);
}

Kross::Api::Object::Ptr Wavelet::getSize(Kross::Api::List::Ptr)
{
    return new Kross::Api::Variant(m_wavelet->size);
}

Kross::Api::Object::Ptr Wavelet::getNumCoeffs(Kross::Api::List::Ptr)
{
    return new Kross::Api::Variant(m_numCoeff);
}


}

}