summaryrefslogtreecommitdiffstats
path: root/chalk/core/kis_alpha_mask.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_alpha_mask.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_alpha_mask.h')
-rw-r--r--chalk/core/kis_alpha_mask.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/chalk/core/kis_alpha_mask.h b/chalk/core/kis_alpha_mask.h
new file mode 100644
index 00000000..4665857e
--- /dev/null
+++ b/chalk/core/kis_alpha_mask.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2004 Boudewijn Rempt <[email protected]>
+ *
+ * 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_ALPHA_MASK_
+#define KIS_ALPHA_MASK_
+
+#include <tqimage.h>
+#include <tqvaluevector.h>
+
+#include <ksharedptr.h>
+
+#include "kis_global.h"
+#include "kis_types.h"
+
+/**
+ * KisAlphaMask is intended to create alpha values from a TQImage for use
+ * in brush creation. It is not a generic alpha tqmask that can be used with
+ * KisPaintDevices: use a KisSelection for that.
+ */
+class KisAlphaMask : public KShared {
+
+ public:
+ /**
+ Create an alpha tqmask based on the specified TQImage. If the image is
+ not a grayscale, the tqmask value is calculated from the effective grey
+ level and alpha value.
+ */
+ KisAlphaMask(const TQImage& img);
+
+ /**
+ As above except quicker as the image does not need to be scanned
+ to see if it has any colour pixels.
+ */
+ KisAlphaMask(const TQImage& img, bool hasColor);
+
+ /**
+ Create a transparent tqmask.
+ */
+ KisAlphaMask(TQ_INT32 width, TQ_INT32 height);
+
+ virtual ~KisAlphaMask();
+
+ /**
+ @return the number of alpha values in a scanline.
+ */
+ TQ_INT32 height() const;
+
+ /**
+ @return the number of lines in the tqmask.
+ */
+ TQ_INT32 width() const;
+
+ /**
+ @return the alpha value at the specified position.
+
+ Returns TQ_UINT8 OPACITY_TRANSPARENT if the value is
+ outside the bounds of the tqmask.
+
+ XXX: this is, of course, not the best way of tqmasking.
+ Better would be to let KisAlphaMask fill a chunk of memory
+ with the alpha values at the right position, something like
+ void applyMask(TQ_UINT8 *pixeldata, TQ_INT32 pixelWidth,
+ TQ_INT32 alphaPos). That would be fastest, or we could
+ provide an iterator over the tqmask, that would be nice, too.
+ */
+ inline TQ_UINT8 alphaAt(TQ_INT32 x, TQ_INT32 y) const
+ {
+ if (y >= 0 && y < m_height && x >= 0 && x < m_width) {
+ return m_data[(y * m_width) + x];
+ }
+ else {
+ return OPACITY_TRANSPARENT;
+ }
+ }
+
+ void setAlphaAt(TQ_INT32 x, TQ_INT32 y, TQ_UINT8 alpha);
+
+ // Create a new tqmask by interpolating between tqmask1 and tqmask2 as t
+ // goes from 0 to 1.
+ static KisAlphaMaskSP interpolate(KisAlphaMaskSP tqmask1, KisAlphaMaskSP tqmask2, double t);
+
+private:
+ void computeAlpha(const TQImage& img);
+ void copyAlpha(const TQImage& img);
+
+ TQValueVector<TQ_UINT8> m_data;
+ TQ_INT32 m_width;
+ TQ_INT32 m_height;
+};
+
+#endif // KIS_ALPHA_MASK_
+