bit_map.cpp 18 KB

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