[{"id":33951,"web_url":"https://patchwork.libcamera.org/comment/33951/","msgid":"<20250414182057.GA22753@pendragon.ideasonboard.com>","date":"2025-04-14T18:20:57","subject":"Re: [PATCH] libcamera: software_isp: Fix CCM multiplication","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Milan,\n\nThank you for the patch.\n\nOn Mon, Apr 14, 2025 at 07:32:44PM +0200, Milan Zamazal wrote:\n> A colour correction matrix (CCM) is applied like this to an RGB pixel\n> vector P:\n> \n>   CCM * P\n> \n> White balance must be applied before CCM.  If CCM is used, software ISP\n> makes a combined matrix by multiplying the CCM by a white balance gains\n> CCM-like matrix (WBG).  The multiplication should be as follows to do it\n> in the correct order:\n> \n>   CCM * (WBG * P) = (CCM * WBG) * P\n> \n> The multiplication order in Lut software ISP algorithm is reversed,\n> resulting in colour casts.  Let's fix the order.\n\nFixes: e2b4000dc9cc (\"libcamera: software_isp: Apply CCM in debayering\")\n\n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n>  src/ipa/simple/algorithms/lut.cpp | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp\n> index e8638f27..d1d5f727 100644\n> --- a/src/ipa/simple/algorithms/lut.cpp\n> +++ b/src/ipa/simple/algorithms/lut.cpp\n> @@ -122,7 +122,7 @@ void Lut::prepare(IPAContext &context,\n>  \t\tMatrix<float, 3, 3> gainCcm = { { gains.r(), 0, 0,\n>  \t\t\t\t\t\t  0, gains.g(), 0,\n>  \t\t\t\t\t\t  0, 0, gains.b() } };\n> -\t\tauto ccm = gainCcm * context.activeState.ccm.ccm;\n> +\t\tauto ccm = context.activeState.ccm.ccm * gainCcm;\n>  \t\tauto &red = params->redCcm;\n>  \t\tauto &green = params->greenCcm;\n>  \t\tauto &blue = params->blueCcm;","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 E5997C327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 14 Apr 2025 18:21:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3AB5F68AB9;\n\tMon, 14 Apr 2025 20:21:00 +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 3555D627F2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 14 Apr 2025 20:20:59 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4065D4CE;\n\tMon, 14 Apr 2025 20:18:57 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"fiMUBqsm\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1744654737;\n\tbh=6gRP8KcaxDF2UlJyyitmzP86grSo/B+JmSrhfOiI0Yg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=fiMUBqsmw1BWn37RirywRtqbPg0nV2pm7sfbV9zdtyJAdVkc5EM/+kbl6oYI2yIk0\n\thyrumAMgCWB/nCHrzYwICXy4BX76wMceEHui/xEo7k1KPNRbS0K/gJV63SIiHDjIWv\n\t/sk/6inLH5dQf2FgH2EzmmTo1WQSXmz4j7iWhIdU=","Date":"Mon, 14 Apr 2025 21:20:57 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org,\n\tKieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"Re: [PATCH] libcamera: software_isp: Fix CCM multiplication","Message-ID":"<20250414182057.GA22753@pendragon.ideasonboard.com>","References":"<20250414173244.118560-1-mzamazal@redhat.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250414173244.118560-1-mzamazal@redhat.com>","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>"}},{"id":33952,"web_url":"https://patchwork.libcamera.org/comment/33952/","msgid":"<174473917157.3572835.3958146161928851947@ping.linuxembedded.co.uk>","date":"2025-04-15T17:46:11","subject":"Re: [PATCH] libcamera: software_isp: Fix CCM multiplication","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart (2025-04-14 19:20:57)\n> Hi Milan,\n> \n> Thank you for the patch.\n> \n> On Mon, Apr 14, 2025 at 07:32:44PM +0200, Milan Zamazal wrote:\n> > A colour correction matrix (CCM) is applied like this to an RGB pixel\n> > vector P:\n> > \n> >   CCM * P\n> > \n> > White balance must be applied before CCM.  If CCM is used, software ISP\n> > makes a combined matrix by multiplying the CCM by a white balance gains\n> > CCM-like matrix (WBG).  The multiplication should be as follows to do it\n> > in the correct order:\n> > \n> >   CCM * (WBG * P) = (CCM * WBG) * P\n> > \n> > The multiplication order in Lut software ISP algorithm is reversed,\n> > resulting in colour casts.  Let's fix the order.\n> \n> Fixes: e2b4000dc9cc (\"libcamera: software_isp: Apply CCM in debayering\")\n> \n> > Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nThis looks great to me. Fixes the issue I reported with testing the\nSaturation control which now gives clear greyscale values on 0.0\nsaturation.\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nTested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n> > ---\n> >  src/ipa/simple/algorithms/lut.cpp | 2 +-\n> >  1 file changed, 1 insertion(+), 1 deletion(-)\n> > \n> > diff --git a/src/ipa/simple/algorithms/lut.cpp b/src/ipa/simple/algorithms/lut.cpp\n> > index e8638f27..d1d5f727 100644\n> > --- a/src/ipa/simple/algorithms/lut.cpp\n> > +++ b/src/ipa/simple/algorithms/lut.cpp\n> > @@ -122,7 +122,7 @@ void Lut::prepare(IPAContext &context,\n> >               Matrix<float, 3, 3> gainCcm = { { gains.r(), 0, 0,\n> >                                                 0, gains.g(), 0,\n> >                                                 0, 0, gains.b() } };\n> > -             auto ccm = gainCcm * context.activeState.ccm.ccm;\n> > +             auto ccm = context.activeState.ccm.ccm * gainCcm;\n> >               auto &red = params->redCcm;\n> >               auto &green = params->greenCcm;\n> >               auto &blue = params->blueCcm;\n> \n> -- \n> Regards,\n> \n> Laurent Pinchart","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 BB99CC327D\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 15 Apr 2025 17:46:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BD0E968AB9;\n\tTue, 15 Apr 2025 19:46:15 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 572D4627EF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Apr 2025 19:46:14 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id CDFC1725;\n\tTue, 15 Apr 2025 19:44:11 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"iLRjqQLb\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1744739051;\n\tbh=rp2/8W6fUgcd9Rcd0/B4y6TVz0ImhAMgf/D/adINO48=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=iLRjqQLbsKCq0sRCCrOoapNiaod/ohg35l9gjOxPKuVehk8VIQcpB3ip18hoo3JWd\n\tEjy7VUf61wJt4Nl3Pz4g7k2+w9ukjP/iPgg99w1tA2X0SOjzEJwf8wpfb4saJhuwwM\n\tYZoYgUZ2We+kuDxTM+JuqirtAwPcSdCmp7462pRQ=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250414182057.GA22753@pendragon.ideasonboard.com>","References":"<20250414173244.118560-1-mzamazal@redhat.com>\n\t<20250414182057.GA22753@pendragon.ideasonboard.com>","Subject":"Re: [PATCH] libcamera: software_isp: Fix CCM multiplication","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tMilan Zamazal <mzamazal@redhat.com>","Date":"Tue, 15 Apr 2025 18:46:11 +0100","Message-ID":"<174473917157.3572835.3958146161928851947@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","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>"}}]