Skip to content

Commit cd283ae

Browse files
authored
Add support for L8 and L16 image formats in WideAngleCameraSensor (#494)
Signed-off-by: Ian Chen <[email protected]>
1 parent aaef365 commit cd283ae

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/WideAngleCameraSensor.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,12 @@ bool WideAngleCameraSensor::CreateCamera()
333333
case sdf::PixelFormatType::RGB_INT8:
334334
this->dataPtr->camera->SetImageFormat(gz::rendering::PF_R8G8B8);
335335
break;
336+
case sdf::PixelFormatType::L_INT8:
337+
this->dataPtr->camera->SetImageFormat(gz::rendering::PF_L8);
338+
break;
339+
case sdf::PixelFormatType::L_INT16:
340+
this->dataPtr->camera->SetImageFormat(gz::rendering::PF_L16);
341+
break;
336342
default:
337343
gzerr << "Unsupported pixel format ["
338344
<< static_cast<int>(pixelFormat) << "]\n";
@@ -367,7 +373,9 @@ void WideAngleCameraSensor::OnNewWideAngleFrame(
367373
{
368374
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
369375

370-
unsigned int len = _width * _height * _channels;
376+
unsigned int bytesPerChannel = rendering::PixelUtil::BytesPerChannel(
377+
this->dataPtr->camera->ImageFormat());
378+
unsigned int len = _width * _height * _channels * bytesPerChannel;
371379
unsigned int bufferSize = len * sizeof(unsigned char);
372380

373381
if (!this->dataPtr->imageBuffer)
@@ -467,6 +475,12 @@ bool WideAngleCameraSensor::Update(
467475
format = gz::common::Image::RGB_INT8;
468476
msgsPixelFormat = msgs::PixelFormatType::RGB_INT8;
469477
break;
478+
case gz::rendering::PF_L8:
479+
msgsPixelFormat = msgs::PixelFormatType::L_INT8;
480+
break;
481+
case gz::rendering::PF_L16:
482+
msgsPixelFormat = msgs::PixelFormatType::L_INT16;
483+
break;
470484
default:
471485
gzerr << "Unsupported pixel format ["
472486
<< this->dataPtr->camera->ImageFormat() << "]\n";

0 commit comments

Comments
 (0)