camera_feed.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**************************************************************************/
  2. /* camera_feed.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 CAMERA_FEED_H
  31. #define CAMERA_FEED_H
  32. #include "core/io/image.h"
  33. #include "core/math/transform_2d.h"
  34. #include "servers/camera_server.h"
  35. #include "servers/rendering_server.h"
  36. /**
  37. The camera server is a singleton object that gives access to the various
  38. camera feeds that can be used as the background for our environment.
  39. **/
  40. class CameraFeed : public RefCounted {
  41. GDCLASS(CameraFeed, RefCounted);
  42. public:
  43. enum FeedDataType {
  44. FEED_NOIMAGE, // we don't have an image yet
  45. FEED_RGB, // our texture will contain a normal RGB texture that can be used directly
  46. FEED_YCBCR, // our texture will contain a YCbCr texture that needs to be converted to RGB before output
  47. FEED_YCBCR_SEP // our camera is split into two textures, first plane contains Y data, second plane contains CbCr data
  48. };
  49. enum FeedPosition {
  50. FEED_UNSPECIFIED, // we have no idea
  51. FEED_FRONT, // this is a camera on the front of the device
  52. FEED_BACK // this is a camera on the back of the device
  53. };
  54. private:
  55. int id; // unique id for this, for internal use in case feeds are removed
  56. int base_width;
  57. int base_height;
  58. protected:
  59. String name; // name of our camera feed
  60. FeedDataType datatype; // type of texture data stored
  61. FeedPosition position; // position of camera on the device
  62. Transform2D transform; // display transform
  63. bool active; // only when active do we actually update the camera texture each frame
  64. RID texture[CameraServer::FEED_IMAGES]; // texture images needed for this
  65. static void _bind_methods();
  66. public:
  67. int get_id() const;
  68. bool is_active() const;
  69. void set_active(bool p_is_active);
  70. String get_name() const;
  71. void set_name(String p_name);
  72. int get_base_width() const;
  73. int get_base_height() const;
  74. FeedPosition get_position() const;
  75. void set_position(FeedPosition p_position);
  76. Transform2D get_transform() const;
  77. void set_transform(const Transform2D &p_transform);
  78. RID get_texture(CameraServer::FeedImage p_which);
  79. CameraFeed();
  80. CameraFeed(String p_name, FeedPosition p_position = CameraFeed::FEED_UNSPECIFIED);
  81. virtual ~CameraFeed();
  82. FeedDataType get_datatype() const;
  83. void set_RGB_img(const Ref<Image> &p_rgb_img);
  84. void set_YCbCr_img(const Ref<Image> &p_ycbcr_img);
  85. void set_YCbCr_imgs(const Ref<Image> &p_y_img, const Ref<Image> &p_cbcr_img);
  86. virtual bool activate_feed();
  87. virtual void deactivate_feed();
  88. };
  89. VARIANT_ENUM_CAST(CameraFeed::FeedDataType);
  90. VARIANT_ENUM_CAST(CameraFeed::FeedPosition);
  91. #endif // CAMERA_FEED_H