bit_map.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /*************************************************************************/
  2. /* bit_map.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "bit_map.h"
  31. #include "core/io/image_loader.h"
  32. void BitMap::create(const Size2 &p_size) {
  33. ERR_FAIL_COND(p_size.width < 1);
  34. ERR_FAIL_COND(p_size.height < 1);
  35. width = p_size.width;
  36. height = p_size.height;
  37. bitmask.resize(((width * height) / 8) + 1);
  38. zeromem(bitmask.ptrw(), bitmask.size());
  39. }
  40. void BitMap::create_from_image_alpha(const Ref<Image> &p_image, float p_threshold) {
  41. ERR_FAIL_COND(p_image.is_null() || p_image->empty());
  42. Ref<Image> img = p_image->duplicate();
  43. img->convert(Image::FORMAT_LA8);
  44. ERR_FAIL_COND(img->get_format() != Image::FORMAT_LA8);
  45. create(Size2(img->get_width(), img->get_height()));
  46. PoolVector<uint8_t>::Read r = img->get_data().read();
  47. uint8_t *w = bitmask.ptrw();
  48. for (int i = 0; i < width * height; i++) {
  49. int bbyte = i / 8;
  50. int bbit = i % 8;
  51. if (r[i * 2 + 1] / 255.0 > p_threshold) {
  52. w[bbyte] |= (1 << bbit);
  53. }
  54. }
  55. }
  56. void BitMap::set_bit_rect(const Rect2 &p_rect, bool p_value) {
  57. Rect2i current = Rect2i(0, 0, width, height).clip(p_rect);
  58. uint8_t *data = bitmask.ptrw();
  59. for (int i = current.position.x; i < current.position.x + current.size.x; i++) {
  60. for (int j = current.position.y; j < current.position.y + current.size.y; j++) {
  61. int ofs = width * j + i;
  62. int bbyte = ofs / 8;
  63. int bbit = ofs % 8;
  64. uint8_t b = data[bbyte];
  65. if (p_value)
  66. b |= (1 << bbit);
  67. else
  68. b &= ~(1 << bbit);
  69. data[bbyte] = b;
  70. }
  71. }
  72. }
  73. int BitMap::get_true_bit_count() const {
  74. int ds = bitmask.size();
  75. const uint8_t *d = bitmask.ptr();
  76. int c = 0;
  77. //fast, almost branchless version
  78. for (int i = 0; i < ds; i++) {
  79. c += (d[i] & (1 << 7)) >> 7;
  80. c += (d[i] & (1 << 6)) >> 6;
  81. c += (d[i] & (1 << 5)) >> 5;
  82. c += (d[i] & (1 << 4)) >> 4;
  83. c += (d[i] & (1 << 3)) >> 3;
  84. c += (d[i] & (1 << 2)) >> 2;
  85. c += (d[i] & (1 << 1)) >> 1;
  86. c += d[i] & 1;
  87. }
  88. return c;
  89. }
  90. void BitMap::set_bit(const Point2 &p_pos, bool p_value) {
  91. int x = p_pos.x;
  92. int y = p_pos.y;
  93. ERR_FAIL_INDEX(x, width);
  94. ERR_FAIL_INDEX(y, height);
  95. int ofs = width * y + x;
  96. int bbyte = ofs / 8;
  97. int bbit = ofs % 8;
  98. uint8_t b = bitmask[bbyte];
  99. if (p_value)
  100. b |= (1 << bbit);
  101. else
  102. b &= ~(1 << bbit);
  103. bitmask.write[bbyte] = b;
  104. }
  105. bool BitMap::get_bit(const Point2 &p_pos) const {
  106. int x = Math::fast_ftoi(p_pos.x);
  107. int y = Math::fast_ftoi(p_pos.y);
  108. ERR_FAIL_INDEX_V(x, width, false);
  109. ERR_FAIL_INDEX_V(y, height, false);
  110. int ofs = width * y + x;
  111. int bbyte = ofs / 8;
  112. int bbit = ofs % 8;
  113. return (bitmask[bbyte] & (1 << bbit)) != 0;
  114. }
  115. Size2 BitMap::get_size() const {
  116. return Size2(width, height);
  117. }
  118. void BitMap::_set_data(const Dictionary &p_d) {
  119. ERR_FAIL_COND(!p_d.has("size"));
  120. ERR_FAIL_COND(!p_d.has("data"));
  121. create(p_d["size"]);
  122. bitmask = p_d["data"];
  123. }
  124. Dictionary BitMap::_get_data() const {
  125. Dictionary d;
  126. d["size"] = get_size();
  127. d["data"] = bitmask;
  128. return d;
  129. }
  130. Vector<Vector2> BitMap::_march_square(const Rect2i &rect, const Point2i &start) const {
  131. int stepx = 0;
  132. int stepy = 0;
  133. int prevx = 0;
  134. int prevy = 0;
  135. int startx = start.x;
  136. int starty = start.y;
  137. int curx = startx;
  138. int cury = starty;
  139. unsigned int count = 0;
  140. Set<Point2i> case9s;
  141. Set<Point2i> case6s;
  142. Vector<Vector2> _points;
  143. do {
  144. int sv = 0;
  145. { //square value
  146. /*
  147. checking the 2x2 pixel grid, assigning these values to each pixel, if not transparent
  148. +---+---+
  149. | 1 | 2 |
  150. +---+---+
  151. | 4 | 8 | <- current pixel (curx,cury)
  152. +---+---+
  153. */
  154. Point2i tl = Point2i(curx - 1, cury - 1);
  155. sv += (rect.has_point(tl) && get_bit(tl)) ? 1 : 0;
  156. Point2i tr = Point2i(curx, cury - 1);
  157. sv += (rect.has_point(tr) && get_bit(tr)) ? 2 : 0;
  158. Point2i bl = Point2i(curx - 1, cury);
  159. sv += (rect.has_point(bl) && get_bit(bl)) ? 4 : 0;
  160. Point2i br = Point2i(curx, cury);
  161. sv += (rect.has_point(br) && get_bit(br)) ? 8 : 0;
  162. ERR_FAIL_COND_V(sv == 0 || sv == 15, Vector<Vector2>());
  163. }
  164. switch (sv) {
  165. case 1:
  166. case 5:
  167. case 13:
  168. /* going UP with these cases:
  169. 1 5 13
  170. +---+---+ +---+---+ +---+---+
  171. | 1 | | | 1 | | | 1 | |
  172. +---+---+ +---+---+ +---+---+
  173. | | | | 4 | | | 4 | 8 |
  174. +---+---+ +---+---+ +---+---+
  175. */
  176. stepx = 0;
  177. stepy = -1;
  178. break;
  179. case 8:
  180. case 10:
  181. case 11:
  182. /* going DOWN with these cases:
  183. 8 10 11
  184. +---+---+ +---+---+ +---+---+
  185. | | | | | 2 | | 1 | 2 |
  186. +---+---+ +---+---+ +---+---+
  187. | | 8 | | | 8 | | | 8 |
  188. +---+---+ +---+---+ +---+---+
  189. */
  190. stepx = 0;
  191. stepy = 1;
  192. break;
  193. case 4:
  194. case 12:
  195. case 14:
  196. /* going LEFT with these cases:
  197. 4 12 14
  198. +---+---+ +---+---+ +---+---+
  199. | | | | | | | | 2 |
  200. +---+---+ +---+---+ +---+---+
  201. | 4 | | | 4 | 8 | | 4 | 8 |
  202. +---+---+ +---+---+ +---+---+
  203. */
  204. stepx = -1;
  205. stepy = 0;
  206. break;
  207. case 2:
  208. case 3:
  209. case 7:
  210. /* going RIGHT with these cases:
  211. 2 3 7
  212. +---+---+ +---+---+ +---+---+
  213. | | 2 | | 1 | 2 | | 1 | 2 |
  214. +---+---+ +---+---+ +---+---+
  215. | | | | | | | 4 | |
  216. +---+---+ +---+---+ +---+---+
  217. */
  218. stepx = 1;
  219. stepy = 0;
  220. break;
  221. case 9:
  222. /*
  223. +---+---+
  224. | 1 | |
  225. +---+---+
  226. | | 8 |
  227. +---+---+
  228. this should normally go UP, but if we already been here, we go down
  229. */
  230. if (case9s.has(Point2i(curx, cury))) {
  231. //found, so we go down, and delete from case9s;
  232. stepx = 0;
  233. stepy = 1;
  234. case9s.erase(Point2i(curx, cury));
  235. } else {
  236. //not found, we go up, and add to case9s;
  237. stepx = 0;
  238. stepy = -1;
  239. case9s.insert(Point2i(curx, cury));
  240. }
  241. break;
  242. case 6:
  243. /*
  244. 6
  245. +---+---+
  246. | | 2 |
  247. +---+---+
  248. | 4 | |
  249. +---+---+
  250. this normally go RIGHT, but if its coming from RIGHT, it should go LEFT
  251. */
  252. if (case6s.has(Point2i(curx, cury))) {
  253. //found, so we go left, and delete from case6s;
  254. stepx = -1;
  255. stepy = 0;
  256. case6s.erase(Point2i(curx, cury));
  257. } else {
  258. //not found, we go right, and add to case6s;
  259. stepx = 1;
  260. stepy = 0;
  261. case6s.insert(Point2i(curx, cury));
  262. }
  263. break;
  264. default:
  265. ERR_PRINT("this shouldn't happen.");
  266. }
  267. //little optimization
  268. // if previous direction is same as current direction,
  269. // then we should modify the last vec to current
  270. curx += stepx;
  271. cury += stepy;
  272. if (stepx == prevx && stepy == prevy) {
  273. _points.write[_points.size() - 1].x = (float)(curx - rect.position.x);
  274. _points.write[_points.size() - 1].y = (float)(cury + rect.position.y);
  275. } else {
  276. _points.push_back(Vector2((float)(curx - rect.position.x), (float)(cury + rect.position.y)));
  277. }
  278. count++;
  279. prevx = stepx;
  280. prevy = stepy;
  281. ERR_FAIL_COND_V((int)count > width * height, _points);
  282. } while (curx != startx || cury != starty);
  283. return _points;
  284. }
  285. static float perpendicular_distance(const Vector2 &i, const Vector2 &start, const Vector2 &end) {
  286. float res;
  287. float slope;
  288. float intercept;
  289. if (start.x == end.x) {
  290. res = Math::absf(i.x - end.x);
  291. } else if (start.y == end.y) {
  292. res = Math::absf(i.y - end.y);
  293. } else {
  294. slope = (end.y - start.y) / (end.x - start.x);
  295. intercept = start.y - (slope * start.x);
  296. res = Math::absf(slope * i.x - i.y + intercept) / Math::sqrt(Math::pow(slope, 2.0f) + 1.0);
  297. }
  298. return res;
  299. }
  300. static Vector<Vector2> rdp(const Vector<Vector2> &v, float optimization) {
  301. if (v.size() < 3)
  302. return v;
  303. int index = -1;
  304. float dist = 0;
  305. //not looping first and last point
  306. for (size_t i = 1, size = v.size(); i < size - 1; ++i) {
  307. float cdist = perpendicular_distance(v[i], v[0], v[v.size() - 1]);
  308. if (cdist > dist) {
  309. dist = cdist;
  310. index = static_cast<int>(i);
  311. }
  312. }
  313. if (dist > optimization) {
  314. Vector<Vector2> left, right;
  315. left.resize(index);
  316. for (int i = 0; i < index; i++) {
  317. left.write[i] = v[i];
  318. }
  319. right.resize(v.size() - index);
  320. for (int i = 0; i < right.size(); i++) {
  321. right.write[i] = v[index + i];
  322. }
  323. Vector<Vector2> r1 = rdp(left, optimization);
  324. Vector<Vector2> r2 = rdp(right, optimization);
  325. int middle = r1.size();
  326. r1.resize(r1.size() + r2.size());
  327. for (int i = 0; i < r2.size(); i++) {
  328. r1.write[middle + i] = r2[i];
  329. }
  330. return r1;
  331. } else {
  332. Vector<Vector2> ret;
  333. ret.push_back(v[0]);
  334. ret.push_back(v[v.size() - 1]);
  335. return ret;
  336. }
  337. }
  338. static Vector<Vector2> reduce(const Vector<Vector2> &points, const Rect2i &rect, float epsilon) {
  339. int size = points.size();
  340. // if there are less than 3 points, then we have nothing
  341. ERR_FAIL_COND_V(size < 3, Vector<Vector2>());
  342. // if there are less than 9 points (but more than 3), then we don't need to reduce it
  343. if (size < 9) {
  344. return points;
  345. }
  346. float maxEp = MIN(rect.size.width, rect.size.height);
  347. float ep = CLAMP(epsilon, 0.0, maxEp / 2);
  348. Vector<Vector2> result = rdp(points, ep);
  349. Vector2 last = result[result.size() - 1];
  350. if (last.y > result[0].y && last.distance_to(result[0]) < ep * 0.5f) {
  351. result.write[0].y = last.y;
  352. result.resize(result.size() - 1);
  353. }
  354. return result;
  355. }
  356. struct FillBitsStackEntry {
  357. Point2i pos;
  358. int i;
  359. int j;
  360. };
  361. static void fill_bits(const BitMap *p_src, Ref<BitMap> &p_map, const Point2i &p_pos, const Rect2i &rect) {
  362. // Using a custom stack to work iteratively to avoid stack overflow on big bitmaps
  363. PoolVector<FillBitsStackEntry> stack;
  364. // Tracking size since we won't be shrinking the stack vector
  365. int stack_size = 0;
  366. Point2i pos = p_pos;
  367. int next_i = 0;
  368. int next_j = 0;
  369. bool reenter = true;
  370. bool popped = false;
  371. do {
  372. if (reenter) {
  373. next_i = pos.x - 1;
  374. next_j = pos.y - 1;
  375. reenter = false;
  376. }
  377. for (int i = next_i; i <= pos.x + 1; i++) {
  378. for (int j = next_j; j <= pos.y + 1; j++) {
  379. if (popped) {
  380. // The next loop over j must start normally
  381. next_j = pos.y;
  382. popped = false;
  383. // Skip because an iteration was already executed with current counter values
  384. continue;
  385. }
  386. if (i < rect.position.x || i >= rect.position.x + rect.size.x)
  387. continue;
  388. if (j < rect.position.y || j >= rect.position.y + rect.size.y)
  389. continue;
  390. if (p_map->get_bit(Vector2(i, j)))
  391. continue;
  392. else if (p_src->get_bit(Vector2(i, j))) {
  393. p_map->set_bit(Vector2(i, j), true);
  394. FillBitsStackEntry se = { pos, i, j };
  395. stack.resize(MAX(stack_size + 1, stack.size()));
  396. stack.set(stack_size, se);
  397. stack_size++;
  398. pos = Point2i(i, j);
  399. reenter = true;
  400. break;
  401. }
  402. }
  403. if (reenter) {
  404. break;
  405. }
  406. }
  407. if (!reenter) {
  408. if (stack_size) {
  409. FillBitsStackEntry se = stack.get(stack_size - 1);
  410. stack_size--;
  411. pos = se.pos;
  412. next_i = se.i;
  413. next_j = se.j;
  414. popped = true;
  415. }
  416. }
  417. } while (reenter || popped);
  418. print_verbose("BitMap: Max stack size: " + itos(stack.size()));
  419. }
  420. Vector<Vector<Vector2> > BitMap::clip_opaque_to_polygons(const Rect2 &p_rect, float p_epsilon) const {
  421. Rect2i r = Rect2i(0, 0, width, height).clip(p_rect);
  422. print_verbose("BitMap: Rect: " + r);
  423. Point2i from;
  424. Ref<BitMap> fill;
  425. fill.instance();
  426. fill->create(get_size());
  427. Vector<Vector<Vector2> > polygons;
  428. for (int i = r.position.y; i < r.position.y + r.size.height; i++) {
  429. for (int j = r.position.x; j < r.position.x + r.size.width; j++) {
  430. if (!fill->get_bit(Point2(j, i)) && get_bit(Point2(j, i))) {
  431. fill_bits(this, fill, Point2i(j, i), r);
  432. Vector<Vector2> polygon = _march_square(r, Point2i(j, i));
  433. print_verbose("BitMap: Pre reduce: " + itos(polygon.size()));
  434. polygon = reduce(polygon, r, p_epsilon);
  435. print_verbose("BitMap: Post reduce: " + itos(polygon.size()));
  436. if (polygon.size() < 3) {
  437. print_verbose("Invalid polygon, skipped");
  438. continue;
  439. }
  440. polygons.push_back(polygon);
  441. }
  442. }
  443. }
  444. return polygons;
  445. }
  446. void BitMap::grow_mask(int p_pixels, const Rect2 &p_rect) {
  447. if (p_pixels == 0) {
  448. return;
  449. }
  450. bool bit_value = p_pixels > 0;
  451. p_pixels = Math::abs(p_pixels);
  452. Rect2i r = Rect2i(0, 0, width, height).clip(p_rect);
  453. Ref<BitMap> copy;
  454. copy.instance();
  455. copy->create(get_size());
  456. copy->bitmask = bitmask;
  457. for (int i = r.position.y; i < r.position.y + r.size.height; i++) {
  458. for (int j = r.position.x; j < r.position.x + r.size.width; j++) {
  459. if (bit_value == get_bit(Point2(j, i)))
  460. continue;
  461. bool found = false;
  462. for (int y = i - p_pixels; y <= i + p_pixels; y++) {
  463. for (int x = j - p_pixels; x <= j + p_pixels; x++) {
  464. bool outside = false;
  465. if ((x < p_rect.position.x) || (x >= p_rect.position.x + p_rect.size.x) || (y < p_rect.position.y) || (y >= p_rect.position.y + p_rect.size.y)) {
  466. // outside of rectangle counts as bit not set
  467. if (!bit_value)
  468. outside = true;
  469. else
  470. continue;
  471. }
  472. float d = Point2(j, i).distance_to(Point2(x, y)) - CMP_EPSILON;
  473. if (d > p_pixels)
  474. continue;
  475. if (outside || (bit_value == copy->get_bit(Point2(x, y)))) {
  476. found = true;
  477. break;
  478. }
  479. }
  480. if (found)
  481. break;
  482. }
  483. if (found) {
  484. set_bit(Point2(j, i), bit_value);
  485. }
  486. }
  487. }
  488. }
  489. void BitMap::shrink_mask(int p_pixels, const Rect2 &p_rect) {
  490. grow_mask(-p_pixels, p_rect);
  491. }
  492. Array BitMap::_opaque_to_polygons_bind(const Rect2 &p_rect, float p_epsilon) const {
  493. Vector<Vector<Vector2> > result = clip_opaque_to_polygons(p_rect, p_epsilon);
  494. // Convert result to bindable types
  495. Array result_array;
  496. result_array.resize(result.size());
  497. for (int i = 0; i < result.size(); i++) {
  498. const Vector<Vector2> &polygon = result[i];
  499. PoolVector2Array polygon_array;
  500. polygon_array.resize(polygon.size());
  501. {
  502. PoolVector2Array::Write w = polygon_array.write();
  503. for (int j = 0; j < polygon.size(); j++) {
  504. w[j] = polygon[j];
  505. }
  506. }
  507. result_array[i] = polygon_array;
  508. }
  509. return result_array;
  510. }
  511. void BitMap::resize(const Size2 &p_new_size) {
  512. Ref<BitMap> new_bitmap;
  513. new_bitmap.instance();
  514. new_bitmap->create(p_new_size);
  515. int lw = MIN(width, p_new_size.width);
  516. int lh = MIN(height, p_new_size.height);
  517. for (int x = 0; x < lw; x++) {
  518. for (int y = 0; y < lh; y++) {
  519. new_bitmap->set_bit(Vector2(x, y), get_bit(Vector2(x, y)));
  520. }
  521. }
  522. width = new_bitmap->width;
  523. height = new_bitmap->height;
  524. bitmask = new_bitmap->bitmask;
  525. }
  526. Ref<Image> BitMap::convert_to_image() const {
  527. Ref<Image> image;
  528. image.instance();
  529. image->create(width, height, false, Image::FORMAT_L8);
  530. image->lock();
  531. for (int i = 0; i < width; i++) {
  532. for (int j = 0; j < height; j++) {
  533. image->set_pixel(i, j, get_bit(Point2(i, j)) ? Color(1, 1, 1) : Color(0, 0, 0));
  534. }
  535. }
  536. image->unlock();
  537. return image;
  538. }
  539. void BitMap::blit(const Vector2 &p_pos, const Ref<BitMap> &p_bitmap) {
  540. int x = p_pos.x;
  541. int y = p_pos.y;
  542. int w = p_bitmap->get_size().width;
  543. int h = p_bitmap->get_size().height;
  544. for (int i = 0; i < w; i++) {
  545. for (int j = 0; j < h; j++) {
  546. int px = x + i;
  547. int py = y + j;
  548. if (px < 0 || px >= width)
  549. continue;
  550. if (py < 0 || py >= height)
  551. continue;
  552. if (p_bitmap->get_bit(Vector2(i, j))) {
  553. set_bit(Vector2(x, y), true);
  554. }
  555. }
  556. }
  557. }
  558. void BitMap::_bind_methods() {
  559. ClassDB::bind_method(D_METHOD("create", "size"), &BitMap::create);
  560. ClassDB::bind_method(D_METHOD("create_from_image_alpha", "image", "threshold"), &BitMap::create_from_image_alpha, DEFVAL(0.1));
  561. ClassDB::bind_method(D_METHOD("set_bit", "position", "bit"), &BitMap::set_bit);
  562. ClassDB::bind_method(D_METHOD("get_bit", "position"), &BitMap::get_bit);
  563. ClassDB::bind_method(D_METHOD("set_bit_rect", "rect", "bit"), &BitMap::set_bit_rect);
  564. ClassDB::bind_method(D_METHOD("get_true_bit_count"), &BitMap::get_true_bit_count);
  565. ClassDB::bind_method(D_METHOD("get_size"), &BitMap::get_size);
  566. ClassDB::bind_method(D_METHOD("_set_data"), &BitMap::_set_data);
  567. ClassDB::bind_method(D_METHOD("_get_data"), &BitMap::_get_data);
  568. ClassDB::bind_method(D_METHOD("grow_mask", "pixels", "rect"), &BitMap::grow_mask);
  569. ClassDB::bind_method(D_METHOD("opaque_to_polygons", "rect", "epsilon"), &BitMap::_opaque_to_polygons_bind, DEFVAL(2.0));
  570. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_data", "_get_data");
  571. }
  572. BitMap::BitMap() {
  573. width = 0;
  574. height = 0;
  575. }
  576. //////////////////////////////////////