[v2,3/5] utils: libtuning: modules: Add skeletal CCM module
diff mbox series

Message ID 20240517075751.3866269-4-paul.elder@ideasonboard.com
State Superseded
Headers show
Series
  • utils: tuning: Add AGC and CCM
Related show

Commit Message

Paul Elder May 17, 2024, 7:57 a.m. UTC
Add a skeletal CCM module just so that we can have some CCM tuning
values that we can use to test during development of CCM in the IPAs. As
rkisp1 is the main target, we only add support for rkisp1 for now.

The parameters are mostly copied from the hardcoded values in ctt,
except for the metering modes.

As CCM is called CTK (for crosstalk) in rkisp1, that is the name that
will be used for rkisp1.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>

---
Changes in v2:
- move converting floating to fixed point from the tuning script to the
  IPA
- reorganize the ccm list to mirror the format of lsc
- add offset vectors
---
 .../tuning/libtuning/modules/ccm/__init__.py  |  6 ++
 utils/tuning/libtuning/modules/ccm/ccm.py     | 22 +++++
 utils/tuning/libtuning/modules/ccm/rkisp1.py  | 89 +++++++++++++++++++
 3 files changed, 117 insertions(+)
 create mode 100644 utils/tuning/libtuning/modules/ccm/__init__.py
 create mode 100644 utils/tuning/libtuning/modules/ccm/ccm.py
 create mode 100644 utils/tuning/libtuning/modules/ccm/rkisp1.py

Comments

Stefan Klug May 17, 2024, 10:24 a.m. UTC | #1
Hi Paul,

thanks for the patch.

