image_encodings.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2009, Willow Garage, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of the Willow Garage nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *********************************************************************/
35 
36 #ifndef SENSOR_MSGS_IMAGE_ENCODINGS_H
37 #define SENSOR_MSGS_IMAGE_ENCODINGS_H
38 
39 #include <stdexcept>
40 #include <string>
41 
42 namespace sensor_msgs
43 {
44  namespace image_encodings
45  {
46  const std::string RGB8 = "rgb8";
47  const std::string RGBA8 = "rgba8";
48  const std::string RGB16 = "rgb16";
49  const std::string RGBA16 = "rgba16";
50  const std::string BGR8 = "bgr8";
51  const std::string BGRA8 = "bgra8";
52  const std::string BGR16 = "bgr16";
53  const std::string BGRA16 = "bgra16";
54  const std::string MONO8="mono8";
55  const std::string MONO16="mono16";
56 
57  // OpenCV CvMat types
58  const std::string TYPE_8UC1="8UC1";
59  const std::string TYPE_8UC2="8UC2";
60  const std::string TYPE_8UC3="8UC3";
61  const std::string TYPE_8UC4="8UC4";
62  const std::string TYPE_8SC1="8SC1";
63  const std::string TYPE_8SC2="8SC2";
64  const std::string TYPE_8SC3="8SC3";
65  const std::string TYPE_8SC4="8SC4";
66  const std::string TYPE_16UC1="16UC1";
67  const std::string TYPE_16UC2="16UC2";
68  const std::string TYPE_16UC3="16UC3";
69  const std::string TYPE_16UC4="16UC4";
70  const std::string TYPE_16SC1="16SC1";
71  const std::string TYPE_16SC2="16SC2";
72  const std::string TYPE_16SC3="16SC3";
73  const std::string TYPE_16SC4="16SC4";
74  const std::string TYPE_32SC1="32SC1";
75  const std::string TYPE_32SC2="32SC2";
76  const std::string TYPE_32SC3="32SC3";
77  const std::string TYPE_32SC4="32SC4";
78  const std::string TYPE_32FC1="32FC1";
79  const std::string TYPE_32FC2="32FC2";
80  const std::string TYPE_32FC3="32FC3";
81  const std::string TYPE_32FC4="32FC4";
82  const std::string TYPE_64FC1="64FC1";
83  const std::string TYPE_64FC2="64FC2";
84  const std::string TYPE_64FC3="64FC3";
85  const std::string TYPE_64FC4="64FC4";
86 
87  // Bayer encodings
88  const std::string BAYER_RGGB8="bayer_rggb8";
89  const std::string BAYER_BGGR8="bayer_bggr8";
90  const std::string BAYER_GBRG8="bayer_gbrg8";
91  const std::string BAYER_GRBG8="bayer_grbg8";
92  const std::string BAYER_RGGB16="bayer_rggb16";
93  const std::string BAYER_BGGR16="bayer_bggr16";
94  const std::string BAYER_GBRG16="bayer_gbrg16";
95  const std::string BAYER_GRBG16="bayer_grbg16";
96 
97  // Miscellaneous
98  // This is the UYVY version of YUV422 codec http://www.fourcc.org/yuv.php#UYVY
99  // with an 8-bit depth
100  const std::string YUV422="yuv422";
101 
102  // Prefixes for abstract image encodings
104  "8UC", "8SC", "16UC", "16SC", "32SC", "32FC", "64FC"};
105 
106  // Utility functions for inspecting an encoding string
107  static inline bool isColor(const std::string& encoding)
108  {
109  return encoding == RGB8 || encoding == BGR8 ||
110  encoding == RGBA8 || encoding == BGRA8 ||
111  encoding == RGB16 || encoding == BGR16 ||
112  encoding == RGBA16 || encoding == BGRA16;
113  }
114 
115  static inline bool isMono(const std::string& encoding)
116  {
117  return encoding == MONO8 || encoding == MONO16;
118  }
119 
120  static inline bool isBayer(const std::string& encoding)
121  {
122  return encoding == BAYER_RGGB8 || encoding == BAYER_BGGR8 ||
123  encoding == BAYER_GBRG8 || encoding == BAYER_GRBG8 ||
124  encoding == BAYER_RGGB16 || encoding == BAYER_BGGR16 ||
125  encoding == BAYER_GBRG16 || encoding == BAYER_GRBG16;
126  }
127 
128  static inline bool hasAlpha(const std::string& encoding)
129  {
130  return encoding == RGBA8 || encoding == BGRA8 ||
131  encoding == RGBA16 || encoding == BGRA16;
132  }
133 
134  static inline int numChannels(const std::string& encoding)
135  {
136  // First do the common-case encodings
137  if (encoding == MONO8 ||
138  encoding == MONO16)
139  return 1;
140  if (encoding == BGR8 ||
141  encoding == RGB8 ||
142  encoding == BGR16 ||
143  encoding == RGB16)
144  return 3;
145  if (encoding == BGRA8 ||
146  encoding == RGBA8 ||
147  encoding == BGRA16 ||
148  encoding == RGBA16)
149  return 4;
150  if (encoding == BAYER_RGGB8 ||
151  encoding == BAYER_BGGR8 ||
152  encoding == BAYER_GBRG8 ||
153  encoding == BAYER_GRBG8 ||
154  encoding == BAYER_RGGB16 ||
155  encoding == BAYER_BGGR16 ||
156  encoding == BAYER_GBRG16 ||
157  encoding == BAYER_GRBG16)
158  return 1;
159 
160  // Now all the generic content encodings
161  // TODO: Rewrite with regex when ROS supports C++11
162  for (size_t i=0; i < sizeof(ABSTRACT_ENCODING_PREFIXES) / sizeof(*ABSTRACT_ENCODING_PREFIXES); i++)
163  {
164  std::string prefix = ABSTRACT_ENCODING_PREFIXES[i];
165  if (encoding.substr(0, prefix.size()) != prefix)
166  continue;
167  if (encoding.size() == prefix.size())
168  return 1; // ex. 8UC -> 1
169  int n_channel = atoi(encoding.substr(prefix.size(),
170  encoding.size() - prefix.size()).c_str()); // ex. 8UC5 -> 5
171  if (n_channel != 0)
172  return n_channel; // valid encoding string
173  }
174 
175  if (encoding == YUV422)
176  return 2;
177 
178  throw std::runtime_error("Unknown encoding " + encoding);
179  return -1;
180  }
181 
182  static inline int bitDepth(const std::string& encoding)
183  {
184  if (encoding == MONO16)
185  return 16;
186  if (encoding == MONO8 ||
187  encoding == BGR8 ||
188  encoding == RGB8 ||
189  encoding == BGRA8 ||
190  encoding == RGBA8 ||
191  encoding == BAYER_RGGB8 ||
192  encoding == BAYER_BGGR8 ||
193  encoding == BAYER_GBRG8 ||
194  encoding == BAYER_GRBG8)
195  return 8;
196 
197  if (encoding == MONO16 ||
198  encoding == BGR16 ||
199  encoding == RGB16 ||
200  encoding == BGRA16 ||
201  encoding == RGBA16 ||
202  encoding == BAYER_RGGB16 ||
203  encoding == BAYER_BGGR16 ||
204  encoding == BAYER_GBRG16 ||
205  encoding == BAYER_GRBG16)
206  return 16;
207 
208  // Now all the generic content encodings
209  // TODO: Rewrite with regex when ROS supports C++11
210  for (size_t i=0; i < sizeof(ABSTRACT_ENCODING_PREFIXES) / sizeof(*ABSTRACT_ENCODING_PREFIXES); i++)
211  {
212  std::string prefix = ABSTRACT_ENCODING_PREFIXES[i];
213  if (encoding.substr(0, prefix.size()) != prefix)
214  continue;
215  if (encoding.size() == prefix.size())
216  return atoi(prefix.c_str()); // ex. 8UC -> 8
217  int n_channel = atoi(encoding.substr(prefix.size(),
218  encoding.size() - prefix.size()).c_str()); // ex. 8UC10 -> 10
219  if (n_channel != 0)
220  return atoi(prefix.c_str()); // valid encoding string
221  }
222 
223  if (encoding == YUV422)
224  return 8;
225 
226  throw std::runtime_error("Unknown encoding " + encoding);
227  return -1;
228  }
229  }
230 }
231 
232 #endif
const std::string TYPE_16UC4
const std::string BAYER_GRBG8
const std::string BAYER_GRBG16
const std::string TYPE_64FC3
const std::string BAYER_RGGB16
static bool isBayer(const std::string &encoding)
const std::string TYPE_32FC4
GLsizei const GLchar *const * string
static bool hasAlpha(const std::string &encoding)
const std::string BAYER_GBRG8
const std::string BAYER_GBRG16
static bool isMono(const std::string &encoding)
const std::string BAYER_BGGR16
static bool isColor(const std::string &encoding)
Tools for manipulating sensor_msgs.
Definition: BatteryState.h:20
const std::string ABSTRACT_ENCODING_PREFIXES[]
const std::string TYPE_32FC1
const std::string TYPE_16SC3
const std::string TYPE_16UC1
const std::string TYPE_64FC4
const std::string TYPE_16UC3
const std::string TYPE_16UC2
const std::string TYPE_32SC2
const std::string BAYER_BGGR8
const std::string TYPE_64FC1
static int numChannels(const std::string &encoding)
const std::string TYPE_64FC2
const std::string TYPE_32SC3
static const char * encoding
Definition: model-views.h:201
const std::string BAYER_RGGB8
const std::string TYPE_32SC4
const std::string TYPE_32FC3
int i
static int bitDepth(const std::string &encoding)
const std::string TYPE_16SC2
const std::string TYPE_32FC2
const std::string TYPE_32SC1
const std::string TYPE_16SC4
const std::string TYPE_16SC1


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:17