bit_mask.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*************************************************************************/
  2. /* bit_mask.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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. #ifndef BIT_MASK_H
  31. #define BIT_MASK_H
  32. #include "core/image.h"
  33. #include "core/io/resource_loader.h"
  34. #include "core/resource.h"
  35. class BitMap : public Resource {
  36. GDCLASS(BitMap, Resource);
  37. OBJ_SAVE_TYPE(BitMap);
  38. Vector<uint8_t> bitmask;
  39. int width;
  40. int height;
  41. Vector<Vector2> _march_square(const Rect2i &rect, const Point2i &start) const;
  42. Array _opaque_to_polygons_bind(const Rect2 &p_rect, float p_epsilon) const;
  43. protected:
  44. void _set_data(const Dictionary &p_d);
  45. Dictionary _get_data() const;
  46. static void _bind_methods();
  47. public:
  48. void create(const Size2 &p_size);
  49. void create_from_image_alpha(const Ref<Image> &p_image, float p_threshold = 0.1);
  50. void set_bit(const Point2 &p_pos, bool p_value);
  51. bool get_bit(const Point2 &p_pos) const;
  52. void set_bit_rect(const Rect2 &p_rect, bool p_value);
  53. int get_true_bit_count() const;
  54. Size2 get_size() const;
  55. void grow_mask(int p_pixels, const Rect2 &p_rect);
  56. Vector<Vector<Vector2> > clip_opaque_to_polygons(const Rect2 &p_rect, float p_epsilon = 2.0) const;
  57. BitMap();
  58. };
  59. #endif // BIT_MASK_H