@@ -129,6 +129,7 @@ private:
unsigned int lineBufferIndex_;
unsigned int x_shift_; /* Offset of 0/1 applied to window_.x */
bool enableInputMemcpy_;
+ bool swapRedBlueGains_;
float gamma_correction_;
int measuredFrames_;
int64_t frameProcessTime_;
@@ -221,7 +221,7 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf
config.bpp = (bayerFormat.bitDepth + 7) & ~7;
config.patternSize.width = 2;
config.patternSize.height = 2;
- config.outputFormats = std::vector<PixelFormat>({ formats::RGB888 });
+ config.outputFormats = std::vector<PixelFormat>({ formats::RGB888, formats::BGR888 });
return 0;
}
@@ -231,7 +231,7 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf
config.bpp = 10;
config.patternSize.width = 4; /* 5 bytes per *4* pixels */
config.patternSize.height = 2;
- config.outputFormats = std::vector<PixelFormat>({ formats::RGB888 });
+ config.outputFormats = std::vector<PixelFormat>({ formats::RGB888, formats::BGR888 });
return 0;
}
@@ -242,7 +242,7 @@ int DebayerCpu::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf
int DebayerCpu::getOutputConfig(PixelFormat outputFormat, DebayerOutputConfig &config)
{
- if (outputFormat == formats::RGB888) {
+ if (outputFormat == formats::RGB888 || outputFormat == formats::BGR888) {
config.bpp = 24;
return 0;
}
@@ -278,12 +278,41 @@ int DebayerCpu::setupStandardBayerOrder(BayerFormat::Order order)
return 0;
}
-/* TODO: this ignores outputFormat since there is only 1 supported outputFormat for now */
-int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat, [[maybe_unused]] PixelFormat outputFormat)
+int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat, PixelFormat outputFormat)
{
BayerFormat bayerFormat =
BayerFormat::fromPixelFormat(inputFormat);
+ swapRedBlueGains_ = false;
+
+ switch (outputFormat) {
+ case formats::RGB888:
+ break;
+ case formats::BGR888:
+ /* Swap R and B in bayer order to generate BGR888 instead of RGB888 */
+ swapRedBlueGains_ = true;
+
+ switch (bayerFormat.order) {
+ case BayerFormat::BGGR:
+ bayerFormat.order = BayerFormat::RGGB;
+ break;
+ case BayerFormat::GBRG:
+ bayerFormat.order = BayerFormat::GRBG;
+ break;
+ case BayerFormat::GRBG:
+ bayerFormat.order = BayerFormat::GBRG;
+ break;
+ case BayerFormat::RGGB:
+ bayerFormat.order = BayerFormat::BGGR;
+ break;
+ default:
+ goto invalid_fmt;
+ }
+ break;
+ default:
+ goto invalid_fmt;
+ }
+
x_shift_ = 0;
if ((bayerFormat.bitDepth == 8 || bayerFormat.bitDepth == 10) &&
@@ -327,6 +356,7 @@ int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat, [[maybe_unused]] Pi
}
}
+invalid_fmt:
LOG(Debayer, Error) << "Unsupported input output format combination";
return -EINVAL;
}
@@ -566,6 +596,9 @@ void DebayerCpu::process(FrameBuffer *input, FrameBuffer *output, DebayerParams
gamma_correction_ = params.gamma;
}
+ if (swapRedBlueGains_)
+ std::swap(params.gainR, params.gainB);
+
for (int i = 0; i < 256; i++) {
int idx;