protocol modified

This commit is contained in:
Xisco Bosch 2017-04-05 18:07:42 +02:00
parent 8ead5d0b2c
commit 35a3803977
2 changed files with 34 additions and 14 deletions

View File

@ -19,12 +19,19 @@ namespace server {
#ifdef WITH_TURBOJPEG
enum ImageType{
IMAGE_1,
IMAGE_2,
DEPTH_1,
DEPTH_2,
};
static bool getJPEGImage(
const int jpeg_quality,
const size_t width,
const size_t height,
const std::vector<Color> &image,
bool depth,
ImageType image_type,
Reward &rwd){
long unsigned int jpegSize = 0;
unsigned char *compressedImage;
@ -47,10 +54,20 @@ namespace server {
&compressedImage, &jpegSize, TJSAMP_444, jpeg_quality, TJFLAG_FASTDCT);
tjDestroy(jpegCompressor);
if (!depth) {
rwd.add_image((char*)compressedImage);
} else {
rwd.add_depth((char*)compressedImage);
switch (image_type){
case IMAGE_1:
rwd.set_image1(compressedImage, jpegSize);
break;
case IMAGE_2:
rwd.set_image2(compressedImage, jpegSize);
break;
case DEPTH_1:
rwd.set_depth1(compressedImage, jpegSize);
break;
case DEPTH_2:
rwd.set_depth2(compressedImage, jpegSize);
break;
}
return true;
@ -85,19 +102,20 @@ namespace server {
// Compress images to JPEG
struct ImageHolder {
bool isDepth;
ImageType type;
const decltype(values.image_rgb_0) &image;
};
std::vector<ImageHolder> images;
if (_communication->GetMode() == Mode::MONO) {
images.push_back({false, values.image_rgb_0});
images.push_back({IMAGE_1, values.image_rgb_0});
} else if (_communication->GetMode() == Mode::STEREO) {
images.reserve(4u);
images.push_back({false, values.image_rgb_0});
images.push_back({false, values.image_rgb_1});
images.push_back({true, values.image_depth_0});
images.push_back({true, values.image_depth_1});
images.push_back({IMAGE_1, values.image_rgb_0});
images.push_back({IMAGE_2, values.image_rgb_1});
images.push_back({DEPTH_1, values.image_depth_0});
images.push_back({DEPTH_2, values.image_depth_1});
} else {
std::cerr << "Error, invalid mode" << std::endl;
return;
@ -110,7 +128,7 @@ namespace server {
values.image_width,
values.image_height,
holder.image,
holder.isDepth,
holder.type,
reward)) {
std::cerr << "Error compressing image to JPEG" << std::endl;
}

View File

@ -100,6 +100,8 @@ message Reward {
optional float ori_x = 13;
optional float ori_y = 14;
optional float ori_z = 15;
repeated bytes image = 16;
repeated bytes depth = 17;
optional bytes image1 = 16;
optional bytes image2 = 17;
optional bytes depth1 = 18;
optional bytes depth2 = 19;
}