On Fri, May 17, 2024 at 04:57:49PM +0900, Paul Elder wrote:
> Add a skeletal CCM module just so that we can have some CCM tuning
> values that we can use to test during development of CCM in the IPAs. As
> rkisp1 is the main target, we only add support for rkisp1 for now.
> 
> The parameters are mostly copied from the hardcoded values in ctt,
> except for the metering modes.
> 
> As CCM is called CTK (for crosstalk) in rkisp1, that is the name that
> will be used for rkisp1.
> 
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> 
> ---
> Changes in v2:
> - move converting floating to fixed point from the tuning script to the
>   IPA
> - reorganize the ccm list to mirror the format of lsc
> - add offset vectors
> ---
>  .../tuning/libtuning/modules/ccm/__init__.py  |  6 ++
>  utils/tuning/libtuning/modules/ccm/ccm.py     | 22 +++++
>  utils/tuning/libtuning/modules/ccm/rkisp1.py  | 89 +++++++++++++++++++
>  3 files changed, 117 insertions(+)
>  create mode 100644 utils/tuning/libtuning/modules/ccm/__init__.py
>  create mode 100644 utils/tuning/libtuning/modules/ccm/ccm.py
>  create mode 100644 utils/tuning/libtuning/modules/ccm/rkisp1.py
> 
> diff --git a/utils/tuning/libtuning/modules/ccm/__init__.py b/utils/tuning/libtuning/modules/ccm/__init__.py
> new file mode 100644
> index 000000000..322602afe
> --- /dev/null
> +++ b/utils/tuning/libtuning/modules/ccm/__init__.py
> @@ -0,0 +1,6 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +#
> +# Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>
> +
> +from libtuning.modules.ccm.ccm import CCM
> +from libtuning.modules.ccm.rkisp1 import CCMRkISP1
> diff --git a/utils/tuning/libtuning/modules/ccm/ccm.py b/utils/tuning/libtuning/modules/ccm/ccm.py
> new file mode 100644
> index 000000000..7ddf0a8ca
> --- /dev/null
> +++ b/utils/tuning/libtuning/modules/ccm/ccm.py
> @@ -0,0 +1,22 @@
> +# SPDX-License-Identifier: BSD-2-Clause
> +#
> +# Copyright (C) 2019, Raspberry Pi Ltd
> +# Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>
> +
> +from ..module import Module
> +
> +import libtuning as lt
> +import libtuning.utils as utils
> +
> +import numpy as np
> +
> +class CCM(Module):
> +    type = 'ccm'
> +    hr_name = 'CCM (Base)'
> +    out_name = 'GenericCCM'
> +
> +    def __init__(self, *,
> +                 debug: list):
> +        super().__init__()
> +
> +        self.debug = debug
> diff --git a/utils/tuning/libtuning/modules/ccm/rkisp1.py b/utils/tuning/libtuning/modules/ccm/rkisp1.py
> new file mode 100644
> index 000000000..acae0a9b0
> --- /dev/null
> +++ b/utils/tuning/libtuning/modules/ccm/rkisp1.py
> @@ -0,0 +1,89 @@
> +# SPDX-License-Identifier: BSD-2-Clause
> +#
> +# Copyright (C) 2019, Raspberry Pi Ltd
> +# Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>
> +#
> +# rkisp1.py - Ccm module for tuning rkisp1
> +
> +from .ccm import CCM
> +
> +import libtuning as lt
> +import libtuning.utils as utils
> +
> +from numbers import Number
> +import numpy as np
> +
> +
> +class CCMRkISP1(CCM):
> +    hr_name = 'Crosstalk Correction (RkISP1)'
> +    out_name = 'Ccm'
> +    # \todo Not sure if this is useful. Probably will remove later.
> +    compatible = ['rkisp1']
> +
> +    def __init__(self, **kwargs):
> +        super().__init__(**kwargs)
> +
> +    # We don't actually need anything from the config file
> +    def validate_config(self, config: dict) -> bool:
> +        return True
> +
> +    def _generate_ccms(self) -> dict:
> +        ccms = [
> +                {
> +                    'ct': 2860,
> +                    'ccm': [ 2.12089, -0.52461, -0.59629,
> +                            -0.85342,  2.80445, -0.95103,
> +                            -0.26897, -1.14788,  2.41685 ],
> +                    'offsets': [ 0, 0, 0 ]

I stumbled over that. Should it be named 'offset' (singular)?

With or without that changed:

Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> 

Cheers,
Stefan

> +                },
> +
> +                {
> +                    'ct': 2960,
> +                    'ccm': [ 2.26962, -0.54174, -0.72789,
> +                            -0.77008,  2.60271, -0.83262,
> +                            -0.26036, -1.51254,  2.77289 ],
> +                    'offsets': [ 0, 0, 0 ]
> +                },
> +
> +                {
> +                    'ct': 3603,
> +                    'ccm': [ 2.18644, -0.66148, -0.52496,
> +                            -0.77828,  2.69474, -0.91645,
> +                            -0.25239, -0.83059,  2.08298 ],
> +                    'offsets': [ 0, 0, 0 ]
> +                },
> +
> +                {
> +                    'ct': 4650,
> +                    'ccm': [ 2.18174, -0.70887, -0.47287,
> +                            -0.70196,  2.76426, -1.06231,
> +                            -0.25157, -0.71978,  1.97135 ],
> +                    'offsets': [ 0, 0, 0 ]
> +                },
> +
> +                {
> +                    'ct': 5858,
> +                    'ccm': [ 2.32392, -0.88421, -0.43971,
> +                            -0.63821,  2.58348, -0.94527,
> +                            -0.28541, -0.54112,  1.82653 ],
> +                    'offsets': [ 0, 0, 0 ]
> +                },
> +
> +                {
> +                    'ct': 7580,
> +                    'ccm': [ 2.21175, -0.53242, -0.67933,
> +                            -0.57875,  3.07922, -1.50047,
> +                            -0.27709, -0.73338,  2.01048 ],
> +                    'offsets': [ 0, 0, 0 ]
> +                },
> +        ]
> +
> +        return ccms
> +
> +    def process(self, config: dict, images: list, outputs: dict) -> dict:
> +        output = {}
> +
> +        output['ccms'] = self._generate_ccms()
> +        # \todo Debug functionality
> +
> +        return output
> -- 
> 2.39.2
>
Dan Scally May 20, 2024, 1:30 p.m. UTC | #2
Hi Paul

