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

prevent conversion of single channel 16bit integer images to/from colour #412

Merged
Merged
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
33 changes: 19 additions & 14 deletions cv_bridge/src/cv_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ void CvImage::toCompressedImageMsg(sensor_msgs::CompressedImage& ros_image, cons
{
ros_image.header = header;
cv::Mat image;
if (encoding == enc::BGR8 || encoding == enc::BGRA8)
if (encoding == enc::BGR8 || encoding == enc::BGRA8 || encoding == enc::MONO8 || encoding == enc::MONO16)
{
image = this->image;
}
Expand Down Expand Up @@ -519,19 +519,24 @@ CvImagePtr toCvCopy(const sensor_msgs::CompressedImage& source, const std::strin
// Loads as BGR or BGRA.
const cv::Mat rgb_a = cv::imdecode(in, cv::IMREAD_UNCHANGED);

switch (rgb_a.channels())
{
case 4:
return toCvCopyImpl(rgb_a, source.header, enc::BGRA8, encoding);
break;
case 3:
return toCvCopyImpl(rgb_a, source.header, enc::BGR8, encoding);
break;
case 1:
return toCvCopyImpl(rgb_a, source.header, enc::MONO8, encoding);
break;
default:
return CvImagePtr();
if (encoding != enc::MONO16) {
switch (rgb_a.channels())
{
case 4:
return toCvCopyImpl(rgb_a, source.header, enc::BGRA8, encoding);
break;
case 3:
return toCvCopyImpl(rgb_a, source.header, enc::BGR8, encoding);
break;
case 1:
return toCvCopyImpl(rgb_a, source.header, enc::MONO8, encoding);
break;
default:
return CvImagePtr();
}
}
else {
return toCvCopyImpl(rgb_a, source.header, enc::MONO16, encoding);
}
}

Expand Down