36 #ifndef SENSOR_MSGS_IMAGE_ENCODINGS_H 37 #define SENSOR_MSGS_IMAGE_ENCODINGS_H 45 namespace image_encodings
47 const std::string
RGB8 =
"rgb8";
48 const std::string
RGBA8 =
"rgba8";
49 const std::string
RGB16 =
"rgb16";
51 const std::string
BGR8 =
"bgr8";
52 const std::string
BGRA8 =
"bgra8";
53 const std::string
BGR16 =
"bgr16";
55 const std::string
MONO8=
"mono8";
105 "8UC",
"8SC",
"16UC",
"16SC",
"32SC",
"32FC",
"64FC"};
108 static inline bool isColor(
const std::string& encoding)
110 return encoding == RGB8 || encoding == BGR8 ||
111 encoding == RGBA8 || encoding == BGRA8 ||
112 encoding == RGB16 || encoding == BGR16 ||
113 encoding == RGBA16 || encoding ==
BGRA16;
116 static inline bool isMono(
const std::string& encoding)
118 return encoding == MONO8 || encoding ==
MONO16;
121 static inline bool isBayer(
const std::string& encoding)
123 return encoding == BAYER_RGGB8 || encoding == BAYER_BGGR8 ||
124 encoding == BAYER_GBRG8 || encoding == BAYER_GRBG8 ||
125 encoding == BAYER_RGGB16 || encoding == BAYER_BGGR16 ||
129 static inline bool hasAlpha(
const std::string& encoding)
131 return encoding == RGBA8 || encoding == BGRA8 ||
132 encoding == RGBA16 || encoding ==
BGRA16;
138 if (encoding == MONO8 ||
141 if (encoding == BGR8 ||
146 if (encoding == BGRA8 ||
148 encoding == BGRA16 ||
151 if (encoding == BAYER_RGGB8 ||
152 encoding == BAYER_BGGR8 ||
153 encoding == BAYER_GBRG8 ||
154 encoding == BAYER_GRBG8 ||
155 encoding == BAYER_RGGB16 ||
156 encoding == BAYER_BGGR16 ||
157 encoding == BAYER_GBRG16 ||
158 encoding == BAYER_GRBG16)
165 std::string prefix = ABSTRACT_ENCODING_PREFIXES[i];
166 if (encoding.substr(0, prefix.size()) != prefix)
168 if (encoding.size() == prefix.size())
170 int n_channel = atoi(encoding.substr(prefix.size(),
171 encoding.size() - prefix.size()).c_str());
176 if (encoding == YUV422)
179 throw std::runtime_error(
"Unknown encoding " + encoding);
183 static inline int bitDepth(
const std::string& encoding)
185 if (encoding == MONO16)
187 if (encoding == MONO8 ||
192 encoding == BAYER_RGGB8 ||
193 encoding == BAYER_BGGR8 ||
194 encoding == BAYER_GBRG8 ||
195 encoding == BAYER_GRBG8)
198 if (encoding == MONO16 ||
201 encoding == BGRA16 ||
202 encoding == RGBA16 ||
203 encoding == BAYER_RGGB16 ||
204 encoding == BAYER_BGGR16 ||
205 encoding == BAYER_GBRG16 ||
206 encoding == BAYER_GRBG16)
213 std::string prefix = ABSTRACT_ENCODING_PREFIXES[i];
214 if (encoding.substr(0, prefix.size()) != prefix)
216 if (encoding.size() == prefix.size())
217 return atoi(prefix.c_str());
218 int n_channel = atoi(encoding.substr(prefix.size(),
219 encoding.size() - prefix.size()).c_str());
221 return atoi(prefix.c_str());
224 if (encoding == YUV422)
227 throw std::runtime_error(
"Unknown encoding " + encoding);
const std::string TYPE_16UC4
const std::string BAYER_GRBG8
const std::string BAYER_GRBG16
const std::string TYPE_8SC4
const std::string TYPE_64FC3
const std::string TYPE_8UC4
const std::string BAYER_RGGB16
static bool isBayer(const std::string &encoding)
const std::string TYPE_32FC4
const std::string TYPE_8UC1
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 TYPE_8SC3
const std::string BAYER_BGGR16
static bool isColor(const std::string &encoding)
Tools for manipulating sensor_msgs.
const std::string ABSTRACT_ENCODING_PREFIXES[]
const std::string TYPE_32FC1
const std::string TYPE_16SC3
const std::string TYPE_8UC2
const std::string TYPE_16UC1
const std::string TYPE_8SC1
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
const std::string BAYER_RGGB8
const std::string TYPE_8UC3
const std::string TYPE_32SC4
const std::string TYPE_32FC3
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_8SC2
const std::string TYPE_16SC1