On 17/05/2024 08:57, Paul Elder wrote:
> Add a skeletal CCM module just so that we can have some CCM tuning
> values that we can use to test during development of CCM in the IPAs. As
> rkisp1 is the main target, we only add support for rkisp1 for now.
>
> The parameters are mostly copied from the hardcoded values in ctt,
> except for the metering modes.
>
> As CCM is called CTK (for crosstalk) in rkisp1, that is the name that
> will be used for rkisp1.
>
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
>
> ---
> Changes in v2:
> - move converting floating to fixed point from the tuning script to the
>    IPA
> - reorganize the ccm list to mirror the format of lsc
> - add offset vectors
> ---
>   .../tuning/libtuning/modules/ccm/__init__.py  |  6 ++
>   utils/tuning/libtuning/modules/ccm/ccm.py     | 22 +++++
>   utils/tuning/libtuning/modules/ccm/rkisp1.py  | 89 +++++++++++++++++++
>   3 files changed, 117 insertions(+)
>   create mode 100644 utils/tuning/libtuning/modules/ccm/__init__.py
>   create mode 100644 utils/tuning/libtuning/modules/ccm/ccm.py
>   create mode 100644 utils/tuning/libtuning/modules/ccm/rkisp1.py
>
> diff --git a/utils/tuning/libtuning/modules/ccm/__init__.py b/utils/tuning/libtuning/modules/ccm/__init__.py
> new file mode 100644
> index 000000000..322602afe
> --- /dev/null
> +++ b/utils/tuning/libtuning/modules/ccm/__init__.py
> @@ -0,0 +1,6 @@
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +#
> +# Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>
> +
> +from libtuning.modules.ccm.ccm import CCM
> +from libtuning.modules.ccm.rkisp1 import CCMRkISP1
> diff --git a/utils/tuning/libtuning/modules/ccm/ccm.py b/utils/tuning/libtuning/modules/ccm/ccm.py
> new file mode 100644
> index 000000000..7ddf0a8ca
> --- /dev/null
> +++ b/utils/tuning/libtuning/modules/ccm/ccm.py
> @@ -0,0 +1,22 @@
> +# SPDX-License-Identifier: BSD-2-Clause
> +#
> +# Copyright (C) 2019, Raspberry Pi Ltd
> +# Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>
> +
> +from ..module import Module
> +
> +import libtuning as lt
> +import libtuning.utils as utils
> +
> +import numpy as np
> +
> +class CCM(Module):
> +    type = 'ccm'
> +    hr_name = 'CCM (Base)'
> +    out_name = 'GenericCCM'
> +
> +    def __init__(self, *,
> +                 debug: list):
> +        super().__init__()
> +
> +        self.debug = debug
> diff --git a/utils/tuning/libtuning/modules/ccm/rkisp1.py b/utils/tuning/libtuning/modules/ccm/rkisp1.py
> new file mode 100644
> index 000000000..acae0a9b0
> --- /dev/null
> +++ b/utils/tuning/libtuning/modules/ccm/rkisp1.py
> @@ -0,0 +1,89 @@
> +# SPDX-License-Identifier: BSD-2-Clause
> +#
> +# Copyright (C) 2019, Raspberry Pi Ltd
> +# Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>
> +#
> +# rkisp1.py - Ccm module for tuning rkisp1
> +
> +from .ccm import CCM
> +
> +import libtuning as lt
> +import libtuning.utils as utils
> +
> +from numbers import Number
> +import numpy as np
> +
> +
> +class CCMRkISP1(CCM):
> +    hr_name = 'Crosstalk Correction (RkISP1)'
> +    out_name = 'Ccm'
> +    # \todo Not sure if this is useful. Probably will remove later.
> +    compatible = ['rkisp1']

Let's drop it now :)


Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>

> +
> +    def __init__(self, **kwargs):
> +        super().__init__(**kwargs)
> +
> +    # We don't actually need anything from the config file
> +    def validate_config(self, config: dict) -> bool:
> +        return True
> +
> +    def _generate_ccms(self) -> dict:
> +        ccms = [
> +                {
> +                    'ct': 2860,
> +                    'ccm': [ 2.12089, -0.52461, -0.59629,
> +                            -0.85342,  2.80445, -0.95103,
> +                            -0.26897, -1.14788,  2.41685 ],
> +                    'offsets': [ 0, 0, 0 ]
> +                },
> +
> +                {
> +                    'ct': 2960,
> +                    'ccm': [ 2.26962, -0.54174, -0.72789,
> +                            -0.77008,  2.60271, -0.83262,
> +                            -0.26036, -1.51254,  2.77289 ],
> +                    'offsets': [ 0, 0, 0 ]
> +                },
> +
> +                {
> +                    'ct': 3603,
> +                    'ccm': [ 2.18644, -0.66148, -0.52496,
> +                            -0.77828,  2.69474, -0.91645,
> +                            -0.25239, -0.83059,  2.08298 ],
> +                    'offsets': [ 0, 0, 0 ]
> +                },
> +
> +                {
> +                    'ct': 4650,
> +                    'ccm': [ 2.18174, -0.70887, -0.47287,
> +                            -0.70196,  2.76426, -1.06231,
> +                            -0.25157, -0.71978,  1.97135 ],
> +                    'offsets': [ 0, 0, 0 ]
> +                },
> +
> +                {
> +                    'ct': 5858,
> +                    'ccm': [ 2.32392, -0.88421, -0.43971,
> +                            -0.63821,  2.58348, -0.94527,
> +                            -0.28541, -0.54112,  1.82653 ],
> +                    'offsets': [ 0, 0, 0 ]
> +                },
> +
> +                {
> +                    'ct': 7580,
> +                    'ccm': [ 2.21175, -0.53242, -0.67933,
> +                            -0.57875,  3.07922, -1.50047,
> +                            -0.27709, -0.73338,  2.01048 ],
> +                    'offsets': [ 0, 0, 0 ]
> +                },
> +        ]
> +
> +        return ccms
> +
> +    def process(self, config: dict, images: list, outputs: dict) -> dict:
> +        output = {}
> +
> +        output['ccms'] = self._generate_ccms()
> +        # \todo Debug functionality
> +
> +        return output

