krita

kis_alpha_mask.h

00001 /*
00002  *  Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 #ifndef KIS_ALPHA_MASK_
00019 #define KIS_ALPHA_MASK_
00020 
00021 #include <qimage.h>
00022 #include <qvaluevector.h>
00023 
00024 #include <ksharedptr.h>
00025 
00026 #include "kis_global.h"
00027 #include "kis_types.h"
00028 
00034 class KisAlphaMask : public KShared {
00035     
00036  public:
00042     KisAlphaMask(const QImage& img);
00043 
00048     KisAlphaMask(const QImage& img, bool hasColor);
00049 
00053     KisAlphaMask(Q_INT32 width, Q_INT32 height);
00054 
00055     virtual ~KisAlphaMask();
00056 
00060     Q_INT32 height() const;
00061 
00065        Q_INT32 width() const;
00066 
00080     inline Q_UINT8 alphaAt(Q_INT32 x, Q_INT32 y) const
00081     {
00082     if (y >= 0 && y < m_height && x >= 0 && x < m_width) {
00083         return m_data[(y * m_width) + x];
00084     }
00085     else {
00086         return OPACITY_TRANSPARENT;
00087     }
00088     }
00089 
00090     void setAlphaAt(Q_INT32 x, Q_INT32 y, Q_UINT8 alpha);
00091 
00092     // Create a new mask by interpolating between mask1 and mask2 as t
00093     // goes from 0 to 1.
00094     static KisAlphaMaskSP interpolate(KisAlphaMaskSP mask1, KisAlphaMaskSP mask2, double t);
00095 
00096 private:
00097     void computeAlpha(const QImage& img);
00098     void copyAlpha(const QImage& img);
00099 
00100     QValueVector<Q_UINT8> m_data;
00101     Q_INT32 m_width;
00102     Q_INT32 m_height;
00103 };
00104 
00105 #endif // KIS_ALPHA_MASK_
00106 
KDE Home | KDE Accessibility Home | Description of Access Keys