|
Urbi SDK Remote for C++
2.7.3
|
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_FWARN("Parse image format failed on %s (scanned %s)", s, 00061 cardinality_of(formats)); 00062 return IMAGE_UNKNOWN; 00063 } 00064 00065 00066 /*---------. 00067 | UImage. | 00068 `---------*/ 00069 00070 void 00071 UImage::init() 00072 { 00073 data = 0; 00074 size = width = height = 0; 00075 imageFormat = IMAGE_UNKNOWN; 00076 } 00077 00078 UImage 00079 UImage::make() 00080 { 00081 UImage res; 00082 res.init(); 00083 return res; 00084 } 00085 00086 const char* 00087 UImage::format_string() const 00088 { 00089 return ::urbi::format_string(imageFormat); 00090 } 00091 00092 std::string 00093 UImage::headers_() const 00094 { 00095 return libport::format("%s %s %s", 00096 format_string(), width, height); 00097 } 00098 00099 } // namespace urbi