chalk

kis_brush.h
1/*
2 * Copyright (c) 1999 Matthias Elter <me@kde.org>
3 * Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
4 * Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20#ifndef KIS_BRUSH_
21#define KIS_BRUSH_
22
23#include <tqcstring.h>
24#include <tqstring.h>
25#include <tqsize.h>
26#include <tqimage.h>
27#include <tqvaluevector.h>
28
29#include <tdeio/job.h>
30
31#include "kis_resource.h"
32#include "kis_types.h"
33#include "kis_point.h"
34#include "kis_alpha_mask.h"
35#include "koffice_export.h"
36#include "kis_boundary.h"
37#include "kis_paintop.h"
38
39class TQPoint;
40class TQPixmap;
41class KisBoundary;
42class KisColorSpace;
43class TQIODevice;
44
45enum enumBrushType {
46 INVALID,
47 MASK,
48 IMAGE,
49 PIPE_MASK,
50 PIPE_IMAGE,
51 AIRBRUSH
52};
53
54class KRITACORE_EXPORT KisBrush : public KisResource {
55 typedef KisResource super;
56 TQ_OBJECT
57
58
59public:
61 KisBrush(const TQString& filename);
63 KisBrush(const TQString& filename,
64 const TQByteArray & data,
65 TQ_UINT32 & dataPos);
67 KisBrush(KisPaintDevice* image, int x, int y, int w, int h);
69 KisBrush(const TQImage& image, const TQString& name = TQString(""));
70
71 virtual ~KisBrush();
72
73 virtual bool load();
75 virtual bool save();
76 virtual TQImage img();
77 virtual bool saveToDevice(TQIODevice* dev) const;
78
83 virtual KisAlphaMaskSP mask(const KisPaintInformation& info,
84 double subPixelX = 0, double subPixelY = 0) const;
85 // XXX: return non-tiled simple buffer
86 virtual KisPaintDeviceSP image(KisColorSpace * colorSpace, const KisPaintInformation& info,
87 double subPixelX = 0, double subPixelY = 0) const;
88
89 void setHotSpot(KisPoint);
90 KisPoint hotSpot(const KisPaintInformation& info = KisPaintInformation()) const;
91
92 void setSpacing(double s) { m_spacing = s; }
93 double spacing() const { return m_spacing; }
94 double xSpacing(double pressure = PRESSURE_DEFAULT) const;
95 double ySpacing(double pressure = PRESSURE_DEFAULT) const;
96
97 // Dimensions in pixels of the mask/image at a given pressure.
98 TQ_INT32 maskWidth(const KisPaintInformation& info) const;
99 TQ_INT32 maskHeight(const KisPaintInformation& info) const;
100
101 virtual void setUseColorAsMask(bool useColorAsMask) { m_useColorAsMask = useColorAsMask; }
102 virtual bool useColorAsMask() const { return m_useColorAsMask; }
103 virtual bool hasColor() const;
104
105 virtual void makeMaskImage();
106 TQ_INT32 width() const;
107 TQ_INT32 height() const;
108
109 virtual enumBrushType brushType() const;
110
111 //TQImage outline(double pressure = PRESSURE_DEFAULT);
112 virtual KisBoundary boundary();
113
118 virtual bool canPaintFor(const KisPaintInformation& /*info*/) { return true; }
119
120 virtual KisBrush* clone() const;
121
122protected:
123 void setWidth(TQ_INT32 w);
124 void setHeight(TQ_INT32 h);
125 void setImage(const TQImage& img);
126 void setBrushType(enumBrushType type) { m_brushType = type; };
127 static double scaleForPressure(double pressure);
128
129private:
130 class ScaledBrush {
131 public:
132 ScaledBrush();
133 ScaledBrush(KisAlphaMaskSP scaledMask, const TQImage& scaledImage, double scale, double xScale, double yScale);
134
135 double scale() const { return m_scale; }
136 double xScale() const { return m_xScale; }
137 double yScale() const { return m_yScale; }
138 KisAlphaMaskSP mask() const { return m_mask; }
139 TQImage image() const { return m_image; }
140
141 private:
142 KisAlphaMaskSP m_mask;
143 TQImage m_image;
144 double m_scale;
145 double m_xScale;
146 double m_yScale;
147 };
148
149
150 bool init();
151 bool initFromPaintDev(KisPaintDevice* image, int x, int y, int w, int h);
152 void createScaledBrushes() const;
153
154 KisAlphaMaskSP scaleMask(const ScaledBrush *srcBrush, double scale, double subPixelX, double subPixelY) const;
155 TQImage scaleImage(const ScaledBrush *srcBrush, double scale, double subPixelX, double subPixelY) const;
156
157 static TQImage scaleImage(const TQImage& srcImage, int width, int height);
158 static TQImage interpolate(const TQImage& image1, const TQImage& image2, double t);
159
160 static KisAlphaMaskSP scaleSinglePixelMask(double scale, TQ_UINT8 maskValue, double subPixelX, double subPixelY);
161 static TQImage scaleSinglePixelImage(double scale, TQRgb pixel, double subPixelX, double subPixelY);
162
163 // Find the scaled brush(es) nearest to the given scale.
164 void findScaledBrushes(double scale, const ScaledBrush **aboveBrush, const ScaledBrush **belowBrush) const;
165
166 // Initialize our boundary
167 void generateBoundary();
168
169 TQByteArray m_data;
170 bool m_ownData;
171 KisPoint m_hotSpot;
172 double m_spacing;
173 bool m_useColorAsMask;
174 bool m_hasColor;
175 TQImage m_img;
176 mutable TQValueVector<ScaledBrush> m_scaledBrushes;
177
178 TQ_INT32 m_width;
179 TQ_INT32 m_height;
180
181 TQ_UINT32 m_header_size; /* header_size = sizeof (BrushHeader) + brush name */
182 TQ_UINT32 m_version; /* brush file version # */
183 TQ_UINT32 m_bytes; /* depth of brush in bytes */
184 TQ_UINT32 m_magic_number; /* GIMP brush magic number */
185
186 enumBrushType m_brushType;
187
188 KisBoundary* m_boundary;
189
190};
191#endif // KIS_BRUSH_
192
Generates an 'outline' for a paint device.
A colorspace is the definition of a certain color model in Chalk.
The KisResource class provides a representation of Chalk image resources.
virtual TQImage img()=0
Returns a TQImage representing this resource.
virtual bool save()=0
Save this resource asynchronously.
virtual bool load()=0
Load this resource.