chalk

kis_math_toolbox.h
1/*
2 * This file is part of the KDE project
3 *
4 * Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#ifndef KIS_MATH_TOOLBOX_H
22#define KIS_MATH_TOOLBOX_H
23
24#include <tqobject.h>
25
26// typedef unsigned int uint;
27
28#include <kis_generic_registry.h>
29#include "kis_paint_device.h"
30#include "kis_types.h"
31
32#include <new>
33
34class KisMathToolbox : public TQObject {
35 TQ_OBJECT
36
37 public:
38 struct KisFloatRepresentation {
39 KisFloatRepresentation(uint nsize, uint ndepth) : coeffs(new float[nsize*nsize*ndepth]) ,size(nsize), depth(ndepth)
40 {
41 // XXX: Valgrind shows that these are being used without being initialised.
42 for (TQ_UINT32 i = 0; i < nsize*nsize*ndepth; ++i) {
43 coeffs[i] = 0;
44 }
45 }
46 ~KisFloatRepresentation() { if(coeffs) delete[] coeffs; }
47 float* coeffs;
48 uint size;
49 uint depth;
50 };
51 typedef KisFloatRepresentation KisWavelet;
52 public:
53 KisMathToolbox(KisID id);
54 ~KisMathToolbox();
55 public:
56 inline KisID id() { return m_id; };
61 inline KisWavelet* initWavelet(KisPaintDeviceSP lay, const TQRect&);
62 inline uint fastWaveletTotalSteps(const TQRect&);
71 virtual KisWavelet* fastWaveletTransformation(KisPaintDeviceSP src, const TQRect&, KisWavelet* buff = 0) =0;
81 virtual void fastWaveletUntransformation(KisPaintDeviceSP dst, const TQRect&, KisWavelet* wav, KisWavelet* buff = 0) =0;
82 signals:
83 void nextStep();
84 protected:
89 void transformToFR(KisPaintDeviceSP src, KisFloatRepresentation*, const TQRect&);
94 void transformFromFR(KisPaintDeviceSP dst, KisFloatRepresentation*, const TQRect&);
95 private:
96 KisID m_id;
97};
98
99class KisMathToolboxFactoryRegistry : public KisGenericRegistry<KisMathToolbox*> {
100 public:
101 KisMathToolboxFactoryRegistry();
102 ~KisMathToolboxFactoryRegistry();
103};
104
105
106inline KisMathToolbox::KisWavelet* KisMathToolbox::initWavelet(KisPaintDeviceSP src, const TQRect& rect)
107{
108 int size;
109 int maxrectsize = (rect.height() < rect.width()) ? rect.width() : rect.height();
110 for(size = 2; size < maxrectsize; size *= 2) ;
111 TQ_INT32 depth = src->colorSpace()->nColorChannels();
112 return new KisWavelet(size, depth);
113}
114
115inline uint KisMathToolbox::fastWaveletTotalSteps(const TQRect& rect)
116{
117 int size, steps;
118 int maxrectsize = (rect.height() < rect.width()) ? rect.width() : rect.height();
119 steps = 0;
120 for(size = 2; size < maxrectsize; size *= 2) steps += size / 2; ;
121 return steps;
122}
123
124#endif
Base class for registry objects in Chalk.
Chalk has a large number of extensible resources.
Definition kis_id.h:57