[{"id":32266,"web_url":"https://patchwork.libcamera.org/comment/32266/","msgid":"<874j43h5o1.fsf@redhat.com>","date":"2024-11-19T10:35:58","subject":"Re: [PATCH v3 14/17] ipa: libipa: colour: Use Vector and Matrix for\n\tlinear algebra","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Laurent Pinchart <laurent.pinchart@ideasonboard.com> writes:\n\n> Replace the manual vector and matrix calculations with usage of the\n> Vector and Matrix classes. This simplifies the code and improves\n> readability.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\n\n> ---\n>  src/ipa/libipa/colours.cpp | 26 +++++++++++++++++---------\n>  1 file changed, 17 insertions(+), 9 deletions(-)\n>\n> diff --git a/src/ipa/libipa/colours.cpp b/src/ipa/libipa/colours.cpp\n> index 6c597093ddf8..97124cf460d4 100644\n> --- a/src/ipa/libipa/colours.cpp\n> +++ b/src/ipa/libipa/colours.cpp\n> @@ -31,7 +31,11 @@ namespace ipa {\n>   */\n>  double rec601LuminanceFromRGB(const RGB<double> &rgb)\n>  {\n> -\treturn (rgb.r() * .299) + (rgb.g() * .587) + (rgb.b() * .114);\n> +\tstatic const Vector<double, 3> rgb2y{{\n> +\t\t0.299, 0.587, 0.114\n> +\t}};\n> +\n> +\treturn rgb.dot(rgb2y);\n>  }\n>  \n>  /**\n> @@ -54,17 +58,21 @@ double rec601LuminanceFromRGB(const RGB<double> &rgb)\n>   */\n>  uint32_t estimateCCT(const RGB<double> &rgb)\n>  {\n> -\t/* Convert the RGB values to CIE tristimulus values (XYZ) */\n> -\tdouble X = (-0.14282) * rgb.r() + (1.54924) * rgb.g() + (-0.95641) * rgb.b();\n> -\tdouble Y = (-0.32466) * rgb.r() + (1.57837) * rgb.g() + (-0.73191) * rgb.b();\n> -\tdouble Z = (-0.68202) * rgb.r() + (0.77073) * rgb.g() + (0.56332) * rgb.b();\n> +\t/*\n> +\t * Convert the RGB values to CIE tristimulus values (XYZ) and divide by\n> +\t * the sum of X, Y and Z to calculate the CIE xy chromaticity.\n> +\t */\n> +\tstatic const Matrix<double, 3, 3> rgb2xyz({\n> +\t\t-0.14282, 1.54924, -0.95641,\n> +\t\t-0.32466, 1.57837, -0.73191,\n> +\t\t-0.68202, 0.77073,  0.56332\n> +\t});\n>  \n> -\t/* Calculate the normalized chromaticity values */\n> -\tdouble x = X / (X + Y + Z);\n> -\tdouble y = Y / (X + Y + Z);\n> +\tVector<double, 3> xyz = rgb2xyz * rgb;\n> +\txyz /= xyz.sum();\n>  \n>  \t/* Calculate CCT */\n> -\tdouble n = (x - 0.3320) / (0.1858 - y);\n> +\tdouble n = (xyz.x() - 0.3320) / (0.1858 - xyz.y());\n>  \treturn 449 * n * n * n + 3525 * n * n + 6823.3 * n + 5520.33;\n>  }","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 22D69C32F1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 19 Nov 2024 10:36:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5BA9A65EF0;\n\tTue, 19 Nov 2024 11:36:07 +0100 (CET)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id A9C4A65EEB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 11:36:05 +0100 (CET)","from mail-ej1-f69.google.com (mail-ej1-f69.google.com\n\t[209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-618-PkSENoy6NcSqEc35zTd8yw-1; Tue, 19 Nov 2024 05:36:03 -0500","by mail-ej1-f69.google.com with SMTP id\n\ta640c23a62f3a-a9a1b872d8bso187584066b.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 19 Nov 2024 02:36:02 -0800 (PST)","from nuthatch ([2a00:102a:400a:489a:34bf:5bf1:e776:7185])\n\tby smtp.gmail.com with ESMTPSA id\n\ta640c23a62f3a-aa20e0869cdsm638274966b.192.2024.11.19.02.36.00\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 19 Nov 2024 02:36:00 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"VMhmRY0h\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1732012564;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=Mq+s/TgXO/qk0t9df+hgQAQLwa9IPKYU+Y4GYNBQvCc=;\n\tb=VMhmRY0hL/ST53AfU5owjrwDzMIwfRbW2nskvu53jI3dVk9x6S4HV8GauwOqLx/ofvuVO+\n\tjX/g45XGrbSjPo/uf2qsIVHEVlDXwzZQLMwQN4q1/gDqx+XV+zaPkxHajlDet22cPHl7xx\n\t48nOW7/eQzyE6ER2Gc6o5YWvaRrHjCM=","X-MC-Unique":"PkSENoy6NcSqEc35zTd8yw-1","X-Mimecast-MFC-AGG-ID":"PkSENoy6NcSqEc35zTd8yw","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1732012561; x=1732617361;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=Mq+s/TgXO/qk0t9df+hgQAQLwa9IPKYU+Y4GYNBQvCc=;\n\tb=SpFpphNtjRIcBaQ6/+R2bJz9qI8fDwONm0/8JvSiRQRdLV0tId/eKF0TQn4hSMmbcK\n\tc5MnlUjFnPPubt0xhFikml0mbffUFZNSFmhH7RJoqIj06Eq4jr4S5G5dZBRQD4HbDNsK\n\t+jh488HbB2Ne0EsIie+AY6I7MVvSLnBOLbH9kZIEpzRCYClIg9WdbgapjC+Rf+sQntUx\n\tzU1hcYKWpixkEbid5xwK/IUTA2x3J7bZhpiuI5qN12gywlYN1OLKRv54huiaa11XQi9b\n\tFszugTKZ86xyLJknlW1HqU5jMc10SYI8dkHIiy6Cdy3APD+dPxU83nDe68wFV0S8ySaz\n\tYwPg==","X-Gm-Message-State":"AOJu0YysShEEuurCJaydWsuTVAlUCJhlEBDlIK+TnXk05zg00Z4EAsqW\n\tUcz/d+WTc6TauN5oZVynebEHIWFS80ydxwdvXnR2nRotDaQCXFV9XT9cQH4dfuaRTBfnxCx5oSx\n\tGAthz13/BgEHHCUM7SyNdismUml9WjMRhBC32MFBvnlinf9Pqvbw6X4VwMsbDcZakIuRd76gwKe\n\tlsclW3LmFJDACDIKfNAyhiFeaU0FtMM7W0i2eCmIH818OtNzfwYXREP6k=","X-Received":["by 2002:a17:907:2d90:b0:aa3:5ca5:2ca4 with SMTP id\n\ta640c23a62f3a-aa483441d9cmr1526577266b.25.1732012561442; \n\tTue, 19 Nov 2024 02:36:01 -0800 (PST)","by 2002:a17:907:2d90:b0:aa3:5ca5:2ca4 with SMTP id\n\ta640c23a62f3a-aa483441d9cmr1526575266b.25.1732012561081; \n\tTue, 19 Nov 2024 02:36:01 -0800 (PST)"],"X-Google-Smtp-Source":"AGHT+IF1/LImV7D8i6znnDwDJ7dy5YIBwdrUORHoxtLRLlwVHsA+Qn4sAe/70mfnK2ZvTEB0kaB9Fw==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v3 14/17] ipa: libipa: colour: Use Vector and Matrix for\n\tlinear algebra","In-Reply-To":"<20241118221618.13953-15-laurent.pinchart@ideasonboard.com>\n\t(Laurent Pinchart's message of \"Tue, 19 Nov 2024 00:16:15 +0200\")","References":"<20241118221618.13953-1-laurent.pinchart@ideasonboard.com>\n\t<20241118221618.13953-15-laurent.pinchart@ideasonboard.com>","Date":"Tue, 19 Nov 2024 11:35:58 +0100","Message-ID":"<874j43h5o1.fsf@redhat.com>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"TU5WNVDcSMlZPxvn-F71S7EpxUHxf7QgOLEjgVCvbbk_1732012562","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]