[{"id":15853,"web_url":"https://patchwork.libcamera.org/comment/15853/","msgid":"<462df1b3-83c6-7322-d56d-c31290ca6998@ideasonboard.com>","date":"2021-03-24T07:14:37","subject":"Re: [libcamera-devel] [PATCH 3/7] libcamera: ipu3: imgu: Fix BDS\n\theight calculation","submitter":{"id":75,"url":"https://patchwork.libcamera.org/api/people/75/","name":"Jean-Michel Hautbois","email":"jeanmichel.hautbois@ideasonboard.com"},"content":"Hi Jacopo,\n\nThanks for the patch,\n\nOn 18/03/2021 11:39, Jacopo Mondi wrote:\n> The IF rectangle height is iteratively computed by first subtracting\n> the scaling factor to the estimated height, then in a successive loop\n> by adding the same scaling factor until the maximum IF size is not\n> reached.\n> \n> As the computed IF height is not cached in any variable, the second\n> loop over-writes the result of the first one, even if the BDS alignment\n> condition is not satisfied.\n> \n> Fix this by caching the result of the two iterations, and use the one\n> that produced any result, with a preference for the one produced by the\n> second loop, as implemented in the reference python script.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\nTested-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\nReviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>\n> ---\n>  src/libcamera/pipeline/ipu3/imgu.cpp | 13 +++++++++----\n>  1 file changed, 9 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp\n> index d9296ea3e674..11bb7cb95084 100644\n> --- a/src/libcamera/pipeline/ipu3/imgu.cpp\n> +++ b/src/libcamera/pipeline/ipu3/imgu.cpp\n> @@ -129,10 +129,10 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n>  \tfloat bdsHeight;\n>  \n>  \tif (!isSameRatio(pipe->input, gdc)) {\n> +\t\tunsigned int foundIfHeights[2] = { 0, 0 };\n>  \t\tfloat estIFHeight = (iif.width * gdc.height) /\n>  \t\t\t\t    static_cast<float>(gdc.width);\n>  \t\testIFHeight = std::clamp<float>(estIFHeight, minIFHeight, iif.height);\n> -\t\tbool found = false;\n>  \n>  \t\tifHeight = utils::alignUp(estIFHeight, IF_ALIGN_H);\n>  \t\twhile (ifHeight >= minIFHeight && ifHeight / bdsSF >= minBDSHeight) {\n> @@ -142,7 +142,7 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n>  \t\t\t\tunsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);\n>  \n>  \t\t\t\tif (!(bdsIntHeight % BDS_ALIGN_H)) {\n> -\t\t\t\t\tfound = true;\n> +\t\t\t\t\tfoundIfHeights[0] = ifHeight;\n>  \t\t\t\t\tbreak;\n>  \t\t\t\t}\n>  \t\t\t}\n> @@ -158,7 +158,7 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n>  \t\t\t\tunsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);\n>  \n>  \t\t\t\tif (!(bdsIntHeight % BDS_ALIGN_H)) {\n> -\t\t\t\t\tfound = true;\n> +\t\t\t\t\tfoundIfHeights[1] = ifHeight;\n>  \t\t\t\t\tbreak;\n>  \t\t\t\t}\n>  \t\t\t}\n> @@ -166,7 +166,12 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n>  \t\t\tifHeight += IF_ALIGN_H;\n>  \t\t}\n>  \n> -\t\tif (found) {\n> +\t\tif (foundIfHeights[0])\n> +\t\t\tifHeight = foundIfHeights[0];\n> +\t\tif (foundIfHeights[1])\n> +\t\t\tifHeight = foundIfHeights[1];\n> +\n> +\t\tif (foundIfHeights[0] || foundIfHeights[1]) {\n>  \t\t\tunsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);\n>  \n>  \t\t\tpipeConfigs.push_back({ bdsSF, { iif.width, ifHeight },\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 BE7B5C32E7\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 24 Mar 2021 07:14:39 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7CC9468D63;\n\tWed, 24 Mar 2021 08:14:39 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3FF6A68D47\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Mar 2021 08:14:38 +0100 (CET)","from [IPv6:2a01:e0a:169:7140:21bd:98cc:c21e:1364] (unknown\n\t[IPv6:2a01:e0a:169:7140:21bd:98cc:c21e:1364])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E7F06883;\n\tWed, 24 Mar 2021 08:14:37 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"pWVfQLgT\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1616570078;\n\tbh=bVFT5Z5P0DFfOqXJQp36l0W5wyf01HOtIiUjvmlYXTg=;\n\th=Subject:To:References:From:Date:In-Reply-To:From;\n\tb=pWVfQLgTt47XIaLPcWW4lU4Ff4lksDX4Cmj8r7ZF3TsJFBT/UU8vdzXHyx3WOuYsS\n\tlH9EHmHrO6OxRKdXWzDqKBrJSdWg4rk1wP3yRYH+A8JQrZD5k8Z55y1HS/Iyi2c2Ta\n\ts1WVq2TjawqlD/+J6+SV5M0HO/HVFIACvZ0yg+sE=","To":"Jacopo Mondi <jacopo@jmondi.org>, libcamera-devel@lists.libcamera.org","References":"<20210318103941.18837-1-jacopo@jmondi.org>\n\t<20210318103941.18837-4-jacopo@jmondi.org>","From":"Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>","Message-ID":"<462df1b3-83c6-7322-d56d-c31290ca6998@ideasonboard.com>","Date":"Wed, 24 Mar 2021 08:14:37 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101\n\tThunderbird/78.7.1","MIME-Version":"1.0","In-Reply-To":"<20210318103941.18837-4-jacopo@jmondi.org>","Content-Language":"en-US","Subject":"Re: [libcamera-devel] [PATCH 3/7] libcamera: ipu3: imgu: Fix BDS\n\theight calculation","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":16196,"web_url":"https://patchwork.libcamera.org/comment/16196/","msgid":"<YHTjOprGyq+jZ3Uq@pendragon.ideasonboard.com>","date":"2021-04-13T00:18:02","subject":"Re: [libcamera-devel] [PATCH 3/7] libcamera: ipu3: imgu: Fix BDS\n\theight calculation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Thu, Mar 18, 2021 at 11:39:37AM +0100, Jacopo Mondi wrote:\n> The IF rectangle height is iteratively computed by first subtracting\n> the scaling factor to the estimated height, then in a successive loop\n> by adding the same scaling factor until the maximum IF size is not\n> reached.\n> \n> As the computed IF height is not cached in any variable, the second\n> loop over-writes the result of the first one, even if the BDS alignment\n> condition is not satisfied.\n> \n> Fix this by caching the result of the two iterations, and use the one\n> that produced any result, with a preference for the one produced by the\n> second loop, as implemented in the reference python script.\n> \n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/libcamera/pipeline/ipu3/imgu.cpp | 13 +++++++++----\n>  1 file changed, 9 insertions(+), 4 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp\n> index d9296ea3e674..11bb7cb95084 100644\n> --- a/src/libcamera/pipeline/ipu3/imgu.cpp\n> +++ b/src/libcamera/pipeline/ipu3/imgu.cpp\n> @@ -129,10 +129,10 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n>  \tfloat bdsHeight;\n>  \n>  \tif (!isSameRatio(pipe->input, gdc)) {\n> +\t\tunsigned int foundIfHeights[2] = { 0, 0 };\n\nYou don't need two values, a single one will do, it can be overwritten\nin the second loop.\n\nWith an updated commit message,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n>  \t\tfloat estIFHeight = (iif.width * gdc.height) /\n>  \t\t\t\t    static_cast<float>(gdc.width);\n>  \t\testIFHeight = std::clamp<float>(estIFHeight, minIFHeight, iif.height);\n> -\t\tbool found = false;\n>  \n>  \t\tifHeight = utils::alignUp(estIFHeight, IF_ALIGN_H);\n>  \t\twhile (ifHeight >= minIFHeight && ifHeight / bdsSF >= minBDSHeight) {\n> @@ -142,7 +142,7 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n>  \t\t\t\tunsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);\n>  \n>  \t\t\t\tif (!(bdsIntHeight % BDS_ALIGN_H)) {\n> -\t\t\t\t\tfound = true;\n> +\t\t\t\t\tfoundIfHeights[0] = ifHeight;\n>  \t\t\t\t\tbreak;\n>  \t\t\t\t}\n>  \t\t\t}\n> @@ -158,7 +158,7 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n>  \t\t\t\tunsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);\n>  \n>  \t\t\t\tif (!(bdsIntHeight % BDS_ALIGN_H)) {\n> -\t\t\t\t\tfound = true;\n> +\t\t\t\t\tfoundIfHeights[1] = ifHeight;\n>  \t\t\t\t\tbreak;\n>  \t\t\t\t}\n>  \t\t\t}\n> @@ -166,7 +166,12 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n>  \t\t\tifHeight += IF_ALIGN_H;\n>  \t\t}\n>  \n> -\t\tif (found) {\n> +\t\tif (foundIfHeights[0])\n> +\t\t\tifHeight = foundIfHeights[0];\n> +\t\tif (foundIfHeights[1])\n> +\t\t\tifHeight = foundIfHeights[1];\n> +\n> +\t\tif (foundIfHeights[0] || foundIfHeights[1]) {\n>  \t\t\tunsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);\n>  \n>  \t\t\tpipeConfigs.push_back({ bdsSF, { iif.width, ifHeight },","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 18574BD224\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 13 Apr 2021 00:18:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8FADF687F4;\n\tTue, 13 Apr 2021 02:18:53 +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 EB5B5605AE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 13 Apr 2021 02:18:51 +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 64E0D6F2;\n\tTue, 13 Apr 2021 02:18:51 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"vWKXy1XW\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1618273131;\n\tbh=XmLTiKOO+2/fOUFxfW6a75eh634sKkQ5lxThJVs+wpo=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=vWKXy1XWPeboiOl7VQQhsUPCXO7dceNFxzhOPY2CoCBgQD0qpiYVp3kiAn1yluuNu\n\tWAZ8bI6T+RbcbtkhqOWukxtPe916u+L4j6GrxKquJqn90S2GTMzfCqsNow/mMT+PCY\n\t6yeaMiInF3XxrmsQ7YQ+sNgLmBXoPsFbLIs4Zmxo=","Date":"Tue, 13 Apr 2021 03:18:02 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<YHTjOprGyq+jZ3Uq@pendragon.ideasonboard.com>","References":"<20210318103941.18837-1-jacopo@jmondi.org>\n\t<20210318103941.18837-4-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210318103941.18837-4-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH 3/7] libcamera: ipu3: imgu: Fix BDS\n\theight calculation","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":16453,"web_url":"https://patchwork.libcamera.org/comment/16453/","msgid":"<20210421125756.6p5aj4vhjfdwz23i@uno.localdomain>","date":"2021-04-21T12:57:56","subject":"Re: [libcamera-devel] [PATCH 3/7] libcamera: ipu3: imgu: Fix BDS\n\theight calculation","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Tue, Apr 13, 2021 at 03:18:02AM +0300, Laurent Pinchart wrote:\n> Hi Jacopo,\n>\n> Thank you for the patch.\n>\n> On Thu, Mar 18, 2021 at 11:39:37AM +0100, Jacopo Mondi wrote:\n> > The IF rectangle height is iteratively computed by first subtracting\n> > the scaling factor to the estimated height, then in a successive loop\n> > by adding the same scaling factor until the maximum IF size is not\n> > reached.\n> >\n> > As the computed IF height is not cached in any variable, the second\n> > loop over-writes the result of the first one, even if the BDS alignment\n> > condition is not satisfied.\n> >\n> > Fix this by caching the result of the two iterations, and use the one\n> > that produced any result, with a preference for the one produced by the\n> > second loop, as implemented in the reference python script.\n> >\n> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> > ---\n> >  src/libcamera/pipeline/ipu3/imgu.cpp | 13 +++++++++----\n> >  1 file changed, 9 insertions(+), 4 deletions(-)\n> >\n> > diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp\n> > index d9296ea3e674..11bb7cb95084 100644\n> > --- a/src/libcamera/pipeline/ipu3/imgu.cpp\n> > +++ b/src/libcamera/pipeline/ipu3/imgu.cpp\n> > @@ -129,10 +129,10 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n> >  \tfloat bdsHeight;\n> >\n> >  \tif (!isSameRatio(pipe->input, gdc)) {\n> > +\t\tunsigned int foundIfHeights[2] = { 0, 0 };\n>\n> You don't need two values, a single one will do, it can be overwritten\n> in the second loop.\n\nCorrect, I got the same understanding but I would prefer to use the\nsame \"style\" as the python script, not to diverge...\n\nWhat do you think ?\n\n>\n> With an updated commit message,\n>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nThanks\n  j\n\n>\n> >  \t\tfloat estIFHeight = (iif.width * gdc.height) /\n> >  \t\t\t\t    static_cast<float>(gdc.width);\n> >  \t\testIFHeight = std::clamp<float>(estIFHeight, minIFHeight, iif.height);\n> > -\t\tbool found = false;\n> >\n> >  \t\tifHeight = utils::alignUp(estIFHeight, IF_ALIGN_H);\n> >  \t\twhile (ifHeight >= minIFHeight && ifHeight / bdsSF >= minBDSHeight) {\n> > @@ -142,7 +142,7 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n> >  \t\t\t\tunsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);\n> >\n> >  \t\t\t\tif (!(bdsIntHeight % BDS_ALIGN_H)) {\n> > -\t\t\t\t\tfound = true;\n> > +\t\t\t\t\tfoundIfHeights[0] = ifHeight;\n> >  \t\t\t\t\tbreak;\n> >  \t\t\t\t}\n> >  \t\t\t}\n> > @@ -158,7 +158,7 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n> >  \t\t\t\tunsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);\n> >\n> >  \t\t\t\tif (!(bdsIntHeight % BDS_ALIGN_H)) {\n> > -\t\t\t\t\tfound = true;\n> > +\t\t\t\t\tfoundIfHeights[1] = ifHeight;\n> >  \t\t\t\t\tbreak;\n> >  \t\t\t\t}\n> >  \t\t\t}\n> > @@ -166,7 +166,12 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n> >  \t\t\tifHeight += IF_ALIGN_H;\n> >  \t\t}\n> >\n> > -\t\tif (found) {\n> > +\t\tif (foundIfHeights[0])\n> > +\t\t\tifHeight = foundIfHeights[0];\n> > +\t\tif (foundIfHeights[1])\n> > +\t\t\tifHeight = foundIfHeights[1];\n> > +\n> > +\t\tif (foundIfHeights[0] || foundIfHeights[1]) {\n> >  \t\t\tunsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);\n> >\n> >  \t\t\tpipeConfigs.push_back({ bdsSF, { iif.width, ifHeight },\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 8DC20BDB15\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 21 Apr 2021 12:57:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CE85C6884B;\n\tWed, 21 Apr 2021 14:57:16 +0200 (CEST)","from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6652F68835\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 21 Apr 2021 14:57:15 +0200 (CEST)","from uno.localdomain (93-34-118-233.ip49.fastwebnet.it\n\t[93.34.118.233]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay10.mail.gandi.net (Postfix) with ESMTPSA id E2C61240009;\n\tWed, 21 Apr 2021 12:57:14 +0000 (UTC)"],"Date":"Wed, 21 Apr 2021 14:57:56 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20210421125756.6p5aj4vhjfdwz23i@uno.localdomain>","References":"<20210318103941.18837-1-jacopo@jmondi.org>\n\t<20210318103941.18837-4-jacopo@jmondi.org>\n\t<YHTjOprGyq+jZ3Uq@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<YHTjOprGyq+jZ3Uq@pendragon.ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 3/7] libcamera: ipu3: imgu: Fix BDS\n\theight calculation","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":16455,"web_url":"https://patchwork.libcamera.org/comment/16455/","msgid":"<YIArsPXEb3Yyue8E@pendragon.ideasonboard.com>","date":"2021-04-21T13:42:08","subject":"Re: [libcamera-devel] [PATCH 3/7] libcamera: ipu3: imgu: Fix BDS\n\theight calculation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Wed, Apr 21, 2021 at 02:57:56PM +0200, Jacopo Mondi wrote:\n> On Tue, Apr 13, 2021 at 03:18:02AM +0300, Laurent Pinchart wrote:\n> > On Thu, Mar 18, 2021 at 11:39:37AM +0100, Jacopo Mondi wrote:\n> > > The IF rectangle height is iteratively computed by first subtracting\n> > > the scaling factor to the estimated height, then in a successive loop\n> > > by adding the same scaling factor until the maximum IF size is not\n> > > reached.\n> > >\n> > > As the computed IF height is not cached in any variable, the second\n> > > loop over-writes the result of the first one, even if the BDS alignment\n> > > condition is not satisfied.\n> > >\n> > > Fix this by caching the result of the two iterations, and use the one\n> > > that produced any result, with a preference for the one produced by the\n> > > second loop, as implemented in the reference python script.\n> > >\n> > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> > > ---\n> > >  src/libcamera/pipeline/ipu3/imgu.cpp | 13 +++++++++----\n> > >  1 file changed, 9 insertions(+), 4 deletions(-)\n> > >\n> > > diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp\n> > > index d9296ea3e674..11bb7cb95084 100644\n> > > --- a/src/libcamera/pipeline/ipu3/imgu.cpp\n> > > +++ b/src/libcamera/pipeline/ipu3/imgu.cpp\n> > > @@ -129,10 +129,10 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n> > >  \tfloat bdsHeight;\n> > >\n> > >  \tif (!isSameRatio(pipe->input, gdc)) {\n> > > +\t\tunsigned int foundIfHeights[2] = { 0, 0 };\n> >\n> > You don't need two values, a single one will do, it can be overwritten\n> > in the second loop.\n> \n> Correct, I got the same understanding but I would prefer to use the\n> same \"style\" as the python script, not to diverge...\n> \n> What do you think ?\n\nI don't think diverging is an issue, as I believe this code should be\ncompletely rewritten based on an actual understanding of the procedures,\ninstead of blindly mimicking python code that has known issues. I'm OK\nwith this series as a short term, stop-gap measure, but it's clearly not\nwhat we need longer term. I will likely insist more strongly to have\nthis rewritten the next time code from python is integrated.\n\n> > With an updated commit message,\n> >\n> > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> >\n> > >  \t\tfloat estIFHeight = (iif.width * gdc.height) /\n> > >  \t\t\t\t    static_cast<float>(gdc.width);\n> > >  \t\testIFHeight = std::clamp<float>(estIFHeight, minIFHeight, iif.height);\n> > > -\t\tbool found = false;\n> > >\n> > >  \t\tifHeight = utils::alignUp(estIFHeight, IF_ALIGN_H);\n> > >  \t\twhile (ifHeight >= minIFHeight && ifHeight / bdsSF >= minBDSHeight) {\n> > > @@ -142,7 +142,7 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n> > >  \t\t\t\tunsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);\n> > >\n> > >  \t\t\t\tif (!(bdsIntHeight % BDS_ALIGN_H)) {\n> > > -\t\t\t\t\tfound = true;\n> > > +\t\t\t\t\tfoundIfHeights[0] = ifHeight;\n> > >  \t\t\t\t\tbreak;\n> > >  \t\t\t\t}\n> > >  \t\t\t}\n> > > @@ -158,7 +158,7 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n> > >  \t\t\t\tunsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);\n> > >\n> > >  \t\t\t\tif (!(bdsIntHeight % BDS_ALIGN_H)) {\n> > > -\t\t\t\t\tfound = true;\n> > > +\t\t\t\t\tfoundIfHeights[1] = ifHeight;\n> > >  \t\t\t\t\tbreak;\n> > >  \t\t\t\t}\n> > >  \t\t\t}\n> > > @@ -166,7 +166,12 @@ void calculateBDSHeight(ImgUDevice::Pipe *pipe, const Size &iif, const Size &gdc\n> > >  \t\t\tifHeight += IF_ALIGN_H;\n> > >  \t\t}\n> > >\n> > > -\t\tif (found) {\n> > > +\t\tif (foundIfHeights[0])\n> > > +\t\t\tifHeight = foundIfHeights[0];\n> > > +\t\tif (foundIfHeights[1])\n> > > +\t\t\tifHeight = foundIfHeights[1];\n> > > +\n> > > +\t\tif (foundIfHeights[0] || foundIfHeights[1]) {\n> > >  \t\t\tunsigned int bdsIntHeight = static_cast<unsigned int>(bdsHeight);\n> > >\n> > >  \t\t\tpipeConfigs.push_back({ bdsSF, { iif.width, ifHeight },","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 CA45EBDB16\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 21 Apr 2021 13:42:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9439168849;\n\tWed, 21 Apr 2021 15:42:14 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C6A068835\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 21 Apr 2021 15:42:13 +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 741554AE;\n\tWed, 21 Apr 2021 15:42:12 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Mzn/pkoL\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1619012532;\n\tbh=n+OFix2xHkHcBHsp7j70Xu2aJqdD39jFnBuXdgo+PSQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Mzn/pkoLSX2AevTCIbdLxJ9Qf5Thjsxh5+Hnvbjy7k36NdanFZYAr2fvUCPs/hvrK\n\tFQg3zY9kIdpr+i0RwhfamCoLEEzG3X97JYvV1C28rz6tqMotzId10l7SswPamnnm1z\n\tLOGFxLqrfnaBj5Fo/sxVBXxLvdXPYo1u66n0ylgY=","Date":"Wed, 21 Apr 2021 16:42:08 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<YIArsPXEb3Yyue8E@pendragon.ideasonboard.com>","References":"<20210318103941.18837-1-jacopo@jmondi.org>\n\t<20210318103941.18837-4-jacopo@jmondi.org>\n\t<YHTjOprGyq+jZ3Uq@pendragon.ideasonboard.com>\n\t<20210421125756.6p5aj4vhjfdwz23i@uno.localdomain>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210421125756.6p5aj4vhjfdwz23i@uno.localdomain>","Subject":"Re: [libcamera-devel] [PATCH 3/7] libcamera: ipu3: imgu: Fix BDS\n\theight calculation","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>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]