image_pair.cpp
Go to the documentation of this file.
00001 
00006 /*****************************************************************************
00007 ** Includes
00008 *****************************************************************************/
00009 
00010 #include "../../include/mm_vision_msgs/image_pair.hpp"
00011 
00012 /*****************************************************************************
00013 ** Namespaces
00014 *****************************************************************************/
00015 
00016 namespace mm_vision_msgs {
00017 
00018 ImagePair::ImagePair(const unsigned char* left_buffer,
00019                      const unsigned char *right_buffer,
00020                      const unsigned int& size)
00021 : left(left_buffer, left_buffer + size),
00022   right(right_buffer, right_buffer + size),
00023   size(size)
00024 {
00025   // this is very similar to the decoder
00026   if (size == 76800) { // QVGA
00027     width = 320;
00028     height = 240;
00029     colour = false;
00030   } else if (size == 153600) { // CQVGA
00031     width = 320;
00032     height = 240;
00033     colour = true;
00034   } else if (size == 307200) { // VGA
00035     width = 640;
00036     height = 480;
00037     colour = false;
00038   } else if (size == 614400) { // CVGA
00039     width = 640;
00040     height = 480;
00041     colour = true;
00042   }
00043 }
00044 
00045 
00046 } // namespace mm_vision_msgs
00047 
00048 /*****************************************************************************
00049 ** Namespaces
00050 *****************************************************************************/
00051 
00052 namespace mm_messages {
00053 
00054 /*****************************************************************************
00055 ** Implementation
00056 *****************************************************************************/
00068 void Message<mm_vision_msgs::ImagePairPtr>::encode(const mm_vision_msgs::ImagePairPtr& pair, ByteArray& buffer) {
00069   // we might like to do something more tricky once we can use c++11 here (like std::move) to avoid
00070   // copying buffers.
00071   buffer = pair->left;
00072   buffer.insert(buffer.end(), pair->right.begin(), pair->right.end());
00073 }
00074 
00082 mm_vision_msgs::ImagePairPtr Message<mm_vision_msgs::ImagePairPtr>::decode(const unsigned char* buffer, const unsigned int& size) {
00083   mm_vision_msgs::ImagePairPtr pair = std::make_shared<mm_vision_msgs::ImagePair>();
00084   pair->left.assign(buffer, buffer + size/2); // c++0x buffer+size -> std::end(buffer) instead of size?
00085   pair->right.assign(buffer + size/2, buffer + size); // c++0x buffer+size -> std::end(buffer) instead of size?
00086   pair->size = size/2;  // single image size
00087   if (pair->size == 76800) { // QVGA
00088     pair->width = 320;
00089     pair->height = 240;
00090     pair->colour = false;
00091   } else if (pair->size == 153600) { // CQVGA
00092     pair->width = 320;
00093     pair->height = 240;
00094     pair->colour = true;
00095   } else if (pair->size == 307200) { // VGA
00096     pair->width = 640;
00097     pair->height = 480;
00098     pair->colour = false;
00099   } else if (pair->size == 614400) { // CVGA
00100     pair->width = 640;
00101     pair->height = 480;
00102     pair->colour = true;
00103   }
00104   return pair;
00105 }
00106 
00107 
00108 } // namespace mm_messages


mm_vision_msgs
Author(s): Daniel Stonier
autogenerated on Sun Jun 7 2015 12:58:20