[libcamera-devel,7/7,DNI] utils: tuning: Add tuning script for rkisp1
diff mbox series

Message ID 20221006120105.3861831-8-paul.elder@ideasonboard.com
State Superseded
Headers show
Series
  • utils: tuning: Add a new tuning infrastructure
Related show

Commit Message

Paul Elder Oct. 6, 2022, 12:01 p.m. UTC
Add a tuning script for rkisp1 that uses libtuning.

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

---
This won't run as we're missing the necessary parser and generator for
yaml, parabolic gradient support, and multiple green support in the ALSC
module, hence the DNI. As soon as those are added though, this *should*
work.
---
 utils/tuning/rkisp1.py | 69 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 utils/tuning/rkisp1.py

Patch
diff mbox series

diff --git a/utils/tuning/rkisp1.py b/utils/tuning/rkisp1.py
new file mode 100644
index 00000000..6ccd8ceb
--- /dev/null
+++ b/utils/tuning/rkisp1.py
@@ -0,0 +1,69 @@ 
+#!/usr/bin/env python3
+
+import sys
+
+import libtuning as lt
+from libtuning.modules import ALSC
+from libtuning.parsers import YamlParser
+from libtuning.generators import YamlOutput
+
+tuner = lt.Camera('RkISP1')
+tuner.add(ALSC(do_color=lt.param('do_alsc_colour', lt.param.mode.Optional, True),
+
+               # This can support other debug options (I can't think of any rn
+               # but for future-proofing)
+               debug=[lt.debug.Plot],
+
+               # The name of IfUnSet can obviously be changed, but really I
+               # just want something that says "it must be specified in the
+               # configuration, and get the value from there" or "if the value
+               # is not in the configuration, use this"
+               luminance_strength=lt.param('luminance_strength', lt.param.mode.Optional, 0.5),
+
+               sector_shape=(16, 16),
+
+               # Other functions might include Circular, Hyperbolic, Gaussian,
+               # Linear, Exponential, Logarithmic, etc
+               # Of course, both need not be the same function
+               # Some functions would need a sector_x_parameter (eg. sigma for Gaussian)
+               # Alternatively: sector_x_sizes = [] ? I don't think it would work tho
+               sector_x_gradient=lt.gradient.Parabolic,
+               sector_y_gradient=lt.gradient.Parabolic,
+
+               # This is the function that will be used to average the pixels in each sector
+               # This can also be a custom function.
+               sector_average_function=lt.average_functions.Mean,
+
+               # This is the function that will be used to smooth the color ratio values
+               # This can also be a custom function.
+               smoothing_function=lt.smoothing.MedianBlur,
+               smoothing_parameters=[3],
+
+               # Are there any platforms that use integer values for their lsc table?
+               output_type=lt.type.Float,
+
+               # Required if and only if do_color can be or is True
+               output_color_channels=[lt.color.R, lt.color.GR, lt.color.GB, lt.color.B],
+
+               # Required if and only if do_color can be or is False
+               output_luminance_channels=[lt.color.GR, lt.color.GB],
+
+               # Automatically get the precision from this
+               output_range=(0, 3.999)
+
+               # Do we need a flag to enable/disable calculating sigmas? afaik
+               # the rkisp1 IPA doesn't use it? But we could output it anyway
+               # and algorithms can decide whether or not if they want to use
+               # it. Oh well, no flag for now, we can always add it later if
+               # there's a big demand, plus it's only two to three values and
+               # not an entire table.
+               ))
+tuner.setInputType(YamlParser)
+tuner.setOutputType(YamlOutput)
+tuner.setOutputOrder([ALSC])
+
+# Maybe this should be wrapped in an if __main__ = '__main__' ? That way the
+# developer can control which tuner they want to be executed based on another
+# layer of arguments? But I was thinking that this would handle *all* arguments
+# based on the modules' and the input/output configurations.
+tuner.run(sys.argv)