libcamera: software_isp: Set initial values of DebayerParams
diff mbox series

Message ID 20260223141945.58779-1-mzamazal@redhat.com
State Accepted
Commit 0d3e543b4d6690f65070b95450aecb5792d0d51f
Headers show
Series
  • libcamera: software_isp: Set initial values of DebayerParams
Related show

Commit Message

Milan Zamazal Feb. 23, 2026, 2:19 p.m. UTC
Debayer parameters and processing are currently run asynchronously.
This can lead to assertion errors in case the processing tries to use
not yet computed debayer parameters.  To prevent this situation, specify
some default values for DebayerParams members.  This doesn't make
correct parameters but prevents crashes or other crazy behaviours at
least.

Note this patch is just a workaround.  The mutually asynchronous
parameters computation and processing can cause more problems, like
using parameters computed for a different frame.  But it is non-trivial
to fix that; in the meantime, setting the default values solves the
worst problem.

Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/311
Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 .../libcamera/internal/software_isp/debayer_params.h | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Hans de Goede Feb. 24, 2026, 6:50 p.m. UTC | #1
Hi,

On 23-Feb-26 15:19, Milan Zamazal wrote:
> Debayer parameters and processing are currently run asynchronously.
> This can lead to assertion errors in case the processing tries to use
> not yet computed debayer parameters.  To prevent this situation, specify
> some default values for DebayerParams members.  This doesn't make
> correct parameters but prevents crashes or other crazy behaviours at
> least.
> 
> Note this patch is just a workaround.  The mutually asynchronous
> parameters computation and processing can cause more problems, like
> using parameters computed for a different frame.  But it is non-trivial
> to fix that; in the meantime, setting the default values solves the
> worst problem.
> 
> Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/311
> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com>

Regards,

Hans



> ---
>  .../libcamera/internal/software_isp/debayer_params.h | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/include/libcamera/internal/software_isp/debayer_params.h b/include/libcamera/internal/software_isp/debayer_params.h
> index 1c0412d75..6772b43bc 100644
> --- a/include/libcamera/internal/software_isp/debayer_params.h
> +++ b/include/libcamera/internal/software_isp/debayer_params.h
> @@ -18,11 +18,13 @@
>  namespace libcamera {
>  
>  struct DebayerParams {
> -	Matrix<float, 3, 3> combinedMatrix;
> -	RGB<float> blackLevel;
> -	float gamma;
> -	float contrastExp;
> -	RGB<float> gains;
> +	Matrix<float, 3, 3> combinedMatrix = { { 1.0, 0.0, 0.0,
> +						 0.0, 1.0, 0.0,
> +						 0.0, 0.0, 1.0 } };
> +	RGB<float> blackLevel = RGB<float>({ 0.0, 0.0, 0.0 });
> +	float gamma = 1.0;
> +	float contrastExp = 1.0;
> +	RGB<float> gains = RGB<float>({ 1.0, 1.0, 1.0 });
>  };
>  
>  } /* namespace libcamera */
Kieran Bingham Feb. 25, 2026, 11:58 a.m. UTC | #2
Quoting Milan Zamazal (2026-02-23 14:19:45)
> Debayer parameters and processing are currently run asynchronously.
> This can lead to assertion errors in case the processing tries to use
> not yet computed debayer parameters.  To prevent this situation, specify
> some default values for DebayerParams members.  This doesn't make
> correct parameters but prevents crashes or other crazy behaviours at
> least.
> 
> Note this patch is just a workaround.  The mutually asynchronous
> parameters computation and processing can cause more problems, like
> using parameters computed for a different frame.  But it is non-trivial
> to fix that; in the meantime, setting the default values solves the
> worst problem.

I think these look like sane initialisation defaults.


Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> 
> Closes: https://gitlab.freedesktop.org/camera/libcamera/-/issues/311
> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
> ---
>  .../libcamera/internal/software_isp/debayer_params.h | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/include/libcamera/internal/software_isp/debayer_params.h b/include/libcamera/internal/software_isp/debayer_params.h
> index 1c0412d75..6772b43bc 100644
> --- a/include/libcamera/internal/software_isp/debayer_params.h
> +++ b/include/libcamera/internal/software_isp/debayer_params.h
> @@ -18,11 +18,13 @@
>  namespace libcamera {
>  
>  struct DebayerParams {
> -       Matrix<float, 3, 3> combinedMatrix;
> -       RGB<float> blackLevel;
> -       float gamma;
> -       float contrastExp;
> -       RGB<float> gains;
> +       Matrix<float, 3, 3> combinedMatrix = { { 1.0, 0.0, 0.0,
> +                                                0.0, 1.0, 0.0,
> +                                                0.0, 0.0, 1.0 } };
> +       RGB<float> blackLevel = RGB<float>({ 0.0, 0.0, 0.0 });
> +       float gamma = 1.0;
> +       float contrastExp = 1.0;
> +       RGB<float> gains = RGB<float>({ 1.0, 1.0, 1.0 });
>  };
>  
>  } /* namespace libcamera */
> -- 
> 2.53.0
>

Patch
diff mbox series

diff --git a/include/libcamera/internal/software_isp/debayer_params.h b/include/libcamera/internal/software_isp/debayer_params.h
index 1c0412d75..6772b43bc 100644
--- a/include/libcamera/internal/software_isp/debayer_params.h
+++ b/include/libcamera/internal/software_isp/debayer_params.h
@@ -18,11 +18,13 @@ 
 namespace libcamera {
 
 struct DebayerParams {
-	Matrix<float, 3, 3> combinedMatrix;
-	RGB<float> blackLevel;
-	float gamma;
-	float contrastExp;
-	RGB<float> gains;
+	Matrix<float, 3, 3> combinedMatrix = { { 1.0, 0.0, 0.0,
+						 0.0, 1.0, 0.0,
+						 0.0, 0.0, 1.0 } };
+	RGB<float> blackLevel = RGB<float>({ 0.0, 0.0, 0.0 });
+	float gamma = 1.0;
+	float contrastExp = 1.0;
+	RGB<float> gains = RGB<float>({ 1.0, 1.0, 1.0 });
 };
 
 } /* namespace libcamera */