@@ -102,6 +102,7 @@ private:
DmaBufAllocator dmaHeap_;
bool ccmEnabled_;
bool lscEnabled_;
+ std::optional<Size> lscGridSize_;
std::unique_ptr<ipa::softisp::IPAProxySoftIsp> ipa_;
std::deque<FrameBuffer *> queuedInputBuffers_;
@@ -112,7 +112,8 @@ Debayer::~Debayer()
* \param[in] inputCfg The input configuration
* \param[in] outputCfgs The output configurations
* \param[in] ccmEnabled Whether a color correction matrix is applied
- * \param[in] lscEnabled Whether lens shading correction grid is provided
+ * \param[in] lscGridSize The size of the lens shading correction grid;
+ empty if the correction is not enabled
*
* \return 0 on success, a negative errno on failure
*/
@@ -41,7 +41,7 @@ public:
virtual int configure(const StreamConfiguration &inputCfg,
const std::vector<std::reference_wrapper<const StreamConfiguration>> &outputCfgs,
bool ccmEnabled,
- bool lscEnabled) = 0;
+ const std::optional<Size> &lscGridSize) = 0;
virtual std::vector<PixelFormat> formats(PixelFormat inputFormat) = 0;
@@ -625,7 +625,7 @@ int DebayerCpu::setDebayerFunctions(PixelFormat inputFormat,
int DebayerCpu::configure(const StreamConfiguration &inputCfg,
const std::vector<std::reference_wrapper<const StreamConfiguration>> &outputCfgs,
bool ccmEnabled,
- [[maybe_unused]] bool lscEnabled)
+ [[maybe_unused]] const std::optional<Size> &lscGridSize)
{
if (getInputConfig(inputCfg.pixelFormat, inputConfig_) != 0) {
LOG(Debayer, Error)
@@ -38,7 +38,7 @@ public:
int configure(const StreamConfiguration &inputCfg,
const std::vector<std::reference_wrapper<const StreamConfiguration>> &outputCfgs,
bool ccmEnabled,
- bool lscEnabled) override;
+ const std::optional<Size> &lscGridSize) override;
Size patternSize(PixelFormat inputFormat) override;
std::vector<PixelFormat> formats(PixelFormat input) override;
std::tuple<unsigned int, unsigned int>
@@ -146,7 +146,7 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm
/* Specify GL_OES_EGL_image_external */
egl_.pushEnv(shaderEnv, "#extension GL_OES_EGL_image_external: enable");
- if (lscEnabled_)
+ if (lscGridSize_)
egl_.pushEnv(shaderEnv, "#define APPLY_LSC");
/*
@@ -280,7 +280,7 @@ int DebayerEGL::initBayerShaders(PixelFormat inputFormat, PixelFormat outputForm
int DebayerEGL::configure(const StreamConfiguration &inputCfg,
const std::vector<std::reference_wrapper<const StreamConfiguration>> &outputCfgs,
[[maybe_unused]] bool ccmEnabled,
- bool lscEnabled)
+ const std::optional<Size> &lscGridSize)
{
if (getInputConfig(inputCfg.pixelFormat, inputConfig_) != 0) {
LOG(Debayer, Error)
@@ -300,7 +300,7 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg,
return -EINVAL;
}
- lscEnabled_ = lscEnabled;
+ lscGridSize_ = lscGridSize;
inputConfig_.stride = inputCfg.stride;
inputPixelFormat_ = inputCfg.pixelFormat;
@@ -478,7 +478,7 @@ void DebayerEGL::setShaderVariableValues(eGLImage &eglImageIn, const DebayerPara
glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm.data().data());
LOG(Debayer, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix;
- if (lscEnabled_ && params.lscLutVersion != lscLutVersion_) {
+ if (lscGridSize_ && params.lscLutVersion != lscLutVersion_) {
egl_.updateTexture2D(*eglImageLscLookup_, params.lscLut.data());
lscLutVersion_ = params.lscLutVersion;
glUniform1i(textureUniformLsc_, eglImageLscLookup_->texture_unit_uniform_id_);
@@ -691,12 +691,12 @@ int DebayerEGL::start()
if (initBayerShaders(inputPixelFormat_, outputPixelFormat_))
return -EINVAL;
- if (lscEnabled_) {
- constexpr unsigned int gridSize = DebayerParams::kLscGridSize;
- constexpr unsigned int stride = gridSize * DebayerParams::kLscBytesPerCell;
+ if (lscGridSize_) {
+ const Size &gridSize = lscGridSize_.value();
+ const unsigned int stride = gridSize.width * DebayerParams::kLscBytesPerCell;
eglImageLscLookup_.emplace(GL_RGBA,
- gridSize,
- gridSize,
+ gridSize.width,
+ gridSize.height,
stride,
GL_TEXTURE2,
2);
@@ -46,7 +46,7 @@ public:
int configure(const StreamConfiguration &inputCfg,
const std::vector<std::reference_wrapper<const StreamConfiguration>> &outputCfgs,
bool ccmEnabled,
- bool lscEnabled) override;
+ const std::optional<Size> &lscGridSize) override;
Size patternSize(PixelFormat inputFormat) override;
@@ -84,7 +84,7 @@ private:
unsigned int outputBufferCount_;
/* LSC lookup table */
- bool lscEnabled_;
+ std::optional<Size> lscGridSize_;
std::optional<eGLImage> eglImageLscLookup_;
std::optional<uint64_t> lscLutVersion_;
@@ -171,6 +171,11 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,
return;
}
+ if (lscEnabled_)
+ lscGridSize_ = Size(DebayerParams::kLscGridSize, DebayerParams::kLscGridSize);
+ else
+ lscGridSize_.reset();
+
ipa_->paramsComputed.connect(this, &SoftwareIsp::saveIspParams);
ipa_->metadataReady.connect(this,
[this](uint32_t frame, const ControlList &metadata) {
@@ -294,7 +299,7 @@ int SoftwareIsp::configure(const StreamConfiguration &inputCfg,
if (ret < 0)
return ret;
- ret = debayer_->configure(inputCfg, outputCfgs, ccmEnabled_, lscEnabled_);
+ ret = debayer_->configure(inputCfg, outputCfgs, ccmEnabled_, lscGridSize_);
if (ret < 0)
return ret;
The lens shading correction texture (grid) has currently the fixed size of 17x17 cells in software ISP. Let's make the size flexible instead, in order to be able to reuse external tuning data, perhaps make GPU happier with sizes of powers of 2, and to provide size flexibility generally. This commit prepares GPU debayering for this change. lscEnabled_ is replaced by lscGridSize_. It is empty in case lens shading correction is disabled and contains the grid size otherwise. Software ISP still passes to GPU debayering either an empty grid size or the grid size of 17x17. Making the grid size flexible is implemented in the followup commits. Signed-off-by: Milan Zamazal <mzamazal@redhat.com> --- .../internal/software_isp/software_isp.h | 1 + src/libcamera/software_isp/debayer.cpp | 3 ++- src/libcamera/software_isp/debayer.h | 2 +- src/libcamera/software_isp/debayer_cpu.cpp | 2 +- src/libcamera/software_isp/debayer_cpu.h | 2 +- src/libcamera/software_isp/debayer_egl.cpp | 18 +++++++++--------- src/libcamera/software_isp/debayer_egl.h | 4 ++-- src/libcamera/software_isp/software_isp.cpp | 7 ++++++- 8 files changed, 23 insertions(+), 16 deletions(-)