Patch Detail
Show a patch.
GET /api/1.1/patches/14748/?format=api
{ "id": 14748, "url": "https://patchwork.libcamera.org/api/1.1/patches/14748/?format=api", "web_url": "https://patchwork.libcamera.org/patch/14748/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20211124103447.102069-2-hpa@redhat.com>", "date": "2021-11-24T10:34:47", "name": "[libcamera-devel,RFC,v2,1/1] ipa: ipu3: af: Auto focus for dw9719 Surface Go2 VCM", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "b43344a0c387cba771bd4e71da61cd23976cdbc5", "submitter": { "id": 105, "url": "https://patchwork.libcamera.org/api/1.1/people/105/?format=api", "name": "Kate Hsuan", "email": "hpa@redhat.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/14748/mbox/", "series": [ { "id": 2750, "url": "https://patchwork.libcamera.org/api/1.1/series/2750/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2750", "date": "2021-11-24T10:34:46", "name": "ipa: ipu3: af: Auto focus for dw9719 Surface Go2 VCM", "version": 2, "mbox": "https://patchwork.libcamera.org/series/2750/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/14748/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/14748/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 7EDB2BF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 24 Nov 2021 10:35:35 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2ED1460233;\n\tWed, 24 Nov 2021 11:35:35 +0100 (CET)", "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 12A1D6022F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Nov 2021 11:35:32 +0100 (CET)", "from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com\n\t[209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n\tus-mta-587-h0S3v6bqMg2KLmApvJ7oVQ-1; Wed, 24 Nov 2021 05:35:26 -0500", "from smtp.corp.redhat.com\n\t(int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4E5C3100E320\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 24 Nov 2021 10:35:25 +0000 (UTC)", "from fedora.redhat.com (unknown [10.39.195.110])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 2B9EC100EBBF;\n\tWed, 24 Nov 2021 10:35:20 +0000 (UTC)" ], "Authentication-Results": [ "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"LN9EdhZj\"; dkim-atps=neutral", "relay.mimecast.com;\n\tauth=pass smtp.auth=CUSA124A263 smtp.mailfrom=hpa@redhat.com" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1637750131;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=CoeVZNcI43sAgIYsoc/YNlmjnItajyqNOXyM5dCoJkQ=;\n\tb=LN9EdhZjlojfJ3NdIR3/pZOW5HWYc9KyN4x9YClxUzZE8YL19PECxcMxIvSPCiDiSPynxw\n\tSn3qTjixJMuVRq8uCT3OMbP3W9mfvCZB6RrGzrAJx/eLRDGNVV828qtM2XPbZq5e/oWdhw\n\t00YBmHLShXVBiIgNSzQ5HYwMdSPHYkA=", "X-MC-Unique": "h0S3v6bqMg2KLmApvJ7oVQ-1", "From": "Kate Hsuan <hpa@redhat.com>", "To": "libcamera devel <libcamera-devel@lists.libcamera.org>", "Date": "Wed, 24 Nov 2021 18:34:47 +0800", "Message-Id": "<20211124103447.102069-2-hpa@redhat.com>", "In-Reply-To": "<20211124103447.102069-1-hpa@redhat.com>", "References": "<20211124103447.102069-1-hpa@redhat.com>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 2.84 on 10.5.11.22", "X-Mimecast-Spam-Score": "0", "X-Mimecast-Originator": "redhat.com", "Content-Transfer-Encoding": "8bit", "Content-Type": "text/plain; charset=\"US-ASCII\"", "Subject": "[libcamera-devel] [RFC v2 1/1] ipa: ipu3: af: Auto focus for dw9719\n\tSurface Go2 VCM", "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>" }, "content": "Since VCM for surface Go 2 (dw9719) had been successfully\ndriven, this Af module can be used to control the VCM and\ndetermine the focus value based on the IPU3 AF state.\n\nThe variance of each focus step is determined and a greedy\napproah is used to find the maximum variance of the AF\nstate and a appropriate focus value.\n\nChanges since v2:\n1. Add grid configuration interface.\n2. Add AF accelerator configuration.\n3. Move default focus area to the center of the image.\n\nSigned-off-by: Kate Hsuan <hpa@redhat.com>\n---\n src/ipa/ipu3/algorithms/af.cpp | 284 ++++++++++++++++++++++++++++\n src/ipa/ipu3/algorithms/af.h | 54 ++++++\n src/ipa/ipu3/algorithms/agc.cpp | 2 +-\n src/ipa/ipu3/algorithms/meson.build | 3 +-\n src/ipa/ipu3/ipa_context.cpp | 26 +++\n src/ipa/ipu3/ipa_context.h | 11 ++\n src/ipa/ipu3/ipu3.cpp | 2 +\n 7 files changed, 380 insertions(+), 2 deletions(-)\n create mode 100644 src/ipa/ipu3/algorithms/af.cpp\n create mode 100644 src/ipa/ipu3/algorithms/af.h", "diff": "diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp\nnew file mode 100644\nindex 00000000..b0359721\n--- /dev/null\n+++ b/src/ipa/ipu3/algorithms/af.cpp\n@@ -0,0 +1,284 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Red Hat\n+ *\n+ * af.cpp - IPU3 auto focus control\n+ */\n+\n+#include \"af.h\"\n+\n+#include <algorithm>\n+#include <chrono>\n+#include <cmath>\n+#include <fcntl.h>\n+#include <numeric>\n+#include <sys/ioctl.h>\n+#include <sys/stat.h>\n+#include <sys/types.h>\n+#include <unistd.h>\n+\n+#include <linux/videodev2.h>\n+\n+#include <libcamera/base/log.h>\n+\n+#include <libcamera/ipa/core_ipa_interface.h>\n+\n+#include \"libipa/histogram.h\"\n+\n+/**\n+ * \\file af.h\n+ */\n+\n+namespace libcamera {\n+\n+using namespace std::literals::chrono_literals;\n+\n+namespace ipa::ipu3::algorithms {\n+\n+/**\n+ * \\class Af\n+ * \\brief A IPU3 auto-focus accelerator based auto focus algorthim\n+ *\n+ * This algorithm is used to determine the position of the lens and get a\n+ * focused image. The IPU3 AF accelerator computes the statistics, composed\n+ * by high pass and low pass filtered value and stores in a AF buffer.\n+ * Typically, for a focused image, it has relative high contrast than a\n+ * blurred image, i.e. an out of focus image. Therefore, if an image with the\n+ * highest contrast can be found from the AF scan, the lens' position is the\n+ * best step of the focus.\n+ *\n+ */\n+\n+LOG_DEFINE_CATEGORY(IPU3Af)\n+\n+/**\n+ * Maximum focus value of the VCM control\n+ * \\todo should be obtained from the VCM driver\n+ */\n+static constexpr uint32_t MaxFocusSteps_ = 1023;\n+\n+/* Minimum focus step for searching appropriate focus*/\n+static constexpr uint32_t MinSearchStep_ = 5;\n+\n+/* max ratio of variance change, 0.0 < MaxChange_ < 1.0*/\n+static constexpr double MaxChange_ = 0.8;\n+\n+Af::Af()\n+\t: focus_(0), currentVariance_(0.0)\n+{\n+\t/**\n+\t * For surface Go 2 back camera VCM (dw9719)\n+\t * \\todo move to control class\n+\t*/\n+\tvcmFd_ = open(\"/dev/v4l-subdev8\", O_RDWR);\n+}\n+\n+Af::~Af()\n+{\n+\tif (vcmFd_ != -1)\n+\t\tclose(vcmFd_);\n+}\n+\n+void Af::prepare(IPAContext &context, ipu3_uapi_params *params)\n+{\n+\t/* AF grid config */\n+\tparams->acc_param.af.grid_cfg.width = 16;\n+\tparams->acc_param.af.grid_cfg.height = 16;\n+\tparams->acc_param.af.grid_cfg.block_height_log2 = 3;\n+\tparams->acc_param.af.grid_cfg.block_width_log2 = 3;\n+\tparams->acc_param.af.grid_cfg.height_per_slice = 2;\n+\t/* Start position of AF area */\n+\tparams->acc_param.af.grid_cfg.x_start = context.configuration.af.start_x;\n+\tparams->acc_param.af.grid_cfg.y_start = context.configuration.af.start_y | IPU3_UAPI_GRID_Y_START_EN;\n+\n+\tparams->acc_param.af.filter_config.y1_sign_vec = 0;\n+\tparams->acc_param.af.filter_config.y2_sign_vec = 0;\n+\n+\t/* b + gb + gr + r = 32 */\n+\tparams->acc_param.af.filter_config.y_calc.y_gen_rate_b = 8;\n+\tparams->acc_param.af.filter_config.y_calc.y_gen_rate_gb = 8;\n+\tparams->acc_param.af.filter_config.y_calc.y_gen_rate_gr = 8;\n+\tparams->acc_param.af.filter_config.y_calc.y_gen_rate_r = 8;\n+\n+\t/* 2^7 = 128, a1 + a2 + ... + a12 = 128, log2 of sum of a1 to a12*/\n+\tparams->acc_param.af.filter_config.nf.y1_nf = 7;\n+\tparams->acc_param.af.filter_config.nf.y2_nf = 7;\n+\n+\t/* Low pass filter configuration (y1_coeff_n) */\n+\tparams->acc_param.af.filter_config.y1_coeff_0.a1 = 0;\n+\tparams->acc_param.af.filter_config.y1_coeff_0.a2 = 0;\n+\tparams->acc_param.af.filter_config.y1_coeff_0.a3 = 0;\n+\tparams->acc_param.af.filter_config.y1_coeff_0.a4 = 0;\n+\n+\tparams->acc_param.af.filter_config.y1_coeff_1.a5 = 0;\n+\tparams->acc_param.af.filter_config.y1_coeff_1.a6 = 0;\n+\tparams->acc_param.af.filter_config.y1_coeff_1.a7 = 0;\n+\tparams->acc_param.af.filter_config.y1_coeff_1.a8 = 0;\n+\n+\tparams->acc_param.af.filter_config.y1_coeff_2.a9 = 0;\n+\tparams->acc_param.af.filter_config.y1_coeff_2.a10 = 0;\n+\tparams->acc_param.af.filter_config.y1_coeff_2.a11 = 0;\n+\tparams->acc_param.af.filter_config.y1_coeff_2.a12 = 128;\n+\n+\t/* High pass filter configuration (y2_coeff_n) */\n+\tparams->acc_param.af.filter_config.y2_coeff_0.a1 = 0;\n+\tparams->acc_param.af.filter_config.y2_coeff_0.a2 = 0;\n+\tparams->acc_param.af.filter_config.y2_coeff_0.a3 = 0;\n+\tparams->acc_param.af.filter_config.y2_coeff_0.a4 = 0;\n+\n+\tparams->acc_param.af.filter_config.y2_coeff_1.a5 = 0;\n+\tparams->acc_param.af.filter_config.y2_coeff_1.a6 = 0;\n+\tparams->acc_param.af.filter_config.y2_coeff_1.a7 = 0;\n+\tparams->acc_param.af.filter_config.y2_coeff_1.a8 = 0;\n+\n+\tparams->acc_param.af.filter_config.y2_coeff_2.a9 = 0;\n+\tparams->acc_param.af.filter_config.y2_coeff_2.a10 = 0;\n+\tparams->acc_param.af.filter_config.y2_coeff_2.a11 = 0;\n+\tparams->acc_param.af.filter_config.y2_coeff_2.a12 = 128;\n+\n+\t/* Enable AF accelerator */\n+\tparams->use.acc_af = 1;\n+}\n+\n+/**\n+ * \\brief Configure the Af given a configInfo\n+ * \\param[in] context The shared IPA context\n+ * \\param[in] configInfo The IPA configuration data\n+ *\n+ * \\return 0\n+ */\n+int Af::configure(IPAContext &context, [[maybe_unused]] const IPAConfigInfo &configInfo)\n+{\n+\t/* Determined focus value i.e. current focus value */\n+\tcontext.frameContext.af.focus = 0;\n+\t/* Maximum variance of the AF statistics */\n+\tcontext.frameContext.af.maxVariance = 0;\n+\t/* is focused? if it is true, the AF should be in a stable state. */\n+\tcontext.frameContext.af.stable = false;\n+\t/* Frame to be ignored before start to estimate AF variance. */\n+\tignoreFrame_ = 10;\n+\n+\t/*\n+\t * AF default area configuration\n+\t * Move AF area to the center of the image.\n+\t */\n+\t/* AF width is 16x8 = 128 */\n+\tcontext.configuration.af.start_x = (1280 / 2) - 64;\n+\tcontext.configuration.af.start_y = (720 / 2) - 64;\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * \\brief Send focus step to the VCM.\n+ * \\param[in] value Set lens position.\n+ * \\todo It is hardcoded here for the dw9717 VCM and will be moved to the\n+ * subdev control in the future.\n+ */\n+int Af::vcmSet(int value)\n+{\n+\tint ret;\n+\tstruct v4l2_control ctrl;\n+\tif (vcmFd_ == -1)\n+\t\treturn -EINVAL;\n+\tmemset(&ctrl, 0, sizeof(struct v4l2_control));\n+\tctrl.id = V4L2_CID_FOCUS_ABSOLUTE;\n+\tctrl.value = value;\n+\tret = ioctl(vcmFd_, VIDIOC_S_CTRL, &ctrl);\n+\treturn ret;\n+}\n+\n+/**\n+ * \\brief Determine the max contrast image and lens position. y_table is the\n+ * statictic data from IPU3 and is composed of low pass and high pass filtered\n+ * value. High pass filtered value also represents the sharpness of the image.\n+ * Based on this, if the image with highest variance of the high pass filtered\n+ * value (contrast) during the AF scan, the position of the len should be the\n+ * best focus.\n+ * \\param[in] context The shared IPA context.\n+ * \\param[in] stats The statistic buffer of 3A from the IPU3.\n+ */\n+void Af::process(IPAContext &context, const ipu3_uapi_stats_3a *stats)\n+{\n+\tuint32_t total = 0;\n+\tdouble mean;\n+\tuint64_t var_sum = 0;\n+\ty_table_item_t *y_item;\n+\tint z = 0;\n+\n+\ty_item = (y_table_item_t *)stats->af_raw_buffer.y_table;\n+\n+\t/**\n+\t * Calculate the mean of each non-zero AF statistics, since IPU3 only determine the AF value\n+\t * for a given grid.\n+\t */\n+\tfor (z = 0; z < (IPU3_UAPI_AF_Y_TABLE_MAX_SIZE) / 4; z++) {\n+\t\tprintf(\"%d, \", y_item[z].y2_avg);\n+\t\ttotal = total + y_item[z].y2_avg;\n+\t\tif (y_item[z].y2_avg == 0)\n+\t\t\tbreak;\n+\t}\n+\tmean = total / z;\n+\n+\t/* Calculate the variance of every AF statistic value. */\n+\tfor (z = 0; z < (IPU3_UAPI_AF_Y_TABLE_MAX_SIZE) / 4 && y_item[z].y2_avg != 0; z++) {\n+\t\tvar_sum = var_sum + ((y_item[z].y2_avg - mean) * (y_item[z].y2_avg - mean));\n+\t\tif (y_item[z].y2_avg == 0)\n+\t\t\tbreak;\n+\t}\n+\n+\t/* Determine the average variance of the frame. */\n+\tcurrentVariance_ = static_cast<double>(var_sum) / static_cast<double>(z);\n+\tLOG(IPU3Af, Debug) << \"variance: \" << currentVariance_;\n+\n+\tif (context.frameContext.af.stable == true) {\n+\t\tconst uint32_t diff_var = std::abs(currentVariance_ - context.frameContext.af.maxVariance);\n+\t\tconst double var_ratio = diff_var / context.frameContext.af.maxVariance;\n+\t\tLOG(IPU3Af, Debug) << \"Change ratio: \"\n+\t\t\t\t << var_ratio\n+\t\t\t\t << \" current focus: \"\n+\t\t\t\t << context.frameContext.af.focus;\n+\t\t/**\n+\t\t * If the change ratio of contrast is over Maxchange_ (out of focus),\n+\t\t * trigger AF again.\n+\t\t */\n+\t\tif (var_ratio > MaxChange_) {\n+\t\t\tif (ignoreFrame_ == 0) {\n+\t\t\t\tcontext.frameContext.af.maxVariance = 0;\n+\t\t\t\tcontext.frameContext.af.focus = 0;\n+\t\t\t\tfocus_ = 0;\n+\t\t\t\tcontext.frameContext.af.stable = false;\n+\t\t\t\tignoreFrame_ = 60;\n+\t\t\t} else\n+\t\t\t\tignoreFrame_--;\n+\t\t} else\n+\t\t\tignoreFrame_ = 10;\n+\t} else {\n+\t\tif (ignoreFrame_ != 0)\n+\t\t\tignoreFrame_--;\n+\t\telse {\n+\t\t\t/* Find the maximum variance during the AF scan using a greedy strategy */\n+\t\t\tif (currentVariance_ > context.frameContext.af.maxVariance) {\n+\t\t\t\tcontext.frameContext.af.maxVariance = currentVariance_;\n+\t\t\t\tcontext.frameContext.af.focus = focus_;\n+\t\t\t}\n+\n+\t\t\tif (focus_ > MaxFocusSteps_) {\n+\t\t\t\t/* If reach the max step, move lens to the position and set \"focus stable\". */\n+\t\t\t\tcontext.frameContext.af.stable = true;\n+\t\t\t\tvcmSet(context.frameContext.af.focus);\n+\t\t\t} else {\n+\t\t\t\tfocus_ += MinSearchStep_;\n+\t\t\t\tvcmSet(focus_);\n+\t\t\t}\n+\t\t\tLOG(IPU3Af, Debug) << \"Focus searching max variance is: \"\n+\t\t\t\t\t << context.frameContext.af.maxVariance\n+\t\t\t\t\t << \" Focus step is \"\n+\t\t\t\t\t << context.frameContext.af.focus;\n+\t\t}\n+\t}\n+}\n+\n+} /* namespace ipa::ipu3::algorithms */\n+\n+} /* namespace libcamera */\ndiff --git a/src/ipa/ipu3/algorithms/af.h b/src/ipa/ipu3/algorithms/af.h\nnew file mode 100644\nindex 00000000..b5c11874\n--- /dev/null\n+++ b/src/ipa/ipu3/algorithms/af.h\n@@ -0,0 +1,54 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Red Hat\n+ *\n+ * af.h - IPU3 Af control\n+ */\n+#ifndef __LIBCAMERA_IPU3_ALGORITHMS_AF_H__\n+#define __LIBCAMERA_IPU3_ALGORITHMS_AF_H__\n+\n+#include <linux/intel-ipu3.h>\n+\n+#include <libcamera/base/utils.h>\n+\n+#include <libcamera/geometry.h>\n+\n+#include \"algorithm.h\"\n+\n+namespace libcamera {\n+\n+namespace ipa::ipu3::algorithms {\n+\n+class Af : public Algorithm\n+{\n+\t/* The format of y_table. From ipu3-ipa repo */\n+\ttypedef struct y_table_item {\n+\t\tuint16_t y1_avg;\n+\t\tuint16_t y2_avg;\n+\t} y_table_item_t;\n+\n+public:\n+\tAf();\n+\t~Af();\n+\n+\tvoid prepare(IPAContext &context, ipu3_uapi_params *params) override;\n+\tint configure(IPAContext &context, const IPAConfigInfo &configInfo) override;\n+\tvoid process(IPAContext &context, const ipu3_uapi_stats_3a *stats) override;\n+\n+private:\n+\tint vcmSet(int value);\n+\n+\tint vcmFd_;\n+\t/* Used for focus scan. */\n+\tuint32_t focus_;\n+\t/* Recent AF statistic variance. */\n+\tdouble currentVariance_;\n+\t/* The frames to be ignore before starting measuring. */\n+\tuint32_t ignoreFrame_;\n+};\n+\n+} /* namespace ipa::ipu3::algorithms */\n+\n+} /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_IPU3_ALGORITHMS_AF_H__ */\ndiff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp\nindex b5d736c1..70ae4e59 100644\n--- a/src/ipa/ipu3/algorithms/agc.cpp\n+++ b/src/ipa/ipu3/algorithms/agc.cpp\n@@ -138,7 +138,7 @@ void Agc::measureBrightness(const ipu3_uapi_stats_3a *stats,\n \t}\n \n \t/* Estimate the quantile mean of the top 2% of the histogram */\n-\tiqMean_ = Histogram(Span<uint32_t>(hist)).interQuantileMean(0.98, 1.0);\n+\tiqMean_ = Histogram(Span<uint32_t>(hist)).interQuantileMean(0.7, 1.0);\n }\n \n /**\ndiff --git a/src/ipa/ipu3/algorithms/meson.build b/src/ipa/ipu3/algorithms/meson.build\nindex 3ec42f72..8574416e 100644\n--- a/src/ipa/ipu3/algorithms/meson.build\n+++ b/src/ipa/ipu3/algorithms/meson.build\n@@ -1,9 +1,10 @@\n # SPDX-License-Identifier: CC0-1.0\n \n ipu3_ipa_algorithms = files([\n+ 'af.cpp',\n 'agc.cpp',\n 'algorithm.cpp',\n 'awb.cpp',\n 'blc.cpp',\n- 'tone_mapping.cpp',\n+ 'tone_mapping.cpp'\n ])\ndiff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp\nindex 2355a9c7..1064d62d 100644\n--- a/src/ipa/ipu3/ipa_context.cpp\n+++ b/src/ipa/ipu3/ipa_context.cpp\n@@ -69,6 +69,17 @@ namespace libcamera::ipa::ipu3 {\n * \\brief Number of cells on one line including the ImgU padding\n */\n \n+/**\n+ * \\var IPASessionConfiguration::af\n+ * \\brief AF parameters configuration of the IPA\n+ *\n+ * \\var IPASessionConfiguration::af.start_x\n+ * \\brief The start X position of the AF area\n+ *\n+ * \\var IPASessionConfiguration::af.start_y\n+ * \\brief The start Y position of the AF area\n+ */\n+\n /**\n * \\var IPASessionConfiguration::agc\n * \\brief AGC parameters configuration of the IPA\n@@ -86,6 +97,21 @@ namespace libcamera::ipa::ipu3 {\n * \\brief Maximum analogue gain supported with the configured sensor\n */\n \n+/**\n+ * \\var IPAFrameContext::af\n+ * \\brief Context for the Automatic Focus algorithm\n+ *\n+ * \\struct IPAFrameContext::af\n+ * \\var IPAFrameContext::af.focus\n+ * \\brief Current position of the lens\n+ *\n+ * \\var IPAFrameContext::af.maxVariance\n+ * \\brief The maximum variance of the current image.\n+ *\n+ * \\var IPAFrameContext::af.stable\n+ * \\brief is the image focused?\n+ */\n+\n /**\n * \\var IPAFrameContext::agc\n * \\brief Context for the Automatic Gain Control algorithm\ndiff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h\nindex 1e46c61a..a7ffcbed 100644\n--- a/src/ipa/ipu3/ipa_context.h\n+++ b/src/ipa/ipu3/ipa_context.h\n@@ -31,6 +31,11 @@ struct IPASessionConfiguration {\n \t\tdouble minAnalogueGain;\n \t\tdouble maxAnalogueGain;\n \t} agc;\n+\n+\tstruct {\n+\t\tuint32_t start_x;\n+\t\tuint32_t start_y;\n+\t} af;\n };\n \n struct IPAFrameContext {\n@@ -47,6 +52,12 @@ struct IPAFrameContext {\n \t\t} gains;\n \t} awb;\n \n+\tstruct {\n+\t\tuint32_t focus;\n+\t\tdouble maxVariance;\n+\t\tbool stable;\n+\t} af;\n+\n \tstruct {\n \t\tdouble gamma;\n \t\tstruct ipu3_uapi_gamma_corr_lut gammaCorrection;\ndiff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 5c51607d..f19d0059 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -30,6 +30,7 @@\n \n #include \"libcamera/internal/mapped_framebuffer.h\"\n \n+#include \"algorithms/af.h\"\n #include \"algorithms/agc.h\"\n #include \"algorithms/algorithm.h\"\n #include \"algorithms/awb.h\"\n@@ -298,6 +299,7 @@ int IPAIPU3::init(const IPASettings &settings,\n \t}\n \n \t/* Construct our Algorithms */\n+\talgorithms_.push_back(std::make_unique<algorithms::Af>());\n \talgorithms_.push_back(std::make_unique<algorithms::Agc>());\n \talgorithms_.push_back(std::make_unique<algorithms::Awb>());\n \talgorithms_.push_back(std::make_unique<algorithms::BlackLevelCorrection>());\n", "prefixes": [ "libcamera-devel", "RFC", "v2", "1/1" ] }