The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

839 lines
22KB

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