Patch
diff mbox series

diff --git a/utils/tuning/libtuning/modules/ccm/__init__.py b/utils/tuning/libtuning/modules/ccm/__init__.py
new file mode 100644
index 000000000..322602afe
--- /dev/null
+++ b/utils/tuning/libtuning/modules/ccm/__init__.py
@@ -0,0 +1,6 @@ 
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>
+
+from libtuning.modules.ccm.ccm import CCM
+from libtuning.modules.ccm.rkisp1 import CCMRkISP1
diff --git a/utils/tuning/libtuning/modules/ccm/ccm.py b/utils/tuning/libtuning/modules/ccm/ccm.py
new file mode 100644
index 000000000..7ddf0a8ca
--- /dev/null
+++ b/utils/tuning/libtuning/modules/ccm/ccm.py
@@ -0,0 +1,22 @@ 
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (C) 2019, Raspberry Pi Ltd
+# Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>
+
+from ..module import Module
+
+import libtuning as lt
+import libtuning.utils as utils
+
+import numpy as np
+
+class CCM(Module):
+    type = 'ccm'
+    hr_name = 'CCM (Base)'
+    out_name = 'GenericCCM'
+
+    def __init__(self, *,
+                 debug: list):
+        super().__init__()
+
+        self.debug = debug
diff --git a/utils/tuning/libtuning/modules/ccm/rkisp1.py b/utils/tuning/libtuning/modules/ccm/rkisp1.py
new file mode 100644
index 000000000..acae0a9b0
--- /dev/null
+++ b/utils/tuning/libtuning/modules/ccm/rkisp1.py
@@ -0,0 +1,89 @@ 
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (C) 2019, Raspberry Pi Ltd
+# Copyright (C) 2024, Paul Elder <paul.elder@ideasonboard.com>
+#
+# rkisp1.py - Ccm module for tuning rkisp1
+
+from .ccm import CCM
+
+import libtuning as lt
+import libtuning.utils as utils
+
+from numbers import Number
+import numpy as np
+
+
+class CCMRkISP1(CCM):
+    hr_name = 'Crosstalk Correction (RkISP1)'
+    out_name = 'Ccm'
+    # \todo Not sure if this is useful. Probably will remove later.
+    compatible = ['rkisp1']
+
+    def __init__(self, **kwargs):
+        super().__init__(**kwargs)
+
+    # We don't actually need anything from the config file
+    def validate_config(self, config: dict) -> bool:
+        return True
+
+    def _generate_ccms(self) -> dict:
+        ccms = [
+                {
+                    'ct': 2860,
+                    'ccm': [ 2.12089, -0.52461, -0.59629,
+                            -0.85342,  2.80445, -0.95103,
+                            -0.26897, -1.14788,  2.41685 ],
+                    'offsets': [ 0, 0, 0 ]
+                },
+
+                {
+                    'ct': 2960,
+                    'ccm': [ 2.26962, -0.54174, -0.72789,
+                            -0.77008,  2.60271, -0.83262,
+                            -0.26036, -1.51254,  2.77289 ],
+                    'offsets': [ 0, 0, 0 ]
+                },
+
+                {
+                    'ct': 3603,
+                    'ccm': [ 2.18644, -0.66148, -0.52496,
+                            -0.77828,  2.69474, -0.91645,
+                            -0.25239, -0.83059,  2.08298 ],
+                    'offsets': [ 0, 0, 0 ]
+                },
+
+                {
+                    'ct': 4650,
+                    'ccm': [ 2.18174, -0.70887, -0.47287,
+                            -0.70196,  2.76426, -1.06231,
+                            -0.25157, -0.71978,  1.97135 ],
+                    'offsets': [ 0, 0, 0 ]
+                },
+
+                {
+                    'ct': 5858,
+                    'ccm': [ 2.32392, -0.88421, -0.43971,
+                            -0.63821,  2.58348, -0.94527,
+                            -0.28541, -0.54112,  1.82653 ],
+                    'offsets': [ 0, 0, 0 ]
+                },
+
+                {
+                    'ct': 7580,
+                    'ccm': [ 2.21175, -0.53242, -0.67933,
+                            -0.57875,  3.07922, -1.50047,
+                            -0.27709, -0.73338,  2.01048 ],
+                    'offsets': [ 0, 0, 0 ]
+                },
+        ]
+
+        return ccms
+
+    def process(self, config: dict, images: list, outputs: dict) -> dict:
+        output = {}
+
+        output['ccms'] = self._generate_ccms()
+        # \todo Debug functionality
+
+        return output