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