/**************************************************************************/1/* camera_feed.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/io/image.h"33#include "core/math/transform_2d.h"34#include "servers/camera_server.h"3536/**37The camera server is a singleton object that gives access to the various38camera feeds that can be used as the background for our environment.39**/4041class CameraFeed : public RefCounted {42GDCLASS(CameraFeed, RefCounted);4344public:45enum FeedDataType {46FEED_NOIMAGE, // we don't have an image yet47FEED_RGB, // our texture will contain a normal RGB texture that can be used directly48FEED_YCBCR, // our texture will contain a YCbCr texture that needs to be converted to RGB before output49FEED_YCBCR_SEP, // our camera is split into two textures, first plane contains Y data, second plane contains CbCr data50FEED_EXTERNAL, // specific for android atm, camera feed is managed externally, assumed RGB for now51};5253enum FeedPosition {54FEED_UNSPECIFIED, // we have no idea55FEED_FRONT, // this is a camera on the front of the device56FEED_BACK // this is a camera on the back of the device57};5859private:60int id; // unique id for this, for internal use in case feeds are removed61const StringName format_changed_signal_name = "format_changed";62const StringName frame_changed_signal_name = "frame_changed";6364protected:65struct FeedFormat {66int width = 0;67int height = 0;68String format;69int frame_numerator = 0;70int frame_denominator = 0;71uint32_t pixel_format = 0;72};7374String name; // name of our camera feed75FeedDataType datatype; // type of texture data stored76FeedPosition position; // position of camera on the device77Transform2D transform; // display transform78int base_width = 0;79int base_height = 0;80Vector<FeedFormat> formats;81Dictionary parameters;82int selected_format = -1;8384bool active; // only when active do we actually update the camera texture each frame85RID texture[CameraServer::FEED_IMAGES]; // texture images needed for this8687static void _bind_methods();8889public:90int get_id() const;91bool is_active() const;92void set_active(bool p_is_active);9394String get_name() const;95void set_name(String p_name);9697int get_base_width() const;98int get_base_height() const;99100FeedPosition get_position() const;101void set_position(FeedPosition p_position);102103Transform2D get_transform() const;104void set_transform(const Transform2D &p_transform);105106RID get_texture(CameraServer::FeedImage p_which);107uint64_t get_texture_tex_id(CameraServer::FeedImage p_which);108109CameraFeed();110CameraFeed(String p_name, FeedPosition p_position = CameraFeed::FEED_UNSPECIFIED);111virtual ~CameraFeed();112113FeedDataType get_datatype() const;114void set_rgb_image(const Ref<Image> &p_rgb_img);115void set_ycbcr_image(const Ref<Image> &p_ycbcr_img);116void set_ycbcr_images(const Ref<Image> &p_y_img, const Ref<Image> &p_cbcr_img);117void set_external(int p_width, int p_height);118119virtual bool set_format(int p_index, const Dictionary &p_parameters);120virtual Array get_formats() const;121virtual FeedFormat get_format() const;122123virtual bool activate_feed();124virtual void deactivate_feed();125126GDVIRTUAL0R(bool, _activate_feed)127GDVIRTUAL0(_deactivate_feed)128};129130VARIANT_ENUM_CAST(CameraFeed::FeedDataType);131VARIANT_ENUM_CAST(CameraFeed::FeedPosition);132133134