--- format7.h.orig 2011-07-13 10:32:04.000000000 +0200 +++ format7.h 2011-07-13 11:36:28.000000000 +0200 @@ -70,7 +70,8 @@ maxWidth_(0), maxHeight_(0), binning_x_(0), - binning_y_(0) + binning_y_(0), + BayerPattern_((dc1394color_filter_t) DC1394_COLOR_FILTER_NUM) {}; ~Format7() {}; @@ -87,6 +88,7 @@ void setOperationalParameters(sensor_msgs::CameraInfo &cinfo); private: + dc1394color_filter_t findBayerPattern(const char* bayer); bool active_; dc1394color_coding_t coding_; --- format7.cpp.orig 2011-07-13 12:56:59.000000000 +0200 +++ format7.cpp 2011-07-13 13:00:16.000000000 +0200 @@ -81,6 +81,18 @@ newconfig.bayer_method = ""; } + const char* pattern = newconfig.bayer_pattern.c_str(); + dc1394color_filter_t bayer_pattern = findBayerPattern(pattern); + if ((bayer_pattern >= DC1394_COLOR_FILTER_MIN) && (bayer_pattern <= DC1394_COLOR_FILTER_MAX)) + { + BayerPattern_ = bayer_pattern; + } + else + { + ROS_WARN_STREAM("Bayer pattern [" << newconfig.bayer_pattern << " (" + << bayer_pattern << ")] is invalid."); + } + // scan all Format7 modes to determine the full-sensor image size, // from which we will calculate the binning values uint32_t sensor_width = 0, sensor_height = 0; @@ -267,12 +279,23 @@ if (coding_ == DC1394_COLOR_CODING_RAW8 || coding_ == DC1394_COLOR_CODING_RAW16) { + dc1394color_filter_t color_filter = (dc1394color_filter_t) DC1394_COLOR_FILTER_NUM; if (DC1394_SUCCESS != dc1394_format7_get_color_filter(camera, mode, - &BayerPattern_)) + &color_filter)) { ROS_ERROR("Could not determine color pattern"); return false; } + if (BayerPattern_ == (dc1394color_filter_t) DC1394_COLOR_FILTER_NUM) + { + BayerPattern_ = color_filter; + } + else if ( BayerPattern_ != color_filter ) + { + ROS_WARN_STREAM("Bayer Pattern was set to " + << BayerPattern_ << "but get_color_filter returned " + << color_filter << ". Using " << BayerPattern_); + } } active_ = true; // Format7 mode is active @@ -470,3 +493,38 @@ } } } + +/** returns the DC1394 color filter for the given bayer pattern string + * + * @param bayer the string describing the pattern (e.g. bggr, rggb, ...) + * @return the dc1394color_filter_t corresponding to the given string + * + */ +dc1394color_filter_t Format7::findBayerPattern(const char* bayer) +{ + // determine Bayer color encoding pattern + // (default is different from any color filter provided by DC1394) + dc1394color_filter_t pattern = (dc1394color_filter_t) DC1394_COLOR_FILTER_NUM; + if (0 == strcmp(bayer, "bggr")) + { + pattern = DC1394_COLOR_FILTER_BGGR; + } + else if (0 == strcmp(bayer, "grbg")) + { + pattern = DC1394_COLOR_FILTER_GRBG; + } + else if (0 == strcmp(bayer, "rggb")) + { + pattern = DC1394_COLOR_FILTER_RGGB; + } + else if (0 == strcmp(bayer, "gbrg")) + { + pattern = DC1394_COLOR_FILTER_GBRG; + } + else if (0 != strcmp(bayer, "")) + { + ROS_ERROR("unknown bayer pattern [%s]", bayer); + } + return pattern; +} +