Skip to content

Commit 952b590

Browse files
committed
Fix final confusion between format and encoding.
Format is file format like jpg, bmp and more, encoding is color encoding like bgr8, rgb8 and more.
1 parent f72d1f4 commit 952b590

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

cv_bridge/src/cv_bridge.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,16 @@ Encoding getEncoding(const std::string& encoding)
134134
return INVALID;
135135
}
136136

137-
static const int SAME_FORMAT = -1;
137+
static const int SAME_ENCODING = -1;
138138

139-
/** Return a lit of OpenCV conversion codes to get from one Format to the other
140-
* The key is a pair: <FromFormat, ToFormat> and the value a succession of OpenCV code conversion
139+
/** Return a lit of OpenCV conversion codes to get from one encoding to the other
140+
* The key is a pair: <FromEncoding, ToEncoding> and the value a succession of OpenCV code conversion
141141
* It's not efficient code but it is only called once and the structure is small enough
142142
*/
143143
std::map<std::pair<Encoding, Encoding>, std::vector<int> > getConversionCodes() {
144144
std::map<std::pair<Encoding, Encoding>, std::vector<int> > res;
145145
for(int i=0; i<=5; ++i)
146-
res[std::pair<Encoding, Encoding>(Encoding(i),Encoding(i))].push_back(SAME_FORMAT);
146+
res[std::pair<Encoding, Encoding>(Encoding(i),Encoding(i))].push_back(SAME_ENCODING);
147147

148148
res[std::make_pair(GRAY, RGB)].push_back(cv::COLOR_GRAY2RGB);
149149
res[std::make_pair(GRAY, BGR)].push_back(cv::COLOR_GRAY2BGR);
@@ -214,7 +214,7 @@ const std::vector<int> getConversionCode(std::string src_encoding, std::string d
214214
"] is. The conversion does not make sense");
215215
if (!is_num_channels_the_same)
216216
throw Exception("[" + src_encoding + "] and [" + dst_encoding + "] do not have the same number of channel");
217-
return std::vector<int>(1, SAME_FORMAT);
217+
return std::vector<int>(1, SAME_ENCODING);
218218
}
219219

220220
// If we are converting from a color type to a non color type, we can only do so if we stick
@@ -223,7 +223,7 @@ const std::vector<int> getConversionCode(std::string src_encoding, std::string d
223223
if (!is_num_channels_the_same)
224224
throw Exception("[" + src_encoding + "] is a color encoding but [" + dst_encoding + "] " +
225225
"is not so they must have the same OpenCV type, CV_8UC3, CV16UC1 ....");
226-
return std::vector<int>(1, SAME_FORMAT);
226+
return std::vector<int>(1, SAME_ENCODING);
227227
}
228228

229229
// If we are converting from a color type to another type, then everything is fine
@@ -238,7 +238,7 @@ const std::vector<int> getConversionCode(std::string src_encoding, std::string d
238238
// And deal with depth differences if the colors are different
239239
std::vector<int> res = val->second;
240240
if ((enc::bitDepth(src_encoding) != enc::bitDepth(dst_encoding)) && (getEncoding(src_encoding) != getEncoding(dst_encoding)))
241-
res.push_back(SAME_FORMAT);
241+
res.push_back(SAME_ENCODING);
242242

243243
return res;
244244
}
@@ -320,7 +320,7 @@ CvImagePtr toCvCopyImpl(const cv::Mat& source,
320320
cv::Mat image2;
321321
for(size_t i=0; i<conversion_codes.size(); ++i) {
322322
int conversion_code = conversion_codes[i];
323-
if (conversion_code == SAME_FORMAT)
323+
if (conversion_code == SAME_ENCODING)
324324
{
325325
// Same number of channels, but different bit depth
326326
int src_depth = enc::bitDepth(src_encoding);
@@ -550,7 +550,7 @@ CvImageConstPtr cvtColorForDisplay(const CvImageConstPtr& source,
550550
{
551551
try
552552
{
553-
// Let's decide upon an output format
553+
// Let's decide upon an output encoding
554554
if (enc::numChannels(source->encoding) == 1)
555555
{
556556
if ((source->encoding == enc::TYPE_32SC1) ||
@@ -661,13 +661,13 @@ CvImageConstPtr cvtColorForDisplay(const CvImageConstPtr& source,
661661
return cvtColor(img_scaled, encoding);
662662
}
663663

664-
// If no color conversion is possible, we must "guess" the input format
664+
// If no color conversion is possible, we must "guess" the input encoding
665665
CvImagePtr source_typed(new CvImage());
666666
source_typed->image = source->image;
667667
source_typed->header = source->header;
668668
source_typed->encoding = source->encoding;
669669

670-
// If we get the OpenCV format, if we have 1,3 or 4 channels, we are most likely in mono, BGR or BGRA modes
670+
// If we get the OpenCV encoding, if we have 1,3 or 4 channels, we are most likely in mono, BGR or BGRA modes
671671
if (source->encoding == "CV_8UC1")
672672
source_typed->encoding = enc::MONO8;
673673
else if (source->encoding == "16UC1")
@@ -687,7 +687,7 @@ CvImageConstPtr cvtColorForDisplay(const CvImageConstPtr& source,
687687

688688
try
689689
{
690-
// Now that the output is a proper color format, try to see if any conversion is possible
690+
// Now that the output is a proper color encoding, try to see if any conversion is possible
691691
return cvtColor(source_typed, encoding);
692692
}
693693
catch (cv_bridge::Exception& e)

0 commit comments

Comments
 (0)