From 38d7ec1640ece8cdf6774ff5ae1f9f37d0a5cc66 Mon Sep 17 00:00:00 2001 From: Jason Kuo Date: Fri, 27 Sep 2024 18:10:59 +0800 Subject: [PATCH] Expose CameraFeed setters --- doc/classes/CameraFeed.xml | 28 ++++++++++++++++++++++++++++ modules/camera/buffer_decoder.cpp | 10 +++++----- modules/camera/camera_macos.mm | 2 +- servers/camera/camera_feed.cpp | 17 +++++++---------- servers/camera/camera_feed.h | 6 +++--- 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/doc/classes/CameraFeed.xml b/doc/classes/CameraFeed.xml index 8033c0880b5..2b6db13906c 100644 --- a/doc/classes/CameraFeed.xml +++ b/doc/classes/CameraFeed.xml @@ -45,6 +45,34 @@ [code]copy[/code] will result in FEED_YCBCR + + + + + Sets the camera's name. + + + + + + + Sets the position of this camera. + + + + + + + Sets RGB image for this feed. + + + + + + + Sets YCbCr image for this feed. + + diff --git a/modules/camera/buffer_decoder.cpp b/modules/camera/buffer_decoder.cpp index 024a68f0803..85cfea242c9 100644 --- a/modules/camera/buffer_decoder.cpp +++ b/modules/camera/buffer_decoder.cpp @@ -105,7 +105,7 @@ void SeparateYuyvBufferDecoder::decode(StreamingBuffer p_buffer) { cbcr_image.instantiate(width, height, false, Image::FORMAT_RGB8, cbcr_image_data); } - camera_feed->set_YCbCr_imgs(y_image, cbcr_image); + camera_feed->set_ycbcr_images(y_image, cbcr_image); } YuyvToGrayscaleBufferDecoder::YuyvToGrayscaleBufferDecoder(CameraFeed *p_camera_feed) : @@ -133,7 +133,7 @@ void YuyvToGrayscaleBufferDecoder::decode(StreamingBuffer p_buffer) { image.instantiate(width, height, false, Image::FORMAT_RGB8, image_data); } - camera_feed->set_RGB_img(image); + camera_feed->set_rgb_image(image); } YuyvToRgbBufferDecoder::YuyvToRgbBufferDecoder(CameraFeed *p_camera_feed) : @@ -176,7 +176,7 @@ void YuyvToRgbBufferDecoder::decode(StreamingBuffer p_buffer) { image.instantiate(width, height, false, Image::FORMAT_RGB8, image_data); } - camera_feed->set_RGB_img(image); + camera_feed->set_rgb_image(image); } CopyBufferDecoder::CopyBufferDecoder(CameraFeed *p_camera_feed, bool p_rgba) : @@ -195,7 +195,7 @@ void CopyBufferDecoder::decode(StreamingBuffer p_buffer) { image.instantiate(width, height, false, rgba ? Image::FORMAT_RGBA8 : Image::FORMAT_LA8, image_data); } - camera_feed->set_RGB_img(image); + camera_feed->set_rgb_image(image); } JpegBufferDecoder::JpegBufferDecoder(CameraFeed *p_camera_feed) : @@ -207,6 +207,6 @@ void JpegBufferDecoder::decode(StreamingBuffer p_buffer) { uint8_t *dst = (uint8_t *)image_data.ptrw(); memcpy(dst, p_buffer.start, p_buffer.length); if (image->load_jpg_from_buffer(image_data) == OK) { - camera_feed->set_RGB_img(image); + camera_feed->set_rgb_image(image); } } diff --git a/modules/camera/camera_macos.mm b/modules/camera/camera_macos.mm index 578a1d63252..de4f814846d 100644 --- a/modules/camera/camera_macos.mm +++ b/modules/camera/camera_macos.mm @@ -182,7 +182,7 @@ } // set our texture... - feed->set_YCbCr_imgs(img[0], img[1]); + feed->set_ycbcr_images(img[0], img[1]); } // and unlock diff --git a/servers/camera/camera_feed.cpp b/servers/camera/camera_feed.cpp index 8f6a40481d7..4021d9564bf 100644 --- a/servers/camera/camera_feed.cpp +++ b/servers/camera/camera_feed.cpp @@ -33,26 +33,23 @@ #include "servers/rendering_server.h" void CameraFeed::_bind_methods() { - // The setters prefixed with _ are only exposed so we can have feeds through GDExtension! - // They should not be called by the end user. - ClassDB::bind_method(D_METHOD("get_id"), &CameraFeed::get_id); ClassDB::bind_method(D_METHOD("is_active"), &CameraFeed::is_active); ClassDB::bind_method(D_METHOD("set_active", "active"), &CameraFeed::set_active); ClassDB::bind_method(D_METHOD("get_name"), &CameraFeed::get_name); - ClassDB::bind_method(D_METHOD("_set_name", "name"), &CameraFeed::set_name); + ClassDB::bind_method(D_METHOD("set_name", "name"), &CameraFeed::set_name); ClassDB::bind_method(D_METHOD("get_position"), &CameraFeed::get_position); - ClassDB::bind_method(D_METHOD("_set_position", "position"), &CameraFeed::set_position); + ClassDB::bind_method(D_METHOD("set_position", "position"), &CameraFeed::set_position); // Note, for transform some feeds may override what the user sets (such as ARKit) ClassDB::bind_method(D_METHOD("get_transform"), &CameraFeed::get_transform); ClassDB::bind_method(D_METHOD("set_transform", "transform"), &CameraFeed::set_transform); - ClassDB::bind_method(D_METHOD("_set_RGB_img", "rgb_img"), &CameraFeed::set_RGB_img); - ClassDB::bind_method(D_METHOD("_set_YCbCr_img", "ycbcr_img"), &CameraFeed::set_YCbCr_img); + ClassDB::bind_method(D_METHOD("set_rgb_image", "rgb_image"), &CameraFeed::set_rgb_image); + ClassDB::bind_method(D_METHOD("set_ycbcr_image", "ycbcr_image"), &CameraFeed::set_ycbcr_image); ClassDB::bind_method(D_METHOD("get_datatype"), &CameraFeed::get_datatype); @@ -175,7 +172,7 @@ CameraFeed::~CameraFeed() { RenderingServer::get_singleton()->free(texture[CameraServer::FEED_CBCR_IMAGE]); } -void CameraFeed::set_RGB_img(const Ref &p_rgb_img) { +void CameraFeed::set_rgb_image(const Ref &p_rgb_img) { ERR_FAIL_COND(p_rgb_img.is_null()); if (active) { int new_width = p_rgb_img->get_width(); @@ -198,7 +195,7 @@ void CameraFeed::set_RGB_img(const Ref &p_rgb_img) { } } -void CameraFeed::set_YCbCr_img(const Ref &p_ycbcr_img) { +void CameraFeed::set_ycbcr_image(const Ref &p_ycbcr_img) { ERR_FAIL_COND(p_ycbcr_img.is_null()); if (active) { int new_width = p_ycbcr_img->get_width(); @@ -221,7 +218,7 @@ void CameraFeed::set_YCbCr_img(const Ref &p_ycbcr_img) { } } -void CameraFeed::set_YCbCr_imgs(const Ref &p_y_img, const Ref &p_cbcr_img) { +void CameraFeed::set_ycbcr_images(const Ref &p_y_img, const Ref &p_cbcr_img) { ERR_FAIL_COND(p_y_img.is_null()); ERR_FAIL_COND(p_cbcr_img.is_null()); if (active) { diff --git a/servers/camera/camera_feed.h b/servers/camera/camera_feed.h index 5d1f54be07e..492a909239e 100644 --- a/servers/camera/camera_feed.h +++ b/servers/camera/camera_feed.h @@ -110,9 +110,9 @@ public: virtual ~CameraFeed(); FeedDataType get_datatype() const; - void set_RGB_img(const Ref &p_rgb_img); - void set_YCbCr_img(const Ref &p_ycbcr_img); - void set_YCbCr_imgs(const Ref &p_y_img, const Ref &p_cbcr_img); + void set_rgb_image(const Ref &p_rgb_img); + void set_ycbcr_image(const Ref &p_ycbcr_img); + void set_ycbcr_images(const Ref &p_y_img, const Ref &p_cbcr_img); virtual bool set_format(int p_index, const Dictionary &p_parameters); virtual Array get_formats() const;