camera_feed.h 4.8 KB

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