krita
kis_math_toolbox.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KIS_MATH_TOOLBOX_H
00022 #define KIS_MATH_TOOLBOX_H
00023
00024 #include <qobject.h>
00025
00026
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
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
|