Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose CameraFeed setters #97534

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions doc/classes/CameraFeed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@
[code]copy[/code] will result in FEED_YCBCR
</description>
</method>
<method name="set_name">
<return type="void" />
<param index="0" name="name" type="String" />
<description>
Sets the camera's name.
</description>
</method>
<method name="set_position">
<return type="void" />
<param index="0" name="position" type="int" enum="CameraFeed.FeedPosition" />
<description>
Sets the position of this camera.
</description>
</method>
<method name="set_rgb_image">
<return type="void" />
<param index="0" name="rgb_image" type="Image" />
<description>
Sets RGB image for this feed.
</description>
</method>
<method name="set_ycbcr_image">
<return type="void" />
<param index="0" name="ycbcr_image" type="Image" />
<description>
Sets YCbCr image for this feed.
</description>
</method>
</methods>
<members>
<member name="feed_is_active" type="bool" setter="set_active" getter="is_active" default="false">
Expand Down
10 changes: 5 additions & 5 deletions modules/camera/buffer_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) :
Expand Down Expand Up @@ -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) :
Expand Down Expand Up @@ -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) :
Expand All @@ -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) :
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion modules/camera/camera_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM
}

// set our texture...
feed->set_YCbCr_imgs(img[0], img[1]);
feed->set_ycbcr_images(img[0], img[1]);
}

// and unlock
Expand Down
17 changes: 7 additions & 10 deletions servers/camera/camera_feed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -175,7 +172,7 @@ CameraFeed::~CameraFeed() {
RenderingServer::get_singleton()->free(texture[CameraServer::FEED_CBCR_IMAGE]);
}

void CameraFeed::set_RGB_img(const Ref<Image> &p_rgb_img) {
void CameraFeed::set_rgb_image(const Ref<Image> &p_rgb_img) {
ERR_FAIL_COND(p_rgb_img.is_null());
if (active) {
int new_width = p_rgb_img->get_width();
Expand All @@ -198,7 +195,7 @@ void CameraFeed::set_RGB_img(const Ref<Image> &p_rgb_img) {
}
}

void CameraFeed::set_YCbCr_img(const Ref<Image> &p_ycbcr_img) {
void CameraFeed::set_ycbcr_image(const Ref<Image> &p_ycbcr_img) {
ERR_FAIL_COND(p_ycbcr_img.is_null());
if (active) {
int new_width = p_ycbcr_img->get_width();
Expand All @@ -221,7 +218,7 @@ void CameraFeed::set_YCbCr_img(const Ref<Image> &p_ycbcr_img) {
}
}

void CameraFeed::set_YCbCr_imgs(const Ref<Image> &p_y_img, const Ref<Image> &p_cbcr_img) {
void CameraFeed::set_ycbcr_images(const Ref<Image> &p_y_img, const Ref<Image> &p_cbcr_img) {
ERR_FAIL_COND(p_y_img.is_null());
ERR_FAIL_COND(p_cbcr_img.is_null());
if (active) {
Expand Down
6 changes: 3 additions & 3 deletions servers/camera/camera_feed.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ class CameraFeed : public RefCounted {
virtual ~CameraFeed();

FeedDataType get_datatype() const;
void set_RGB_img(const Ref<Image> &p_rgb_img);
void set_YCbCr_img(const Ref<Image> &p_ycbcr_img);
void set_YCbCr_imgs(const Ref<Image> &p_y_img, const Ref<Image> &p_cbcr_img);
void set_rgb_image(const Ref<Image> &p_rgb_img);
void set_ycbcr_image(const Ref<Image> &p_ycbcr_img);
void set_ycbcr_images(const Ref<Image> &p_y_img, const Ref<Image> &p_cbcr_img);

virtual bool set_format(int p_index, const Dictionary &p_parameters);
virtual Array get_formats() const;
Expand Down
Loading