@@ -35,6 +35,7 @@ struct DebayerParams {
using LscLookupTable =
std::array<LscValueType, kLscGridSize * kLscGridSize * kLscValuesPerCell>;
enum LscType : uint32_t {
+ LscNone,
LscTable,
};
LscLookupTable lscLut{};
@@ -99,7 +99,7 @@ private:
DebayerParams debayerParams_;
DmaBufAllocator dmaHeap_;
bool ccmEnabled_;
- bool lscEnabled_;
+ uint32_t lscType_;
std::unique_ptr<ipa::soft::IPAProxySoft> ipa_;
std::deque<FrameBuffer *> queuedInputBuffers_;
@@ -20,7 +20,7 @@ interface IPASoftInterface {
libcamera.ControlInfoMap sensorControls)
=> (int32 ret,
libcamera.ControlInfoMap ipaControls,
- bool ccmEnabled, bool lscEnabled);
+ bool ccmEnabled, uint32 lscType);
start() => (int32 ret);
stop();
configure(IPAConfigInfo configInfo)
@@ -36,7 +36,7 @@ int Lsc::init(IPAContext &context, const ValueNode &tuningData)
return -EINVAL;
}
- context.lscEnabled = true;
+ context.lscType = type_;
return 0;
}
@@ -14,6 +14,7 @@
#include <libcamera/controls.h>
#include "libcamera/internal/matrix.h"
+#include "libcamera/internal/software_isp/debayer_params.h"
#include "libcamera/internal/vector.h"
#include <libipa/fc_queue.h>
@@ -93,7 +94,7 @@ struct IPAContext {
FCQueue<IPAFrameContext> frameContexts;
ControlInfoMap::Map ctrlMap;
bool ccmEnabled = false;
- bool lscEnabled = false;
+ DebayerParams::LscType lscType = DebayerParams::LscNone;
};
} /* namespace ipa::soft */
@@ -58,7 +58,7 @@ public:
const ControlInfoMap &sensorControls,
ControlInfoMap *ipaControls,
bool *ccmEnabled,
- bool *lscEnabled) override;
+ uint32_t *lscType) override;
int configure(const IPAConfigInfo &configInfo) override;
int start() override;
@@ -99,7 +99,7 @@ int IPASoftSimple::init(const IPASettings &settings,
const ControlInfoMap &sensorControls,
ControlInfoMap *ipaControls,
bool *ccmEnabled,
- bool *lscEnabled)
+ uint32_t *lscType)
{
camHelper_ = CameraSensorHelperFactoryBase::create(settings.sensorModel);
if (!camHelper_) {
@@ -138,7 +138,7 @@ int IPASoftSimple::init(const IPASettings &settings,
return ret;
*ccmEnabled = context_.ccmEnabled;
- *lscEnabled = context_.lscEnabled;
+ *lscType = context_.lscType;
params_ = nullptr;
stats_ = nullptr;
@@ -70,7 +70,7 @@ uniform vec3 blacklevel;
uniform float gamma;
uniform float contrastExp;
-#if defined(APPLY_LSC)
+#if defined(APPLY_LSC_TABLE)
uniform sampler2D lsc_tex;
#endif
@@ -231,7 +231,7 @@ void main(void)
rgb = rgb - blacklevel;
-#if defined(APPLY_LSC)
+#if defined(APPLY_LSC_TABLE)
rgb = rgb * texture2D(lsc_tex, textureOut).rgb;
#endif
@@ -29,7 +29,7 @@ uniform vec3 blacklevel;
uniform float gamma;
uniform float contrastExp;
-#if defined(APPLY_LSC)
+#if defined(APPLY_LSC_TABLE)
uniform sampler2D lsc_tex;
#endif
@@ -134,7 +134,7 @@ void main(void) {
rgb = rgb - blacklevel;
-#if defined(APPLY_LSC)
+#if defined(APPLY_LSC_TABLE)
rgb = rgb * texture2D(lsc_tex, center.xy).rgb;
#endif
@@ -114,7 +114,7 @@ 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] lscType Type of lens shading correction
*
* \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;
+ uint32_t lscType) = 0;
virtual std::vector<PixelFormat> formats(PixelFormat inputFormat) = 0;
@@ -544,7 +544,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]] uint32_t lscType)
{
if (getInputConfig(inputCfg.pixelFormat, inputConfig_) != 0)
return -EINVAL;
@@ -38,7 +38,7 @@ public:
int configure(const StreamConfiguration &inputCfg,
const std::vector<std::reference_wrapper<const StreamConfiguration>> &outputCfgs,
bool ccmEnabled,
- bool lscEnabled) override;
+ uint32_t lscType) override;
Size patternSize(PixelFormat inputFormat) override;
std::vector<PixelFormat> formats(PixelFormat input) override;
std::tuple<unsigned int, unsigned int>
@@ -147,8 +147,13 @@ 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_)
- egl_.pushEnv(shaderEnv, "#define APPLY_LSC");
+ switch (lscType_) {
+ case DebayerParams::LscNone:
+ break;
+ case DebayerParams::LscTable:
+ egl_.pushEnv(shaderEnv, "#define APPLY_LSC_TABLE");
+ break;
+ }
/*
* Tell shaders how to re-order output taking account of how the pixels
@@ -289,7 +294,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)
+ uint32_t lscType)
{
if (getInputConfig(inputCfg.pixelFormat, inputConfig_) != 0)
return -EINVAL;
@@ -306,7 +311,7 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg,
return -EINVAL;
}
- lscEnabled_ = lscEnabled;
+ lscType_ = lscType;
inputConfig_.stride = inputCfg.stride;
inputPixelFormat_ = inputCfg.pixelFormat;
@@ -349,7 +354,7 @@ int DebayerEGL::configure(const StreamConfiguration &inputCfg,
*/
stats_->setWindow(Rectangle(window_.size()));
- if (lscEnabled_) {
+ if (lscType_ == DebayerParams::LscTable) {
constexpr unsigned int gridSize = DebayerParams::kLscGridSize;
const unsigned int stride = gridSize * DebayerParams::kLscBytesPerCell;
eglImageLscLookup_ =
@@ -499,11 +504,15 @@ void DebayerEGL::setShaderVariableValues(const DebayerParams ¶ms)
glUniformMatrix3fv(ccmUniformDataIn_, 1, GL_FALSE, ccm);
LOG(Debayer, Debug) << " ccmUniformDataIn_ " << ccmUniformDataIn_ << " data " << params.combinedMatrix;
- if (lscEnabled_) {
+ switch (lscType_) {
+ case DebayerParams::LscNone:
+ break;
+ case DebayerParams::LscTable:
egl_.createTexture2D(*eglImageLscLookup_, GL_RGB16F, GL_RGB, GL_FLOAT,
DebayerParams::kLscGridSize, DebayerParams::kLscGridSize,
params.lscLut.data(), GL_LINEAR);
glUniform1i(textureUniformLsc_, eglImageLscLookup_->texture_unit_uniform_id_);
+ break;
}
/*
@@ -45,7 +45,7 @@ public:
int configure(const StreamConfiguration &inputCfg,
const std::vector<std::reference_wrapper<const StreamConfiguration>> &outputCfgs,
bool ccmEnabled,
- bool lscEnabled) override;
+ uint32_t lscType) override;
Size patternSize(PixelFormat inputFormat) override;
@@ -77,9 +77,9 @@ private:
std::unique_ptr<eGLImage> eglImageBayerIn_;
std::unique_ptr<eGLImage> eglImageBayerOut_;
- /* LSC lookup table */
+ /* Lens shading correction */
+ uint32_t lscType_;
std::unique_ptr<eGLImage> eglImageLscLookup_;
- bool lscEnabled_;
/* Shader parameters */
float firstRed_x_;
@@ -158,7 +158,7 @@ SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,
sensor->controls(),
ipaControls,
&ccmEnabled_,
- &lscEnabled_);
+ &lscType_);
if (ret) {
LOG(SoftwareIsp, Error) << "IPA init failed";
debayer_.reset();
@@ -274,7 +274,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_, lscType_);
if (ret < 0)
return ret;
With the upcoming introduction of polynomial lens shading correction, let's replace the boolean LSC-enabled flag with an enum / integer indicating the type of the LSC to apply. For the case when LSC is not enabled, LscNone enum value is introduced. The switch passed to the shaders is renamed from APPLY_LSC to APPLY_LSC_TABLE to get ready for other LSC types and other APPLY_LSC_* switches for shaders. Signed-off-by: Milan Zamazal <mzamazal@redhat.com> --- .../internal/software_isp/debayer_params.h | 1 + .../internal/software_isp/software_isp.h | 2 +- include/libcamera/ipa/soft.mojom | 2 +- src/ipa/simple/algorithms/lsc.cpp | 2 +- src/ipa/simple/ipa_context.h | 3 ++- src/ipa/simple/soft_simple.cpp | 6 +++--- src/libcamera/shaders/bayer_1x_packed.frag | 4 ++-- src/libcamera/shaders/bayer_unpacked.frag | 4 ++-- src/libcamera/software_isp/debayer.cpp | 2 +- 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 | 21 +++++++++++++------ src/libcamera/software_isp/debayer_egl.h | 6 +++--- src/libcamera/software_isp/software_isp.cpp | 4 ++-- 15 files changed, 37 insertions(+), 26 deletions(-)