24
|
1 |
#ifndef __RIPATH_H
|
|
2 |
#define __RIPATH_H
|
|
3 |
|
|
4 |
/*------------------------------------------------------------------------
|
|
5 |
*
|
|
6 |
* OpenVG 1.1 Reference Implementation
|
|
7 |
* -----------------------------------
|
|
8 |
*
|
|
9 |
* Copyright (c) 2007 The Khronos Group Inc.
|
|
10 |
* Portions copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
11 |
*
|
|
12 |
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
13 |
* copy of this software and /or associated documentation files
|
|
14 |
* (the "Materials "), to deal in the Materials without restriction,
|
|
15 |
* including without limitation the rights to use, copy, modify, merge,
|
|
16 |
* publish, distribute, sublicense, and/or sell copies of the Materials,
|
|
17 |
* and to permit persons to whom the Materials are furnished to do so,
|
|
18 |
* subject to the following conditions:
|
|
19 |
*
|
|
20 |
* The above copyright notice and this permission notice shall be included
|
|
21 |
* in all copies or substantial portions of the Materials.
|
|
22 |
*
|
|
23 |
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
24 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
25 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26 |
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
27 |
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
28 |
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR
|
|
29 |
* THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
|
30 |
*
|
|
31 |
*//**
|
|
32 |
* \file
|
|
33 |
* \brief Path class.
|
|
34 |
* \note
|
|
35 |
*//*-------------------------------------------------------------------*/
|
|
36 |
|
|
37 |
#ifndef _OPENVG_H
|
|
38 |
#include "openvg.h"
|
|
39 |
#endif
|
|
40 |
|
|
41 |
#ifndef __RIMATH_H
|
|
42 |
#include "riMath.h"
|
|
43 |
#endif
|
|
44 |
|
|
45 |
#ifndef __RIARRAY_H
|
|
46 |
#include "riArray.h"
|
|
47 |
#endif
|
|
48 |
|
|
49 |
#ifndef __RIRASTERIZER_H
|
|
50 |
#include "riRasterizer.h"
|
|
51 |
#endif
|
|
52 |
|
|
53 |
//==============================================================================================
|
|
54 |
|
|
55 |
namespace OpenVGRI
|
|
56 |
{
|
|
57 |
|
|
58 |
/*-------------------------------------------------------------------*//*!
|
|
59 |
* \brief Storage and operations for VGPath.
|
|
60 |
* \param
|
|
61 |
* \return
|
|
62 |
* \note
|
|
63 |
*//*-------------------------------------------------------------------*/
|
|
64 |
|
|
65 |
class Path
|
|
66 |
{
|
|
67 |
public:
|
|
68 |
Path(VGint format, VGPathDatatype datatype, RIfloat scale, RIfloat bias, int segmentCapacityHint, int coordCapacityHint, VGbitfield caps); //throws bad_alloc
|
|
69 |
~Path();
|
|
70 |
|
|
71 |
VGint getFormat() const { return m_format; }
|
|
72 |
VGPathDatatype getDatatype() const { return m_datatype; }
|
|
73 |
RIfloat getScale() const { return m_scale; }
|
|
74 |
RIfloat getBias() const { return m_bias; }
|
|
75 |
VGbitfield getCapabilities() const { return m_capabilities; }
|
|
76 |
void setCapabilities(VGbitfield caps) { m_capabilities = caps; }
|
|
77 |
int getNumSegments() const { return m_segments.size(); }
|
|
78 |
int getNumCoordinates() const { return m_data.size() / getBytesPerCoordinate(m_datatype); }
|
|
79 |
void addReference() { m_referenceCount++; }
|
|
80 |
int removeReference() { m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; }
|
|
81 |
|
|
82 |
void clear(VGbitfield capabilities);
|
|
83 |
void appendData(const RIuint8* segments, int numSegments, const RIuint8* data); //throws bad_alloc
|
|
84 |
void append(const Path* srcPath); //throws bad_alloc
|
|
85 |
void modifyCoords(int startIndex, int numSegments, const RIuint8* data);
|
|
86 |
void transform(const Path* srcPath, const Matrix3x3& matrix); //throws bad_alloc
|
|
87 |
//returns true if interpolation succeeds, false if start and end paths are not compatible
|
|
88 |
bool interpolate(const Path* startPath, const Path* endPath, RIfloat amount); //throws bad_alloc
|
|
89 |
void fill(const Matrix3x3& pathToSurface, Rasterizer& rasterizer); //throws bad_alloc
|
|
90 |
void stroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const Array<RIfloat>& dashPattern, RIfloat dashPhase, bool dashPhaseReset, RIfloat strokeWidth, VGCapStyle capStyle, VGJoinStyle joinStyle, RIfloat miterLimit); //throws bad_alloc
|
|
91 |
|
|
92 |
void getPointAlong(int startIndex, int numSegments, RIfloat distance, Vector2& p, Vector2& t); //throws bad_alloc
|
|
93 |
RIfloat getPathLength(int startIndex, int numSegments); //throws bad_alloc
|
|
94 |
void getPathBounds(RIfloat& minx, RIfloat& miny, RIfloat& maxx, RIfloat& maxy); //throws bad_alloc
|
|
95 |
void getPathTransformedBounds(const Matrix3x3& pathToSurface, RIfloat& minx, RIfloat& miny, RIfloat& maxx, RIfloat& maxy); //throws bad_alloc
|
|
96 |
int coordsSizeInBytes( int startIndex, int numSegments );
|
|
97 |
|
|
98 |
private:
|
|
99 |
enum VertexFlags
|
|
100 |
{
|
|
101 |
START_SUBPATH = (1<<0),
|
|
102 |
END_SUBPATH = (1<<1),
|
|
103 |
START_SEGMENT = (1<<2),
|
|
104 |
END_SEGMENT = (1<<3),
|
|
105 |
CLOSE_SUBPATH = (1<<4),
|
|
106 |
IMPLICIT_CLOSE_SUBPATH = (1<<5)
|
|
107 |
};
|
|
108 |
struct Vertex
|
|
109 |
{
|
|
110 |
Vertex() : userPosition(), userTangent(), pathLength(0.0f), flags(0) {}
|
|
111 |
Vector2 userPosition;
|
|
112 |
Vector2 userTangent;
|
|
113 |
RIfloat pathLength;
|
|
114 |
unsigned int flags;
|
|
115 |
};
|
|
116 |
struct StrokeVertex
|
|
117 |
{
|
|
118 |
StrokeVertex() : p(), t(), ccw(), cw(), pathLength(0.0f), flags(0), inDash(false) {}
|
|
119 |
Vector2 p;
|
|
120 |
Vector2 t;
|
|
121 |
Vector2 ccw;
|
|
122 |
Vector2 cw;
|
|
123 |
RIfloat pathLength;
|
|
124 |
unsigned int flags;
|
|
125 |
bool inDash;
|
|
126 |
};
|
|
127 |
|
|
128 |
Path(const Path&); //!< Not allowed.
|
|
129 |
const Path& operator=(const Path&); //!< Not allowed.
|
|
130 |
|
|
131 |
static VGPathSegment getPathSegment(RIuint8 data) { return (VGPathSegment)(data & 0x1e); }
|
|
132 |
static VGPathAbsRel getPathAbsRel(RIuint8 data) { return (VGPathAbsRel)(data & 0x1); }
|
|
133 |
static int segmentToNumCoordinates(VGPathSegment segment);
|
|
134 |
static int countNumCoordinates(const RIuint8* segments, int numSegments);
|
|
135 |
static int getBytesPerCoordinate(VGPathDatatype datatype);
|
|
136 |
|
|
137 |
static void setCoordinate(Array<RIuint8>& data, VGPathDatatype datatype, RIfloat scale, RIfloat bias, int i, RIfloat c);
|
|
138 |
|
|
139 |
RIfloat getCoordinate(int i) const;
|
|
140 |
void setCoordinate(int i, RIfloat c) { setCoordinate(m_data, m_datatype, m_scale, m_bias, i, c); }
|
|
141 |
|
|
142 |
void addVertex(const Vector2& p, const Vector2& t, RIfloat pathLength, unsigned int flags); //throws bad_alloc
|
|
143 |
void addEdge(const Vector2& p0, const Vector2& p1, const Vector2& t0, const Vector2& t1, unsigned int startFlags, unsigned int endFlags); //throws bad_alloc
|
|
144 |
|
|
145 |
void addEndPath(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, bool subpathHasGeometry, unsigned int flags); //throws bad_alloc
|
|
146 |
bool addLineTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, bool subpathHasGeometry); //throws bad_alloc
|
|
147 |
bool addQuadTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, const Vector2& p2, bool subpathHasGeometry, float strokeWidth); //throws bad_alloc
|
|
148 |
bool addCubicTo(const Matrix3x3& pathToSurface, const Vector2& p0, const Vector2& p1, const Vector2& p2, const Vector2& p3, bool subpathHasGeometry, float strokeWidth); //throws bad_alloc
|
|
149 |
bool addArcTo(const Matrix3x3& pathToSurface, const Vector2& p0, RIfloat rh, RIfloat rv, RIfloat rot, const Vector2& p1, const Vector2& p1r, VGPathSegment segment, bool subpathHasGeometry, float strokeWidth); //throws bad_alloc
|
|
150 |
|
|
151 |
void tessellate(const Matrix3x3& pathToSurface, float strokeWidth); //throws bad_alloc
|
|
152 |
|
|
153 |
void normalizeForInterpolation(const Path* srcPath); //throws bad_alloc
|
|
154 |
|
|
155 |
void interpolateStroke(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v0, const StrokeVertex& v1, RIfloat strokeWidth) const; //throws bad_alloc
|
|
156 |
void doCap(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v, RIfloat strokeWidth, VGCapStyle capStyle) const; //throws bad_alloc
|
|
157 |
void doJoin(const Matrix3x3& pathToSurface, Rasterizer& rasterizer, const StrokeVertex& v0, const StrokeVertex& v1, RIfloat strokeWidth, VGJoinStyle joinStyle, RIfloat miterLimit) const; //throws bad_alloc
|
|
158 |
|
|
159 |
//input data
|
|
160 |
VGint m_format;
|
|
161 |
VGPathDatatype m_datatype;
|
|
162 |
RIfloat m_scale;
|
|
163 |
RIfloat m_bias;
|
|
164 |
VGbitfield m_capabilities;
|
|
165 |
int m_referenceCount;
|
|
166 |
Array<RIuint8> m_segments;
|
|
167 |
Array<RIuint8> m_data;
|
|
168 |
|
|
169 |
//data produced by tessellation
|
|
170 |
struct VertexIndex
|
|
171 |
{
|
|
172 |
int start;
|
|
173 |
int end;
|
|
174 |
};
|
|
175 |
Array<Vertex> m_vertices;
|
|
176 |
int m_numTessVertices;
|
|
177 |
Array<VertexIndex> m_segmentToVertex;
|
|
178 |
RIfloat m_userMinx;
|
|
179 |
RIfloat m_userMiny;
|
|
180 |
RIfloat m_userMaxx;
|
|
181 |
RIfloat m_userMaxy;
|
|
182 |
|
|
183 |
bool m_mirror;
|
|
184 |
};
|
|
185 |
|
|
186 |
//==============================================================================================
|
|
187 |
|
|
188 |
} //namespace OpenVGRI
|
|
189 |
|
|
190 |
//==============================================================================================
|
|
191 |
|
|
192 |
#endif /* __RIPATH_H */
|