utils: rkisp1: gen-csc-table: Support printing CCM in decimal
diff mbox series

Message ID 20250405025122.6960-1-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • utils: rkisp1: gen-csc-table: Support printing CCM in decimal
Related show

Commit Message

Laurent Pinchart April 5, 2025, 2:51 a.m. UTC
Add an option to the gen-csc-table.py script to output the CCM matrix in
decimal format instead of hexadecimal. This makes no functional
difference, but is useful to adapt to different coding styles.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 utils/rkisp1/gen-csc-table.py | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)


base-commit: a2a7f4fc2d2a3fa7e5cb1b7d35b369d64f86c2ab
--
Regards,

Laurent Pinchart

Comments

Kieran Bingham April 17, 2025, 11:03 a.m. UTC | #1
Quoting Laurent Pinchart (2025-04-05 03:51:22)
> Add an option to the gen-csc-table.py script to output the CCM matrix in
> decimal format instead of hexadecimal. This makes no functional
> difference, but is useful to adapt to different coding styles.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

I wonder if anyone expect you uses/would use this ;-)


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

> ---
>  utils/rkisp1/gen-csc-table.py | 24 ++++++++++++++++++------
>  1 file changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/utils/rkisp1/gen-csc-table.py b/utils/rkisp1/gen-csc-table.py
> index ffc0370acaeb..2db84feb5cd0 100755
> --- a/utils/rkisp1/gen-csc-table.py
> +++ b/utils/rkisp1/gen-csc-table.py
> @@ -147,6 +147,8 @@ def main(argv):
>          description='Generate color space conversion table coefficients with '
>          'configurable fixed-point precision.'
>      )
> +    parser.add_argument('--format', '-f', choices=['dec', 'hex'], default='hex',
> +                        help='Number format')
>      parser.add_argument('--invert', '-i', action='store_true',
>                          help='Invert the color space conversion (YUV -> RGB)')
>      parser.add_argument('--precision', '-p', default='Q1.7',
> @@ -190,19 +192,29 @@ def main(argv):
>          else:
>              line = round_array(line)
> 
> -        # Convert coefficients to the number of bits selected by the precision.
> -        # Negative values will be turned into positive integers using 2's
> -        # complement.
> -        line = [coeff & ((1 << precision.total) - 1) for coeff in line]
> +        if args.format == 'hex':
> +            # Convert coefficients to the number of bits selected by the precision.
> +            # Negative values will be turned into positive integers using 2's
> +            # complement.
> +            line = [coeff & ((1 << precision.total) - 1) for coeff in line]
> +
>          rounded_coeffs.append(line)
> 
>      # Print the result as C code.
>      nbits = 1 << (precision.total - 1).bit_length()
>      nbytes = nbits // 4
> -    print(f'static const u{nbits} {"yuv2rgb" if args.invert else "rgb2yuv"}_{args.encoding}_{quantization.name.lower()}_coeffs[] = {{')
> +
> +    if args.format == 'hex':
> +        coeff_fmt = '0x{0:0' + str(nbytes) + 'x}'
> +        sign = 'u'
> +    else:
> +        coeff_fmt = '{0}'
> +        sign = 's'
> +
> +    print(f'static const {sign}{nbits} {"yuv2rgb" if args.invert else "rgb2yuv"}_{args.encoding}_{quantization.name.lower()}_coeffs[] = {{')
> 
>      for line in rounded_coeffs:
> -        line = [f'0x{coeff:0{nbytes}x}' for coeff in line]
> +        line = [coeff_fmt.format(coeff) for coeff in line]
> 
>          print(f'\t{", ".join(line)},')
> 
> 
> base-commit: a2a7f4fc2d2a3fa7e5cb1b7d35b369d64f86c2ab
> --
> Regards,
> 
> Laurent Pinchart
>

Patch
diff mbox series

diff --git a/utils/rkisp1/gen-csc-table.py b/utils/rkisp1/gen-csc-table.py
index ffc0370acaeb..2db84feb5cd0 100755
--- a/utils/rkisp1/gen-csc-table.py
+++ b/utils/rkisp1/gen-csc-table.py
@@ -147,6 +147,8 @@  def main(argv):
         description='Generate color space conversion table coefficients with '
         'configurable fixed-point precision.'
     )
+    parser.add_argument('--format', '-f', choices=['dec', 'hex'], default='hex',
+                        help='Number format')
     parser.add_argument('--invert', '-i', action='store_true',
                         help='Invert the color space conversion (YUV -> RGB)')
     parser.add_argument('--precision', '-p', default='Q1.7',
@@ -190,19 +192,29 @@  def main(argv):
         else:
             line = round_array(line)

-        # Convert coefficients to the number of bits selected by the precision.
-        # Negative values will be turned into positive integers using 2's
-        # complement.
-        line = [coeff & ((1 << precision.total) - 1) for coeff in line]
+        if args.format == 'hex':
+            # Convert coefficients to the number of bits selected by the precision.
+            # Negative values will be turned into positive integers using 2's
+            # complement.
+            line = [coeff & ((1 << precision.total) - 1) for coeff in line]
+
         rounded_coeffs.append(line)

     # Print the result as C code.
     nbits = 1 << (precision.total - 1).bit_length()
     nbytes = nbits // 4
-    print(f'static const u{nbits} {"yuv2rgb" if args.invert else "rgb2yuv"}_{args.encoding}_{quantization.name.lower()}_coeffs[] = {{')
+
+    if args.format == 'hex':
+        coeff_fmt = '0x{0:0' + str(nbytes) + 'x}'
+        sign = 'u'
+    else:
+        coeff_fmt = '{0}'
+        sign = 's'
+
+    print(f'static const {sign}{nbits} {"yuv2rgb" if args.invert else "rgb2yuv"}_{args.encoding}_{quantization.name.lower()}_coeffs[] = {{')

     for line in rounded_coeffs:
-        line = [f'0x{coeff:0{nbytes}x}' for coeff in line]
+        line = [coeff_fmt.format(coeff) for coeff in line]

         print(f'\t{", ".join(line)},')