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

reapply yuv encoding deprecation #257

Open
wants to merge 4 commits into
base: rolling
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions sensor_msgs/include/sensor_msgs/image_encodings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ const char BAYER_GRBG16[] = "bayer_grbg16";
// https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/pixfmt-packed-yuv.html#id1
// fourcc: UYVY
const char UYVY[] = "uyvy";
[[deprecated("use sensor_msgs::image_encodings::UYVY")]]
const char YUV422[] = "yuv422"; // deprecated
// fourcc: YUYV
const char YUYV[] = "yuyv";
[[deprecated("use sensor_msgs::image_encodings::YUYV")]]
const char YUV422_YUY2[] = "yuv422_yuy2"; // deprecated

// YUV 4:2:0 encodings with an 8-bit depth
Expand All @@ -120,13 +122,25 @@ const std::regex cv_type_regex("(8|16|32|64)(U|S|F)C([0-9]*)");
// Utility functions for inspecting an encoding string
static inline bool isColor(const std::string & encoding)
{
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the sake of maintenance, can we scope down where the ifdef/pragmas are required?

I think we could use a function like:

static inline bool isPackedYUV(const std::string& encoding)

That contains the deprecation suppression, and then use that in the other functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also want to use isPackedYUV as a public function? Eventually, the deprecated encodings will be removed. If this is a functionality that is supposed to be exposed to a user and used often, then I can add a isPackedYUV. But doing this just for the more narrow scoping of the encodings is a maintenance overhead IMHO.

return encoding == RGB8 || encoding == BGR8 ||
encoding == RGBA8 || encoding == BGRA8 ||
encoding == RGB16 || encoding == BGR16 ||
encoding == RGBA16 || encoding == BGRA16 ||
encoding == YUV422 || encoding == YUV422_YUY2 ||
encoding == UYVY || encoding == YUYV ||
encoding == NV21 || encoding == NV24;
#ifdef _MSC_VER
#pragma warning(pop)
#else
#pragma GCC diagnostic pop
#endif
}

static inline bool isMono(const std::string & encoding)
Expand Down Expand Up @@ -189,6 +203,13 @@ static inline int numChannels(const std::string & encoding)
return (m[3] == "") ? 1 : std::atoi(m[3].str().c_str());
}

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
if (encoding == YUV422 ||
encoding == YUV422_YUY2 ||
encoding == UYVY ||
Expand All @@ -198,6 +219,11 @@ static inline int numChannels(const std::string & encoding)
{
return 2;
}
#ifdef _MSC_VER
#pragma warning(pop)
#else
#pragma GCC diagnostic pop
#endif

throw std::runtime_error("Unknown encoding " + encoding);
return -1;
Expand Down Expand Up @@ -241,6 +267,13 @@ static inline int bitDepth(const std::string & encoding)
return std::atoi(m[0].str().c_str());
}

#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#else
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif
if (encoding == YUV422 ||
encoding == YUV422_YUY2 ||
encoding == UYVY ||
Expand All @@ -250,6 +283,11 @@ static inline int bitDepth(const std::string & encoding)
{
return 8;
}
#ifdef _MSC_VER
#pragma warning(pop)
#else
#pragma GCC diagnostic pop
#endif

throw std::runtime_error("Unknown encoding " + encoding);
return -1;
Expand Down
8 changes: 4 additions & 4 deletions sensor_msgs/test/test_image_encodings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ TEST(sensor_msgs, NumChannels)
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("64FC"), 1);
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("64FC3"), 3);
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("64FC10"), 10);
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("yuv422"), 2);
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("yuv422_yuy2"), 2);
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("uyvy"), 2);
ASSERT_EQ(sensor_msgs::image_encodings::numChannels("yuyv"), 2);
}

TEST(sensor_msgs, bitDepth)
Expand All @@ -68,6 +68,6 @@ TEST(sensor_msgs, bitDepth)
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("64FC"), 64);
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("64FC3"), 64);
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("64FC10"), 64);
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("yuv422"), 8);
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("yuv422_yuy2"), 8);
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("uyvy"), 8);
ASSERT_EQ(sensor_msgs::image_encodings::bitDepth("yuyv"), 8);
}