Enhance NV12 and NV21 Support in sensor_msgs::image_encodings
Description
This pull request introduces significant improvements to the sensor_msgs::image_encodings module in ROS2 Rolling, specifically enhancing support for NV12 and NV21 image encodings. The changes aim to provide more accurate channel definitions, facilitate planar encoding detection, and offer height scaling factors necessary for proper image buffer management.
Changes Made
-
Redefine
numChannelsfor NV12 and NV21:- Updated the
numChannelsfunction to return 1 for NV12 and NV21 instead of 2. This change accurately represents their planar YUV 4:2:0 structure, where the image data is split into Y and UV planes.
- Updated the
-
Add
isPlanarFunction:- Introduced a new utility function
isPlanarto check if a given encoding is planar. This function currently identifies NV12, NV21, and NV24 as planar encodings. -
Usage:
bool is_planar = sensor_msgs::image_encodings::isPlanar(encoding);
- Introduced a new utility function
-
Introduce
getHeightScalingFunction:- Added
getHeightScalingto provide the height scaling factor for planar encodings. For example, NV21 images with heightHwill have an actual buffer height ofH * 1.5to accommodate the UV planes. -
Usage:
float scaling_factor = sensor_msgs::image_encodings::getHeightScaling(encoding);
- Added
-
Correct
bitDepthFunction:- Fixed the
bitDepthfunction to accurately parse and return bit depths for complex encoding strings such as "8UC10".
- Fixed the
-
Code Consistency and Documentation:
- Unified the handling of planar formats to ensure consistency across different encoding types.
- Added detailed documentation comments for the newly introduced functions to aid developers in understanding and utilizing them effectively.
@zycczy could you please follow up on @sloretz's feedback?
@zycczy could you please follow up on @sloretz's feedback?
Sorry for the late reply, Has pushed new changes, these days are Chinese New Year, so I have some days vacation, back to work now
@sloretz @Yadunund @ahcorde could you please have a review for this PR?
Pulls: ros2/common_interfaces#264 Gist: https://gist.githubusercontent.com/ahcorde/51a66c824e3b09acaacf3666af403e5d/raw/4932642bb4790d1a78b8b61e483d915659b07b64/ros2.repos BUILD args: --packages-above-and-dependencies sensor_msgs TEST args: --packages-above sensor_msgs ROS Distro: rolling Job: ci_launcher ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15568
Hi @ahcorde @sloretz Can we merge this PR? So that next I will work on RQT and image transport NV12 support, the local change has almost done, depends on this PR merge
Thanks. Zhaoyuan
@sloretz you already review this PR, do you mind to take another look ?