{"id":18181,"url":"https://patchwork.libcamera.org/api/1.1/patches/18181/?format=json","web_url":"https://patchwork.libcamera.org/patch/18181/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20230123154934.27803-7-naush@raspberrypi.com>","date":"2023-01-23T15:49:26","name":"[libcamera-devel,v2,06/14] ipa: raspberrypi: Add autofocus algorithm interface headers","commit_ref":"23aefee3378afc71a98b6c5a9e07e60591fec344","pull_url":null,"state":"accepted","archived":false,"hash":"6005c4e17683c7d0b527462aaa6ccef6a631636a","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/18181/mbox/","series":[{"id":3719,"url":"https://patchwork.libcamera.org/api/1.1/series/3719/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3719","date":"2023-01-23T15:49:20","name":"Raspberry Pi: Camera Module 3 support","version":2,"mbox":"https://patchwork.libcamera.org/series/3719/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/18181/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/18181/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 46839C3240\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Jan 2023 15:49:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id DD001625FD;\n\tMon, 23 Jan 2023 16:49:57 +0100 (CET)","from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com\n\t[IPv6:2a00:1450:4864:20::32e])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DE269625DF\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Jan 2023 16:49:51 +0100 (CET)","by mail-wm1-x32e.google.com with SMTP id\n\te19-20020a05600c439300b003db1cac0c1fso9438488wmn.5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Jan 2023 07:49:51 -0800 (PST)","from localhost.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tn16-20020a05600c181000b003d1de805de5sm10339689wmp.16.2023.01.23.07.49.50\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 23 Jan 2023 07:49:50 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1674488998;\n\tbh=eACv0BMC4sIml13m6Dl1ayBXch/Gz9qY634FpBRZK7g=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=KsDn1b5dPj6qYLAbnZNPITj768/DVg+6Lpk7RFmOgMmwluyXpY1iQwhINpdnndIeY\n\teS+kFNHgemVWf4ce5ohSmuuZ2y8rn90Zn1EXBjsKaFjXID1otrSm4G7ViyDCR600ic\n\txFlGjZxgvXJxuc0neJFb/9BUIOJhLpu6lqOqp7qEiudJijgevuOelO7fhVI3oFrhvE\n\ttpgKPTUIhfAuZc0QUom7Pftc80SnIfU0gcD6/BKmQsbQ81I2wKYMDh8UCqZXnqGOAU\n\t19rzOvYYiC+hrfXL0RshFfgiS+YwgPUZuDCnRBPzz3wfeeukdHLW2aBoo9Z25TWb1A\n\tKbpUtSigGoGCQ==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=+XOYlVwonbW9GffEkAtSqcC2zDy9aGi8XiunyvhmLkE=;\n\tb=BFjas/Q1X5Nujzb5YNgAYiusNy1sIIto8+cNU0z2yd810tQPUIA6QG4vr21P99epDg\n\tMhFIAPguwxon/A/PMiFVMzbbZyDKihPqZeg8YaSLGCIri5skDHNBaMnaWGWSZvFog9+E\n\tQvkFn4CUpue6rCPkJ/1g6TKyEYjtnHECt/12OhLCQGwKy/T0i/3wCFzCqP95alcP7QT3\n\t2OmambJqjYS4O72rUbHMkfciIgfSG0qBxXauBu1W3UtnkiZIenQDjs0WmozSDL/bVH0q\n\tLYuttpArCCVCvn6XOWVhqRi/zjZqrt5pL6ykBoP4bd2ty2txPPnEaKtwOcPAH+JLwZ4w\n\taIgA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"BFjas/Q1\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=+XOYlVwonbW9GffEkAtSqcC2zDy9aGi8XiunyvhmLkE=;\n\tb=AIHOXnjHByOCiiDQ8uaPR/cuUsZzfzWHdWsxEL58lNPzg4FKOJwHg5OaZc/gVoqyYz\n\txz+v9g5Ukf5LP3oRHuikZnIBeZgoNlsrLEkBrMnXfCmK4CcYevU5meodIuY+5On59DJ5\n\tTuVZAiGpJlCSgIUg8+VKDMitTQZ/Mbm7DCS4Ahr9qrZaL3kffCuVuQ9abMduUcBsmbyT\n\t8fQ3+UqUKH2XE0/xPCm85E1fQO6W0gdGe83A5g2D9w0/5lHMoFTJ0WXozEB5RKEuqY9t\n\tlWwVjluhuhP9mWfeF+4kXfDj2p9TBYKwn4oC0GH/zVE8ZnjnFCjDRMl7tFNyDxR4n/Ci\n\t6UuA==","X-Gm-Message-State":"AFqh2kpb/AxSpYQ4RKz7lmOpM6CBcGE2k1YHZQKXnXYpcCYyBNP9T54P\n\tZ7crArL3NS8ig+QeWknA0wRPsAJwc9JU47EOpWw=","X-Google-Smtp-Source":"AMrXdXtTPTTi1+HP12Om3rgRbAf13JQZZXCATSXSKC+M40AFyVYT+FqUEJEkx60hhKYlRCt7W1f1IQ==","X-Received":"by 2002:a1c:7907:0:b0:3cf:a39f:eb2a with SMTP id\n\tl7-20020a1c7907000000b003cfa39feb2amr24066242wme.11.1674488991303; \n\tMon, 23 Jan 2023 07:49:51 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 23 Jan 2023 15:49:26 +0000","Message-Id":"<20230123154934.27803-7-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20230123154934.27803-1-naush@raspberrypi.com>","References":"<20230123154934.27803-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 06/14] ipa: raspberrypi: Add autofocus\n\talgorithm interface headers","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>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Cc":"Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"From: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>\n\nAdd a new AfAlgorithm class that defines the interface for the Raspberry Pi\nautofocus algorithm.\n\nAdd an AfStatus structure that returns the results of the autofocus algorithm\nback to the IPA.\n\nAdd a structure for PDAF statistics provided by supported sensors for use with\nan autofocus algorithm. This structure is currently based on the IMX708's PDAF\n\"Type 1\" statistics.\n\nSigned-off-by: Nick Hollinghurst <nick.hollinghurst@raspberrypi.com>\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n---\n src/ipa/raspberrypi/controller/af_algorithm.h | 76 +++++++++++++++++++\n src/ipa/raspberrypi/controller/af_status.h    | 35 +++++++++\n src/ipa/raspberrypi/controller/pdaf_data.h    | 21 +++++\n 3 files changed, 132 insertions(+)\n create mode 100644 src/ipa/raspberrypi/controller/af_algorithm.h\n create mode 100644 src/ipa/raspberrypi/controller/af_status.h\n create mode 100644 src/ipa/raspberrypi/controller/pdaf_data.h","diff":"diff --git a/src/ipa/raspberrypi/controller/af_algorithm.h b/src/ipa/raspberrypi/controller/af_algorithm.h\nnew file mode 100644\nindex 000000000000..ad9b575450e3\n--- /dev/null\n+++ b/src/ipa/raspberrypi/controller/af_algorithm.h\n@@ -0,0 +1,76 @@\n+/* SPDX-License-Identifier: BSD-2-Clause */\n+/*\n+ * Copyright (C) 2022, Raspberry Pi Ltd\n+ *\n+ * af_algorithm.hpp - auto focus algorithm interface\n+ */\n+#pragma once\n+\n+#include <optional>\n+\n+#include <libcamera/base/span.h>\n+\n+#include \"algorithm.h\"\n+\n+namespace RPiController {\n+\n+class AfAlgorithm : public Algorithm\n+{\n+public:\n+\tAfAlgorithm(Controller *controller)\n+\t\t: Algorithm(controller) {}\n+\n+\t/*\n+\t * An autofocus algorithm should provide the following calls.\n+\t *\n+\t * Where a ControlList combines a change of AfMode with other AF\n+\t * controls, setMode() should be called first, to ensure the\n+\t * algorithm will be in the correct state to handle controls.\n+\t *\n+\t * setLensPosition() returns true if the mode was AfModeManual and\n+\t * the lens position has changed, otherwise returns false. When it\n+\t * returns true, hwpos should be sent immediately to the lens driver.\n+\t *\n+\t * getMode() is provided mainly for validating controls.\n+\t * getLensPosition() is provided for populating DeviceStatus.\n+\t */\n+\n+\tenum AfRange { AfRangeNormal = 0,\n+\t\t       AfRangeMacro,\n+\t\t       AfRangeFull,\n+\t\t       AfRangeMax };\n+\n+\tenum AfSpeed { AfSpeedNormal = 0,\n+\t\t       AfSpeedFast,\n+\t\t       AfSpeedMax };\n+\n+\tenum AfMode { AfModeManual = 0,\n+\t\t      AfModeAuto,\n+\t\t      AfModeContinuous };\n+\n+\tenum AfPause { AfPauseImmediate = 0,\n+\t\t       AfPauseDeferred,\n+\t\t       AfPauseResume };\n+\n+\tvirtual void setRange([[maybe_unused]] AfRange range)\n+\t{\n+\t}\n+\tvirtual void setSpeed([[maybe_unused]] AfSpeed speed)\n+\t{\n+\t}\n+\tvirtual void setMetering([[maybe_unused]] bool use_windows)\n+\t{\n+\t}\n+\tvirtual void setWindows([[maybe_unused]] libcamera::Span<libcamera::Rectangle const> const &wins)\n+\t{\n+\t}\n+\tvirtual void setMode(AfMode mode) = 0;\n+\tvirtual AfMode getMode() const = 0;\n+\tvirtual bool setLensPosition(double dioptres, int32_t *hwpos) = 0;\n+\tvirtual std::optional<double> getLensPosition() const = 0;\n+\tvirtual void triggerScan() = 0;\n+\tvirtual void cancelScan() = 0;\n+\tvirtual void pause(AfPause pause) = 0;\n+};\n+\n+} // namespace RPiController\ndiff --git a/src/ipa/raspberrypi/controller/af_status.h b/src/ipa/raspberrypi/controller/af_status.h\nnew file mode 100644\nindex 000000000000..92c088126733\n--- /dev/null\n+++ b/src/ipa/raspberrypi/controller/af_status.h\n@@ -0,0 +1,35 @@\n+/* SPDX-License-Identifier: BSD-2-Clause */\n+/*\n+ * Copyright (C) 2022, Raspberry Pi Ltd\n+ *\n+ * af_status.h - AF control algorithm status\n+ */\n+#pragma once\n+\n+#include <optional>\n+\n+/*\n+ * The AF algorithm should post the following structure into the image's\n+ * \"af.status\" metadata. lensSetting should control the lens.\n+ */\n+\n+enum class AfState {\n+\tIdle = 0,\n+\tScanning,\n+\tFocused,\n+\tFailed\n+};\n+\n+enum class AfPauseState {\n+\tRunning = 0,\n+\tPausing,\n+\tPaused\n+};\n+\n+struct AfStatus {\n+\t/* state for reporting */\n+\tAfState state;\n+\tAfPauseState pauseState;\n+\t/* lensSetting should be sent to the lens driver, when valid */\n+\tstd::optional<int> lensSetting;\n+};\ndiff --git a/src/ipa/raspberrypi/controller/pdaf_data.h b/src/ipa/raspberrypi/controller/pdaf_data.h\nnew file mode 100644\nindex 000000000000..03c00d72c0e8\n--- /dev/null\n+++ b/src/ipa/raspberrypi/controller/pdaf_data.h\n@@ -0,0 +1,21 @@\n+/* SPDX-License-Identifier: BSD-2-Clause */\n+/*\n+ * Copyright (C) 2022, Raspberry Pi Ltd\n+ *\n+ * pdaf_data.h - PDAF Metadata; for now this is\n+ * largely based on IMX708's PDAF \"Type 1\" output.\n+ */\n+#pragma once\n+\n+#include <stdint.h>\n+\n+#define PDAF_DATA_ROWS 12\n+#define PDAF_DATA_COLS 16\n+\n+struct PdafData {\n+\t/* Confidence values, in raster order, in arbitrary units */\n+\tuint16_t conf[PDAF_DATA_ROWS][PDAF_DATA_COLS];\n+\n+\t/* Phase error, in raster order, in s11 Q4 format (S.6.4) */\n+\tint16_t phase[PDAF_DATA_ROWS][PDAF_DATA_COLS];\n+};\n","prefixes":["libcamera-devel","v2","06/14"]}