@@ -61,6 +61,21 @@ int DebayerEGL::getInputConfig(PixelFormat inputFormat, DebayerInputConfig &conf
formats::XBGR8888,
formats::ABGR8888 };
+ if (bayerFormat.order == BayerFormat::Order::MONO) {
+ if (bayerFormat.packing == BayerFormat::Packing::None) {
+ config.bpp = (bayerFormat.bitDepth + 7) & ~7;
+ config.patternSize.width = 2;
+ config.patternSize.height = 2;
+ } else if (bayerFormat.packing == BayerFormat::Packing::CSI2) {
+ config.bpp = bayerFormat.bitDepth;
+ config.patternSize.width = (bayerFormat.bitDepth == 12) ? 2 : 4;
+ config.patternSize.height = 2;
+ }
+
+ config.outputFormats = outputFormats;
+ return 0;
+ }
+
if ((bayerFormat.bitDepth == 8 || bayerFormat.bitDepth == 10) &&
bayerFormat.packing == BayerFormat::Packing::None &&
isStandardBayerOrder(bayerFormat.order)) {
@@ -172,6 +187,13 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm
shaderStridePixels_ = inputConfig_.stride;
switch (inputFormat) {
+ case libcamera::formats::R8:
+ case libcamera::formats::R10:
+ case libcamera::formats::R12:
+ case libcamera::formats::R16:
+ firstRed_x_ = 0.0;
+ firstRed_y_ = 0.0;
+ break;
case libcamera::formats::SBGGR8:
case libcamera::formats::SBGGR10_CSI2P:
case libcamera::formats::SBGGR12_CSI2P:
@@ -201,8 +223,56 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm
return -EINVAL;
};
+ BayerFormat bayerFormat = BayerFormat::fromPixelFormat(inputFormat);
+
/* Shader selection */
switch (inputFormat) {
+ case libcamera::formats::R8:
+ fragmentShaderData = mono_frag;
+ vertexShaderData = identity_vert;
+ egl_.pushEnv(shaderEnv, "#define INV_MAX_VAL (1.0 / 255.0)");
+ egl_.pushEnv(shaderEnv, "#define RAW8");
+ break;
+ case libcamera::formats::R10:
+ fragmentShaderData = mono_frag;
+ vertexShaderData = identity_vert;
+ egl_.pushEnv(shaderEnv, "#define INV_MAX_VAL (1.0 / 1023.0)");
+ if (bayerFormat.packing == BayerFormat::Packing::None) {
+ egl_.pushEnv(shaderEnv, "#define RAW10");
+ glFormat_ = GL_RG;
+ bytesPerPixel_ = 2;
+ } else {
+ egl_.pushEnv(shaderEnv, "#define RAW10P");
+ egl_.pushEnv(shaderEnv, "#define BLOCK_PIXELS 4.0");
+ egl_.pushEnv(shaderEnv, "#define BLOCK_BYTES 5.0");
+ egl_.pushEnv(shaderEnv, (std::string("#define TEX_WIDTH ") + std::to_string(inputConfig_.stride) + ".0").c_str());
+ shaderStridePixels_ = width_;
+ }
+ break;
+ case libcamera::formats::R12:
+ fragmentShaderData = mono_frag;
+ vertexShaderData = identity_vert;
+ egl_.pushEnv(shaderEnv, "#define INV_MAX_VAL (1.0 / 4095.0)");
+ if (bayerFormat.packing == BayerFormat::Packing::None) {
+ egl_.pushEnv(shaderEnv, "#define RAW12");
+ glFormat_ = GL_RG;
+ bytesPerPixel_ = 2;
+ } else {
+ egl_.pushEnv(shaderEnv, "#define RAW12P");
+ egl_.pushEnv(shaderEnv, "#define BLOCK_PIXELS 2.0");
+ egl_.pushEnv(shaderEnv, "#define BLOCK_BYTES 3.0");
+ egl_.pushEnv(shaderEnv, (std::string("#define TEX_WIDTH ") + std::to_string(inputConfig_.stride) + ".0").c_str());
+ shaderStridePixels_ = width_;
+ }
+ break;
+ case libcamera::formats::R16:
+ fragmentShaderData = mono_frag;
+ vertexShaderData = identity_vert;
+ egl_.pushEnv(shaderEnv, "#define INV_MAX_VAL (1.0 / 65535.0)");
+ egl_.pushEnv(shaderEnv, "#define RAW16");
+ glFormat_ = GL_RG;
+ bytesPerPixel_ = 2;
+ break;
case libcamera::formats::SBGGR8:
case libcamera::formats::SGBRG8:
case libcamera::formats::SGRBG8:
@@ -474,9 +544,11 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara
<< " textureUniformProjMatrix_ " << textureUniformProjMatrix_;
/* Pre-transpose matrix for GLES 2.0. */
- Matrix<float, 3, 3> ccm = params.combinedMatrix.transpose();
- glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm.data().data());
- LOG(Debayer, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix;
+ if (ccmUniformDataIn_ != -1) {
+ Matrix<float, 3, 3> ccm = params.combinedMatrix.transpose();
+ glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm.data().data());
+ LOG(Debayer, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix;
+ }
if (lscEnabled_ && params.lscLutVersion != lscLutVersion_) {
egl_.updateTexture2D(*eglImageLscLookup_, params.lscLut.data());
@@ -723,12 +795,11 @@ void DebayerEGL::stop()
SizeRange DebayerEGL::sizes(PixelFormat inputFormat, const Size &inputSize)
{
Size patternSize = this->patternSize(inputFormat);
- unsigned int borderHeight = patternSize.height;
-
if (patternSize.isNull())
return {};
/* No need for top/bottom border with a pattern height of 2 */
+ unsigned int borderHeight = patternSize.height;
if (patternSize.height == 2)
borderHeight = 0;
@@ -743,9 +814,12 @@ SizeRange DebayerEGL::sizes(PixelFormat inputFormat, const Size &inputSize)
return {};
}
+ BayerFormat bayerFormat = BayerFormat::fromPixelFormat(inputFormat);
+ bool localIsMono = (bayerFormat.order == BayerFormat::Order::MONO);
+
return SizeRange(Size(patternSize.width, patternSize.height),
- Size((inputSize.width - 2 * patternSize.width) & ~(patternSize.width - 1),
- (inputSize.height - 2 * borderHeight) & ~(patternSize.height - 1)),
+ Size((inputSize.width - (localIsMono ? 0 : 2 * patternSize.width)) & ~(patternSize.width - 1),
+ (inputSize.height - (localIsMono ? 0 : 2 * borderHeight)) & ~(patternSize.height - 1)),
patternSize.width, patternSize.height);
}
Select mono.frag for R8, R10, R12 and R16 in DebayerEGL. Unpacked 10, 12 and 16-bit data is sent as a two-channel texture, 8-bit and packed data as a single-channel texture. For packed formats, TEX_WIDTH is the stride in bytes and the shader stride is width_, as for the Bayer shaders. Unlike the CPU, which only uses the 8 most significant bits, the GPU uses the full depth of the pixel. As for the CPU, the pattern size follows the Bayer formats and the statistics. firstRed_ is meaningless for monochrome and set to 0. The CCM is now only sent to the shader if it has a "ccm" input: Bayer shaders do, mono.frag does not. sizes() keeps no border for monochrome. Signed-off-by: Alain CousiniƩ <alain.cousinie@laposte.net> --- src/libcamera/software_isp/debayer_egl.cpp | 88 ++++++++++++++++++++-- 1 file changed, 81 insertions(+), 7 deletions(-)