Skip to content

Commit d1f3063

Browse files
committed
Make image encoding explicit
1 parent ea81ac3 commit d1f3063

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

aegis_grpc/src/robot_read_service.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <cassert>
12
#include "aegis_grpc/robot_read_service.hpp"
23

34
namespace aegis_grpc {
@@ -300,6 +301,18 @@ void RobotReadServiceImpl::FillProtoJointState(
300301
proto_aegis_grpc::v1::Image* out,
301302
cv::Mat& buffer)
302303
{
304+
assert((ros.encoding == "bgr8" &&"Unsupported image enconding (expected BGR8)."));
305+
if (!enable_image_resize_) {
306+
out->set_height(ros.height);
307+
out->set_width(ros.width);
308+
out->set_step(ros.step);
309+
out->set_data(
310+
const_cast<uint8_t*>(ros.data.data()),
311+
static_cast<size_t>(ros.height * ros.step)
312+
);
313+
return;
314+
}
315+
303316
const cv::Mat src(
304317
ros.height,
305318
ros.width,
@@ -308,22 +321,17 @@ void RobotReadServiceImpl::FillProtoJointState(
308321
ros.step
309322
);
310323

311-
const cv::Mat* img = &src;
312-
313-
if (enable_image_resize_) {
314-
cv::resize(
315-
src,
316-
buffer,
317-
cv::Size(target_img_width_, target_img_height_),
318-
0, 0, cv::INTER_LINEAR
319-
);
320-
img = &buffer;
321-
}
324+
cv::resize(
325+
src,
326+
buffer,
327+
cv::Size(target_img_width_, target_img_height_),
328+
0, 0, cv::INTER_LINEAR
329+
);
322330

323-
out->set_height(img->rows);
324-
out->set_width(img->cols);
325-
out->set_step(img->step);
326-
out->set_data(img->data, img->total() * img->elemSize());
331+
out->set_height(buffer.rows);
332+
out->set_width(buffer.cols);
333+
out->set_step(buffer.step);
334+
out->set_data(buffer.data, buffer.total() * buffer.elemSize());
327335
}
328336

329337

0 commit comments

Comments
 (0)