[{"id":5397,"web_url":"https://patchwork.libcamera.org/comment/5397/","msgid":"<20200625034605.GI5980@pendragon.ideasonboard.com>","date":"2020-06-25T03:46:05","subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: Add \"focus\" algorithm","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi David,\n\nThank you for the patch.\n\nOn Thu, May 28, 2020 at 03:51:32PM +0100, Naushir Patuck wrote:\n> From: David Plowman <david.plowman@raspberrypi.com>\n> \n> Adds FocusStatus to the image metadata, containing contrast measurements\n> across the image. Optionally also prints a contrast measure to the\n> console, to aid in manual adjustment of the lens. Note that it is not an\n> actual auto-focus algorithm that can drive a lens!\n\nAn interesting exercise for a motivated reader :-)\n\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  src/ipa/raspberrypi/controller/focus_status.h | 26 ++++++++++\n>  src/ipa/raspberrypi/controller/rpi/focus.cpp  | 51 +++++++++++++++++++\n>  src/ipa/raspberrypi/controller/rpi/focus.hpp  | 31 +++++++++++\n>  src/ipa/raspberrypi/data/imx477.json          |  4 ++\n>  src/ipa/raspberrypi/meson.build               |  1 +\n>  5 files changed, 113 insertions(+)\n>  create mode 100644 src/ipa/raspberrypi/controller/focus_status.h\n>  create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.cpp\n>  create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.hpp\n> \n> diff --git a/src/ipa/raspberrypi/controller/focus_status.h b/src/ipa/raspberrypi/controller/focus_status.h\n> new file mode 100644\n> index 00000000..3ad88777\n> --- /dev/null\n> +++ b/src/ipa/raspberrypi/controller/focus_status.h\n> @@ -0,0 +1,26 @@\n> +/* SPDX-License-Identifier: BSD-2-Clause */\n> +/*\n> + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> + *\n> + * focus_status.h - focus measurement status\n> + */\n> +#pragma once\n> +\n> +#include <linux/bcm2835-isp.h>\n> +\n> +// The focus algorithm should post the following structure into the image's\n> +// \"focus.status\" metadata. Recall that it's only reporting focus (contrast)\n> +// measurements, it's not driving any kind of auto-focus algorithm!\n> +\n> +#ifdef __cplusplus\n> +extern \"C\" {\n> +#endif\n> +\n> +struct FocusStatus {\n> +\tint num;\n> +\tuint32_t focus_measures[FOCUS_REGIONS];\n> +};\n> +\n> +#ifdef __cplusplus\n> +}\n> +#endif\n> diff --git a/src/ipa/raspberrypi/controller/rpi/focus.cpp b/src/ipa/raspberrypi/controller/rpi/focus.cpp\n> new file mode 100644\n> index 00000000..d6cdc4bf\n> --- /dev/null\n> +++ b/src/ipa/raspberrypi/controller/rpi/focus.cpp\n> @@ -0,0 +1,51 @@\n> +/* SPDX-License-Identifier: BSD-2-Clause */\n> +/*\n> + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> + *\n> + * focus.cpp - focus algorithm\n> + */\n> +#include <stdint.h>\n> +\n> +#include \"../focus_status.h\"\n> +#include \"../logging.hpp\"\n> +#include \"focus.hpp\"\n> +\n> +using namespace RPi;\n> +\n> +#define NAME \"rpi.focus\"\n> +\n> +Focus::Focus(Controller *controller)\n> +\t: Algorithm(controller)\n> +{\n> +}\n> +\n> +char const *Focus::Name() const\n> +{\n> +\treturn NAME;\n> +}\n> +\n> +void Focus::Read(boost::property_tree::ptree const &params)\n> +{\n> +\tprint_ = params.get<int>(\"print\", 0);\n> +}\n> +\n> +void Focus::Process(StatisticsPtr &stats, Metadata *image_metadata)\n> +{\n> +\tFocusStatus status;\n> +\tint i;\n\nAs i is never negative, should it be an unsigned int ?\n\nApart from this,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nLet me know if you're fine with the change, in which case I'll modify\nthe patch when applying.\n\n> +\tfor (i = 0; i < FOCUS_REGIONS; i++)\n> +\t\tstatus.focus_measures[i] = stats->focus_stats[i].contrast_val[1][1] / 1000;\n> +\tstatus.num = i;\n> +\timage_metadata->Set(\"focus.status\", status);\n> +\tif (print_) {\n> +\t\tuint32_t value = (status.focus_measures[5] + status.focus_measures[6]) / 10;\n> +\t\tRPI_LOG(\"Focus contrast measure: \" << value);\n> +\t}\n> +}\n> +\n> +/* Register algorithm with the system. */\n> +static Algorithm *Create(Controller *controller)\n> +{\n> +\treturn new Focus(controller);\n> +}\n> +static RegisterAlgorithm reg(NAME, &Create);\n> diff --git a/src/ipa/raspberrypi/controller/rpi/focus.hpp b/src/ipa/raspberrypi/controller/rpi/focus.hpp\n> new file mode 100644\n> index 00000000..d53401f7\n> --- /dev/null\n> +++ b/src/ipa/raspberrypi/controller/rpi/focus.hpp\n> @@ -0,0 +1,31 @@\n> +/* SPDX-License-Identifier: BSD-2-Clause */\n> +/*\n> + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> + *\n> + * focus.hpp - focus algorithm\n> + */\n> +#pragma once\n> +\n> +#include \"../algorithm.hpp\"\n> +#include \"../metadata.hpp\"\n> +\n> +/*\n> + * The \"focus\" algorithm. All it does it print out a version of the\n> + * focus contrast measure; there is no actual auto-focus mechanism to\n> + * control.\n> + */\n> +\n> +namespace RPi {\n> +\n> +class Focus : public Algorithm\n> +{\n> +public:\n> +\tFocus(Controller *controller);\n> +\tchar const *Name() const override;\n> +\tvoid Read(boost::property_tree::ptree const &params) override;\n> +\tvoid Process(StatisticsPtr &stats, Metadata *image_metadata) override;\n> +private:\n> +\tbool print_;\n> +};\n> +\n> +} /* namespace RPi */\n> diff --git a/src/ipa/raspberrypi/data/imx477.json b/src/ipa/raspberrypi/data/imx477.json\n> index dce5234f..389e8ce8 100644\n> --- a/src/ipa/raspberrypi/data/imx477.json\n> +++ b/src/ipa/raspberrypi/data/imx477.json\n> @@ -412,5 +412,9 @@\n>      \"rpi.sharpen\":\n>      {\n>  \n> +    },\n> +    \"rpi.focus\":\n> +    {\n> +\t\"print\": 1\n>      }\n>  }\n> diff --git a/src/ipa/raspberrypi/meson.build b/src/ipa/raspberrypi/meson.build\n> index 697902e9..9445cd09 100644\n> --- a/src/ipa/raspberrypi/meson.build\n> +++ b/src/ipa/raspberrypi/meson.build\n> @@ -29,6 +29,7 @@ rpi_ipa_sources = files([\n>      'controller/rpi/awb.cpp',\n>      'controller/rpi/sharpen.cpp',\n>      'controller/rpi/black_level.cpp',\n> +    'controller/rpi/focus.cpp',\n>      'controller/rpi/geq.cpp',\n>      'controller/rpi/noise.cpp',\n>      'controller/rpi/lux.cpp',","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 D501CC0101\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 25 Jun 2020 03:46:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 40DCF609A5;\n\tThu, 25 Jun 2020 05:46:08 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7465B603BB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Jun 2020 05:46:07 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DFE75521;\n\tThu, 25 Jun 2020 05:46:06 +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=\"ncCg2nWt\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593056767;\n\tbh=orFphWyuFUEUD+yVNI24+qCWp2uqb0cFCS8RkbYBbBc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=ncCg2nWtGq2MGC04nRmLXGKLdc42Pkf8Vad+b5dxo3LQDHKlZ9zn98enn68ZuLl2/\n\tgdjSq/vzZyyzWVnPF9C+dns81DHwgpfOX2MSPnwlylt0o6bpCOVkLWeiTfDbp5Fc82\n\tyK4OkhJ5nzJ2fpzqdNNNUZG0r+S+CQDSTQlGytiY=","Date":"Thu, 25 Jun 2020 06:46:05 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<20200625034605.GI5980@pendragon.ideasonboard.com>","References":"<20200528145132.96102-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200528145132.96102-1-naush@raspberrypi.com>","Subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: Add \"focus\" algorithm","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":5398,"web_url":"https://patchwork.libcamera.org/comment/5398/","msgid":"<20200625034651.GJ5980@pendragon.ideasonboard.com>","date":"2020-06-25T03:46:51","subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: Add \"focus\" algorithm","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Thu, Jun 25, 2020 at 06:46:05AM +0300, Laurent Pinchart wrote:\n> Hi David,\n\nI meant Naush. Or Naush and David. Or the other way around. Or I should\ngo to bed :-)\n\n> Thank you for the patch.\n> \n> On Thu, May 28, 2020 at 03:51:32PM +0100, Naushir Patuck wrote:\n> > From: David Plowman <david.plowman@raspberrypi.com>\n> > \n> > Adds FocusStatus to the image metadata, containing contrast measurements\n> > across the image. Optionally also prints a contrast measure to the\n> > console, to aid in manual adjustment of the lens. Note that it is not an\n> > actual auto-focus algorithm that can drive a lens!\n> \n> An interesting exercise for a motivated reader :-)\n> \n> > Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> > ---\n> >  src/ipa/raspberrypi/controller/focus_status.h | 26 ++++++++++\n> >  src/ipa/raspberrypi/controller/rpi/focus.cpp  | 51 +++++++++++++++++++\n> >  src/ipa/raspberrypi/controller/rpi/focus.hpp  | 31 +++++++++++\n> >  src/ipa/raspberrypi/data/imx477.json          |  4 ++\n> >  src/ipa/raspberrypi/meson.build               |  1 +\n> >  5 files changed, 113 insertions(+)\n> >  create mode 100644 src/ipa/raspberrypi/controller/focus_status.h\n> >  create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.cpp\n> >  create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.hpp\n> > \n> > diff --git a/src/ipa/raspberrypi/controller/focus_status.h b/src/ipa/raspberrypi/controller/focus_status.h\n> > new file mode 100644\n> > index 00000000..3ad88777\n> > --- /dev/null\n> > +++ b/src/ipa/raspberrypi/controller/focus_status.h\n> > @@ -0,0 +1,26 @@\n> > +/* SPDX-License-Identifier: BSD-2-Clause */\n> > +/*\n> > + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> > + *\n> > + * focus_status.h - focus measurement status\n> > + */\n> > +#pragma once\n> > +\n> > +#include <linux/bcm2835-isp.h>\n> > +\n> > +// The focus algorithm should post the following structure into the image's\n> > +// \"focus.status\" metadata. Recall that it's only reporting focus (contrast)\n> > +// measurements, it's not driving any kind of auto-focus algorithm!\n> > +\n> > +#ifdef __cplusplus\n> > +extern \"C\" {\n> > +#endif\n> > +\n> > +struct FocusStatus {\n> > +\tint num;\n> > +\tuint32_t focus_measures[FOCUS_REGIONS];\n> > +};\n> > +\n> > +#ifdef __cplusplus\n> > +}\n> > +#endif\n> > diff --git a/src/ipa/raspberrypi/controller/rpi/focus.cpp b/src/ipa/raspberrypi/controller/rpi/focus.cpp\n> > new file mode 100644\n> > index 00000000..d6cdc4bf\n> > --- /dev/null\n> > +++ b/src/ipa/raspberrypi/controller/rpi/focus.cpp\n> > @@ -0,0 +1,51 @@\n> > +/* SPDX-License-Identifier: BSD-2-Clause */\n> > +/*\n> > + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> > + *\n> > + * focus.cpp - focus algorithm\n> > + */\n> > +#include <stdint.h>\n> > +\n> > +#include \"../focus_status.h\"\n> > +#include \"../logging.hpp\"\n> > +#include \"focus.hpp\"\n> > +\n> > +using namespace RPi;\n> > +\n> > +#define NAME \"rpi.focus\"\n> > +\n> > +Focus::Focus(Controller *controller)\n> > +\t: Algorithm(controller)\n> > +{\n> > +}\n> > +\n> > +char const *Focus::Name() const\n> > +{\n> > +\treturn NAME;\n> > +}\n> > +\n> > +void Focus::Read(boost::property_tree::ptree const &params)\n> > +{\n> > +\tprint_ = params.get<int>(\"print\", 0);\n> > +}\n> > +\n> > +void Focus::Process(StatisticsPtr &stats, Metadata *image_metadata)\n> > +{\n> > +\tFocusStatus status;\n> > +\tint i;\n> \n> As i is never negative, should it be an unsigned int ?\n> \n> Apart from this,\n> \n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> Let me know if you're fine with the change, in which case I'll modify\n> the patch when applying.\n> \n> > +\tfor (i = 0; i < FOCUS_REGIONS; i++)\n> > +\t\tstatus.focus_measures[i] = stats->focus_stats[i].contrast_val[1][1] / 1000;\n> > +\tstatus.num = i;\n> > +\timage_metadata->Set(\"focus.status\", status);\n> > +\tif (print_) {\n> > +\t\tuint32_t value = (status.focus_measures[5] + status.focus_measures[6]) / 10;\n> > +\t\tRPI_LOG(\"Focus contrast measure: \" << value);\n> > +\t}\n> > +}\n> > +\n> > +/* Register algorithm with the system. */\n> > +static Algorithm *Create(Controller *controller)\n> > +{\n> > +\treturn new Focus(controller);\n> > +}\n> > +static RegisterAlgorithm reg(NAME, &Create);\n> > diff --git a/src/ipa/raspberrypi/controller/rpi/focus.hpp b/src/ipa/raspberrypi/controller/rpi/focus.hpp\n> > new file mode 100644\n> > index 00000000..d53401f7\n> > --- /dev/null\n> > +++ b/src/ipa/raspberrypi/controller/rpi/focus.hpp\n> > @@ -0,0 +1,31 @@\n> > +/* SPDX-License-Identifier: BSD-2-Clause */\n> > +/*\n> > + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> > + *\n> > + * focus.hpp - focus algorithm\n> > + */\n> > +#pragma once\n> > +\n> > +#include \"../algorithm.hpp\"\n> > +#include \"../metadata.hpp\"\n> > +\n> > +/*\n> > + * The \"focus\" algorithm. All it does it print out a version of the\n> > + * focus contrast measure; there is no actual auto-focus mechanism to\n> > + * control.\n> > + */\n> > +\n> > +namespace RPi {\n> > +\n> > +class Focus : public Algorithm\n> > +{\n> > +public:\n> > +\tFocus(Controller *controller);\n> > +\tchar const *Name() const override;\n> > +\tvoid Read(boost::property_tree::ptree const &params) override;\n> > +\tvoid Process(StatisticsPtr &stats, Metadata *image_metadata) override;\n> > +private:\n> > +\tbool print_;\n> > +};\n> > +\n> > +} /* namespace RPi */\n> > diff --git a/src/ipa/raspberrypi/data/imx477.json b/src/ipa/raspberrypi/data/imx477.json\n> > index dce5234f..389e8ce8 100644\n> > --- a/src/ipa/raspberrypi/data/imx477.json\n> > +++ b/src/ipa/raspberrypi/data/imx477.json\n> > @@ -412,5 +412,9 @@\n> >      \"rpi.sharpen\":\n> >      {\n> >  \n> > +    },\n> > +    \"rpi.focus\":\n> > +    {\n> > +\t\"print\": 1\n> >      }\n> >  }\n> > diff --git a/src/ipa/raspberrypi/meson.build b/src/ipa/raspberrypi/meson.build\n> > index 697902e9..9445cd09 100644\n> > --- a/src/ipa/raspberrypi/meson.build\n> > +++ b/src/ipa/raspberrypi/meson.build\n> > @@ -29,6 +29,7 @@ rpi_ipa_sources = files([\n> >      'controller/rpi/awb.cpp',\n> >      'controller/rpi/sharpen.cpp',\n> >      'controller/rpi/black_level.cpp',\n> > +    'controller/rpi/focus.cpp',\n> >      'controller/rpi/geq.cpp',\n> >      'controller/rpi/noise.cpp',\n> >      'controller/rpi/lux.cpp',","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 37224C0101\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 25 Jun 2020 03:46:55 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F1967603BE;\n\tThu, 25 Jun 2020 05:46:54 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8EB39603BB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Jun 2020 05:46:53 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi\n\t[81.175.216.236])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id C530D521;\n\tThu, 25 Jun 2020 05:46:52 +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=\"Y/tf0iVw\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593056813;\n\tbh=Qk8EPFJBxIT1n5Y5DhOf5qBY19cDtgXAV5yS/wFeKx4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Y/tf0iVwnnQDJTQv7raAWgZi5GiYAFG4WwtHptQDF0iRlHmXfbtTkVSXFm4eLufAF\n\t5/A14oqRcMgpycOYEeX2eBGRhdBk7Fw0X55T9Niw2JaPmtoWwcIm60m7eYR8GCoz2u\n\tAEchxMucx3eYeQZaM3BF8oaIbYNu+ZrzDVa029lw=","Date":"Thu, 25 Jun 2020 06:46:51 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<20200625034651.GJ5980@pendragon.ideasonboard.com>","References":"<20200528145132.96102-1-naush@raspberrypi.com>\n\t<20200625034605.GI5980@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200625034605.GI5980@pendragon.ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: Add \"focus\" algorithm","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":5402,"web_url":"https://patchwork.libcamera.org/comment/5402/","msgid":"<CAHW6GYKPmojpPiVcD0D-GFsvDrxbN5JDCaJcSwujrUWO0NKntg@mail.gmail.com>","date":"2020-06-25T07:29:01","subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: Add \"focus\" algorithm","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Laurent\n\nThanks for the review.\n\nOn Thu, 25 Jun 2020 at 04:46, Laurent Pinchart\n<laurent.pinchart@ideasonboard.com> wrote:\n>\n> Hi David,\n>\n> Thank you for the patch.\n>\n> On Thu, May 28, 2020 at 03:51:32PM +0100, Naushir Patuck wrote:\n> > From: David Plowman <david.plowman@raspberrypi.com>\n> >\n> > Adds FocusStatus to the image metadata, containing contrast measurements\n> > across the image. Optionally also prints a contrast measure to the\n> > console, to aid in manual adjustment of the lens. Note that it is not an\n> > actual auto-focus algorithm that can drive a lens!\n>\n> An interesting exercise for a motivated reader :-)\n>\n> > Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> > ---\n> >  src/ipa/raspberrypi/controller/focus_status.h | 26 ++++++++++\n> >  src/ipa/raspberrypi/controller/rpi/focus.cpp  | 51 +++++++++++++++++++\n> >  src/ipa/raspberrypi/controller/rpi/focus.hpp  | 31 +++++++++++\n> >  src/ipa/raspberrypi/data/imx477.json          |  4 ++\n> >  src/ipa/raspberrypi/meson.build               |  1 +\n> >  5 files changed, 113 insertions(+)\n> >  create mode 100644 src/ipa/raspberrypi/controller/focus_status.h\n> >  create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.cpp\n> >  create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.hpp\n> >\n> > diff --git a/src/ipa/raspberrypi/controller/focus_status.h b/src/ipa/raspberrypi/controller/focus_status.h\n> > new file mode 100644\n> > index 00000000..3ad88777\n> > --- /dev/null\n> > +++ b/src/ipa/raspberrypi/controller/focus_status.h\n> > @@ -0,0 +1,26 @@\n> > +/* SPDX-License-Identifier: BSD-2-Clause */\n> > +/*\n> > + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> > + *\n> > + * focus_status.h - focus measurement status\n> > + */\n> > +#pragma once\n> > +\n> > +#include <linux/bcm2835-isp.h>\n> > +\n> > +// The focus algorithm should post the following structure into the image's\n> > +// \"focus.status\" metadata. Recall that it's only reporting focus (contrast)\n> > +// measurements, it's not driving any kind of auto-focus algorithm!\n> > +\n> > +#ifdef __cplusplus\n> > +extern \"C\" {\n> > +#endif\n> > +\n> > +struct FocusStatus {\n> > +     int num;\n> > +     uint32_t focus_measures[FOCUS_REGIONS];\n> > +};\n> > +\n> > +#ifdef __cplusplus\n> > +}\n> > +#endif\n> > diff --git a/src/ipa/raspberrypi/controller/rpi/focus.cpp b/src/ipa/raspberrypi/controller/rpi/focus.cpp\n> > new file mode 100644\n> > index 00000000..d6cdc4bf\n> > --- /dev/null\n> > +++ b/src/ipa/raspberrypi/controller/rpi/focus.cpp\n> > @@ -0,0 +1,51 @@\n> > +/* SPDX-License-Identifier: BSD-2-Clause */\n> > +/*\n> > + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> > + *\n> > + * focus.cpp - focus algorithm\n> > + */\n> > +#include <stdint.h>\n> > +\n> > +#include \"../focus_status.h\"\n> > +#include \"../logging.hpp\"\n> > +#include \"focus.hpp\"\n> > +\n> > +using namespace RPi;\n> > +\n> > +#define NAME \"rpi.focus\"\n> > +\n> > +Focus::Focus(Controller *controller)\n> > +     : Algorithm(controller)\n> > +{\n> > +}\n> > +\n> > +char const *Focus::Name() const\n> > +{\n> > +     return NAME;\n> > +}\n> > +\n> > +void Focus::Read(boost::property_tree::ptree const &params)\n> > +{\n> > +     print_ = params.get<int>(\"print\", 0);\n> > +}\n> > +\n> > +void Focus::Process(StatisticsPtr &stats, Metadata *image_metadata)\n> > +{\n> > +     FocusStatus status;\n> > +     int i;\n>\n> As i is never negative, should it be an unsigned int ?\n\nThat's fine with me, thanks!\n\nThanks again and best regards\nDavid\n\n>\n> Apart from this,\n>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n>\n> Let me know if you're fine with the change, in which case I'll modify\n> the patch when applying.\n>\n> > +     for (i = 0; i < FOCUS_REGIONS; i++)\n> > +             status.focus_measures[i] = stats->focus_stats[i].contrast_val[1][1] / 1000;\n> > +     status.num = i;\n> > +     image_metadata->Set(\"focus.status\", status);\n> > +     if (print_) {\n> > +             uint32_t value = (status.focus_measures[5] + status.focus_measures[6]) / 10;\n> > +             RPI_LOG(\"Focus contrast measure: \" << value);\n> > +     }\n> > +}\n> > +\n> > +/* Register algorithm with the system. */\n> > +static Algorithm *Create(Controller *controller)\n> > +{\n> > +     return new Focus(controller);\n> > +}\n> > +static RegisterAlgorithm reg(NAME, &Create);\n> > diff --git a/src/ipa/raspberrypi/controller/rpi/focus.hpp b/src/ipa/raspberrypi/controller/rpi/focus.hpp\n> > new file mode 100644\n> > index 00000000..d53401f7\n> > --- /dev/null\n> > +++ b/src/ipa/raspberrypi/controller/rpi/focus.hpp\n> > @@ -0,0 +1,31 @@\n> > +/* SPDX-License-Identifier: BSD-2-Clause */\n> > +/*\n> > + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> > + *\n> > + * focus.hpp - focus algorithm\n> > + */\n> > +#pragma once\n> > +\n> > +#include \"../algorithm.hpp\"\n> > +#include \"../metadata.hpp\"\n> > +\n> > +/*\n> > + * The \"focus\" algorithm. All it does it print out a version of the\n> > + * focus contrast measure; there is no actual auto-focus mechanism to\n> > + * control.\n> > + */\n> > +\n> > +namespace RPi {\n> > +\n> > +class Focus : public Algorithm\n> > +{\n> > +public:\n> > +     Focus(Controller *controller);\n> > +     char const *Name() const override;\n> > +     void Read(boost::property_tree::ptree const &params) override;\n> > +     void Process(StatisticsPtr &stats, Metadata *image_metadata) override;\n> > +private:\n> > +     bool print_;\n> > +};\n> > +\n> > +} /* namespace RPi */\n> > diff --git a/src/ipa/raspberrypi/data/imx477.json b/src/ipa/raspberrypi/data/imx477.json\n> > index dce5234f..389e8ce8 100644\n> > --- a/src/ipa/raspberrypi/data/imx477.json\n> > +++ b/src/ipa/raspberrypi/data/imx477.json\n> > @@ -412,5 +412,9 @@\n> >      \"rpi.sharpen\":\n> >      {\n> >\n> > +    },\n> > +    \"rpi.focus\":\n> > +    {\n> > +     \"print\": 1\n> >      }\n> >  }\n> > diff --git a/src/ipa/raspberrypi/meson.build b/src/ipa/raspberrypi/meson.build\n> > index 697902e9..9445cd09 100644\n> > --- a/src/ipa/raspberrypi/meson.build\n> > +++ b/src/ipa/raspberrypi/meson.build\n> > @@ -29,6 +29,7 @@ rpi_ipa_sources = files([\n> >      'controller/rpi/awb.cpp',\n> >      'controller/rpi/sharpen.cpp',\n> >      'controller/rpi/black_level.cpp',\n> > +    'controller/rpi/focus.cpp',\n> >      'controller/rpi/geq.cpp',\n> >      'controller/rpi/noise.cpp',\n> >      'controller/rpi/lux.cpp',\n>\n> --\n> Regards,\n>\n> Laurent Pinchart\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","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 4246DC0100\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 25 Jun 2020 07:29:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0C991609B3;\n\tThu, 25 Jun 2020 09:29:14 +0200 (CEST)","from mail-ot1-x341.google.com (mail-ot1-x341.google.com\n\t[IPv6:2607:f8b0:4864:20::341])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 01DE4609A3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Jun 2020 09:29:13 +0200 (CEST)","by mail-ot1-x341.google.com with SMTP id 64so4368932oti.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Jun 2020 00:29:12 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"eXtgCJwX\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=x8ipmh31f6y7rl8uXUhO3lExZNBtjg4sRQyHPhohDxI=;\n\tb=eXtgCJwXCkBlXtmBiBcXO0DdR3ECj6Yc5P3BdKkGaT5MALsmXGRL49Y7MNJ5RGv9Fh\n\tKEZFLqP8GBmiatlUZPQPV4ubbdkacBHLgIzHumMDBlwCIrxr5KvoI3yX/J9jSFFG3WcB\n\tgkhPat5AMklqpYsCSRJ4p5qwDZhrOgGPDCFmeYHwkefU1f0JGZOUCxEZxkB5XC1RQ+ay\n\tWIWrhIs3ApQ5f3/jTvOhcjFKC7jCSagmTQFRm81Bad5TeNRqiwE6PuCz6ApBivdnlRuO\n\ts5ZtFhR+JHN3+mbXsmJvEJAgDAC+lw+G/KlmV7Q6eAlrcMnxxAP5LQoH8W2Oo0x8YqXZ\n\tL5FQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=x8ipmh31f6y7rl8uXUhO3lExZNBtjg4sRQyHPhohDxI=;\n\tb=saXf+U6en0asrCFH9dItuMKQ08D/0XTLkwuViF/NfEs/YUVrKy7J4EIXC43EJ7Bb+0\n\t6DqLx7yVUEQMV89rTeXeKZmeEvKYvTtHg025hVpjEzsFdyNMg7qfSd/JLLAnP5rEd+L7\n\t/ml/N/1jAdAUkWY1gG7UbbiVPF1dcdr2wYlgsTgOzLR3o+FBQINVxGg8RYbrcFM0+E5O\n\tNMQjsuFvtjmuFPmLv/6+jse6UlmtESgI7suYGzbqwtsUtLRVrh7+ZOs4w8ONf/Xqe9mU\n\tlmzfDFGiPTGpnReZB+lA6Mt75hkD+aTJiE4oVEaqQA69LVjNGkrRSmaZ+wTqhO07aynw\n\twqzg==","X-Gm-Message-State":"AOAM5336ByOt+E3DEFEEiDlx9xCcfd8KGTJ3PwRbZXdV6u3gvvRA43lF\n\t8Uk9kBOrCKmI8XVNVWijcyhAde8aTiNWtUGNP1Hjpw==","X-Google-Smtp-Source":"ABdhPJyZ4Ed42Zt035x9z/Lp+Dj3NdBKO6nyiJLFCG2LsnGfkL4S+yboYsLfY54sQHiKw0oV8s/XFfY+J7IERbzE5LQ=","X-Received":"by 2002:a9d:4813:: with SMTP id\n\tc19mr26849469otf.317.1593070151857; \n\tThu, 25 Jun 2020 00:29:11 -0700 (PDT)","MIME-Version":"1.0","References":"<20200528145132.96102-1-naush@raspberrypi.com>\n\t<20200625034605.GI5980@pendragon.ideasonboard.com>","In-Reply-To":"<20200625034605.GI5980@pendragon.ideasonboard.com>","From":"David Plowman <david.plowman@raspberrypi.com>","Date":"Thu, 25 Jun 2020 08:29:01 +0100","Message-ID":"<CAHW6GYKPmojpPiVcD0D-GFsvDrxbN5JDCaJcSwujrUWO0NKntg@mail.gmail.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: Add \"focus\" algorithm","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":10861,"web_url":"https://patchwork.libcamera.org/comment/10861/","msgid":"<ff3c119e-422f-21d6-6a36-2d3872bcdb01@ideasonboard.com>","date":"2020-06-25T16:27:32","subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: Add \"focus\" algorithm","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi David, Naush,\n\nOn 28/05/2020 15:51, Naushir Patuck wrote:\n> From: David Plowman <david.plowman@raspberrypi.com>\n> \n> Adds FocusStatus to the image metadata, containing contrast measurements\n> across the image. Optionally also prints a contrast measure to the\n> console, to aid in manual adjustment of the lens. Note that it is not an\n> actual auto-focus algorithm that can drive a lens!\n> \n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  src/ipa/raspberrypi/controller/focus_status.h | 26 ++++++++++\n>  src/ipa/raspberrypi/controller/rpi/focus.cpp  | 51 +++++++++++++++++++\n>  src/ipa/raspberrypi/controller/rpi/focus.hpp  | 31 +++++++++++\n>  src/ipa/raspberrypi/data/imx477.json          |  4 ++\n>  src/ipa/raspberrypi/meson.build               |  1 +\n>  5 files changed, 113 insertions(+)\n>  create mode 100644 src/ipa/raspberrypi/controller/focus_status.h\n>  create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.cpp\n>  create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.hpp\n> \n> diff --git a/src/ipa/raspberrypi/controller/focus_status.h b/src/ipa/raspberrypi/controller/focus_status.h\n> new file mode 100644\n> index 00000000..3ad88777\n> --- /dev/null\n> +++ b/src/ipa/raspberrypi/controller/focus_status.h\n> @@ -0,0 +1,26 @@\n> +/* SPDX-License-Identifier: BSD-2-Clause */\n> +/*\n> + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> + *\n> + * focus_status.h - focus measurement status\n> + */\n> +#pragma once\n> +\n> +#include <linux/bcm2835-isp.h>\n> +\n> +// The focus algorithm should post the following structure into the image's\n> +// \"focus.status\" metadata. Recall that it's only reporting focus (contrast)\n> +// measurements, it's not driving any kind of auto-focus algorithm!\n> +\n> +#ifdef __cplusplus\n> +extern \"C\" {\n> +#endif\n> +\n> +struct FocusStatus {\n> +\tint num;\n> +\tuint32_t focus_measures[FOCUS_REGIONS];\n> +};\n> +\n> +#ifdef __cplusplus\n> +}\n> +#endif\n> diff --git a/src/ipa/raspberrypi/controller/rpi/focus.cpp b/src/ipa/raspberrypi/controller/rpi/focus.cpp\n> new file mode 100644\n> index 00000000..d6cdc4bf\n> --- /dev/null\n> +++ b/src/ipa/raspberrypi/controller/rpi/focus.cpp\n> @@ -0,0 +1,51 @@\n> +/* SPDX-License-Identifier: BSD-2-Clause */\n> +/*\n> + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> + *\n> + * focus.cpp - focus algorithm\n> + */\n> +#include <stdint.h>\n> +\n> +#include \"../focus_status.h\"\n> +#include \"../logging.hpp\"\n> +#include \"focus.hpp\"\n> +\n> +using namespace RPi;\n> +\n> +#define NAME \"rpi.focus\"\n> +\n> +Focus::Focus(Controller *controller)\n> +\t: Algorithm(controller)\n> +{\n> +}\n> +\n> +char const *Focus::Name() const\n> +{\n> +\treturn NAME;\n> +}\n> +\n> +void Focus::Read(boost::property_tree::ptree const &params)\n> +{\n> +\tprint_ = params.get<int>(\"print\", 0);\n> +}\n> +\n> +void Focus::Process(StatisticsPtr &stats, Metadata *image_metadata)\n> +{\n> +\tFocusStatus status;\n> +\tint i;\n> +\tfor (i = 0; i < FOCUS_REGIONS; i++)\n> +\t\tstatus.focus_measures[i] = stats->focus_stats[i].contrast_val[1][1] / 1000;\n> +\tstatus.num = i;\n> +\timage_metadata->Set(\"focus.status\", status);\n> +\tif (print_) {\n> +\t\tuint32_t value = (status.focus_measures[5] + status.focus_measures[6]) / 10;\n> +\t\tRPI_LOG(\"Focus contrast measure: \" << value);\n> +\t}\n> +}\n> +\n> +/* Register algorithm with the system. */\n> +static Algorithm *Create(Controller *controller)\n> +{\n> +\treturn new Focus(controller);\n> +}\n> +static RegisterAlgorithm reg(NAME, &Create);\n> diff --git a/src/ipa/raspberrypi/controller/rpi/focus.hpp b/src/ipa/raspberrypi/controller/rpi/focus.hpp\n> new file mode 100644\n> index 00000000..d53401f7\n> --- /dev/null\n> +++ b/src/ipa/raspberrypi/controller/rpi/focus.hpp\n> @@ -0,0 +1,31 @@\n> +/* SPDX-License-Identifier: BSD-2-Clause */\n> +/*\n> + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> + *\n> + * focus.hpp - focus algorithm\n> + */\n> +#pragma once\n> +\n> +#include \"../algorithm.hpp\"\n> +#include \"../metadata.hpp\"\n> +\n> +/*\n> + * The \"focus\" algorithm. All it does it print out a version of the\n> + * focus contrast measure; there is no actual auto-focus mechanism to\n> + * control.\n> + */\n> +\n> +namespace RPi {\n> +\n> +class Focus : public Algorithm\n> +{\n> +public:\n> +\tFocus(Controller *controller);\n> +\tchar const *Name() const override;\n> +\tvoid Read(boost::property_tree::ptree const &params) override;\n> +\tvoid Process(StatisticsPtr &stats, Metadata *image_metadata) override;\n> +private:\n> +\tbool print_;\n\nThis introduces the following coverity warning:\n\n\n** CID 293456:  Uninitialized members  (UNINIT_CTOR)\n/home/linuxembedded/iob/libcamera/libcamera-daily/src/ipa/raspberrypi/controller/rpi/focus.cpp:\n20 in RPi::Focus::Focus(RPi::Controller *)()","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 447BDC0100\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 25 Jun 2020 16:27:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B6D45609C7;\n\tThu, 25 Jun 2020 18:27:37 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3ED6F609A5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 25 Jun 2020 18:27:36 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id B2E1E72E;\n\tThu, 25 Jun 2020 18:27:35 +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=\"t6f6mTam\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593102455;\n\tbh=SLaxJHMLbHQiAJkaFl8yXX3x1gZGnL4R6iWeOoyIzs0=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=t6f6mTamjMd1wfDJHU+sCAzesAnwD7V5ggV0scGRee5l1AVo4rH+CccoTFGLHO3YR\n\tlIkaleuwh500XF1cR6Kv4jW9SlAVoN1pJN89SnX35lmB5pbpoNmqoHoYRbhZYOOOg6\n\tF5gukEqL36azTGRn2VBcXZNXqja3i0nz3AG11e2Q=","To":"Naushir Patuck <naush@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20200528145132.96102-1-naush@raspberrypi.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8\n\tRXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko\n\tlPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+XoAN0w5Eqo4t6qEVbuettxx55gq\n\t8K8FieAjgjMSxngo/HST8TpFeqI5nVeq0/lqtBRQKumuIqDg+Bkr4L1V/P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atCHUXOboUsn54qdxrVDaK+6jIAuo8JiRWctP16KjzUM7MO0/+4zllM8EY57rXrj48j\n\tsbEYX0YQnzaj+jO6kJtoZsIaYR7rMMq9aUAjyiaEZpmP1qF/2sYenDx0Fg2BSlLvLvXM0vU8\n\tpQk3kgDu7kb/7PRYrZvBsr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXc\n\tMW8zs8avFNuA9VpXt0YupJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPU\n\tAfYnB4JBDLmLzBFavQfvonSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<ff3c119e-422f-21d6-6a36-2d3872bcdb01@ideasonboard.com>","Date":"Thu, 25 Jun 2020 17:27:32 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101\n\tThunderbird/68.8.0","MIME-Version":"1.0","In-Reply-To":"<20200528145132.96102-1-naush@raspberrypi.com>","Content-Language":"en-GB","Subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: Add \"focus\" algorithm","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>","Reply-To":"kieran.bingham@ideasonboard.com","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":10882,"web_url":"https://patchwork.libcamera.org/comment/10882/","msgid":"<CAEmqJPo_3Yd0vMKpmQsZiAgLGVCfKgFsxpPYenzKdtKwpRv1oA@mail.gmail.com>","date":"2020-06-26T07:33:25","subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: Add \"focus\" algorithm","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Kieran,\n\nOn Thu, 25 Jun 2020 at 17:27, Kieran Bingham\n<kieran.bingham@ideasonboard.com> wrote:\n>\n> Hi David, Naush,\n>\n> On 28/05/2020 15:51, Naushir Patuck wrote:\n> > From: David Plowman <david.plowman@raspberrypi.com>\n> >\n> > Adds FocusStatus to the image metadata, containing contrast measurements\n> > across the image. Optionally also prints a contrast measure to the\n> > console, to aid in manual adjustment of the lens. Note that it is not an\n> > actual auto-focus algorithm that can drive a lens!\n> >\n> > Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n> > Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> > ---\n> >  src/ipa/raspberrypi/controller/focus_status.h | 26 ++++++++++\n> >  src/ipa/raspberrypi/controller/rpi/focus.cpp  | 51 +++++++++++++++++++\n> >  src/ipa/raspberrypi/controller/rpi/focus.hpp  | 31 +++++++++++\n> >  src/ipa/raspberrypi/data/imx477.json          |  4 ++\n> >  src/ipa/raspberrypi/meson.build               |  1 +\n> >  5 files changed, 113 insertions(+)\n> >  create mode 100644 src/ipa/raspberrypi/controller/focus_status.h\n> >  create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.cpp\n> >  create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.hpp\n> >\n> > diff --git a/src/ipa/raspberrypi/controller/focus_status.h b/src/ipa/raspberrypi/controller/focus_status.h\n> > new file mode 100644\n> > index 00000000..3ad88777\n> > --- /dev/null\n> > +++ b/src/ipa/raspberrypi/controller/focus_status.h\n> > @@ -0,0 +1,26 @@\n> > +/* SPDX-License-Identifier: BSD-2-Clause */\n> > +/*\n> > + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> > + *\n> > + * focus_status.h - focus measurement status\n> > + */\n> > +#pragma once\n> > +\n> > +#include <linux/bcm2835-isp.h>\n> > +\n> > +// The focus algorithm should post the following structure into the image's\n> > +// \"focus.status\" metadata. Recall that it's only reporting focus (contrast)\n> > +// measurements, it's not driving any kind of auto-focus algorithm!\n> > +\n> > +#ifdef __cplusplus\n> > +extern \"C\" {\n> > +#endif\n> > +\n> > +struct FocusStatus {\n> > +     int num;\n> > +     uint32_t focus_measures[FOCUS_REGIONS];\n> > +};\n> > +\n> > +#ifdef __cplusplus\n> > +}\n> > +#endif\n> > diff --git a/src/ipa/raspberrypi/controller/rpi/focus.cpp b/src/ipa/raspberrypi/controller/rpi/focus.cpp\n> > new file mode 100644\n> > index 00000000..d6cdc4bf\n> > --- /dev/null\n> > +++ b/src/ipa/raspberrypi/controller/rpi/focus.cpp\n> > @@ -0,0 +1,51 @@\n> > +/* SPDX-License-Identifier: BSD-2-Clause */\n> > +/*\n> > + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> > + *\n> > + * focus.cpp - focus algorithm\n> > + */\n> > +#include <stdint.h>\n> > +\n> > +#include \"../focus_status.h\"\n> > +#include \"../logging.hpp\"\n> > +#include \"focus.hpp\"\n> > +\n> > +using namespace RPi;\n> > +\n> > +#define NAME \"rpi.focus\"\n> > +\n> > +Focus::Focus(Controller *controller)\n> > +     : Algorithm(controller)\n> > +{\n> > +}\n> > +\n> > +char const *Focus::Name() const\n> > +{\n> > +     return NAME;\n> > +}\n> > +\n> > +void Focus::Read(boost::property_tree::ptree const &params)\n> > +{\n> > +     print_ = params.get<int>(\"print\", 0);\n> > +}\n> > +\n> > +void Focus::Process(StatisticsPtr &stats, Metadata *image_metadata)\n> > +{\n> > +     FocusStatus status;\n> > +     int i;\n> > +     for (i = 0; i < FOCUS_REGIONS; i++)\n> > +             status.focus_measures[i] = stats->focus_stats[i].contrast_val[1][1] / 1000;\n> > +     status.num = i;\n> > +     image_metadata->Set(\"focus.status\", status);\n> > +     if (print_) {\n> > +             uint32_t value = (status.focus_measures[5] + status.focus_measures[6]) / 10;\n> > +             RPI_LOG(\"Focus contrast measure: \" << value);\n> > +     }\n> > +}\n> > +\n> > +/* Register algorithm with the system. */\n> > +static Algorithm *Create(Controller *controller)\n> > +{\n> > +     return new Focus(controller);\n> > +}\n> > +static RegisterAlgorithm reg(NAME, &Create);\n> > diff --git a/src/ipa/raspberrypi/controller/rpi/focus.hpp b/src/ipa/raspberrypi/controller/rpi/focus.hpp\n> > new file mode 100644\n> > index 00000000..d53401f7\n> > --- /dev/null\n> > +++ b/src/ipa/raspberrypi/controller/rpi/focus.hpp\n> > @@ -0,0 +1,31 @@\n> > +/* SPDX-License-Identifier: BSD-2-Clause */\n> > +/*\n> > + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n> > + *\n> > + * focus.hpp - focus algorithm\n> > + */\n> > +#pragma once\n> > +\n> > +#include \"../algorithm.hpp\"\n> > +#include \"../metadata.hpp\"\n> > +\n> > +/*\n> > + * The \"focus\" algorithm. All it does it print out a version of the\n> > + * focus contrast measure; there is no actual auto-focus mechanism to\n> > + * control.\n> > + */\n> > +\n> > +namespace RPi {\n> > +\n> > +class Focus : public Algorithm\n> > +{\n> > +public:\n> > +     Focus(Controller *controller);\n> > +     char const *Name() const override;\n> > +     void Read(boost::property_tree::ptree const &params) override;\n> > +     void Process(StatisticsPtr &stats, Metadata *image_metadata) override;\n> > +private:\n> > +     bool print_;\n>\n> This introduces the following coverity warning:\n>\n>\n> ** CID 293456:  Uninitialized members  (UNINIT_CTOR)\n> /home/linuxembedded/iob/libcamera/libcamera-daily/src/ipa/raspberrypi/controller/rpi/focus.cpp:\n> 20 in RPi::Focus::Focus(RPi::Controller *)()\n>\n>\n> ________________________________________________________________________________________________________\n> *** CID 293456:  Uninitialized members  (UNINIT_CTOR)\n> /home/linuxembedded/iob/libcamera/libcamera-daily/src/ipa/raspberrypi/controller/rpi/focus.cpp:\n> 20 in RPi::Focus::Focus(RPi::Controller *)()\n> 14\n> 15     #define NAME \"rpi.focus\"\n> 16\n> 17     Focus::Focus(Controller *controller)\n> 18      : Algorithm(controller)\n> 19     {\n> >>>     CID 293456:  Uninitialized members  (UNINIT_CTOR)\n> >>>     Non-static class member \"print_\" is not initialized in this\n> constructor nor in any functions that it calls.\n> 20     }\n> 21\n> 22     char const *Focus::Name() const\n> 23     {\n> 24      return NAME;\n> 25     }\n>\n> If you supply a patch to fix, please add the tag:\n>\n> Reported-by: Coverity CID=293456\n>\n>\n> Alternatively, if you believe it's a false positive and should not be\n> fixed, let me know and I'll mark it as such to close the issue.\n>\n\nThanks for the heads-up.  This is not actually a problem, as\nFocus::Read() initialises print_ and is always called before\nfocus::process().  Not surprisingly, Coverity did not spot that.  I'll\nput in an explicit initialiser to fix the defect.  I'm about to push a\nset of patches for focus, so I'll add the fix to that.\n\nRegards,\nNaush","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 A0E83C2E65\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 26 Jun 2020 07:33:44 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 34F95609C8;\n\tFri, 26 Jun 2020 09:33:44 +0200 (CEST)","from mail-lj1-x243.google.com (mail-lj1-x243.google.com\n\t[IPv6:2a00:1450:4864:20::243])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 93FB5603B6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 26 Jun 2020 09:33:42 +0200 (CEST)","by mail-lj1-x243.google.com with SMTP id s9so9237064ljm.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 26 Jun 2020 00:33:42 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"C7vD/OTg\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=Rv9Q7jW+7sus2jHyxQJt90BS3X01M1O0TPMt4jBOL+Y=;\n\tb=C7vD/OTgL78BlR20H1HiaVGxsWK8AM8bO1rRXzfoCowYpsKexCge7FvU0fKMxPAUjA\n\t+D9MDGkH+a5jeKjk4kR7AzqJs8rOzXcnjO6jLpIufRdezxM537/UBJwaKx0oSjOYy2FJ\n\t65PQ7V2NzghPP19c1e/ljFi9F6zy6UVCNm4Y0zM+JYcmQJr0B2BZbOOcEnaijeFlTkd8\n\trCoHr2bT1CocyZ9TbIV1Du3MtMGTFVkOelO1jnt3FxjTYCRCst5IQYk2PEsARH0iE7pk\n\tSmGqwZe1jodcMKqv5Y3mitZH2Vy3SuoCkR51ejBVAbO3ryqgsH37MMKXEtRvEKRD0g+v\n\tutNQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=Rv9Q7jW+7sus2jHyxQJt90BS3X01M1O0TPMt4jBOL+Y=;\n\tb=oRkfllqBDey2kVsY8OZwDEOUMUG1uqOMEsN+KNx03CVwKXdIpsmOSF1xWjNxWWwtSb\n\tib/wH9+K1l5Oo6ZTpbvHf95DOtYuH4tZU0r69EnLB2Hr2rrCyu+L4QZWgNkcKrCmw1Wd\n\tNIJM2WprDEMGlyxRUbST3Cz7FlnerJH9H5tUP12YsMtPcVfhE5O3rFHGs8i6jWP24bCB\n\tSWb+T/4MkDsTXPqgLOxE7rjNrIlif6K3x/8yAFT8X0nCoUD32Y5ZLi2WECfmsqkdVJks\n\twwP/O1ySA/xfx1Ctsou6csVE25h5nMgDOUxRHVFFKHH0i0cvALI0IpryzkM3+z8W3Pcl\n\tLHgw==","X-Gm-Message-State":"AOAM531bFlmQ9tHtpBAYA3G9/kdw3wIYeLCr+/4QipA9OR3QC+HwVHR5\n\teBRLJQSXczu1x3BCF+eW94h/B5J9YmRGiKeDgKO8KQ==","X-Google-Smtp-Source":"ABdhPJzCLoFWm7/RfW8P+qNTVDLtCtTy5i6jpQjhsjBPj24mTbYtTyRxk7fUVBINBSN24Pv3hK+McJe0NC2uO+lW+AA=","X-Received":"by 2002:a2e:a30f:: with SMTP id l15mr779187lje.228.1593156821768;\n\tFri, 26 Jun 2020 00:33:41 -0700 (PDT)","MIME-Version":"1.0","References":"<20200528145132.96102-1-naush@raspberrypi.com>\n\t<ff3c119e-422f-21d6-6a36-2d3872bcdb01@ideasonboard.com>","In-Reply-To":"<ff3c119e-422f-21d6-6a36-2d3872bcdb01@ideasonboard.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Fri, 26 Jun 2020 08:33:25 +0100","Message-ID":"<CAEmqJPo_3Yd0vMKpmQsZiAgLGVCfKgFsxpPYenzKdtKwpRv1oA@mail.gmail.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: Add \"focus\" algorithm","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":10885,"web_url":"https://patchwork.libcamera.org/comment/10885/","msgid":"<60fa6a15-20c0-24dc-3664-39441b4464f0@ideasonboard.com>","date":"2020-06-26T08:23:49","subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: Add \"focus\" algorithm","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Naush,\n\nOn 26/06/2020 08:33, Naushir Patuck wrote:\n> Hi Kieran,\n> \n> On Thu, 25 Jun 2020 at 17:27, Kieran Bingham\n> <kieran.bingham@ideasonboard.com> wrote:\n>>\n>> Hi David, Naush,\n>>\n>> On 28/05/2020 15:51, Naushir Patuck wrote:\n>>> From: David Plowman <david.plowman@raspberrypi.com>\n>>>\n>>> Adds FocusStatus to the image metadata, containing contrast measurements\n>>> across the image. Optionally also prints a contrast measure to the\n>>> console, to aid in manual adjustment of the lens. Note that it is not an\n>>> actual auto-focus algorithm that can drive a lens!\n>>>\n>>> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n>>> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n>>> ---\n>>>  src/ipa/raspberrypi/controller/focus_status.h | 26 ++++++++++\n>>>  src/ipa/raspberrypi/controller/rpi/focus.cpp  | 51 +++++++++++++++++++\n>>>  src/ipa/raspberrypi/controller/rpi/focus.hpp  | 31 +++++++++++\n>>>  src/ipa/raspberrypi/data/imx477.json          |  4 ++\n>>>  src/ipa/raspberrypi/meson.build               |  1 +\n>>>  5 files changed, 113 insertions(+)\n>>>  create mode 100644 src/ipa/raspberrypi/controller/focus_status.h\n>>>  create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.cpp\n>>>  create mode 100644 src/ipa/raspberrypi/controller/rpi/focus.hpp\n>>>\n>>> diff --git a/src/ipa/raspberrypi/controller/focus_status.h b/src/ipa/raspberrypi/controller/focus_status.h\n>>> new file mode 100644\n>>> index 00000000..3ad88777\n>>> --- /dev/null\n>>> +++ b/src/ipa/raspberrypi/controller/focus_status.h\n>>> @@ -0,0 +1,26 @@\n>>> +/* SPDX-License-Identifier: BSD-2-Clause */\n>>> +/*\n>>> + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n>>> + *\n>>> + * focus_status.h - focus measurement status\n>>> + */\n>>> +#pragma once\n>>> +\n>>> +#include <linux/bcm2835-isp.h>\n>>> +\n>>> +// The focus algorithm should post the following structure into the image's\n>>> +// \"focus.status\" metadata. Recall that it's only reporting focus (contrast)\n>>> +// measurements, it's not driving any kind of auto-focus algorithm!\n>>> +\n>>> +#ifdef __cplusplus\n>>> +extern \"C\" {\n>>> +#endif\n>>> +\n>>> +struct FocusStatus {\n>>> +     int num;\n>>> +     uint32_t focus_measures[FOCUS_REGIONS];\n>>> +};\n>>> +\n>>> +#ifdef __cplusplus\n>>> +}\n>>> +#endif\n>>> diff --git a/src/ipa/raspberrypi/controller/rpi/focus.cpp b/src/ipa/raspberrypi/controller/rpi/focus.cpp\n>>> new file mode 100644\n>>> index 00000000..d6cdc4bf\n>>> --- /dev/null\n>>> +++ b/src/ipa/raspberrypi/controller/rpi/focus.cpp\n>>> @@ -0,0 +1,51 @@\n>>> +/* SPDX-License-Identifier: BSD-2-Clause */\n>>> +/*\n>>> + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n>>> + *\n>>> + * focus.cpp - focus algorithm\n>>> + */\n>>> +#include <stdint.h>\n>>> +\n>>> +#include \"../focus_status.h\"\n>>> +#include \"../logging.hpp\"\n>>> +#include \"focus.hpp\"\n>>> +\n>>> +using namespace RPi;\n>>> +\n>>> +#define NAME \"rpi.focus\"\n>>> +\n>>> +Focus::Focus(Controller *controller)\n>>> +     : Algorithm(controller)\n>>> +{\n>>> +}\n>>> +\n>>> +char const *Focus::Name() const\n>>> +{\n>>> +     return NAME;\n>>> +}\n>>> +\n>>> +void Focus::Read(boost::property_tree::ptree const &params)\n>>> +{\n>>> +     print_ = params.get<int>(\"print\", 0);\n>>> +}\n>>> +\n>>> +void Focus::Process(StatisticsPtr &stats, Metadata *image_metadata)\n>>> +{\n>>> +     FocusStatus status;\n>>> +     int i;\n>>> +     for (i = 0; i < FOCUS_REGIONS; i++)\n>>> +             status.focus_measures[i] = stats->focus_stats[i].contrast_val[1][1] / 1000;\n>>> +     status.num = i;\n>>> +     image_metadata->Set(\"focus.status\", status);\n>>> +     if (print_) {\n>>> +             uint32_t value = (status.focus_measures[5] + status.focus_measures[6]) / 10;\n>>> +             RPI_LOG(\"Focus contrast measure: \" << value);\n>>> +     }\n>>> +}\n>>> +\n>>> +/* Register algorithm with the system. */\n>>> +static Algorithm *Create(Controller *controller)\n>>> +{\n>>> +     return new Focus(controller);\n>>> +}\n>>> +static RegisterAlgorithm reg(NAME, &Create);\n>>> diff --git a/src/ipa/raspberrypi/controller/rpi/focus.hpp b/src/ipa/raspberrypi/controller/rpi/focus.hpp\n>>> new file mode 100644\n>>> index 00000000..d53401f7\n>>> --- /dev/null\n>>> +++ b/src/ipa/raspberrypi/controller/rpi/focus.hpp\n>>> @@ -0,0 +1,31 @@\n>>> +/* SPDX-License-Identifier: BSD-2-Clause */\n>>> +/*\n>>> + * Copyright (C) 2020, Raspberry Pi (Trading) Limited\n>>> + *\n>>> + * focus.hpp - focus algorithm\n>>> + */\n>>> +#pragma once\n>>> +\n>>> +#include \"../algorithm.hpp\"\n>>> +#include \"../metadata.hpp\"\n>>> +\n>>> +/*\n>>> + * The \"focus\" algorithm. All it does it print out a version of the\n>>> + * focus contrast measure; there is no actual auto-focus mechanism to\n>>> + * control.\n>>> + */\n>>> +\n>>> +namespace RPi {\n>>> +\n>>> +class Focus : public Algorithm\n>>> +{\n>>> +public:\n>>> +     Focus(Controller *controller);\n>>> +     char const *Name() const override;\n>>> +     void Read(boost::property_tree::ptree const &params) override;\n>>> +     void Process(StatisticsPtr &stats, Metadata *image_metadata) override;\n>>> +private:\n>>> +     bool print_;\n>>\n>> This introduces the following coverity warning:\n>>\n>>\n>> ** CID 293456:  Uninitialized members  (UNINIT_CTOR)\n>> /home/linuxembedded/iob/libcamera/libcamera-daily/src/ipa/raspberrypi/controller/rpi/focus.cpp:\n>> 20 in RPi::Focus::Focus(RPi::Controller *)()\n>>\n>>\n>> ________________________________________________________________________________________________________\n>> *** CID 293456:  Uninitialized members  (UNINIT_CTOR)\n>> /home/linuxembedded/iob/libcamera/libcamera-daily/src/ipa/raspberrypi/controller/rpi/focus.cpp:\n>> 20 in RPi::Focus::Focus(RPi::Controller *)()\n>> 14\n>> 15     #define NAME \"rpi.focus\"\n>> 16\n>> 17     Focus::Focus(Controller *controller)\n>> 18      : Algorithm(controller)\n>> 19     {\n>>>>>     CID 293456:  Uninitialized members  (UNINIT_CTOR)\n>>>>>     Non-static class member \"print_\" is not initialized in this\n>> constructor nor in any functions that it calls.\n>> 20     }\n>> 21\n>> 22     char const *Focus::Name() const\n>> 23     {\n>> 24      return NAME;\n>> 25     }\n>>\n>> If you supply a patch to fix, please add the tag:\n>>\n>> Reported-by: Coverity CID=293456\n>>\n>>\n>> Alternatively, if you believe it's a false positive and should not be\n>> fixed, let me know and I'll mark it as such to close the issue.\n>>\n> \n> Thanks for the heads-up.  This is not actually a problem, as\n> Focus::Read() initialises print_ and is always called before\n> focus::process().  Not surprisingly, Coverity did not spot that.  I'll\n> put in an explicit initialiser to fix the defect.  I'm about to push a\n> set of patches for focus, so I'll add the fix to that.\n\nIndeed, coverity does pick up a few false positives, particularly around\nthese where it can't determine the execution order, so in those cases\nI'll just close them if the submitter choses.\n\nCoverity runs on a daily cron job, but only on the master branch, so\nI'll just send these reports manually until I can figure out how to\nautomate it ;-)\n\nIf you'd like an account to see the results, either sign up at\n\thttps://scan.coverity.com/projects/libcamera\n\nor let me know and I can manually 'invite'.\n\nIdeally, we'll get some 'pre-integration' tests running so that we can\ncatch things before they get merged too, but baby steps for now ... ;-)\n\n\n--\nKieran","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 6818BC0109\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 26 Jun 2020 08:23:54 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 389E6609C6;\n\tFri, 26 Jun 2020 10:23:54 +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 9EA6E609C2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 26 Jun 2020 10:23:52 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 0C5BC72E;\n\tFri, 26 Jun 2020 10:23:52 +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=\"kZuHopjA\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1593159832;\n\tbh=YoZpQcHtI5iAItEkZJVJvbJD8TPGjLTwQ+el90Kj/Us=;\n\th=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From;\n\tb=kZuHopjAbKlmk9/xh7Z0Xgc6A+fetFUsToe5e/QWt5CDj7zlYdiog5rJLrhYskxbr\n\twSUyvH1OKDEGyHsSujFPdA+F81BT6Z74znJ5uV83kk0k9shWmMPLGndXBdLEPh6ITy\n\tCMEK+xrSM2MmdA+05RvmZ8G0cf7Nymgj8oZ8x704=","To":"Naushir Patuck <naush@raspberrypi.com>","References":"<20200528145132.96102-1-naush@raspberrypi.com>\n\t<ff3c119e-422f-21d6-6a36-2d3872bcdb01@ideasonboard.com>\n\t<CAEmqJPo_3Yd0vMKpmQsZiAgLGVCfKgFsxpPYenzKdtKwpRv1oA@mail.gmail.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMOfMwdS+4SNw4rY9f07Xb2K99rjMwZVDgESKIzhsDB5GY465sCsiQ\n\tcSAZRxqE49RTBq2+EQsbrQpIc8XiffAB8qexh5/QPzCmR4kJgCGeHIXBtgRj+nIkCJPZvZtf\n\tKr2EAbc6tgg6DkAEHJb+1okosV09+0+TXywYvtEop/WUOWQ+zo+Y/OBd+8Ptgt1pDRyOBzL8\n\tRXa8ZqRf0Mwg75D+dKntZeJHzPRJyrlfQokngAAs4PaFt6UfS+ypMAF37T6CeDArQC41V3ko\n\tlPn1yMsVD0p+6i3DPvA/GPIksDC4owjnzVX9kM8Zc5Cx+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Up\n\tECzuuRBv8wX4OQl+hbWbB/VKIx5HKlLu1eypen/5lNVzSqMMIYkkZcjV2SWQyUGxSwq0O/sx\n\tS0A8/atCHUXOboUsn54qdxrVDaK+6jIAuo8JiRWctP16KjzUM7MO0/+4zllM8EY57rXrj48j\n\tsbEYX0YQnzaj+jO6kJtoZsIaYR7rMMq9aUAjyiaEZpmP1qF/2sYenDx0Fg2BSlLvLvXM0vU8\n\tpQk3kgDu7kb/7PRYrZvBsr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXc\n\tMW8zs8avFNuA9VpXt0YupJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPU\n\tAfYnB4JBDLmLzBFavQfvonSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<60fa6a15-20c0-24dc-3664-39441b4464f0@ideasonboard.com>","Date":"Fri, 26 Jun 2020 09:23:49 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101\n\tThunderbird/68.8.0","MIME-Version":"1.0","In-Reply-To":"<CAEmqJPo_3Yd0vMKpmQsZiAgLGVCfKgFsxpPYenzKdtKwpRv1oA@mail.gmail.com>","Content-Language":"en-GB","Subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: Add \"focus\" algorithm","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>","Reply-To":"kieran.bingham@ideasonboard.com","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>"}}]