Urbi SDK Remote for C++  2.7.5
uimage.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009-2011, Gostai S.A.S.
00003  *
00004  * This software is provided "as is" without warranty of any kind,
00005  * either expressed or implied, including but not limited to the
00006  * implied warranties of fitness for a particular purpose.
00007  *
00008  * See the LICENSE file for more information.
00009  */
00010 
00012 
00013 #include <libport/debug.hh>
00014 #include <libport/format.hh>
00015 #include <urbi/uimage.hh>
00016 
00017 #define cardinality_of(Array) (sizeof (Array) / sizeof (*(Array)))
00018 
00019 GD_CATEGORY(Urbi.UValue);
00020 
00021 namespace urbi
00022 {
00023 
00024   /*---------------.
00025   | UImageFormat.  |
00026   `---------------*/
00027 
00028   static const char* formats[] =
00029   {
00030     "image_unknown",
00031     "rgb",
00032     "YCbCr",
00033     "jpeg",
00034     "ppm",
00035     "YUV422",
00036     "grey8",
00037     "grey4",
00038     "yuv411_planar",
00039     "nv12",
00040     "yuv420_planar"
00041   };
00042 
00043   const char*
00044   format_string(UImageFormat f)
00045   {
00046     if (f < 0 || int(cardinality_of(formats)) <= f)
00047     {
00048       GD_FERROR("invalid UImageFormat value: %d", f);
00049       f = IMAGE_UNKNOWN;
00050     }
00051     return formats[f];
00052   }
00053 
00054   UImageFormat
00055   parse_image_format(const std::string& s)
00056   {
00057     for (unsigned i = 0; i < cardinality_of(formats); ++i)
00058       if (s == formats[i])
00059         return static_cast<UImageFormat>(i);
00060     GD_FINFO_TRACE("unknown image format: %s", s);
00061     return IMAGE_UNKNOWN;
00062   }
00063 
00064 
00065   /*---------.
00066   | UImage.  |
00067   `---------*/
00068 
00069   void
00070   UImage::init()
00071   {
00072     data = 0;
00073     size = width = height = 0;
00074     imageFormat = IMAGE_UNKNOWN;
00075   }
00076 
00077   UImage
00078   UImage::make()
00079   {
00080     UImage res;
00081     res.init();
00082     return res;
00083   }
00084 
00085   const char*
00086   UImage::format_string() const
00087   {
00088     return ::urbi::format_string(imageFormat);
00089   }
00090 
00091   std::string
00092   UImage::headers_() const
00093   {
00094     return libport::format("%s %s %s",
00095                            format_string(), width, height);
00096   }
00097 
00098 } // namespace urbi