Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

832 lines
23KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. const int juce_edgeTableDefaultEdgesPerLine = 32;
  18. //==============================================================================
  19. EdgeTable::EdgeTable (const Rectangle<int>& area,
  20. const Path& path, const AffineTransform& transform)
  21. : bounds (area),
  22. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  23. lineStrideElements (juce_edgeTableDefaultEdgesPerLine * 2 + 1),
  24. needToCheckEmptiness (true)
  25. {
  26. allocate();
  27. int* t = table;
  28. for (int i = bounds.getHeight(); --i >= 0;)
  29. {
  30. *t = 0;
  31. t += lineStrideElements;
  32. }
  33. const int leftLimit = bounds.getX() << 8;
  34. const int topLimit = bounds.getY() << 8;
  35. const int rightLimit = bounds.getRight() << 8;
  36. const int heightLimit = bounds.getHeight() << 8;
  37. PathFlatteningIterator iter (path, transform);
  38. while (iter.next())
  39. {
  40. int y1 = roundToInt (iter.y1 * 256.0f);
  41. int y2 = roundToInt (iter.y2 * 256.0f);
  42. if (y1 != y2)
  43. {
  44. y1 -= topLimit;
  45. y2 -= topLimit;
  46. const int startY = y1;
  47. int direction = -1;
  48. if (y1 > y2)
  49. {
  50. std::swap (y1, y2);
  51. direction = 1;
  52. }
  53. if (y1 < 0)
  54. y1 = 0;
  55. if (y2 > heightLimit)
  56. y2 = heightLimit;
  57. if (y1 < y2)
  58. {
  59. const double startX = 256.0f * iter.x1;
  60. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  61. const int stepSize = jlimit (1, 256, 256 / (1 + (int) std::abs (multiplier)));
  62. do
  63. {
  64. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  65. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  66. if (x < leftLimit)
  67. x = leftLimit;
  68. else if (x >= rightLimit)
  69. x = rightLimit - 1;
  70. addEdgePoint (x, y1 >> 8, direction * step);
  71. y1 += step;
  72. }
  73. while (y1 < y2);
  74. }
  75. }
  76. }
  77. sanitiseLevels (path.isUsingNonZeroWinding());
  78. }
  79. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd)
  80. : bounds (rectangleToAdd),
  81. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  82. lineStrideElements (juce_edgeTableDefaultEdgesPerLine * 2 + 1),
  83. needToCheckEmptiness (true)
  84. {
  85. allocate();
  86. table[0] = 0;
  87. const int x1 = rectangleToAdd.getX() << 8;
  88. const int x2 = rectangleToAdd.getRight() << 8;
  89. int* t = table;
  90. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  91. {
  92. t[0] = 2;
  93. t[1] = x1;
  94. t[2] = 255;
  95. t[3] = x2;
  96. t[4] = 0;
  97. t += lineStrideElements;
  98. }
  99. }
  100. EdgeTable::EdgeTable (const RectangleList<int>& rectanglesToAdd)
  101. : bounds (rectanglesToAdd.getBounds()),
  102. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  103. lineStrideElements (juce_edgeTableDefaultEdgesPerLine * 2 + 1),
  104. needToCheckEmptiness (true)
  105. {
  106. allocate();
  107. clearLineSizes();
  108. for (const Rectangle<int>* r = rectanglesToAdd.begin(), * const e = rectanglesToAdd.end(); r != e; ++r)
  109. {
  110. const int x1 = r->getX() << 8;
  111. const int x2 = r->getRight() << 8;
  112. int y = r->getY() - bounds.getY();
  113. for (int j = r->getHeight(); --j >= 0;)
  114. addEdgePointPair (x1, x2, y++, 255);
  115. }
  116. sanitiseLevels (true);
  117. }
  118. EdgeTable::EdgeTable (const RectangleList<float>& rectanglesToAdd)
  119. : bounds (rectanglesToAdd.getBounds().getSmallestIntegerContainer()),
  120. maxEdgesPerLine (rectanglesToAdd.getNumRectangles() * 2),
  121. lineStrideElements (rectanglesToAdd.getNumRectangles() * 4 + 1),
  122. needToCheckEmptiness (true)
  123. {
  124. bounds.setHeight (bounds.getHeight() + 1);
  125. allocate();
  126. clearLineSizes();
  127. for (const Rectangle<float>* r = rectanglesToAdd.begin(), * const e = rectanglesToAdd.end(); r != e; ++r)
  128. {
  129. const int x1 = roundToInt (r->getX() * 256.0f);
  130. const int x2 = roundToInt (r->getRight() * 256.0f);
  131. const int y1 = roundToInt (r->getY() * 256.0f) - (bounds.getY() << 8);
  132. const int y2 = roundToInt (r->getBottom() * 256.0f) - (bounds.getY() << 8);
  133. if (x2 <= x1 || y2 <= y1)
  134. continue;
  135. int y = y1 >> 8;
  136. const int lastLine = y2 >> 8;
  137. if (y == lastLine)
  138. {
  139. addEdgePointPair (x1, x2, y, y2 - y1);
  140. }
  141. else
  142. {
  143. addEdgePointPair (x1, x2, y++, 255 - (y1 & 255));
  144. while (y < lastLine)
  145. addEdgePointPair (x1, x2, y++, 255);
  146. jassert (y < bounds.getHeight());
  147. addEdgePointPair (x1, x2, y, y2 & 255);
  148. }
  149. }
  150. sanitiseLevels (true);
  151. }
  152. EdgeTable::EdgeTable (const Rectangle<float>& rectangleToAdd)
  153. : bounds (Rectangle<int> ((int) std::floor (rectangleToAdd.getX()),
  154. roundToInt (rectangleToAdd.getY() * 256.0f) >> 8,
  155. 2 + (int) rectangleToAdd.getWidth(),
  156. 2 + (int) rectangleToAdd.getHeight())),
  157. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  158. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  159. needToCheckEmptiness (true)
  160. {
  161. jassert (! rectangleToAdd.isEmpty());
  162. allocate();
  163. table[0] = 0;
  164. const int x1 = roundToInt (rectangleToAdd.getX() * 256.0f);
  165. const int x2 = roundToInt (rectangleToAdd.getRight() * 256.0f);
  166. int y1 = roundToInt (rectangleToAdd.getY() * 256.0f) - (bounds.getY() << 8);
  167. jassert (y1 < 256);
  168. int y2 = roundToInt (rectangleToAdd.getBottom() * 256.0f) - (bounds.getY() << 8);
  169. if (x2 <= x1 || y2 <= y1)
  170. {
  171. bounds.setHeight (0);
  172. return;
  173. }
  174. int lineY = 0;
  175. int* t = table;
  176. if ((y1 >> 8) == (y2 >> 8))
  177. {
  178. t[0] = 2;
  179. t[1] = x1;
  180. t[2] = y2 - y1;
  181. t[3] = x2;
  182. t[4] = 0;
  183. ++lineY;
  184. t += lineStrideElements;
  185. }
  186. else
  187. {
  188. t[0] = 2;
  189. t[1] = x1;
  190. t[2] = 255 - (y1 & 255);
  191. t[3] = x2;
  192. t[4] = 0;
  193. ++lineY;
  194. t += lineStrideElements;
  195. while (lineY < (y2 >> 8))
  196. {
  197. t[0] = 2;
  198. t[1] = x1;
  199. t[2] = 255;
  200. t[3] = x2;
  201. t[4] = 0;
  202. ++lineY;
  203. t += lineStrideElements;
  204. }
  205. jassert (lineY < bounds.getHeight());
  206. t[0] = 2;
  207. t[1] = x1;
  208. t[2] = y2 & 255;
  209. t[3] = x2;
  210. t[4] = 0;
  211. ++lineY;
  212. t += lineStrideElements;
  213. }
  214. while (lineY < bounds.getHeight())
  215. {
  216. t[0] = 0;
  217. t += lineStrideElements;
  218. ++lineY;
  219. }
  220. }
  221. EdgeTable::EdgeTable (const EdgeTable& other)
  222. {
  223. operator= (other);
  224. }
  225. EdgeTable& EdgeTable::operator= (const EdgeTable& other)
  226. {
  227. bounds = other.bounds;
  228. maxEdgesPerLine = other.maxEdgesPerLine;
  229. lineStrideElements = other.lineStrideElements;
  230. needToCheckEmptiness = other.needToCheckEmptiness;
  231. allocate();
  232. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  233. return *this;
  234. }
  235. EdgeTable::~EdgeTable()
  236. {
  237. }
  238. //==============================================================================
  239. static size_t getEdgeTableAllocationSize (int lineStride, int height) noexcept
  240. {
  241. // (leave an extra line at the end for use as scratch space)
  242. return (size_t) (lineStride * (2 + jmax (0, height)));
  243. }
  244. void EdgeTable::allocate()
  245. {
  246. table.malloc (getEdgeTableAllocationSize (lineStrideElements, bounds.getHeight()));
  247. }
  248. void EdgeTable::clearLineSizes() noexcept
  249. {
  250. int* t = table;
  251. for (int i = bounds.getHeight(); --i >= 0;)
  252. {
  253. *t = 0;
  254. t += lineStrideElements;
  255. }
  256. }
  257. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) noexcept
  258. {
  259. while (--numLines >= 0)
  260. {
  261. memcpy (dest, src, (size_t) (src[0] * 2 + 1) * sizeof (int));
  262. src += srcLineStride;
  263. dest += destLineStride;
  264. }
  265. }
  266. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) noexcept
  267. {
  268. // Convert the table from relative windings to absolute levels..
  269. int* lineStart = table;
  270. for (int y = bounds.getHeight(); --y >= 0;)
  271. {
  272. int num = lineStart[0];
  273. if (num > 0)
  274. {
  275. LineItem* items = reinterpret_cast<LineItem*> (lineStart + 1);
  276. LineItem* const itemsEnd = items + num;
  277. // sort the X coords
  278. std::sort (items, itemsEnd);
  279. const LineItem* src = items;
  280. int correctedNum = num;
  281. int level = 0;
  282. while (src < itemsEnd)
  283. {
  284. level += src->level;
  285. const int x = src->x;
  286. ++src;
  287. while (src < itemsEnd && src->x == x)
  288. {
  289. level += src->level;
  290. ++src;
  291. --correctedNum;
  292. }
  293. int corrected = std::abs (level);
  294. if (corrected >> 8)
  295. {
  296. if (useNonZeroWinding)
  297. {
  298. corrected = 255;
  299. }
  300. else
  301. {
  302. corrected &= 511;
  303. if (corrected >> 8)
  304. corrected = 511 - corrected;
  305. }
  306. }
  307. items->x = x;
  308. items->level = corrected;
  309. ++items;
  310. }
  311. lineStart[0] = correctedNum;
  312. (items - 1)->level = 0; // force the last level to 0, just in case something went wrong in creating the table
  313. }
  314. lineStart += lineStrideElements;
  315. }
  316. }
  317. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine)
  318. {
  319. if (newNumEdgesPerLine != maxEdgesPerLine)
  320. {
  321. maxEdgesPerLine = newNumEdgesPerLine;
  322. jassert (bounds.getHeight() > 0);
  323. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  324. HeapBlock<int> newTable (getEdgeTableAllocationSize (newLineStrideElements, bounds.getHeight()));
  325. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  326. table.swapWith (newTable);
  327. lineStrideElements = newLineStrideElements;
  328. }
  329. }
  330. void EdgeTable::optimiseTable()
  331. {
  332. int maxLineElements = 0;
  333. for (int i = bounds.getHeight(); --i >= 0;)
  334. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  335. remapTableForNumEdges (maxLineElements);
  336. }
  337. void EdgeTable::addEdgePoint (const int x, const int y, const int winding)
  338. {
  339. jassert (y >= 0 && y < bounds.getHeight());
  340. int* line = table + lineStrideElements * y;
  341. const int numPoints = line[0];
  342. if (numPoints >= maxEdgesPerLine)
  343. {
  344. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  345. jassert (numPoints < maxEdgesPerLine);
  346. line = table + lineStrideElements * y;
  347. }
  348. line[0]++;
  349. int n = numPoints << 1;
  350. line [n + 1] = x;
  351. line [n + 2] = winding;
  352. }
  353. void EdgeTable::addEdgePointPair (int x1, int x2, int y, int winding)
  354. {
  355. jassert (y >= 0 && y < bounds.getHeight());
  356. int* line = table + lineStrideElements * y;
  357. const int numPoints = line[0];
  358. if (numPoints + 1 >= maxEdgesPerLine)
  359. {
  360. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  361. jassert (numPoints < maxEdgesPerLine);
  362. line = table + lineStrideElements * y;
  363. }
  364. line[0] = numPoints + 2;
  365. line += numPoints << 1;
  366. line[1] = x1;
  367. line[2] = winding;
  368. line[3] = x2;
  369. line[4] = -winding;
  370. }
  371. void EdgeTable::translate (float dx, const int dy) noexcept
  372. {
  373. bounds.translate ((int) std::floor (dx), dy);
  374. int* lineStart = table;
  375. const int intDx = (int) (dx * 256.0f);
  376. for (int i = bounds.getHeight(); --i >= 0;)
  377. {
  378. int* line = lineStart;
  379. lineStart += lineStrideElements;
  380. int num = *line++;
  381. while (--num >= 0)
  382. {
  383. *line += intDx;
  384. line += 2;
  385. }
  386. }
  387. }
  388. void EdgeTable::multiplyLevels (float amount)
  389. {
  390. int* lineStart = table;
  391. const int multiplier = (int) (amount * 256.0f);
  392. for (int y = 0; y < bounds.getHeight(); ++y)
  393. {
  394. int numPoints = lineStart[0];
  395. LineItem* item = reinterpret_cast<LineItem*> (lineStart + 1);
  396. lineStart += lineStrideElements;
  397. while (--numPoints > 0)
  398. {
  399. item->level = jmin (255, (item->level * multiplier) >> 8);
  400. ++item;
  401. }
  402. }
  403. }
  404. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* const otherLine)
  405. {
  406. jassert (y >= 0 && y < bounds.getHeight());
  407. int* srcLine = table + lineStrideElements * y;
  408. int srcNum1 = *srcLine;
  409. if (srcNum1 == 0)
  410. return;
  411. int srcNum2 = *otherLine;
  412. if (srcNum2 == 0)
  413. {
  414. *srcLine = 0;
  415. return;
  416. }
  417. const int right = bounds.getRight() << 8;
  418. // optimise for the common case where our line lies entirely within a
  419. // single pair of points, as happens when clipping to a simple rect.
  420. if (srcNum2 == 2 && otherLine[2] >= 255)
  421. {
  422. clipEdgeTableLineToRange (srcLine, otherLine[1], jmin (right, otherLine[3]));
  423. return;
  424. }
  425. bool isUsingTempSpace = false;
  426. const int* src1 = srcLine + 1;
  427. int x1 = *src1++;
  428. const int* src2 = otherLine + 1;
  429. int x2 = *src2++;
  430. int destIndex = 0, destTotal = 0;
  431. int level1 = 0, level2 = 0;
  432. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  433. while (srcNum1 > 0 && srcNum2 > 0)
  434. {
  435. int nextX;
  436. if (x1 <= x2)
  437. {
  438. if (x1 == x2)
  439. {
  440. level2 = *src2++;
  441. x2 = *src2++;
  442. --srcNum2;
  443. }
  444. nextX = x1;
  445. level1 = *src1++;
  446. x1 = *src1++;
  447. --srcNum1;
  448. }
  449. else
  450. {
  451. nextX = x2;
  452. level2 = *src2++;
  453. x2 = *src2++;
  454. --srcNum2;
  455. }
  456. if (nextX > lastX)
  457. {
  458. if (nextX >= right)
  459. break;
  460. lastX = nextX;
  461. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  462. jassert (isPositiveAndBelow (nextLevel, (int) 256));
  463. if (nextLevel != lastLevel)
  464. {
  465. if (destTotal >= maxEdgesPerLine)
  466. {
  467. srcLine[0] = destTotal;
  468. if (isUsingTempSpace)
  469. {
  470. const size_t tempSize = (size_t) srcNum1 * 2 * sizeof (int);
  471. int* const oldTemp = static_cast<int*> (alloca (tempSize));
  472. memcpy (oldTemp, src1, tempSize);
  473. remapTableForNumEdges (jmax (256, destTotal * 2));
  474. srcLine = table + lineStrideElements * y;
  475. int* const newTemp = table + lineStrideElements * bounds.getHeight();
  476. memcpy (newTemp, oldTemp, tempSize);
  477. src1 = newTemp;
  478. }
  479. else
  480. {
  481. remapTableForNumEdges (jmax (256, destTotal * 2));
  482. srcLine = table + lineStrideElements * y;
  483. }
  484. }
  485. ++destTotal;
  486. lastLevel = nextLevel;
  487. if (! isUsingTempSpace)
  488. {
  489. isUsingTempSpace = true;
  490. int* const temp = table + lineStrideElements * bounds.getHeight();
  491. memcpy (temp, src1, (size_t) srcNum1 * 2 * sizeof (int));
  492. src1 = temp;
  493. }
  494. srcLine[++destIndex] = nextX;
  495. srcLine[++destIndex] = nextLevel;
  496. }
  497. }
  498. }
  499. if (lastLevel > 0)
  500. {
  501. if (destTotal >= maxEdgesPerLine)
  502. {
  503. srcLine[0] = destTotal;
  504. remapTableForNumEdges (jmax (256, destTotal * 2));
  505. srcLine = table + lineStrideElements * y;
  506. }
  507. ++destTotal;
  508. srcLine[++destIndex] = right;
  509. srcLine[++destIndex] = 0;
  510. }
  511. srcLine[0] = destTotal;
  512. }
  513. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) noexcept
  514. {
  515. int* lastItem = dest + (dest[0] * 2 - 1);
  516. if (x2 < lastItem[0])
  517. {
  518. if (x2 <= dest[1])
  519. {
  520. dest[0] = 0;
  521. return;
  522. }
  523. while (x2 < lastItem[-2])
  524. {
  525. --(dest[0]);
  526. lastItem -= 2;
  527. }
  528. lastItem[0] = x2;
  529. lastItem[1] = 0;
  530. }
  531. if (x1 > dest[1])
  532. {
  533. while (lastItem[0] > x1)
  534. lastItem -= 2;
  535. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  536. if (itemsRemoved > 0)
  537. {
  538. dest[0] -= itemsRemoved;
  539. memmove (dest + 1, lastItem, (size_t) dest[0] * (sizeof (int) * 2));
  540. }
  541. dest[1] = x1;
  542. }
  543. }
  544. //==============================================================================
  545. void EdgeTable::clipToRectangle (const Rectangle<int>& r)
  546. {
  547. const Rectangle<int> clipped (r.getIntersection (bounds));
  548. if (clipped.isEmpty())
  549. {
  550. needToCheckEmptiness = false;
  551. bounds.setHeight (0);
  552. }
  553. else
  554. {
  555. const int top = clipped.getY() - bounds.getY();
  556. const int bottom = clipped.getBottom() - bounds.getY();
  557. if (bottom < bounds.getHeight())
  558. bounds.setHeight (bottom);
  559. for (int i = top; --i >= 0;)
  560. table [lineStrideElements * i] = 0;
  561. if (clipped.getX() > bounds.getX() || clipped.getRight() < bounds.getRight())
  562. {
  563. const int x1 = clipped.getX() << 8;
  564. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  565. int* line = table + lineStrideElements * top;
  566. for (int i = bottom - top; --i >= 0;)
  567. {
  568. if (line[0] != 0)
  569. clipEdgeTableLineToRange (line, x1, x2);
  570. line += lineStrideElements;
  571. }
  572. }
  573. needToCheckEmptiness = true;
  574. }
  575. }
  576. void EdgeTable::excludeRectangle (const Rectangle<int>& r)
  577. {
  578. const Rectangle<int> clipped (r.getIntersection (bounds));
  579. if (! clipped.isEmpty())
  580. {
  581. const int top = clipped.getY() - bounds.getY();
  582. const int bottom = clipped.getBottom() - bounds.getY();
  583. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  584. clipped.getX() << 8, 0,
  585. clipped.getRight() << 8, 255,
  586. std::numeric_limits<int>::max(), 0 };
  587. for (int i = top; i < bottom; ++i)
  588. intersectWithEdgeTableLine (i, rectLine);
  589. needToCheckEmptiness = true;
  590. }
  591. }
  592. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  593. {
  594. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  595. if (clipped.isEmpty())
  596. {
  597. needToCheckEmptiness = false;
  598. bounds.setHeight (0);
  599. }
  600. else
  601. {
  602. const int top = clipped.getY() - bounds.getY();
  603. const int bottom = clipped.getBottom() - bounds.getY();
  604. if (bottom < bounds.getHeight())
  605. bounds.setHeight (bottom);
  606. if (clipped.getRight() < bounds.getRight())
  607. bounds.setRight (clipped.getRight());
  608. for (int i = 0; i < top; ++i)
  609. table [lineStrideElements * i] = 0;
  610. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  611. for (int i = top; i < bottom; ++i)
  612. {
  613. intersectWithEdgeTableLine (i, otherLine);
  614. otherLine += other.lineStrideElements;
  615. }
  616. needToCheckEmptiness = true;
  617. }
  618. }
  619. void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels)
  620. {
  621. y -= bounds.getY();
  622. if (y < 0 || y >= bounds.getHeight())
  623. return;
  624. needToCheckEmptiness = true;
  625. if (numPixels <= 0)
  626. {
  627. table [lineStrideElements * y] = 0;
  628. return;
  629. }
  630. int* tempLine = static_cast<int*> (alloca ((size_t) (numPixels * 2 + 4) * sizeof (int)));
  631. int destIndex = 0, lastLevel = 0;
  632. while (--numPixels >= 0)
  633. {
  634. const int alpha = *mask;
  635. mask += maskStride;
  636. if (alpha != lastLevel)
  637. {
  638. tempLine[++destIndex] = (x << 8);
  639. tempLine[++destIndex] = alpha;
  640. lastLevel = alpha;
  641. }
  642. ++x;
  643. }
  644. if (lastLevel > 0)
  645. {
  646. tempLine[++destIndex] = (x << 8);
  647. tempLine[++destIndex] = 0;
  648. }
  649. tempLine[0] = destIndex >> 1;
  650. intersectWithEdgeTableLine (y, tempLine);
  651. }
  652. bool EdgeTable::isEmpty() noexcept
  653. {
  654. if (needToCheckEmptiness)
  655. {
  656. needToCheckEmptiness = false;
  657. int* t = table;
  658. for (int i = bounds.getHeight(); --i >= 0;)
  659. {
  660. if (t[0] > 1)
  661. return false;
  662. t += lineStrideElements;
  663. }
  664. bounds.setHeight (0);
  665. }
  666. return bounds.getHeight() == 0;
  667. }