krita

kis_math_toolbox.h

00001 /*
00002  *  This file is part of the KDE project
00003  *
00004  *  Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef KIS_MATH_TOOLBOX_H
00022 #define KIS_MATH_TOOLBOX_H
00023 
00024 #include <qobject.h>
00025 
00026 // typedef unsigned int uint;
00027 
00028 #include <kis_generic_registry.h>
00029 #include "kis_paint_device.h"
00030 #include "kis_types.h"
00031 
00032 #include <new>
00033 
00034 class KisMathToolbox : public QObject {
00035     Q_OBJECT
00036     public:
00037         struct KisFloatRepresentation {
00038             KisFloatRepresentation(uint nsize, uint ndepth) throw(std::bad_alloc ) : coeffs(new float[nsize*nsize*ndepth]) ,size(nsize), depth(ndepth)
00039             {
00040                 // XXX: Valgrind shows that these are being used without being initialised.
00041                 for (Q_UINT32 i = 0; i < nsize*nsize*ndepth; ++i) {
00042                     coeffs[i] = 0;
00043                 }
00044             }
00045             ~KisFloatRepresentation() { if(coeffs) delete[] coeffs; }
00046             float* coeffs;
00047             uint size;
00048             uint depth;
00049         };
00050         typedef KisFloatRepresentation KisWavelet;
00051     public:
00052         KisMathToolbox(KisID id);
00053         ~KisMathToolbox();
00054     public:
00055         inline KisID id() { return m_id; };
00060         inline KisWavelet* initWavelet(KisPaintDeviceSP lay, const QRect&) throw(std::bad_alloc );
00061         inline uint fastWaveletTotalSteps(const QRect&);
00070          virtual KisWavelet* fastWaveletTransformation(KisPaintDeviceSP src, const QRect&, KisWavelet* buff = 0) =0;
00080          virtual void fastWaveletUntransformation(KisPaintDeviceSP dst, const QRect&, KisWavelet* wav, KisWavelet* buff = 0) =0;
00081     signals:
00082         void nextStep();
00083     protected:
00088         void transformToFR(KisPaintDeviceSP src, KisFloatRepresentation*, const QRect&);
00093         void transformFromFR(KisPaintDeviceSP dst, KisFloatRepresentation*, const QRect&);
00094     private:
00095         KisID m_id;
00096 };
00097 
00098 class KisMathToolboxFactoryRegistry : public KisGenericRegistry<KisMathToolbox*> {
00099     public:
00100         KisMathToolboxFactoryRegistry();
00101         ~KisMathToolboxFactoryRegistry();
00102 };
00103 
00104 
00105 inline KisMathToolbox::KisWavelet* KisMathToolbox::initWavelet(KisPaintDeviceSP src, const QRect& rect) throw(std::bad_alloc )
00106 {
00107     int size;
00108     int maxrectsize = (rect.height() < rect.width()) ? rect.width() : rect.height();
00109     for(size = 2; size < maxrectsize; size *= 2) ;
00110     Q_INT32 depth = src->colorSpace()->nColorChannels();
00111     return new KisWavelet(size, depth);
00112 }
00113 
00114 inline uint KisMathToolbox::fastWaveletTotalSteps(const QRect& rect)
00115 {
00116     int size, steps;
00117     int maxrectsize = (rect.height() < rect.width()) ? rect.width() : rect.height();
00118     steps = 0;
00119     for(size = 2; size < maxrectsize; size *= 2) steps += size / 2; ;
00120     return steps;
00121 }
00122 
00123 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys