[libcamera-devel] [PATCH] libcamera: ipa: Add IMX335 support

Laurent Pinchart laurent.pinchart at ideasonboard.com
Thu Nov 2 19:41:33 CET 2023


Hi Kieran,

Thank you for the patch.

On Thu, Nov 02, 2023 at 06:09:16PM +0000, Kieran Bingham via libcamera-devel wrote:
> Provide support for the Sony IMX335 in both libipa and RaspberryPi IPA
> modules.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> ---
>  src/ipa/libipa/camera_sensor_helper.cpp      | 23 ++++++
>  src/ipa/rpi/cam_helper/cam_helper_imx335.cpp | 74 ++++++++++++++++++++
>  src/ipa/rpi/cam_helper/meson.build           |  1 +
>  src/libcamera/camera_sensor_properties.cpp   |  4 ++
>  4 files changed, 102 insertions(+)
>  create mode 100644 src/ipa/rpi/cam_helper/cam_helper_imx335.cpp
> 
> diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp
> index f0ecc3830115..ddab5af6eac2 100644
> --- a/src/ipa/libipa/camera_sensor_helper.cpp
> +++ b/src/ipa/libipa/camera_sensor_helper.cpp
> @@ -444,6 +444,29 @@ class CameraSensorHelperImx327 : public CameraSensorHelperImx290
>  };
>  REGISTER_CAMERA_SENSOR_HELPER("imx327", CameraSensorHelperImx327)
>  
> +class CameraSensorHelperImx335 : public CameraSensorHelper
> +{
> +public:
> +	uint32_t gainCode(double gain) const override;
> +	double gain(uint32_t gainCode) const override;
> +private:
> +	static constexpr uint32_t maxGainCode_ = 240;
> +};
> +
> +uint32_t CameraSensorHelperImx335::gainCode(double gain) const
> +{
> +	uint32_t code = 10 * std::log10(gain) * 10 / 3;

That looks like an exponential model, there's a helper for that.

> +
> +	return std::min(code, maxGainCode_);
> +}
> +
> +double CameraSensorHelperImx335::gain(uint32_t gainCode) const
> +{
> +	return std::pow(10.0, gainCode / (10 * 10 / 3));
> +}
> +
> +REGISTER_CAMERA_SENSOR_HELPER("imx335", CameraSensorHelperImx335)
> +
>  class CameraSensorHelperImx477 : public CameraSensorHelper
>  {
>  public:
> diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx335.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx335.cpp
> new file mode 100644
> index 000000000000..659c69d6b6c7
> --- /dev/null
> +++ b/src/ipa/rpi/cam_helper/cam_helper_imx335.cpp
> @@ -0,0 +1,74 @@
> +/* SPDX-License-Identifier: BSD-2-Clause */
> +/*
> + * Copyright (C) 2023, Ideas on Board Oy.
> + *
> + * cam_helper_imx335.cpp - camera information for the Sony IMX335 sensor
> + */
> +
> +#include <assert.h>
> +
> +#include "cam_helper.h"
> +#include "math.h"
> +
> +using namespace RPiController;
> +
> +class CamHelperImx335 : public CamHelper
> +{
> +public:
> +	CamHelperImx335();
> +	uint32_t gainCode(double gain) const override;
> +	double gain(uint32_t gainCode) const override;
> +	void getDelays(int &exposureDelay, int &gainDelay,
> +		       int &vblankDelay, int &hblankDelay) const override;
> +	unsigned int hideFramesModeSwitch() const override;
> +
> +private:
> +	/*
> +	 * Smallest difference between the frame length and integration time,
> +	 * in units of lines.
> +	 */
> +	static constexpr int frameIntegrationDiff = 4;
> +	static constexpr uint32_t maxGainCode = 240;
> +};
> +
> +/*
> + * IMX335 Metadata isn't yet supported.
> + */
> +
> +CamHelperImx335::CamHelperImx335()
> +	: CamHelper({}, frameIntegrationDiff)
> +{
> +}
> +
> +uint32_t CamHelperImx335::gainCode(double gain) const
> +{
> +	uint32_t code = 10 * std::log10(gain) * 10 / 3;
> +	return std::min(code, maxGainCode);
> +}
> +
> +double CamHelperImx335::gain(uint32_t gainCode) const
> +{
> +	return std::pow(10.0, gainCode / (10 * 10 / 3));
> +}
> +
> +void CamHelperImx335::getDelays(int &exposureDelay, int &gainDelay,
> +				int &vblankDelay, int &hblankDelay) const
> +{
> +	exposureDelay = 2;
> +	gainDelay = 2;
> +	vblankDelay = 2;
> +	hblankDelay = 2;

Have you validated all these delays ?

> +}
> +
> +unsigned int CamHelperImx335::hideFramesModeSwitch() const
> +{
> +	/* One bad frame can be expected after a mode switch. */
> +	return 1;

Same here.

> +}
> +
> +static CamHelper *create()
> +{
> +	return new CamHelperImx335();
> +}
> +
> +static RegisterCamHelper reg("imx335", &create);
> diff --git a/src/ipa/rpi/cam_helper/meson.build b/src/ipa/rpi/cam_helper/meson.build
> index bdf2db8eb742..17c25cb0e4a6 100644
> --- a/src/ipa/rpi/cam_helper/meson.build
> +++ b/src/ipa/rpi/cam_helper/meson.build
> @@ -6,6 +6,7 @@ rpi_ipa_cam_helper_sources = files([
>      'cam_helper_imx219.cpp',
>      'cam_helper_imx290.cpp',
>      'cam_helper_imx296.cpp',
> +    'cam_helper_imx335.cpp',
>      'cam_helper_imx477.cpp',
>      'cam_helper_imx519.cpp',
>      'cam_helper_imx708.cpp',
> diff --git a/src/libcamera/camera_sensor_properties.cpp b/src/libcamera/camera_sensor_properties.cpp
> index 27d6799a2686..dc76051fa349 100644
> --- a/src/libcamera/camera_sensor_properties.cpp
> +++ b/src/libcamera/camera_sensor_properties.cpp
> @@ -111,6 +111,10 @@ const CameraSensorProperties *CameraSensorProperties::get(const std::string &sen
>  			.unitCellSize = { 2900, 2900 },
>  			.testPatternModes = {},
>  		} },
> +		{ "imx335", {
> +			.unitCellSize = { 2000, 2000 },
> +			.testPatternModes = {},
> +		} },
>  		{ "imx477", {
>  			.unitCellSize = { 1550, 1550 },
>  			.testPatternModes = {},

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list