krita

kis_brush.h

00001 /*
00002  *  Copyright (c) 1999 Matthias Elter  <me@kde.org>
00003  *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
00004  *  Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
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 #ifndef KIS_BRUSH_
00021 #define KIS_BRUSH_
00022 
00023 #include <qcstring.h>
00024 #include <qstring.h>
00025 #include <qsize.h>
00026 #include <qimage.h>
00027 #include <qvaluevector.h>
00028 
00029 #include <kio/job.h>
00030 
00031 #include "kis_resource.h"
00032 #include "kis_types.h"
00033 #include "kis_point.h"
00034 #include "kis_alpha_mask.h"
00035 #include "koffice_export.h"
00036 #include "kis_boundary.h"
00037 #include "kis_paintop.h"
00038 
00039 class QPoint;
00040 class QPixmap;
00041 class KisBoundary;
00042 class KisColorSpace;
00043 class QIODevice;
00044 
00045 enum enumBrushType {
00046     INVALID,
00047     MASK,
00048     IMAGE,
00049     PIPE_MASK,
00050     PIPE_IMAGE,
00051     AIRBRUSH
00052 };
00053 
00054 class KRITACORE_EXPORT KisBrush : public KisResource {
00055     typedef KisResource super;
00056     Q_OBJECT
00057 
00058 public:
00060     KisBrush(const QString& filename);
00062     KisBrush(const QString& filename,
00063          const QByteArray & data,
00064          Q_UINT32 & dataPos);
00066     KisBrush(KisPaintDevice* image, int x, int y, int w, int h);
00068     KisBrush(const QImage& image, const QString& name = QString(""));
00069 
00070     virtual ~KisBrush();
00071 
00072     virtual bool load();
00074     virtual bool save();
00075     virtual QImage img();
00076     virtual bool saveToDevice(QIODevice* dev) const;
00077 
00082     virtual KisAlphaMaskSP mask(const KisPaintInformation& info,
00083                                 double subPixelX = 0, double subPixelY = 0) const;
00084     // XXX: return non-tiled simple buffer
00085     virtual KisPaintDeviceSP image(KisColorSpace * colorSpace, const KisPaintInformation& info,
00086                              double subPixelX = 0, double subPixelY = 0) const;
00087 
00088     void setHotSpot(KisPoint);
00089     KisPoint hotSpot(const KisPaintInformation& info = KisPaintInformation()) const;
00090 
00091     void setSpacing(double s) { m_spacing = s; }
00092     double spacing() const { return m_spacing; }
00093     double xSpacing(double pressure = PRESSURE_DEFAULT) const;
00094     double ySpacing(double pressure = PRESSURE_DEFAULT) const;
00095 
00096     // Dimensions in pixels of the mask/image at a given pressure.
00097     Q_INT32 maskWidth(const KisPaintInformation& info) const;
00098     Q_INT32 maskHeight(const KisPaintInformation& info) const;
00099 
00100     virtual void setUseColorAsMask(bool useColorAsMask) { m_useColorAsMask = useColorAsMask; }
00101     virtual bool useColorAsMask() const { return m_useColorAsMask; }
00102     virtual bool hasColor() const;
00103 
00104     virtual void makeMaskImage();
00105     Q_INT32 width() const;
00106     Q_INT32 height() const;
00107 
00108     virtual enumBrushType brushType() const;
00109 
00110     //QImage outline(double pressure = PRESSURE_DEFAULT);
00111     virtual KisBoundary boundary();
00112 
00117     virtual bool canPaintFor(const KisPaintInformation& /*info*/) { return true; }
00118 
00119     virtual KisBrush* clone() const;
00120 
00121 protected:
00122     void setWidth(Q_INT32 w);
00123     void setHeight(Q_INT32 h);
00124     void setImage(const QImage& img);
00125     void setBrushType(enumBrushType type) { m_brushType = type; };
00126     static double scaleForPressure(double pressure);
00127 
00128 private:
00129     class ScaledBrush {
00130     public:
00131         ScaledBrush();
00132         ScaledBrush(KisAlphaMaskSP scaledMask, const QImage& scaledImage, double scale, double xScale, double yScale);
00133 
00134         double scale() const { return m_scale; }
00135         double xScale() const { return m_xScale; }
00136         double yScale() const { return m_yScale; }
00137         KisAlphaMaskSP mask() const { return m_mask; }
00138         QImage image() const { return m_image; }
00139 
00140     private:
00141         KisAlphaMaskSP m_mask;
00142         QImage m_image;
00143         double m_scale;
00144         double m_xScale;
00145         double m_yScale;
00146     };
00147 
00148 
00149     bool init();
00150     bool initFromPaintDev(KisPaintDevice* image, int x, int y, int w, int h);
00151     void createScaledBrushes() const;
00152 
00153     KisAlphaMaskSP scaleMask(const ScaledBrush *srcBrush, double scale, double subPixelX, double subPixelY) const;
00154     QImage scaleImage(const ScaledBrush *srcBrush, double scale, double subPixelX, double subPixelY) const;
00155 
00156     static QImage scaleImage(const QImage& srcImage, int width, int height);
00157     static QImage interpolate(const QImage& image1, const QImage& image2, double t);
00158 
00159     static KisAlphaMaskSP scaleSinglePixelMask(double scale, Q_UINT8 maskValue, double subPixelX, double subPixelY);
00160     static QImage scaleSinglePixelImage(double scale, QRgb pixel, double subPixelX, double subPixelY);
00161 
00162     // Find the scaled brush(es) nearest to the given scale.
00163     void findScaledBrushes(double scale, const ScaledBrush **aboveBrush, const ScaledBrush **belowBrush) const;
00164 
00165     // Initialize our boundary
00166     void generateBoundary();
00167 
00168     QByteArray m_data;
00169     bool m_ownData;
00170     KisPoint m_hotSpot;
00171     double m_spacing;
00172     bool m_useColorAsMask;
00173     bool m_hasColor;
00174     QImage m_img;
00175     mutable QValueVector<ScaledBrush> m_scaledBrushes;
00176 
00177     Q_INT32 m_width;
00178     Q_INT32 m_height;
00179 
00180     Q_UINT32 m_header_size;  /*  header_size = sizeof (BrushHeader) + brush name  */
00181     Q_UINT32 m_version;      /*  brush file version #  */
00182     Q_UINT32 m_bytes;        /*  depth of brush in bytes */
00183     Q_UINT32 m_magic_number; /*  GIMP brush magic number  */
00184 
00185     enumBrushType m_brushType;
00186 
00187     KisBoundary* m_boundary;
00188 
00189 };
00190 #endif // KIS_BRUSH_
00191 
KDE Home | KDE Accessibility Home | Description of Access Keys