<div dir="ltr">Hi Naushir,<div><br></div><div>I can update the calibration file later this week with the cloudy weather coming up : D.</div><div>I thought the CT curve can extrapolate over the existing range, but if not I can try to covers it.</div><div>Thanks,</div><div>Wei-Chun</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Naushir Patuck <<a href="mailto:naush@raspberrypi.com">naush@raspberrypi.com</a>> 於 2024年3月20日 週三 上午2:22寫道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Will,<br>
<br>
Thank you for this patch!<br>
<br>
On Tue, 19 Mar 2024 at 15:11, Kieran Bingham<br>
<<a href="mailto:kieran.bingham@ideasonboard.com" target="_blank">kieran.bingham@ideasonboard.com</a>> wrote:<br>
><br>
> From: Will Whang <<a href="mailto:will@willwhang.com" target="_blank">will@willwhang.com</a>><br>
><br>
> Add tuning files and camera helpers for the Sony IMX283.<br>
><br>
> Signed-off-by: Will Whang <<a href="mailto:will@willwhang.com" target="_blank">will@willwhang.com</a>><br>
> [Kieran: Fix checkstyle formatting, extend commit message, remove pi5]<br>
> Signed-off-by: Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com" target="_blank">kieran.bingham@ideasonboard.com</a>><br>
><br>
> ---<br>
> This is a partial cherry-pick from<br>
> <a href="https://github.com/raspberrypi/libcamera/pull/118" rel="noreferrer" target="_blank">https://github.com/raspberrypi/libcamera/pull/118</a><br>
><br>
> The Pi5 support has not been included, as Pi5 is not yet upstream.<br>
> Once Pi5 is submitted, the remaining components from<br>
> <a href="https://github.com/raspberrypi/libcamera/pull/118" rel="noreferrer" target="_blank">https://github.com/raspberrypi/libcamera/pull/118</a> for the IMX283 should<br>
> be submitted on top.<br>
><br>
> Signed-off-by: Kieran Bingham <<a href="mailto:kieran.bingham@ideasonboard.com" target="_blank">kieran.bingham@ideasonboard.com</a>><br>
> ---<br>
>  src/ipa/rpi/cam_helper/cam_helper_imx283.cpp |  73 +++++<br>
>  src/ipa/rpi/cam_helper/meson.build           |   1 +<br>
>  src/ipa/rpi/vc4/data/imx283.json             | 320 +++++++++++++++++++<br>
>  src/ipa/rpi/vc4/data/meson.build             |   1 +<br>
>  4 files changed, 395 insertions(+)<br>
>  create mode 100644 src/ipa/rpi/cam_helper/cam_helper_imx283.cpp<br>
>  create mode 100644 src/ipa/rpi/vc4/data/imx283.json<br>
><br>
> diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx283.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx283.cpp<br>
> new file mode 100644<br>
> index 000000000000..5674b75466b5<br>
> --- /dev/null<br>
> +++ b/src/ipa/rpi/cam_helper/cam_helper_imx283.cpp<br>
> @@ -0,0 +1,73 @@<br>
> +/* SPDX-License-Identifier: BSD-2-Clause */<br>
> +/*<br>
> + * Copyright (C) 2021, Raspberry Pi Ltd<br>
> + *<br>
> + * cam_helper_imx283.cpp - camera information for imx283 sensor<br>
> + */<br>
> +<br>
> +#include <assert.h><br>
> +<br>
> +#include "cam_helper.h"<br>
> +#include "math.h"<br>
> +using namespace RPiController;<br>
> +<br>
> +class CamHelperImx283 : public CamHelper<br>
> +{<br>
> +public:<br>
> +       CamHelperImx283();<br>
> +       uint32_t gainCode(double gain) const override;<br>
> +       double gain(uint32_t gainCode) const override;<br>
> +       void getDelays(int &exposureDelay, int &gainDelay,<br>
> +                      int &vblankDelay, int &hblankDelay) const override;<br>
> +       unsigned int hideFramesModeSwitch() const override;<br>
> +<br>
> +private:<br>
> +       /*<br>
> +        * Smallest difference between the frame length and integration time,<br>
> +        * in units of lines.<br>
> +        */<br>
> +       static constexpr int frameIntegrationDiff = 4;<br>
> +};<br>
> +<br>
> +/*<br>
> + * Imx283 doesn't output metadata, so we have to use the "unicam parser" which<br>
> + * works by counting frames.<br>
> + */<br>
> +<br>
> +CamHelperImx283::CamHelperImx283()<br>
> +       : CamHelper({}, frameIntegrationDiff)<br>
> +{<br>
> +}<br>
> +<br>
> +uint32_t CamHelperImx283::gainCode(double gain) const<br>
> +{<br>
> +       return static_cast<uint32_t>(2048.0 - 2048.0 / gain);<br>
> +}<br>
> +<br>
> +double CamHelperImx283::gain(uint32_t gainCode) const<br>
> +{<br>
> +       return static_cast<double>(2048.0 / (2048 - gainCode));<br>
> +}<br>
> +<br>
> +void CamHelperImx283::getDelays(int &exposureDelay, int &gainDelay,<br>
> +                               int &vblankDelay, int &hblankDelay) const<br>
> +{<br>
> +       /* The driver appears to behave as follows: */<br>
> +       exposureDelay = 2;<br>
> +       gainDelay = 2;<br>
> +       vblankDelay = 2;<br>
> +       hblankDelay = 2;<br>
> +}<br>
> +<br>
> +unsigned int CamHelperImx283::hideFramesModeSwitch() const<br>
> +{<br>
> +       /* After a mode switch, we seem to get 1 bad frame. */<br>
> +       return 1;<br>
> +}<br>
> +<br>
> +static CamHelper *create()<br>
> +{<br>
> +       return new CamHelperImx283();<br>
> +}<br>
> +<br>
> +static RegisterCamHelper reg("imx283", &create);<br>
> diff --git a/src/ipa/rpi/cam_helper/meson.build b/src/ipa/rpi/cam_helper/meson.build<br>
> index 7262505742f3..1e43f1da29cd 100644<br>
> --- a/src/ipa/rpi/cam_helper/meson.build<br>
> +++ b/src/ipa/rpi/cam_helper/meson.build<br>
> @@ -4,6 +4,7 @@ rpi_ipa_cam_helper_sources = files([<br>
>      'cam_helper.cpp',<br>
>      'cam_helper_ov5647.cpp',<br>
>      'cam_helper_imx219.cpp',<br>
> +    'cam_helper_imx283.cpp',<br>
>      'cam_helper_imx290.cpp',<br>
>      'cam_helper_imx296.cpp',<br>
>      'cam_helper_imx477.cpp',<br>
> diff --git a/src/ipa/rpi/vc4/data/imx283.json b/src/ipa/rpi/vc4/data/imx283.json<br>
> new file mode 100644<br>
> index 000000000000..20892de19299<br>
> --- /dev/null<br>
> +++ b/src/ipa/rpi/vc4/data/imx283.json<br>
> @@ -0,0 +1,320 @@<br>
> +{<br>
> +    "version": 2.0,<br>
> +    "target": "bcm2835",<br>
> +    "algorithms": [<br>
> +        {<br>
> +            "rpi.black_level":<br>
> +            {<br>
> +                "black_level": 3200<br>
> +            }<br>
> +        },<br>
> +        {<br>
> +            "rpi.dpc": { }<br>
> +        },<br>
> +        {<br>
> +            "rpi.lux":<br>
> +            {<br>
> +                "reference_shutter_speed": 2461,<br>
> +                "reference_gain": 1.0,<br>
> +                "reference_aperture": 1.0,<br>
> +                "reference_lux": 1148,<br>
> +                "reference_Y": 13314<br>
> +            }<br>
> +        },<br>
> +        {<br>
> +            "rpi.noise":<br>
> +            {<br>
> +                "reference_constant": 0,<br>
> +                "reference_slope": 2.204<br>
> +            }<br>
> +        },<br>
> +        {<br>
> +            "rpi.geq":<br>
> +            {<br>
> +                "offset": 199,<br>
> +                "slope": 0.01947<br>
> +            }<br>
> +        },<br>
> +        {<br>
> +            "rpi.sdn": { }<br>
> +        },<br>
> +        {<br>
> +            "rpi.awb":<br>
> +            {<br>
> +                "priors": [<br>
> +                    {<br>
> +                        "lux": 0,<br>
> +                        "prior":<br>
> +                        [<br>
> +                            2000, 1.0,<br>
> +                            3000, 0.0,<br>
> +                            13000, 0.0<br>
> +                        ]<br>
> +                    },<br>
> +                    {<br>
> +                        "lux": 800,<br>
> +                        "prior":<br>
> +                        [<br>
> +                            2000, 0.0,<br>
> +                            6000, 2.0,<br>
> +                            13000, 2.0<br>
> +                        ]<br>
> +                    },<br>
> +                    {<br>
> +                        "lux": 1500,<br>
> +                        "prior":<br>
> +                        [<br>
> +                            2000, 0.0,<br>
> +                            4000, 1.0,<br>
> +                            6000, 6.0,<br>
> +                            6500, 7.0,<br>
> +                            7000, 1.0,<br>
> +                            13000, 1.0<br>
> +                        ]<br>
> +                    }<br>
> +                ],<br>
> +                "modes":<br>
> +                {<br>
> +                    "auto":<br>
> +                    {<br>
> +                        "lo": 2500,<br>
> +                        "hi": 8000<br>
> +                    },<br>
> +                    "incandescent":<br>
> +                    {<br>
> +                        "lo": 2500,<br>
> +                        "hi": 3000<br>
> +                    },<br>
> +                    "tungsten":<br>
> +                    {<br>
> +                        "lo": 3000,<br>
> +                        "hi": 3500<br>
> +                    },<br>
> +                    "fluorescent":<br>
> +                    {<br>
> +                        "lo": 4000,<br>
> +                        "hi": 4700<br>
> +                    },<br>
> +                    "indoor":<br>
> +                    {<br>
> +                        "lo": 3000,<br>
> +                        "hi": 5000<br>
> +                    },<br>
> +                    "daylight":<br>
> +                    {<br>
> +                        "lo": 5500,<br>
> +                        "hi": 6500<br>
> +                    },<br>
> +                    "cloudy":<br>
> +                    {<br>
> +                        "lo": 7000,<br>
> +                        "hi": 8600<br>
> +                    }<br>
> +                },<br>
> +                "bayes": 1,<br>
> +                "ct_curve":<br>
> +                [<br>
> +                    2213.0, 0.9607, 0.2593,<br>
> +                    2255.0, 0.9309, 0.2521,<br>
> +                    2259.0, 0.9257, 0.2508,<br>
> +                    5313.0, 0.4822, 0.5909,<br>
> +                    6237.0, 0.4726, 0.6376<br>
> +                ],<br>
<br>
This is a quirk of our tuning tool (and we should really fix it), but<br>
the CT curve has a range of approx. 2215K - 6235K.  The AWB modes<br>
above should really be constrained to this range, or the search could<br>
jump to a bad target and give invalid results.  This only impacts the<br>
"cloudy" awb mode.  Perhaps it's best to leave that out?<br>
<br>
Naush<br>
<br>
<br>
> +                "sensitivity_r": 1.0,<br>
> +                "sensitivity_b": 1.0,<br>
> +                "transverse_pos": 0.0144,<br>
> +                "transverse_neg": 0.01<br>
> +            }<br>
> +        },<br>
> +        {<br>
> +            "rpi.agc":<br>
> +            {<br>
> +                "metering_modes":<br>
> +                {<br>
> +                    "centre-weighted":<br>
> +                    {<br>
> +                        "weights":<br>
> +                        [<br>
> +                            3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0<br>
> +                        ]<br>
> +                    },<br>
> +                    "spot":<br>
> +                    {<br>
> +                        "weights":<br>
> +                        [<br>
> +                            2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0<br>
> +                        ]<br>
> +                    },<br>
> +                    "matrix":<br>
> +                    {<br>
> +                        "weights":<br>
> +                        [<br>
> +                            1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1<br>
> +                        ]<br>
> +                    }<br>
> +                },<br>
> +                "exposure_modes":<br>
> +                {<br>
> +                    "normal":<br>
> +                    {<br>
> +                        "shutter": [ 100, 10000, 30000, 60000, 120000 ],<br>
> +                        "gain": [ 1.0, 2.0, 4.0, 6.0, 6.0 ]<br>
> +                    },<br>
> +                    "short":<br>
> +                    {<br>
> +                        "shutter": [ 100, 5000, 10000, 20000, 120000 ],<br>
> +                        "gain": [ 1.0, 2.0, 4.0, 6.0, 6.0 ]<br>
> +                    }<br>
> +                },<br>
> +                "constraint_modes":<br>
> +                {<br>
> +                    "normal": [<br>
> +                        {<br>
> +                            "bound": "LOWER",<br>
> +                            "q_lo": 0.98,<br>
> +                            "q_hi": 1.0,<br>
> +                            "y_target":<br>
> +                            [<br>
> +                                0, 0.5,<br>
> +                                1000, 0.5<br>
> +                            ]<br>
> +                        }<br>
> +                    ],<br>
> +                    "highlight": [<br>
> +                        {<br>
> +                            "bound": "LOWER",<br>
> +                            "q_lo": 0.98,<br>
> +                            "q_hi": 1.0,<br>
> +                            "y_target":<br>
> +                            [<br>
> +                                0, 0.5,<br>
> +                                1000, 0.5<br>
> +                            ]<br>
> +                        },<br>
> +                        {<br>
> +                            "bound": "UPPER",<br>
> +                            "q_lo": 0.98,<br>
> +                            "q_hi": 1.0,<br>
> +                            "y_target":<br>
> +                            [<br>
> +                                0, 0.8,<br>
> +                                1000, 0.8<br>
> +                            ]<br>
> +                        }<br>
> +                    ]<br>
> +                },<br>
> +                "y_target":<br>
> +                [<br>
> +                    0, 0.16,<br>
> +                    1000, 0.165,<br>
> +                    10000, 0.17<br>
> +                ]<br>
> +            }<br>
> +        },<br>
> +        {<br>
> +            "rpi.alsc":<br>
> +            {<br>
> +                "omega": 1.3,<br>
> +                "n_iter": 100,<br>
> +                "luminance_strength": 0.7<br>
> +            }<br>
> +        },<br>
> +        {<br>
> +            "rpi.contrast":<br>
> +            {<br>
> +                "ce_enable": 1,<br>
> +                "gamma_curve":<br>
> +                [<br>
> +                    0, 0,<br>
> +                    1024, 5040,<br>
> +                    2048, 9338,<br>
> +                    3072, 12356,<br>
> +                    4096, 15312,<br>
> +                    5120, 18051,<br>
> +                    6144, 20790,<br>
> +                    7168, 23193,<br>
> +                    8192, 25744,<br>
> +                    9216, 27942,<br>
> +                    10240, 30035,<br>
> +                    11264, 32005,<br>
> +                    12288, 33975,<br>
> +                    13312, 35815,<br>
> +                    14336, 37600,<br>
> +                    15360, 39168,<br>
> +                    16384, 40642,<br>
> +                    18432, 43379,<br>
> +                    20480, 45749,<br>
> +                    22528, 47753,<br>
> +                    24576, 49621,<br>
> +                    26624, 51253,<br>
> +                    28672, 52698,<br>
> +                    30720, 53796,<br>
> +                    32768, 54876,<br>
> +                    36864, 57012,<br>
> +                    40960, 58656,<br>
> +                    45056, 59954,<br>
> +                    49152, 61183,<br>
> +                    53248, 62355,<br>
> +                    57344, 63419,<br>
> +                    61440, 64476,<br>
> +                    65535, 65535<br>
> +                ]<br>
> +            }<br>
> +        },<br>
> +        {<br>
> +            "rpi.ccm":<br>
> +            {<br>
> +                "ccms": [<br>
> +                    {<br>
> +                        "ct": 2213,<br>
> +                        "ccm":<br>
> +                        [<br>
> +                            1.91264, -0.27609, -0.63655,<br>
> +                            -0.65708, 2.11718, -0.46009,<br>
> +                            0.03629, -1.38441, 2.34811<br>
> +                        ]<br>
> +                    },<br>
> +                    {<br>
> +                        "ct": 2255,<br>
> +                        "ccm":<br>
> +                        [<br>
> +                            1.90369, -0.29309, -0.61059,<br>
> +                            -0.64693, 2.08169, -0.43476,<br>
> +                            0.04086, -1.29999, 2.25914<br>
> +                        ]<br>
> +                    },<br>
> +                    {<br>
> +                        "ct": 2259,<br>
> +                        "ccm":<br>
> +                        [<br>
> +                            1.92762, -0.35134, -0.57628,<br>
> +                            -0.63523, 2.08481, -0.44958,<br>
> +                            0.06754, -1.32953, 2.26199<br>
> +                        ]<br>
> +                    },<br>
> +                    {<br>
> +                        "ct": 5313,<br>
> +                        "ccm":<br>
> +                        [<br>
> +                            1.75924, -0.54053, -0.21871,<br>
> +                            -0.38159, 1.88671, -0.50511,<br>
> +                            -0.00747, -0.53492, 1.54239<br>
> +                        ]<br>
> +                    },<br>
> +                    {<br>
> +                        "ct": 6237,<br>
> +                        "ccm":<br>
> +                        [<br>
> +                            2.19299, -0.74764, -0.44536,<br>
> +                            -0.51678, 2.27651, -0.75972,<br>
> +                            -0.06498, -0.74269, 1.80767<br>
> +                        ]<br>
> +                    }<br>
> +                ]<br>
> +            }<br>
> +        },<br>
> +        {<br>
> +            "rpi.sharpen": { }<br>
> +        }<br>
> +    ]<br>
> +}<br>
> \ No newline at end of file<br>
> diff --git a/src/ipa/rpi/vc4/data/meson.build b/src/ipa/rpi/vc4/data/meson.build<br>
> index afbf875a113a..60477c112196 100644<br>
> --- a/src/ipa/rpi/vc4/data/meson.build<br>
> +++ b/src/ipa/rpi/vc4/data/meson.build<br>
> @@ -3,6 +3,7 @@<br>
>  conf_files = files([<br>
>      'imx219.json',<br>
>      'imx219_noir.json',<br>
> +    'imx283.json',<br>
>      'imx290.json',<br>
>      'imx296.json',<br>
>      'imx296_mono.json',<br>
> --<br>
> 2.34.1<br>
><br>
</blockquote></div>