LMMS
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//==============================================================================
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 //==============================================================================
78 void clipToEdgeTable (const EdgeTable&);
79 void clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels);
80 bool isEmpty() noexcept;
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;
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
211
212 void allocate();
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
224};
225
226} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
static const unsigned long mask[]
Definition bitwise.c:31
Definition juce_AffineTransform.h:43
bool isEmpty() noexcept
Definition juce_EdgeTable.cpp:819
int maxEdgesPerLine
Definition juce_EdgeTable.h:209
static constexpr auto defaultEdgesPerLine
Definition juce_EdgeTable.h:195
static constexpr auto scale
Definition juce_EdgeTable.h:196
EdgeTable(Rectangle< int > clipLimits, const Path &pathToAdd, const AffineTransform &transform)
Definition juce_EdgeTable.cpp:31
void excludeRectangle(Rectangle< int > r)
Definition juce_EdgeTable.cpp:719
HeapBlock< int > table
Definition juce_EdgeTable.h:207
void clipToEdgeTable(const EdgeTable &)
Definition juce_EdgeTable.cpp:740
void clipLineToMask(int x, int y, const uint8 *mask, int maskStride, int numPixels)
Definition juce_EdgeTable.cpp:775
void iterate(EdgeTableIterationCallback &iterationCallback) const noexcept
Definition juce_EdgeTable.h:112
const Rectangle< int > & getMaximumBounds() const noexcept
Definition juce_EdgeTable.h:81
void remapTableForNumEdges(int newNumEdgesPerLine)
Definition juce_EdgeTable.cpp:389
bool needToCheckEmptiness
Definition juce_EdgeTable.h:210
void clearLineSizes() noexcept
Definition juce_EdgeTable.cpp:304
static void copyEdgeTableData(int *dest, int destLineStride, const int *src, int srcLineStride, int numLines) noexcept
Definition juce_EdgeTable.cpp:315
void remapWithExtraSpace(int numPointsNeeded)
Definition juce_EdgeTable.cpp:407
int lineStrideElements
Definition juce_EdgeTable.h:209
void intersectWithEdgeTableLine(int y, const int *otherLine)
Definition juce_EdgeTable.cpp:503
void clipToRectangle(Rectangle< int > r)
Definition juce_EdgeTable.cpp:680
void allocate()
Definition juce_EdgeTable.cpp:299
Rectangle< int > bounds
Definition juce_EdgeTable.h:208
void sanitiseLevels(bool useNonZeroWinding) noexcept
Definition juce_EdgeTable.cpp:325
void addEdgePointPair(int x1, int x2, int y, int winding)
Definition juce_EdgeTable.cpp:442
void clipEdgeTableLineToRange(int *line, int x1, int x2) noexcept
Definition juce_EdgeTable.cpp:639
void addEdgePoint(int x, int y, int winding)
Definition juce_EdgeTable.cpp:423
Definition juce_HeapBlock.h:87
Definition juce_Path.h:65
Definition juce_Rectangle.h:67
Definition juce_RectangleList.h:43
int y
Definition inflate.c:1588
unsigned x[BMAX+1]
Definition inflate.c:1586
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition juce_LeakedObjectDetector.h:138
#define jassert(expression)
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
JUCE_API String translate(const String &text)
Definition juce_LocalisedStrings.cpp:188
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Definition juce_MathsFunctions.h:279
unsigned char uint8
Definition juce_MathsFunctions.h:37
Definition juce_EdgeTable.h:201
int x
Definition juce_EdgeTable.h:202
int level
Definition juce_EdgeTable.h:202
int r
Definition crypt.c:458
dy
Definition zipinfo.c:2288
#define const
Definition zconf.h:137