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

Add YUV422 support (do not automatically turn into RGB) #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions src/gscam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ namespace gscam {
nh_private_.param("image_encoding", image_encoding_, sensor_msgs::image_encodings::RGB8);
if (image_encoding_ != sensor_msgs::image_encodings::RGB8 &&
image_encoding_ != sensor_msgs::image_encodings::MONO8 &&
image_encoding_ != sensor_msgs::image_encodings::YUV422 &&
image_encoding_ != "jpeg") {
ROS_FATAL_STREAM("Unsupported image encoding: " + image_encoding_);
}
Expand Down Expand Up @@ -132,6 +133,8 @@ namespace gscam {
caps = gst_caps_new_simple("video/x-raw-rgb", NULL);
} else if (image_encoding_ == sensor_msgs::image_encodings::MONO8) {
caps = gst_caps_new_simple("video/x-raw-gray", NULL);
} else if (image_encoding_ == sensor_msgs::image_encodings::YUV422) {
caps = gst_caps_new_simple("video/x-raw-yuv", NULL);
} else if (image_encoding_ == "jpeg") {
caps = gst_caps_new_simple("image/jpeg", NULL);
}
Expand Down Expand Up @@ -302,10 +305,11 @@ namespace gscam {
cinfo_pub_.publish(cinfo);
} else {
// Complain if the returned buffer is smaller than we expect
const unsigned int expected_frame_size =
image_encoding_ == sensor_msgs::image_encodings::RGB8
? width_ * height_ * 3
: width_ * height_;
const unsigned int expected_frame_size = width_ * height_ * (
(image_encoding_ == sensor_msgs::image_encodings::RGB8)*3
+ (image_encoding_ == sensor_msgs::image_encodings::YUV422)*2
+ (image_encoding_ == sensor_msgs::image_encodings::MONO8)
);

if (buf->size < expected_frame_size) {
ROS_WARN_STREAM( "GStreamer image buffer underflow: Expected frame to be "
Expand All @@ -330,6 +334,8 @@ namespace gscam {
// we can free the buffer allocated by gstreamer
if (image_encoding_ == sensor_msgs::image_encodings::RGB8) {
img->step = width_ * 3;
} else if (image_encoding_ == sensor_msgs::image_encodings::YUV422) {
img->step = width_ * 2;
} else {
img->step = width_;
}
Expand Down