{"id":17446,"url":"https://patchwork.libcamera.org/api/1.1/patches/17446/?format=json","web_url":"https://patchwork.libcamera.org/patch/17446/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20220927232707.7596-1-laurent.pinchart@ideasonboard.com>","date":"2022-09-27T23:27:07","name":"[libcamera-devel] utils: rkisp1: gen-csc-table: Add support for inverting the CSC","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"a57bb20931d4b7343610a06d544906a79798d1f2","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17446/mbox/","series":[{"id":3508,"url":"https://patchwork.libcamera.org/api/1.1/series/3508/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3508","date":"2022-09-27T23:27:07","name":"[libcamera-devel] utils: rkisp1: gen-csc-table: Add support for inverting the CSC","version":1,"mbox":"https://patchwork.libcamera.org/series/3508/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17446/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17446/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id E12DAC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 27 Sep 2022 23:27:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5063D62278;\n\tWed, 28 Sep 2022 01:27:11 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 36D2E61F78\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Sep 2022 01:27:09 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B549447C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Sep 2022 01:27:08 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1664321231;\n\tbh=R5bt5TXxHrzzh1Qg+LdKepAPSBvgqbe2AZ1TEbyWkgY=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=pMO9pbXv9PojHxBSreBCyVSToaTDrO83f8H6oI+BlulpzfttefF7od+Xy4aErxCT+\n\tx3asEYiwq+Hk7YxU2xdkU6u7gLUNqOyvSrEDaGuKlUVyZgJN1jamP9TyRBvv+zWcFq\n\tkR9ATUp9k/ZxEUOCQUgeAHIvFRP7NpkRODnZqiognK4S04PnM76C5kq0sDwaOOA+2E\n\tYIpNE5Yz0yf4Txj5EZRnQV+OqPbQ8MJE3SI+4R2MpCrVg0Pzp1NvVrW8dcPY7iTbIh\n\tmPdjfN9b8BbnbXRY/+y44nvmNi9JFAYr6JSI1FSbCilaZ3VEovGpAT9LeRpm6uoyeN\n\tAO9f9kPWknD8w==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1664321228;\n\tbh=R5bt5TXxHrzzh1Qg+LdKepAPSBvgqbe2AZ1TEbyWkgY=;\n\th=From:To:Subject:Date:From;\n\tb=EdBriv0vcoaoNXHSOpHfYTsWdTEoSxXRixOXaX2yKdLIDtBrta1QZJFxHzKP0eSWD\n\tdINhXwnRgD4drcwo2v286+uREfqhWk9Tb/Vyb/H3oCvjQPdlG/wmZh7xFwrOi/jAC2\n\tsCVWdoiB3hSO4XyTF5q+nVXKOevZxzvwuFvjKGyU="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"EdBriv0v\"; dkim-atps=neutral","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 28 Sep 2022 02:27:07 +0300","Message-Id":"<20220927232707.7596-1-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.35.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH] utils: rkisp1: gen-csc-table: Add support\n\tfor inverting the CSC","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Add a -i/--invert command line argument to invert the YCbCr encoding and\noutput a YCbCr to RGB matrix.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n utils/rkisp1/gen-csc-table.py | 15 ++++++++++++---\n 1 file changed, 12 insertions(+), 3 deletions(-)","diff":"diff --git a/utils/rkisp1/gen-csc-table.py b/utils/rkisp1/gen-csc-table.py\nindex 2fb702746421..83aea357966a 100755\n--- a/utils/rkisp1/gen-csc-table.py\n+++ b/utils/rkisp1/gen-csc-table.py\n@@ -7,6 +7,7 @@\n \n import argparse\n import enum\n+import numpy as np\n import sys\n \n \n@@ -63,7 +64,7 @@ class Quantization(enum.Enum):\n     LIMITED = 1\n \n \n-def scale_coeff(coeff, quantization, luma, precision):\n+def scale_coeff(coeff, quantization, luma, precision, invert):\n     \"\"\"Scale a coefficient to the output range dictated by the quantization and\n     the precision.\n \n@@ -91,6 +92,9 @@ def scale_coeff(coeff, quantization, luma, precision):\n     else:\n         out_range = 240 - 16\n \n+    if invert:\n+        in_range, out_range = out_range, in_range\n+\n     return coeff * out_range / in_range * (1 << precision)\n \n \n@@ -150,6 +154,8 @@ def main(argv):\n         description='Generate color space conversion table coefficients with '\n         'configurable fixed-point precision.'\n     )\n+    parser.add_argument('--invert', '-i', action='store_true',\n+                        help='Invert the color space conversion (YUV -> RGB)')\n     parser.add_argument('--precision', '-p', default='Q1.7',\n                         help='The output fixed point precision in Q notation (sign bit excluded)')\n     parser.add_argument('--quantization', '-q', choices=['full', 'limited'],\n@@ -166,12 +172,15 @@ def main(argv):\n     encoding = encodings[args.encoding]\n     quantization = Quantization[args.quantization.upper()]\n \n+    if args.invert:\n+        encoding = np.linalg.inv(encoding)\n+\n     # Scale and round the encoding coefficients based on the precision and\n     # quantization range.\n     luma = True\n     scaled_coeffs = []\n     for line in encoding:\n-        line = [scale_coeff(coeff, quantization, luma, precision.fractional) for coeff in line]\n+        line = [scale_coeff(coeff, quantization, luma, precision.fractional, args.invert) for coeff in line]\n         scaled_coeffs.append(line)\n         luma = False\n \n@@ -188,7 +197,7 @@ def main(argv):\n     # Print the result as C code.\n     nbits = 1 << (precision.total - 1).bit_length()\n     nbytes = nbits // 4\n-    print(f'static const u{nbits} rgb2yuv_{args.encoding}_{quantization.name.lower()}_coeffs[] = {{')\n+    print(f'static const u{nbits} {\"yuv2rgb\" if args.invert else \"rgb2yuv\"}_{args.encoding}_{quantization.name.lower()}_coeffs[] = {{')\n \n     for line in rounded_coeffs:\n         line = [f'0x{coeff:0{nbytes}x}' for coeff in line]\n","prefixes":["libcamera-devel"]}