JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_EdgeTable.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
37class JUCE_API EdgeTable
38{
39public:
40 //==============================================================================
50 EdgeTable (Rectangle<int> clipLimits,
51 const Path& pathToAdd,
52 const AffineTransform& transform);
53
55 explicit EdgeTable (Rectangle<int> rectangleToAdd);
56
58 explicit EdgeTable (Rectangle<float> rectangleToAdd);
59
61 explicit EdgeTable (const RectangleList<int>& rectanglesToAdd);
62
64 explicit EdgeTable (const RectangleList<float>& rectanglesToAdd);
65
67 EdgeTable (const EdgeTable&);
68
70 EdgeTable& operator= (const EdgeTable&);
71
73 ~EdgeTable();
74
75 //==============================================================================
76 void clipToRectangle (Rectangle<int> r);
77 void excludeRectangle (Rectangle<int> r);
78 void clipToEdgeTable (const EdgeTable&);
79 void clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels);
80 bool isEmpty() noexcept;
81 const Rectangle<int>& getMaximumBounds() const noexcept { return bounds; }
82 void translate (float dx, int dy) noexcept;
83
85 void multiplyLevels (float factor);
86
92 void optimiseTable();
93
94
95 //==============================================================================
111 template <class EdgeTableIterationCallback>
112 void iterate (EdgeTableIterationCallback& iterationCallback) const noexcept
113 {
114 const int* lineStart = table;
115
116 for (int y = 0; y < bounds.getHeight(); ++y)
117 {
118 const int* line = lineStart;
119 lineStart += lineStrideElements;
120 int numPoints = line[0];
121
122 if (--numPoints > 0)
123 {
124 int x = *++line;
125 jassert ((x / scale) >= bounds.getX() && (x / scale) < bounds.getRight());
126 int levelAccumulator = 0;
127
128 iterationCallback.setEdgeTableYPos (bounds.getY() + y);
129
130 while (--numPoints >= 0)
131 {
132 const int level = *++line;
133 jassert (isPositiveAndBelow (level, scale));
134 const int endX = *++line;
135 jassert (endX >= x);
136 const int endOfRun = (endX / scale);
137
138 if (endOfRun == (x / scale))
139 {
140 // small segment within the same pixel, so just save it for the next
141 // time round..
142 levelAccumulator += (endX - x) * level;
143 }
144 else
145 {
146 // plot the fist pixel of this segment, including any accumulated
147 // levels from smaller segments that haven't been drawn yet
148 levelAccumulator += (0x100 - (x & 0xff)) * level;
149 levelAccumulator /= scale;
150 x /= scale;
151
152 if (levelAccumulator > 0)
153 {
154 if (levelAccumulator >= 255)
155 iterationCallback.handleEdgeTablePixelFull (x);
156 else
157 iterationCallback.handleEdgeTablePixel (x, levelAccumulator);
158 }
159
160 // if there's a run of similar pixels, do it all in one go..
161 if (level > 0)
162 {
163 jassert (endOfRun <= bounds.getRight());
164 const int numPix = endOfRun - ++x;
165
166 if (numPix > 0)
167 iterationCallback.handleEdgeTableLine (x, numPix, level);
168 }
169
170 // save the bit at the end to be drawn next time round the loop.
171 levelAccumulator = (endX & 0xff) * level;
172 }
173
174 x = endX;
175 }
176
177 levelAccumulator /= scale;
178
179 if (levelAccumulator > 0)
180 {
181 x /= scale;
182 jassert (x >= bounds.getX() && x < bounds.getRight());
183
184 if (levelAccumulator >= 255)
185 iterationCallback.handleEdgeTablePixelFull (x);
186 else
187 iterationCallback.handleEdgeTablePixel (x, levelAccumulator);
188 }
189 }
190 }
191 }
192
193private:
194 //==============================================================================
195 static constexpr auto defaultEdgesPerLine = 32;
196 static constexpr auto scale = 256;
197
198 //==============================================================================
199 // table line format: number of points; point0 x, point0 levelDelta, point1 x, point1 levelDelta, etc
200 struct LineItem
201 {
202 int x, level;
203
204 bool operator< (const LineItem& other) const noexcept { return x < other.x; }
205 };
206
207 HeapBlock<int> table;
208 Rectangle<int> bounds;
209 int maxEdgesPerLine, lineStrideElements;
210 bool needToCheckEmptiness = true;
211
212 void allocate();
213 void clearLineSizes() noexcept;
214 void addEdgePoint (int x, int y, int winding);
215 void addEdgePointPair (int x1, int x2, int y, int winding);
216 void remapTableForNumEdges (int newNumEdgesPerLine);
217 void remapWithExtraSpace (int numPointsNeeded);
218 void intersectWithEdgeTableLine (int y, const int* otherLine);
219 void clipEdgeTableLineToRange (int* line, int x1, int x2) noexcept;
220 void sanitiseLevels (bool useNonZeroWinding) noexcept;
221 static void copyEdgeTableData (int* dest, int destLineStride, const int* src, int srcLineStride, int numLines) noexcept;
222
223 JUCE_LEAK_DETECTOR (EdgeTable)
224};
225
226} // namespace juce
Represents a 2D affine-transformation matrix.
A table of horizontal scan-line segments - used for rasterising Paths.
void iterate(EdgeTableIterationCallback &iterationCallback) const noexcept
Iterates the lines in the table, for rendering.
A path is a sequence of lines and curves that may either form a closed shape or be open-ended.
Definition juce_Path.h:65
Maintains a set of rectangles as a complex region.
Manages a rectangle and allows geometric operations to be performed on it.
#define JUCE_LEAK_DETECTOR(OwnerClass)
This macro lets you embed a leak-detecting object inside a class.
#define jassert(expression)
Platform-independent assertion macro.
JUCE Namespace.
JUCE_API String translate(const String &text)
Uses the LocalisedStrings class to translate the given string literal.
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Returns true if a value is at least zero, and also below a specified upper limit.
unsigned char uint8
A platform-independent 8-bit unsigned integer type.