summaryrefslogtreecommitdiffstats
path: root/chalk/core/kis_math_toolbox.h
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
commit698569f8428ca088f764d704034a1330517b98c0 (patch)
treebf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /chalk/core/kis_math_toolbox.h
parent2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff)
downloadkoffice-698569f8428ca088f764d704034a1330517b98c0.tar.gz
koffice-698569f8428ca088f764d704034a1330517b98c0.zip
Finish rebranding of Krita as Chalk
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238363 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'chalk/core/kis_math_toolbox.h')
-rw-r--r--chalk/core/kis_math_toolbox.h124
1 files changed, 124 insertions, 0 deletions
diff --git a/chalk/core/kis_math_toolbox.h b/chalk/core/kis_math_toolbox.h
new file mode 100644
index 00000000..8d5bef50
--- /dev/null
+++ b/chalk/core/kis_math_toolbox.h
@@ -0,0 +1,124 @@
+/*
+ * This file is part of the KDE project
+ *
+ * Copyright (c) 2005 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.
+ */
+
+#ifndef KIS_MATH_TOOLBOX_H
+#define KIS_MATH_TOOLBOX_H
+
+#include <tqobject.h>
+
+// typedef unsigned int uint;
+
+#include <kis_generic_registry.h>
+#include "kis_paint_device.h"
+#include "kis_types.h"
+
+#include <new>
+
+class KisMathToolbox : public TQObject {
+ Q_OBJECT
+ TQ_OBJECT
+ public:
+ struct KisFloatRepresentation {
+ KisFloatRepresentation(uint nsize, uint ndepth) throw(std::bad_alloc ) : coeffs(new float[nsize*nsize*ndepth]) ,size(nsize), depth(ndepth)
+ {
+ // XXX: Valgrind shows that these are being used without being initialised.
+ for (TQ_UINT32 i = 0; i < nsize*nsize*ndepth; ++i) {
+ coeffs[i] = 0;
+ }
+ }
+ ~KisFloatRepresentation() { if(coeffs) delete[] coeffs; }
+ float* coeffs;
+ uint size;
+ uint depth;
+ };
+ typedef KisFloatRepresentation KisWavelet;
+ public:
+ KisMathToolbox(KisID id);
+ ~KisMathToolbox();
+ public:
+ inline KisID id() { return m_id; };
+ /**
+ * This function initialize a wavelet structure
+ * @param lay the layer that will be used for the transformation
+ */
+ inline KisWavelet* initWavelet(KisPaintDeviceSP lay, const TQRect&) throw(std::bad_alloc );
+ inline uint fastWaveletTotalSteps(const TQRect&);
+ /**
+ * This function reconstruct the layer from the information of a wavelet
+ * @param src layer from which the wavelet will be computed
+ * @param buff if set to 0, the buffer will be initialized by the function,
+ * you might want to give a buff to the function if you want to use the same buffer
+ * in transformToWavelet and in untransformToWavelet, use initWavelet to initialize
+ * the buffer
+ */
+ virtual KisWavelet* fastWaveletTransformation(KisPaintDeviceSP src, const TQRect&, KisWavelet* buff = 0) =0;
+ /**
+ * This function reconstruct the layer from the information of a wavelet
+ * @param dst layer on which the wavelet will be untransform
+ * @param wav the wavelet
+ * @param buff if set to 0, the buffer will be initialized by the function,
+ * you might want to give a buff to the function if you want to use the same buffer
+ * in transformToWavelet and in untransformToWavelet, use initWavelet to initialize
+ * the buffer
+ */
+ virtual void fastWaveletUntransformation(KisPaintDeviceSP dst, const TQRect&, KisWavelet* wav, KisWavelet* buff = 0) =0;
+ signals:
+ void nextStep();
+ protected:
+ /**
+ * This function transform a paint device into a KisFloatRepresentation, this function is colorspace independant,
+ * for Wavelet, Pyramid and FFT the data is allways the exact value of the channel stored in a float.
+ */
+ void transformToFR(KisPaintDeviceSP src, KisFloatRepresentation*, const TQRect&);
+ /**
+ * This function transform a KisFloatRepresentation into a paint device, this function is colorspace independant,
+ * for Wavelet, Pyramid and FFT the data is allways the exact value of the channel stored in a float.
+ */
+ void transformFromFR(KisPaintDeviceSP dst, KisFloatRepresentation*, const TQRect&);
+ private:
+ KisID m_id;
+};
+
+class KisMathToolboxFactoryRegistry : public KisGenericRegistry<KisMathToolbox*> {
+ public:
+ KisMathToolboxFactoryRegistry();
+ ~KisMathToolboxFactoryRegistry();
+};
+
+
+inline KisMathToolbox::KisWavelet* KisMathToolbox::initWavelet(KisPaintDeviceSP src, const TQRect& rect) throw(std::bad_alloc )
+{
+ int size;
+ int maxrectsize = (rect.height() < rect.width()) ? rect.width() : rect.height();
+ for(size = 2; size < maxrectsize; size *= 2) ;
+ TQ_INT32 depth = src->colorSpace()->nColorChannels();
+ return new KisWavelet(size, depth);
+}
+
+inline uint KisMathToolbox::fastWaveletTotalSteps(const TQRect& rect)
+{
+ int size, steps;
+ int maxrectsize = (rect.height() < rect.width()) ? rect.width() : rect.height();
+ steps = 0;
+ for(size = 2; size < maxrectsize; size *= 2) steps += size / 2; ;
+ return steps;
+}
+
+#endif