[{"id":27373,"web_url":"https://patchwork.libcamera.org/comment/27373/","msgid":"<CAPY8ntASGGD6ySz_LrU+Ou5PUCu4haWuv40ri7jXujYD3Vv0cg@mail.gmail.com>","date":"2023-06-16T16:42:46","subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: cam_helper: PDAF support\n\tfor IMX519","submitter":{"id":27,"url":"https://patchwork.libcamera.org/api/people/27/","name":"Dave Stevenson","email":"dave.stevenson@raspberrypi.com"},"content":"Hi Umang\n\nOn Thu, 15 Jun 2023 at 19:20, Umang Jain via libcamera-devel\n<libcamera-devel@lists.libcamera.org> wrote:\n>\n> From: sdfasdf <asdfasdfasdf@asdfasdf.com>\n>\n> Adds the PDAF support for IMX519 camera module by Arducam.\n>\n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n> Patch originally not authored by me, but we are missing main author's\n> full-name and email.\n\nPartly for my own curiosity, where has this patch come from?\n\nArducam have published their libcamera tree[1], and this almost looks\nlike their commit [2] which does have a commit author (no S-o-b\nthough).\n\n  Dave\n\n[1] https://github.com/ArduCAM/libcamera\n[2] https://github.com/ArduCAM/libcamera/commit/b20728fe2a37ee1cbdeb8c4b2473d0f5035771e4\n\n> ---\n>  src/ipa/rpi/cam_helper/cam_helper_imx519.cpp | 50 ++++++++++++++++++++\n>  src/ipa/rpi/vc4/data/imx519.json             | 40 ++++++++++++++++\n>  2 files changed, 90 insertions(+)\n>\n> diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n> index c7262aa0..6d032082 100644\n> --- a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n> +++ b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n> @@ -15,9 +15,13 @@\n>\n>  #include <libcamera/base/log.h>\n>\n> +#include \"controller/pdaf_data.h\"\n> +\n>  #include \"cam_helper.h\"\n>  #include \"md_parser.h\"\n>\n> +#define ALIGN_UP(x, a) (((x) + (a)-1) & ~(a - 1))\n> +\n>  using namespace RPiController;\n>  using namespace libcamera;\n>  using libcamera::utils::Duration;\n> @@ -66,8 +70,13 @@ private:\n>         /* Largest long exposure scale factor given as a left shift on the frame length. */\n>         static constexpr int longExposureShiftMax = 7;\n>\n> +       static constexpr int pdafStatsRows = 12;\n> +       static constexpr int pdafStatsCols = 16;\n> +\n>         void populateMetadata(const MdParser::RegisterMap &registers,\n>                               Metadata &metadata) const override;\n> +       static bool parsePdafData(const uint8_t *ptr, size_t len, unsigned bpp,\n> +                                 PdafRegions &pdaf);\n>  };\n>\n>  CamHelperImx519::CamHelperImx519()\n> @@ -90,6 +99,11 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n>         MdParser::RegisterMap registers;\n>         DeviceStatus deviceStatus;\n>\n> +       LOG(IPARPI, Debug) << \"Embedded buffer size: \" << buffer.size();\n> +\n> +       size_t bytesPerLine = (mode_.width * mode_.bitdepth) >> 3;\n> +       bytesPerLine = ALIGN_UP(bytesPerLine, 16);\n> +\n>         if (metadata.get(\"device.status\", deviceStatus)) {\n>                 LOG(IPARPI, Error) << \"DeviceStatus not found from DelayedControls\";\n>                 return;\n> @@ -97,6 +111,14 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n>\n>         parseEmbeddedData(buffer, metadata);\n>\n> +       if (buffer.size() > 2 * bytesPerLine) {\n> +               PdafRegions pdaf;\n> +               parsePdafData(&buffer[2 * bytesPerLine],\n> +                             buffer.size() - 2 * bytesPerLine,\n> +                             mode_.bitdepth, pdaf);\n> +               metadata.set(\"pdaf.data\", pdaf);\n> +       }\n> +\n>         /*\n>          * The DeviceStatus struct is first populated with values obtained from\n>          * DelayedControls. If this reports frame length is > frameLengthMax,\n> @@ -188,6 +210,34 @@ void CamHelperImx519::populateMetadata(const MdParser::RegisterMap &registers,\n>         metadata.set(\"device.status\", deviceStatus);\n>  }\n>\n> +bool CamHelperImx519::parsePdafData(const uint8_t *ptr, size_t len,\n> +                                   unsigned bpp, PdafRegions &pdaf)\n> +{\n> +       size_t step = bpp >> 1; /* bytes per PDAF grid entry */\n> +\n> +       if (bpp < 10 || bpp > 12 || len < 194 * step || ptr[0] != 0 || ptr[1] >= 0x40) {\n> +               LOG(IPARPI, Error) << \"PDAF data in unsupported format\";\n> +               return false;\n> +       }\n> +\n> +       pdaf.init({ pdafStatsCols, pdafStatsRows });\n> +\n> +       ptr += 2 * step;\n> +       for (unsigned i = 0; i < pdafStatsRows; ++i) {\n> +               for (unsigned j = 0; j < pdafStatsCols; ++j) {\n> +                       unsigned c = (ptr[0] << 3) | (ptr[1] >> 5);\n> +                       int p = (((ptr[1] & 0x0F) - (ptr[1] & 0x10)) << 6) | (ptr[2] >> 2);\n> +                       PdafData pdafData;\n> +                       pdafData.conf = c;\n> +                       pdafData.phase = c ? p : 0;\n> +                       pdaf.set(libcamera::Point(j, i), { pdafData, 1, 0 });\n> +                       ptr += step;\n> +               }\n> +       }\n> +\n> +       return true;\n> +}\n> +\n>  static CamHelper *create()\n>  {\n>         return new CamHelperImx519();\n> diff --git a/src/ipa/rpi/vc4/data/imx519.json b/src/ipa/rpi/vc4/data/imx519.json\n> index 1b0a7747..0733d97e 100644\n> --- a/src/ipa/rpi/vc4/data/imx519.json\n> +++ b/src/ipa/rpi/vc4/data/imx519.json\n> @@ -350,6 +350,46 @@\n>                  ]\n>              }\n>          },\n> +        {\n> +            \"rpi.af\":\n> +            {\n> +                \"ranges\":\n> +                {\n> +                    \"normal\":\n> +                    {\n> +                        \"min\": 0.0,\n> +                        \"max\": 12.0,\n> +                        \"default\": 1.0\n> +                    },\n> +                    \"macro\":\n> +                    {\n> +                        \"min\": 3.0,\n> +                        \"max\": 15.0,\n> +                        \"default\": 4.0\n> +                    }\n> +                },\n> +                \"speeds\":\n> +                {\n> +                    \"normal\":\n> +                    {\n> +                        \"step_coarse\": 1.0,\n> +                        \"step_fine\": 0.25,\n> +                        \"contrast_ratio\": 0.75,\n> +                        \"pdaf_gain\": -0.02,\n> +                        \"pdaf_squelch\": 0.125,\n> +                        \"max_slew\": 2.0,\n> +                        \"pdaf_frames\": 20,\n> +                        \"dropout_frames\": 6,\n> +                        \"step_frames\": 4\n> +                    }\n> +                },\n> +                \"conf_epsilon\": 8,\n> +                \"conf_thresh\": 16,\n> +                \"conf_clip\": 512,\n> +                \"skip_frames\": 5,\n> +                \"map\": [ 0.0, 0.0, 15.0, 4095 ]\n> +            }\n> +        },\n>          {\n>              \"rpi.ccm\":\n>              {\n> --\n> 2.39.1\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 158CDC322E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 16 Jun 2023 16:43:07 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 53405628AD;\n\tFri, 16 Jun 2023 18:43:06 +0200 (CEST)","from mail-ua1-x92b.google.com (mail-ua1-x92b.google.com\n\t[IPv6:2607:f8b0:4864:20::92b])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6439E628AD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Jun 2023 18:43:04 +0200 (CEST)","by mail-ua1-x92b.google.com with SMTP id\n\ta1e0cc1a2514c-783f17f0a00so357300241.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Jun 2023 09:43:04 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1686933786;\n\tbh=E4tmN196iXuF3ZaHt+bTeoQ5Ed/FoMJ8TzaEX6h5Lks=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=ZgRZjDe+HJZdAftDgskTVADMtV1SLes9KKm8OGU5cdMIvbi4xTxHCPUjvcCrMVNRo\n\tClGqDxJIt2c2gtl4Lt4bX4++JnF9gp2X0eYfaoXquFiyJvvBrOcj7EECYMf+dNT0po\n\tBuU8eiF73bRpKF0POVOl4Sy/DH57mH6FfkkK2U5SiVWYN71JNw0vdzU/hc7sqmKYMO\n\tXppog04+ZddW3fRcq8ahW+ZJ6SKTZxc9NWMDqdDHMbvmSGzHwzVVDkTQ2Hsyz/iPkd\n\tATjtxQjJyNdhNR67Y6YCSlZnc7uPN33Nx4T49GWnPfOS/2Sp++kagzb6fTK2G2Cjn/\n\tCX+AhaoVWYrZA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1686933783; x=1689525783;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=Vtb4+FEoy4r+uepKwiW/2f4srLsclZ/TYcjU7E74xZk=;\n\tb=PV5QouyH7MKEbw0DWEV2QA/BQyrvm2tbptgSRp8oDkV3f7Javg7YnzzO20K+5lXbed\n\tFnsAYInBOcBP2XcVYD03G8LCA6wpjPGCZp6DANUNVO5p5R9SmC5GnIbJJI3nkyyZhjJE\n\tKrBO6EyLtnnwEKSU7VZnznlg010vHfou15WGUD/ImeHlyAwM4P9qt2xGlryBlv3yBK+d\n\tuq8EYrX5NolV90MWAKkI7aVweL8qw/gKrAqRfnUFZpqpee8AFTxElydcaX9Th51TSEVf\n\t7B2Vc5oCtFpENFX10ladxfiX1R9NDMOxykkAeHMsfjyaEwj1NdLM2UjBzsSr46hYBc3M\n\tqRUA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"PV5QouyH\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20221208; t=1686933783; x=1689525783;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=Vtb4+FEoy4r+uepKwiW/2f4srLsclZ/TYcjU7E74xZk=;\n\tb=WiD0idfCUKF9CwS2875riaAb1JWo/F+WT/4XovqGKUra2CQxJK7GbFu+XMPThvIku2\n\tzG+6V7jKPCouq+QLn+9oiu09XL4gbwTc71K1/Agm1GVMuNxFFhHXDXJYS0UYgMyaGvTA\n\tyi2J5hIb1dKfPwZtXq1WoswQtA+6FHYKsI82E8Mzqb9G5wwezA88Np+8QF3VFZ5Qs92w\n\t96tUzxrmUws/7gBkOiuQrgAh/zkciQTh6Mz3bPBYGz8e1QGRnztChGaPFUx1fYzUJngq\n\tyj7OO28vInwRgy1yI346WoHAQMLwyxwtLfXbqQRajYZFmv+9O5Zf1BreQftlcvYAQwtd\n\tY2nw==","X-Gm-Message-State":"AC+VfDxOwc7XQVyMXwA3bJEy87Fp18bVEP1FgkVyEcevfQy4qBaBDPlG\n\t7HmeyqcjvkEoROjeUOYPXaD7BhyTNElhHS6GRl0jRcdZD4wpUM7Z+h4=","X-Google-Smtp-Source":"ACHHUZ47VQ+O0JaOgKK9pPlBS3fdcmbriKXiIFFMNVeGCqqu7nyflsLO0K6gH1DD0X0WtC4dxOQfSZVlI+65pCIxbQU=","X-Received":"by 2002:a67:fc04:0:b0:43f:58a1:b22c with SMTP id\n\to4-20020a67fc04000000b0043f58a1b22cmr2347421vsq.16.1686933783047;\n\tFri, 16 Jun 2023 09:43:03 -0700 (PDT)","MIME-Version":"1.0","References":"<20230615182044.95347-1-umang.jain@ideasonboard.com>","In-Reply-To":"<20230615182044.95347-1-umang.jain@ideasonboard.com>","Date":"Fri, 16 Jun 2023 17:42:46 +0100","Message-ID":"<CAPY8ntASGGD6ySz_LrU+Ou5PUCu4haWuv40ri7jXujYD3Vv0cg@mail.gmail.com>","To":"Umang Jain <umang.jain@ideasonboard.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: cam_helper: PDAF support\n\tfor IMX519","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":"Dave Stevenson via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Dave Stevenson <dave.stevenson@raspberrypi.com>","Cc":"sdfasdf <asdfasdfasdf@asdfasdf.com>, libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27374,"web_url":"https://patchwork.libcamera.org/comment/27374/","msgid":"<c1318dd8-cef9-5c94-6c05-81149f65c2be@ideasonboard.com>","date":"2023-06-16T17:27:15","subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: cam_helper: PDAF support\n\tfor IMX519","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi,\n\nOn 6/16/23 10:12 PM, Dave Stevenson wrote:\n> Hi Umang\n>\n> On Thu, 15 Jun 2023 at 19:20, Umang Jain via libcamera-devel\n> <libcamera-devel@lists.libcamera.org> wrote:\n>> From: sdfasdf <asdfasdfasdf@asdfasdf.com>\n>>\n>> Adds the PDAF support for IMX519 camera module by Arducam.\n>>\n>> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n>> ---\n>> Patch originally not authored by me, but we are missing main author's\n>> full-name and email.\n> Partly for my own curiosity, where has this patch come from?\n>\n> Arducam have published their libcamera tree[1], and this almost looks\n> like their commit [2] which does have a commit author (no S-o-b\n> though).\n\nOh so there is a libcamera published tree from them, I didn't know.\n\nI referred to [3] instead and didn't checkout the fork. Anyways, if we \nhave an author and their full name, it should be merged with their name. \nSo will update. It has been modified/rebased as per the latest reworks \non rpi/vc4 PH and IPA to get compiled successfully on master.\n\n[3] \nhttps://github.com/raspberrypi/libcamera/commit/b20728fe2a37ee1cbdeb8c4b2473d0f5035771e4\n>\n>    Dave\n>\n> [1] https://github.com/ArduCAM/libcamera\n> [2] https://github.com/ArduCAM/libcamera/commit/b20728fe2a37ee1cbdeb8c4b2473d0f5035771e4\n>\n>> ---\n>>   src/ipa/rpi/cam_helper/cam_helper_imx519.cpp | 50 ++++++++++++++++++++\n>>   src/ipa/rpi/vc4/data/imx519.json             | 40 ++++++++++++++++\n>>   2 files changed, 90 insertions(+)\n>>\n>> diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n>> index c7262aa0..6d032082 100644\n>> --- a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n>> +++ b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n>> @@ -15,9 +15,13 @@\n>>\n>>   #include <libcamera/base/log.h>\n>>\n>> +#include \"controller/pdaf_data.h\"\n>> +\n>>   #include \"cam_helper.h\"\n>>   #include \"md_parser.h\"\n>>\n>> +#define ALIGN_UP(x, a) (((x) + (a)-1) & ~(a - 1))\n>> +\n>>   using namespace RPiController;\n>>   using namespace libcamera;\n>>   using libcamera::utils::Duration;\n>> @@ -66,8 +70,13 @@ private:\n>>          /* Largest long exposure scale factor given as a left shift on the frame length. */\n>>          static constexpr int longExposureShiftMax = 7;\n>>\n>> +       static constexpr int pdafStatsRows = 12;\n>> +       static constexpr int pdafStatsCols = 16;\n>> +\n>>          void populateMetadata(const MdParser::RegisterMap &registers,\n>>                                Metadata &metadata) const override;\n>> +       static bool parsePdafData(const uint8_t *ptr, size_t len, unsigned bpp,\n>> +                                 PdafRegions &pdaf);\n>>   };\n>>\n>>   CamHelperImx519::CamHelperImx519()\n>> @@ -90,6 +99,11 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n>>          MdParser::RegisterMap registers;\n>>          DeviceStatus deviceStatus;\n>>\n>> +       LOG(IPARPI, Debug) << \"Embedded buffer size: \" << buffer.size();\n>> +\n>> +       size_t bytesPerLine = (mode_.width * mode_.bitdepth) >> 3;\n>> +       bytesPerLine = ALIGN_UP(bytesPerLine, 16);\n>> +\n>>          if (metadata.get(\"device.status\", deviceStatus)) {\n>>                  LOG(IPARPI, Error) << \"DeviceStatus not found from DelayedControls\";\n>>                  return;\n>> @@ -97,6 +111,14 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n>>\n>>          parseEmbeddedData(buffer, metadata);\n>>\n>> +       if (buffer.size() > 2 * bytesPerLine) {\n>> +               PdafRegions pdaf;\n>> +               parsePdafData(&buffer[2 * bytesPerLine],\n>> +                             buffer.size() - 2 * bytesPerLine,\n>> +                             mode_.bitdepth, pdaf);\n>> +               metadata.set(\"pdaf.data\", pdaf);\n>> +       }\n>> +\n>>          /*\n>>           * The DeviceStatus struct is first populated with values obtained from\n>>           * DelayedControls. If this reports frame length is > frameLengthMax,\n>> @@ -188,6 +210,34 @@ void CamHelperImx519::populateMetadata(const MdParser::RegisterMap &registers,\n>>          metadata.set(\"device.status\", deviceStatus);\n>>   }\n>>\n>> +bool CamHelperImx519::parsePdafData(const uint8_t *ptr, size_t len,\n>> +                                   unsigned bpp, PdafRegions &pdaf)\n>> +{\n>> +       size_t step = bpp >> 1; /* bytes per PDAF grid entry */\n>> +\n>> +       if (bpp < 10 || bpp > 12 || len < 194 * step || ptr[0] != 0 || ptr[1] >= 0x40) {\n>> +               LOG(IPARPI, Error) << \"PDAF data in unsupported format\";\n>> +               return false;\n>> +       }\n>> +\n>> +       pdaf.init({ pdafStatsCols, pdafStatsRows });\n>> +\n>> +       ptr += 2 * step;\n>> +       for (unsigned i = 0; i < pdafStatsRows; ++i) {\n>> +               for (unsigned j = 0; j < pdafStatsCols; ++j) {\n>> +                       unsigned c = (ptr[0] << 3) | (ptr[1] >> 5);\n>> +                       int p = (((ptr[1] & 0x0F) - (ptr[1] & 0x10)) << 6) | (ptr[2] >> 2);\n>> +                       PdafData pdafData;\n>> +                       pdafData.conf = c;\n>> +                       pdafData.phase = c ? p : 0;\n>> +                       pdaf.set(libcamera::Point(j, i), { pdafData, 1, 0 });\n>> +                       ptr += step;\n>> +               }\n>> +       }\n>> +\n>> +       return true;\n>> +}\n>> +\n>>   static CamHelper *create()\n>>   {\n>>          return new CamHelperImx519();\n>> diff --git a/src/ipa/rpi/vc4/data/imx519.json b/src/ipa/rpi/vc4/data/imx519.json\n>> index 1b0a7747..0733d97e 100644\n>> --- a/src/ipa/rpi/vc4/data/imx519.json\n>> +++ b/src/ipa/rpi/vc4/data/imx519.json\n>> @@ -350,6 +350,46 @@\n>>                   ]\n>>               }\n>>           },\n>> +        {\n>> +            \"rpi.af\":\n>> +            {\n>> +                \"ranges\":\n>> +                {\n>> +                    \"normal\":\n>> +                    {\n>> +                        \"min\": 0.0,\n>> +                        \"max\": 12.0,\n>> +                        \"default\": 1.0\n>> +                    },\n>> +                    \"macro\":\n>> +                    {\n>> +                        \"min\": 3.0,\n>> +                        \"max\": 15.0,\n>> +                        \"default\": 4.0\n>> +                    }\n>> +                },\n>> +                \"speeds\":\n>> +                {\n>> +                    \"normal\":\n>> +                    {\n>> +                        \"step_coarse\": 1.0,\n>> +                        \"step_fine\": 0.25,\n>> +                        \"contrast_ratio\": 0.75,\n>> +                        \"pdaf_gain\": -0.02,\n>> +                        \"pdaf_squelch\": 0.125,\n>> +                        \"max_slew\": 2.0,\n>> +                        \"pdaf_frames\": 20,\n>> +                        \"dropout_frames\": 6,\n>> +                        \"step_frames\": 4\n>> +                    }\n>> +                },\n>> +                \"conf_epsilon\": 8,\n>> +                \"conf_thresh\": 16,\n>> +                \"conf_clip\": 512,\n>> +                \"skip_frames\": 5,\n>> +                \"map\": [ 0.0, 0.0, 15.0, 4095 ]\n>> +            }\n>> +        },\n>>           {\n>>               \"rpi.ccm\":\n>>               {\n>> --\n>> 2.39.1\n>>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 8FE87BD78E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 16 Jun 2023 17:27:24 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 107DF628AE;\n\tFri, 16 Jun 2023 19:27:24 +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 3F464628AD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 16 Jun 2023 19:27:22 +0200 (CEST)","from [192.168.1.108] (unknown [103.238.109.12])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 081992B3;\n\tFri, 16 Jun 2023 19:26:48 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1686936444;\n\tbh=QTk4tikiKN2ovwonCewydaws+G59fRpwYtTFkdGvxDw=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=CEgRF8vAUR6VBfaBZToY8RgoKKoy0myWliY+x5ei14fH8zZg36V3kqUkuUpNSNFVv\n\t/BsM97l8611wCTZSh+YVVdiIkICXKnwdFL6uY2qeDNFzP1yLcG9WXVQSlJwVm60Sx3\n\tEBR2r3yN3jWfT8kjWi1yKg5MsiYz7tckC1R02iApvzOzwood2nACspBvVVwRZUzpU4\n\tVBcm7F7YvXGqlKeKTiW2NKi0DER9BIn0ev1+48qcq+JE0umUcsDMOj+FrgtHqSqFqU\n\tzhKN7gVAVrqs4pKdhAkBE4fV/y+/sBqOI39LH9mMNt+KgAzJ1gf4QVwhaGCGfzz43W\n\tXWD4A0bEAc9GQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1686936410;\n\tbh=QTk4tikiKN2ovwonCewydaws+G59fRpwYtTFkdGvxDw=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=uxDOBbGWcK8vFshBF9wGLHHXhedOJ83K2PS85v2WPNRuYd1g/3JWqIu/QWEfadm5Z\n\tc/qw9oGbxM1xg37068svDYX/7kwH/sHiHzaCpwP/nppjGpdNiIhEGJQ+yTnBrHcMdi\n\tolnZRAoX11OhDKAzgB6E3mvY52s9RnQVWkxu7PbI="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"uxDOBbGW\"; dkim-atps=neutral","Message-ID":"<c1318dd8-cef9-5c94-6c05-81149f65c2be@ideasonboard.com>","Date":"Fri, 16 Jun 2023 22:57:15 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101\n\tThunderbird/102.7.1","Content-Language":"en-US","To":"Dave Stevenson <dave.stevenson@raspberrypi.com>","References":"<20230615182044.95347-1-umang.jain@ideasonboard.com>\n\t<CAPY8ntASGGD6ySz_LrU+Ou5PUCu4haWuv40ri7jXujYD3Vv0cg@mail.gmail.com>","In-Reply-To":"<CAPY8ntASGGD6ySz_LrU+Ou5PUCu4haWuv40ri7jXujYD3Vv0cg@mail.gmail.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","Subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: cam_helper: PDAF support\n\tfor IMX519","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":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Cc":"sdfasdf <asdfasdfasdf@asdfasdf.com>, libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27375,"web_url":"https://patchwork.libcamera.org/comment/27375/","msgid":"<20230617145019.GK14547@pendragon.ideasonboard.com>","date":"2023-06-17T14:50:19","subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: cam_helper: PDAF support\n\tfor IMX519","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Umang,\n\nOn Thu, Jun 15, 2023 at 11:50:44PM +0530, Umang Jain via libcamera-devel wrote:\n> From: sdfasdf <asdfasdfasdf@asdfasdf.com>\n> \n> Adds the PDAF support for IMX519 camera module by Arducam.\n> \n> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> ---\n> Patch originally not authored by me, but we are missing main author's \n> full-name and email.\n\nThat needs to be fixed. We can't merge code of unknown origin. The\noriginal author has to be recorded, the origin of the code clearly\nindicated, and the author should be CC'ed.\n\n> ---\n>  src/ipa/rpi/cam_helper/cam_helper_imx519.cpp | 50 ++++++++++++++++++++\n>  src/ipa/rpi/vc4/data/imx519.json             | 40 ++++++++++++++++\n>  2 files changed, 90 insertions(+)\n> \n> diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n> index c7262aa0..6d032082 100644\n> --- a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n> +++ b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n> @@ -15,9 +15,13 @@\n>  \n>  #include <libcamera/base/log.h>\n>  \n> +#include \"controller/pdaf_data.h\"\n> +\n>  #include \"cam_helper.h\"\n>  #include \"md_parser.h\"\n>  \n> +#define ALIGN_UP(x, a) (((x) + (a)-1) & ~(a - 1))\n> +\n>  using namespace RPiController;\n>  using namespace libcamera;\n>  using libcamera::utils::Duration;\n> @@ -66,8 +70,13 @@ private:\n>  \t/* Largest long exposure scale factor given as a left shift on the frame length. */\n>  \tstatic constexpr int longExposureShiftMax = 7;\n>  \n> +\tstatic constexpr int pdafStatsRows = 12;\n> +\tstatic constexpr int pdafStatsCols = 16;\n> +\n>  \tvoid populateMetadata(const MdParser::RegisterMap &registers,\n>  \t\t\t      Metadata &metadata) const override;\n> +\tstatic bool parsePdafData(const uint8_t *ptr, size_t len, unsigned bpp,\n> +\t\t\t\t  PdafRegions &pdaf);\n>  };\n>  \n>  CamHelperImx519::CamHelperImx519()\n> @@ -90,6 +99,11 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n>  \tMdParser::RegisterMap registers;\n>  \tDeviceStatus deviceStatus;\n>  \n> +\tLOG(IPARPI, Debug) << \"Embedded buffer size: \" << buffer.size();\n> +\n> +\tsize_t bytesPerLine = (mode_.width * mode_.bitdepth) >> 3;\n> +\tbytesPerLine = ALIGN_UP(bytesPerLine, 16);\n> +\n>  \tif (metadata.get(\"device.status\", deviceStatus)) {\n>  \t\tLOG(IPARPI, Error) << \"DeviceStatus not found from DelayedControls\";\n>  \t\treturn;\n> @@ -97,6 +111,14 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n>  \n>  \tparseEmbeddedData(buffer, metadata);\n>  \n> +\tif (buffer.size() > 2 * bytesPerLine) {\n> +\t\tPdafRegions pdaf;\n> +\t\tparsePdafData(&buffer[2 * bytesPerLine],\n> +\t\t\t      buffer.size() - 2 * bytesPerLine,\n> +\t\t\t      mode_.bitdepth, pdaf);\n> +\t\tmetadata.set(\"pdaf.data\", pdaf);\n> +\t}\n> +\n>  \t/*\n>  \t * The DeviceStatus struct is first populated with values obtained from\n>  \t * DelayedControls. If this reports frame length is > frameLengthMax,\n> @@ -188,6 +210,34 @@ void CamHelperImx519::populateMetadata(const MdParser::RegisterMap &registers,\n>  \tmetadata.set(\"device.status\", deviceStatus);\n>  }\n>  \n> +bool CamHelperImx519::parsePdafData(const uint8_t *ptr, size_t len,\n> +\t\t\t\t    unsigned bpp, PdafRegions &pdaf)\n> +{\n> +\tsize_t step = bpp >> 1; /* bytes per PDAF grid entry */\n> +\n> +\tif (bpp < 10 || bpp > 12 || len < 194 * step || ptr[0] != 0 || ptr[1] >= 0x40) {\n> +\t\tLOG(IPARPI, Error) << \"PDAF data in unsupported format\";\n> +\t\treturn false;\n> +\t}\n> +\n> +\tpdaf.init({ pdafStatsCols, pdafStatsRows });\n> +\n> +\tptr += 2 * step;\n> +\tfor (unsigned i = 0; i < pdafStatsRows; ++i) {\n> +\t\tfor (unsigned j = 0; j < pdafStatsCols; ++j) {\n> +\t\t\tunsigned c = (ptr[0] << 3) | (ptr[1] >> 5);\n> +\t\t\tint p = (((ptr[1] & 0x0F) - (ptr[1] & 0x10)) << 6) | (ptr[2] >> 2);\n> +\t\t\tPdafData pdafData;\n> +\t\t\tpdafData.conf = c;\n> +\t\t\tpdafData.phase = c ? p : 0;\n> +\t\t\tpdaf.set(libcamera::Point(j, i), { pdafData, 1, 0 });\n> +\t\t\tptr += step;\n> +\t\t}\n> +\t}\n> +\n> +\treturn true;\n> +}\n> +\n>  static CamHelper *create()\n>  {\n>  \treturn new CamHelperImx519();\n> diff --git a/src/ipa/rpi/vc4/data/imx519.json b/src/ipa/rpi/vc4/data/imx519.json\n> index 1b0a7747..0733d97e 100644\n> --- a/src/ipa/rpi/vc4/data/imx519.json\n> +++ b/src/ipa/rpi/vc4/data/imx519.json\n> @@ -350,6 +350,46 @@\n>                  ]\n>              }\n>          },\n> +        {\n> +            \"rpi.af\":\n> +            {\n> +                \"ranges\":\n> +                {\n> +                    \"normal\":\n> +                    {\n> +                        \"min\": 0.0,\n> +                        \"max\": 12.0,\n> +                        \"default\": 1.0\n> +                    },\n> +                    \"macro\":\n> +                    {\n> +                        \"min\": 3.0,\n> +                        \"max\": 15.0,\n> +                        \"default\": 4.0\n> +                    }\n> +                },\n> +                \"speeds\":\n> +                {\n> +                    \"normal\":\n> +                    {\n> +                        \"step_coarse\": 1.0,\n> +                        \"step_fine\": 0.25,\n> +                        \"contrast_ratio\": 0.75,\n> +                        \"pdaf_gain\": -0.02,\n> +                        \"pdaf_squelch\": 0.125,\n> +                        \"max_slew\": 2.0,\n> +                        \"pdaf_frames\": 20,\n> +                        \"dropout_frames\": 6,\n> +                        \"step_frames\": 4\n> +                    }\n> +                },\n> +                \"conf_epsilon\": 8,\n> +                \"conf_thresh\": 16,\n> +                \"conf_clip\": 512,\n> +                \"skip_frames\": 5,\n> +                \"map\": [ 0.0, 0.0, 15.0, 4095 ]\n> +            }\n> +        },\n>          {\n>              \"rpi.ccm\":\n>              {","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 68A38C322E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 17 Jun 2023 14:50:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9FBA9628B7;\n\tSat, 17 Jun 2023 16:50:21 +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 4C01A61E45\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 17 Jun 2023 16:50:20 +0200 (CEST)","from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi\n\t[213.243.189.158])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 3492010A;\n\tSat, 17 Jun 2023 16:49:47 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1687013421;\n\tbh=FmLEqpPonZ5NnVP+SyEDV6IeV909qgZ5OA4uArcdBVk=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=2AVLwpuMjEtO7qo5zIuyuHsmqUwWhWm4A4YT3DmFJNXz9s8705Oo4Azd38hbOFv+9\n\tNMp6NAb796QUfDcTMTI2rHfbhxelUu7lB8ektp9r1w5aREfr6hlRwrckEQgjJyMUyO\n\tJBIPLUJIf/B0pQMNAffBoaFVPoc4AYGXeB0d6mpEci103mTCF08aKDMuyzUHX5OoCh\n\ttmhueNvTtn9ZPnHIc1DiZ4nDhgVLZfEIagHP8b7hYudr8GkY2rdMnS9EXyw/02GORf\n\t4BeY85d0cChIr66BaXN76l7zo38WXiIU97F+cckgAfyy1iqBo8zrm40ipt1nYd0aqp\n\tNGwtPHQPfLMqQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1687013387;\n\tbh=FmLEqpPonZ5NnVP+SyEDV6IeV909qgZ5OA4uArcdBVk=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=LH6LMf/W00Xluq7kLCP7LqTZkZrsrhWPR3Ah4sTcYMhSg3pkqBXz+GZAJcTPWxgo+\n\tPiBlpvJEKiA5VZrwYtWnNmASuk3oZM5fdk5oxE7yWnVYDXPSO7zGl+w+iE7DhgwWK3\n\t6ndMe78V6lzYh+KOaHLRfheoike43/mMpwdzK6d4="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"LH6LMf/W\"; dkim-atps=neutral","Date":"Sat, 17 Jun 2023 17:50:19 +0300","To":"Umang Jain <umang.jain@ideasonboard.com>","Message-ID":"<20230617145019.GK14547@pendragon.ideasonboard.com>","References":"<20230615182044.95347-1-umang.jain@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230615182044.95347-1-umang.jain@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: cam_helper: PDAF support\n\tfor IMX519","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":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"sdfasdf <asdfasdfasdf@asdfasdf.com>, libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27383,"web_url":"https://patchwork.libcamera.org/comment/27383/","msgid":"<feefc0e2-7a79-ee70-8a17-f0d5a62464b0@ideasonboard.com>","date":"2023-06-18T10:03:56","subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: cam_helper: PDAF support\n\tfor IMX519","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 6/17/23 8:20 PM, Laurent Pinchart wrote:\n> Hi Umang,\n>\n> On Thu, Jun 15, 2023 at 11:50:44PM +0530, Umang Jain via libcamera-devel wrote:\n>> From: sdfasdf <asdfasdfasdf@asdfasdf.com>\n>>\n>> Adds the PDAF support for IMX519 camera module by Arducam.\n>>\n>> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n>> ---\n>> Patch originally not authored by me, but we are missing main author's\n>> full-name and email.\n> That needs to be fixed. We can't merge code of unknown origin. The\n> original author has to be recorded, the origin of the code clearly\n> indicated, and the author should be CC'ed.\n\nThere is,\n\nAuthor: john <john@arducam.com>\nDate:   Thu Mar 9 16:12:37 2023 +0800\n\nBut no S-o-B tag when the commits are checked on [1]\n\nDoes this suffice ? And should  I add an additional S-o-B ?\n\n     Signed-off-by: john <john@arducam.com>\n\n[1]: https://github.com/ArduCAM/libcamera\n>\n>> ---\n>>   src/ipa/rpi/cam_helper/cam_helper_imx519.cpp | 50 ++++++++++++++++++++\n>>   src/ipa/rpi/vc4/data/imx519.json             | 40 ++++++++++++++++\n>>   2 files changed, 90 insertions(+)\n>>\n>> diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n>> index c7262aa0..6d032082 100644\n>> --- a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n>> +++ b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n>> @@ -15,9 +15,13 @@\n>>   \n>>   #include <libcamera/base/log.h>\n>>   \n>> +#include \"controller/pdaf_data.h\"\n>> +\n>>   #include \"cam_helper.h\"\n>>   #include \"md_parser.h\"\n>>   \n>> +#define ALIGN_UP(x, a) (((x) + (a)-1) & ~(a - 1))\n>> +\n>>   using namespace RPiController;\n>>   using namespace libcamera;\n>>   using libcamera::utils::Duration;\n>> @@ -66,8 +70,13 @@ private:\n>>   \t/* Largest long exposure scale factor given as a left shift on the frame length. */\n>>   \tstatic constexpr int longExposureShiftMax = 7;\n>>   \n>> +\tstatic constexpr int pdafStatsRows = 12;\n>> +\tstatic constexpr int pdafStatsCols = 16;\n>> +\n>>   \tvoid populateMetadata(const MdParser::RegisterMap &registers,\n>>   \t\t\t      Metadata &metadata) const override;\n>> +\tstatic bool parsePdafData(const uint8_t *ptr, size_t len, unsigned bpp,\n>> +\t\t\t\t  PdafRegions &pdaf);\n>>   };\n>>   \n>>   CamHelperImx519::CamHelperImx519()\n>> @@ -90,6 +99,11 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n>>   \tMdParser::RegisterMap registers;\n>>   \tDeviceStatus deviceStatus;\n>>   \n>> +\tLOG(IPARPI, Debug) << \"Embedded buffer size: \" << buffer.size();\n>> +\n>> +\tsize_t bytesPerLine = (mode_.width * mode_.bitdepth) >> 3;\n>> +\tbytesPerLine = ALIGN_UP(bytesPerLine, 16);\n>> +\n>>   \tif (metadata.get(\"device.status\", deviceStatus)) {\n>>   \t\tLOG(IPARPI, Error) << \"DeviceStatus not found from DelayedControls\";\n>>   \t\treturn;\n>> @@ -97,6 +111,14 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n>>   \n>>   \tparseEmbeddedData(buffer, metadata);\n>>   \n>> +\tif (buffer.size() > 2 * bytesPerLine) {\n>> +\t\tPdafRegions pdaf;\n>> +\t\tparsePdafData(&buffer[2 * bytesPerLine],\n>> +\t\t\t      buffer.size() - 2 * bytesPerLine,\n>> +\t\t\t      mode_.bitdepth, pdaf);\n>> +\t\tmetadata.set(\"pdaf.data\", pdaf);\n>> +\t}\n>> +\n>>   \t/*\n>>   \t * The DeviceStatus struct is first populated with values obtained from\n>>   \t * DelayedControls. If this reports frame length is > frameLengthMax,\n>> @@ -188,6 +210,34 @@ void CamHelperImx519::populateMetadata(const MdParser::RegisterMap &registers,\n>>   \tmetadata.set(\"device.status\", deviceStatus);\n>>   }\n>>   \n>> +bool CamHelperImx519::parsePdafData(const uint8_t *ptr, size_t len,\n>> +\t\t\t\t    unsigned bpp, PdafRegions &pdaf)\n>> +{\n>> +\tsize_t step = bpp >> 1; /* bytes per PDAF grid entry */\n>> +\n>> +\tif (bpp < 10 || bpp > 12 || len < 194 * step || ptr[0] != 0 || ptr[1] >= 0x40) {\n>> +\t\tLOG(IPARPI, Error) << \"PDAF data in unsupported format\";\n>> +\t\treturn false;\n>> +\t}\n>> +\n>> +\tpdaf.init({ pdafStatsCols, pdafStatsRows });\n>> +\n>> +\tptr += 2 * step;\n>> +\tfor (unsigned i = 0; i < pdafStatsRows; ++i) {\n>> +\t\tfor (unsigned j = 0; j < pdafStatsCols; ++j) {\n>> +\t\t\tunsigned c = (ptr[0] << 3) | (ptr[1] >> 5);\n>> +\t\t\tint p = (((ptr[1] & 0x0F) - (ptr[1] & 0x10)) << 6) | (ptr[2] >> 2);\n>> +\t\t\tPdafData pdafData;\n>> +\t\t\tpdafData.conf = c;\n>> +\t\t\tpdafData.phase = c ? p : 0;\n>> +\t\t\tpdaf.set(libcamera::Point(j, i), { pdafData, 1, 0 });\n>> +\t\t\tptr += step;\n>> +\t\t}\n>> +\t}\n>> +\n>> +\treturn true;\n>> +}\n>> +\n>>   static CamHelper *create()\n>>   {\n>>   \treturn new CamHelperImx519();\n>> diff --git a/src/ipa/rpi/vc4/data/imx519.json b/src/ipa/rpi/vc4/data/imx519.json\n>> index 1b0a7747..0733d97e 100644\n>> --- a/src/ipa/rpi/vc4/data/imx519.json\n>> +++ b/src/ipa/rpi/vc4/data/imx519.json\n>> @@ -350,6 +350,46 @@\n>>                   ]\n>>               }\n>>           },\n>> +        {\n>> +            \"rpi.af\":\n>> +            {\n>> +                \"ranges\":\n>> +                {\n>> +                    \"normal\":\n>> +                    {\n>> +                        \"min\": 0.0,\n>> +                        \"max\": 12.0,\n>> +                        \"default\": 1.0\n>> +                    },\n>> +                    \"macro\":\n>> +                    {\n>> +                        \"min\": 3.0,\n>> +                        \"max\": 15.0,\n>> +                        \"default\": 4.0\n>> +                    }\n>> +                },\n>> +                \"speeds\":\n>> +                {\n>> +                    \"normal\":\n>> +                    {\n>> +                        \"step_coarse\": 1.0,\n>> +                        \"step_fine\": 0.25,\n>> +                        \"contrast_ratio\": 0.75,\n>> +                        \"pdaf_gain\": -0.02,\n>> +                        \"pdaf_squelch\": 0.125,\n>> +                        \"max_slew\": 2.0,\n>> +                        \"pdaf_frames\": 20,\n>> +                        \"dropout_frames\": 6,\n>> +                        \"step_frames\": 4\n>> +                    }\n>> +                },\n>> +                \"conf_epsilon\": 8,\n>> +                \"conf_thresh\": 16,\n>> +                \"conf_clip\": 512,\n>> +                \"skip_frames\": 5,\n>> +                \"map\": [ 0.0, 0.0, 15.0, 4095 ]\n>> +            }\n>> +        },\n>>           {\n>>               \"rpi.ccm\":\n>>               {","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 7EF70C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 18 Jun 2023 10:04:10 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A8518628C3;\n\tSun, 18 Jun 2023 12:04:09 +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 D9FA861E48\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 18 Jun 2023 12:04:07 +0200 (CEST)","from [192.168.1.108] (unknown [103.238.109.27])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A93A9E4;\n\tSun, 18 Jun 2023 12:03:28 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1687082649;\n\tbh=Jzj3ctGUjAy74nSJ+zM3OQArTAi2K/8LBg0edQyqbCM=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=oWh0t1e5kfP75jNuyMRyJYGCNotnMtzJFyUCwrEeAuvEh+Gwxb2i5pTuBhPjXZm6a\n\tRIPKrRc4/OCj2Kg3ZdUdFiC7G85fnepDlEaxd5wQ9ILQyiQp9FX498XVB35J4gN8Hc\n\tV5WOnOeP9TBltciUXRCpAOPm/0hSe3zn/E9PEjM0MUcPbuxfdeBxrSJldi0L8DbvYu\n\tiv4ClgsZejyeKnrwXG1raobnDg1uDNMVQ18096li0bdgPv9JzOTbJluMK6PT68XD6o\n\tS0TVN8RV0SlSrjPm0YiBc6v3407qByVfcoeyvkFHnBeoRksO3Du/H0rt6vCq8DWroT\n\ttOfGTOevsIykw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1687082614;\n\tbh=Jzj3ctGUjAy74nSJ+zM3OQArTAi2K/8LBg0edQyqbCM=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=nOXW5O/Z78yNK6qutzxUHS5TKrAbcNUrGqkhqYVcGffwTmAkW6btu/wWJc/J5v2W/\n\tE2WCNi9IjWuWG8U1YTOibeLVtjVzojY17jOw7sHPRwP8lFWNwioN5xrFIDTgfnM02R\n\tKJcbfoKe8MIsBTGNa+sVc+lp5bEMbWouEJB+XKkE="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"nOXW5O/Z\"; dkim-atps=neutral","Message-ID":"<feefc0e2-7a79-ee70-8a17-f0d5a62464b0@ideasonboard.com>","Date":"Sun, 18 Jun 2023 15:33:56 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101\n\tThunderbird/102.7.1","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","References":"<20230615182044.95347-1-umang.jain@ideasonboard.com>\n\t<20230617145019.GK14547@pendragon.ideasonboard.com>","Content-Language":"en-US","In-Reply-To":"<20230617145019.GK14547@pendragon.ideasonboard.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: cam_helper: PDAF support\n\tfor IMX519","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":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Cc":"sdfasdf <asdfasdfasdf@asdfasdf.com>, libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27387,"web_url":"https://patchwork.libcamera.org/comment/27387/","msgid":"<168716324724.3585053.11156992585955753457@Monstersaurus>","date":"2023-06-19T08:27:27","subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: cam_helper: PDAF support\n\tfor IMX519","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Umang Jain via libcamera-devel (2023-06-18 11:03:56)\n> Hi Laurent,\n> \n> On 6/17/23 8:20 PM, Laurent Pinchart wrote:\n> > Hi Umang,\n> >\n> > On Thu, Jun 15, 2023 at 11:50:44PM +0530, Umang Jain via libcamera-devel wrote:\n> >> From: sdfasdf <asdfasdfasdf@asdfasdf.com>\n> >>\n> >> Adds the PDAF support for IMX519 camera module by Arducam.\n> >>\n> >> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n> >> ---\n> >> Patch originally not authored by me, but we are missing main author's\n> >> full-name and email.\n> > That needs to be fixed. We can't merge code of unknown origin. The\n> > original author has to be recorded, the origin of the code clearly\n> > indicated, and the author should be CC'ed.\n> \n> There is,\n> \n> Author: john <john@arducam.com>\n> Date:   Thu Mar 9 16:12:37 2023 +0800\n> \n> But no S-o-B tag when the commits are checked on [1]\n> \n> Does this suffice ? And should  I add an additional S-o-B ?\n> \n>      Signed-off-by: john <john@arducam.com>\n\nNo, you can't add someone elses 'signature' if they haven't provided it.\n\nWe'll have to contact Arducam and get them to provide a Signed-off-by:\nto certify they authored the code.\n\n--\nKieran\n\n\n> [1]: https://github.com/ArduCAM/libcamera\n> >\n> >> ---\n> >>   src/ipa/rpi/cam_helper/cam_helper_imx519.cpp | 50 ++++++++++++++++++++\n> >>   src/ipa/rpi/vc4/data/imx519.json             | 40 ++++++++++++++++\n> >>   2 files changed, 90 insertions(+)\n> >>\n> >> diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n> >> index c7262aa0..6d032082 100644\n> >> --- a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n> >> +++ b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n> >> @@ -15,9 +15,13 @@\n> >>   \n> >>   #include <libcamera/base/log.h>\n> >>   \n> >> +#include \"controller/pdaf_data.h\"\n> >> +\n> >>   #include \"cam_helper.h\"\n> >>   #include \"md_parser.h\"\n> >>   \n> >> +#define ALIGN_UP(x, a) (((x) + (a)-1) & ~(a - 1))\n> >> +\n> >>   using namespace RPiController;\n> >>   using namespace libcamera;\n> >>   using libcamera::utils::Duration;\n> >> @@ -66,8 +70,13 @@ private:\n> >>      /* Largest long exposure scale factor given as a left shift on the frame length. */\n> >>      static constexpr int longExposureShiftMax = 7;\n> >>   \n> >> +    static constexpr int pdafStatsRows = 12;\n> >> +    static constexpr int pdafStatsCols = 16;\n> >> +\n> >>      void populateMetadata(const MdParser::RegisterMap &registers,\n> >>                            Metadata &metadata) const override;\n> >> +    static bool parsePdafData(const uint8_t *ptr, size_t len, unsigned bpp,\n> >> +                              PdafRegions &pdaf);\n> >>   };\n> >>   \n> >>   CamHelperImx519::CamHelperImx519()\n> >> @@ -90,6 +99,11 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n> >>      MdParser::RegisterMap registers;\n> >>      DeviceStatus deviceStatus;\n> >>   \n> >> +    LOG(IPARPI, Debug) << \"Embedded buffer size: \" << buffer.size();\n> >> +\n> >> +    size_t bytesPerLine = (mode_.width * mode_.bitdepth) >> 3;\n> >> +    bytesPerLine = ALIGN_UP(bytesPerLine, 16);\n> >> +\n> >>      if (metadata.get(\"device.status\", deviceStatus)) {\n> >>              LOG(IPARPI, Error) << \"DeviceStatus not found from DelayedControls\";\n> >>              return;\n> >> @@ -97,6 +111,14 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n> >>   \n> >>      parseEmbeddedData(buffer, metadata);\n> >>   \n> >> +    if (buffer.size() > 2 * bytesPerLine) {\n> >> +            PdafRegions pdaf;\n> >> +            parsePdafData(&buffer[2 * bytesPerLine],\n> >> +                          buffer.size() - 2 * bytesPerLine,\n> >> +                          mode_.bitdepth, pdaf);\n> >> +            metadata.set(\"pdaf.data\", pdaf);\n> >> +    }\n> >> +\n> >>      /*\n> >>       * The DeviceStatus struct is first populated with values obtained from\n> >>       * DelayedControls. If this reports frame length is > frameLengthMax,\n> >> @@ -188,6 +210,34 @@ void CamHelperImx519::populateMetadata(const MdParser::RegisterMap &registers,\n> >>      metadata.set(\"device.status\", deviceStatus);\n> >>   }\n> >>   \n> >> +bool CamHelperImx519::parsePdafData(const uint8_t *ptr, size_t len,\n> >> +                                unsigned bpp, PdafRegions &pdaf)\n> >> +{\n> >> +    size_t step = bpp >> 1; /* bytes per PDAF grid entry */\n> >> +\n> >> +    if (bpp < 10 || bpp > 12 || len < 194 * step || ptr[0] != 0 || ptr[1] >= 0x40) {\n> >> +            LOG(IPARPI, Error) << \"PDAF data in unsupported format\";\n> >> +            return false;\n> >> +    }\n> >> +\n> >> +    pdaf.init({ pdafStatsCols, pdafStatsRows });\n> >> +\n> >> +    ptr += 2 * step;\n> >> +    for (unsigned i = 0; i < pdafStatsRows; ++i) {\n> >> +            for (unsigned j = 0; j < pdafStatsCols; ++j) {\n> >> +                    unsigned c = (ptr[0] << 3) | (ptr[1] >> 5);\n> >> +                    int p = (((ptr[1] & 0x0F) - (ptr[1] & 0x10)) << 6) | (ptr[2] >> 2);\n> >> +                    PdafData pdafData;\n> >> +                    pdafData.conf = c;\n> >> +                    pdafData.phase = c ? p : 0;\n> >> +                    pdaf.set(libcamera::Point(j, i), { pdafData, 1, 0 });\n> >> +                    ptr += step;\n> >> +            }\n> >> +    }\n> >> +\n> >> +    return true;\n> >> +}\n> >> +\n> >>   static CamHelper *create()\n> >>   {\n> >>      return new CamHelperImx519();\n> >> diff --git a/src/ipa/rpi/vc4/data/imx519.json b/src/ipa/rpi/vc4/data/imx519.json\n> >> index 1b0a7747..0733d97e 100644\n> >> --- a/src/ipa/rpi/vc4/data/imx519.json\n> >> +++ b/src/ipa/rpi/vc4/data/imx519.json\n> >> @@ -350,6 +350,46 @@\n> >>                   ]\n> >>               }\n> >>           },\n> >> +        {\n> >> +            \"rpi.af\":\n> >> +            {\n> >> +                \"ranges\":\n> >> +                {\n> >> +                    \"normal\":\n> >> +                    {\n> >> +                        \"min\": 0.0,\n> >> +                        \"max\": 12.0,\n> >> +                        \"default\": 1.0\n> >> +                    },\n> >> +                    \"macro\":\n> >> +                    {\n> >> +                        \"min\": 3.0,\n> >> +                        \"max\": 15.0,\n> >> +                        \"default\": 4.0\n> >> +                    }\n> >> +                },\n> >> +                \"speeds\":\n> >> +                {\n> >> +                    \"normal\":\n> >> +                    {\n> >> +                        \"step_coarse\": 1.0,\n> >> +                        \"step_fine\": 0.25,\n> >> +                        \"contrast_ratio\": 0.75,\n> >> +                        \"pdaf_gain\": -0.02,\n> >> +                        \"pdaf_squelch\": 0.125,\n> >> +                        \"max_slew\": 2.0,\n> >> +                        \"pdaf_frames\": 20,\n> >> +                        \"dropout_frames\": 6,\n> >> +                        \"step_frames\": 4\n> >> +                    }\n> >> +                },\n> >> +                \"conf_epsilon\": 8,\n> >> +                \"conf_thresh\": 16,\n> >> +                \"conf_clip\": 512,\n> >> +                \"skip_frames\": 5,\n> >> +                \"map\": [ 0.0, 0.0, 15.0, 4095 ]\n> >> +            }\n> >> +        },\n> >>           {\n> >>               \"rpi.ccm\":\n> >>               {\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 2074CBD78E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 19 Jun 2023 08:27:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 399DA628C0;\n\tMon, 19 Jun 2023 10:27:32 +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 847F3614FD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 19 Jun 2023 10:27:30 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net\n\t[82.37.23.78])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 522C1547;\n\tMon, 19 Jun 2023 10:26:56 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1687163252;\n\tbh=sVsc6trt/VUtrG3NnV5m/+zUhLnsvIuVCxXIWSE7x4w=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=fbG3UFTRgo2NaGfJynpvcpJj5Zvz1+DkisxB1U/tgizke13J0cK59EeMLFysG66Ww\n\tHCrtg4gmSHIzzV9l3QOA0Zt/XJga+wwri+pOI5rdBMBSnFwddnGYOyqMtOGqR8AjuX\n\tLkGLtRIYx1AIUABbZISuuLlFjV+GzTTASiXMNgKg0ro5qLkMS4OaKbHXqi0MqAH9uj\n\trB4Etxx8WQoQ3sizJnUWJRxQw7T5seaYMG7PgtP0auszMj+Es6tRFOnXDBN9ExNhR4\n\tx4dRLoXwFKczRL6dyv9s8O/3JB/pWgUpcltRaicWBhS4PwYSDy572wokSRC+J/hCu0\n\t0OFn6H8mHNJBw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1687163216;\n\tbh=sVsc6trt/VUtrG3NnV5m/+zUhLnsvIuVCxXIWSE7x4w=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=iyiiXcdzdi/W9k3TFxYR+xEiLRR8PvRd/TT0aWWB3pKcXAlGdYxp6eOBmbGzAcacS\n\t7Jz5rRpd3WDEMyfBKo/bW7JMaMf3wviASJLtW4gEZ1alqnYefMRC16QiD5RnoKKZlI\n\tOYg6MqcBg2spq9i6pBgot0PEiUQDwFw2M8s62VXM="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"iyiiXcdz\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<feefc0e2-7a79-ee70-8a17-f0d5a62464b0@ideasonboard.com>","References":"<20230615182044.95347-1-umang.jain@ideasonboard.com>\n\t<20230617145019.GK14547@pendragon.ideasonboard.com>\n\t<feefc0e2-7a79-ee70-8a17-f0d5a62464b0@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tUmang Jain <umang.jain@ideasonboard.com>,\n\tUmang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Date":"Mon, 19 Jun 2023 09:27:27 +0100","Message-ID":"<168716324724.3585053.11156992585955753457@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: cam_helper: PDAF support\n\tfor IMX519","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":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":27388,"web_url":"https://patchwork.libcamera.org/comment/27388/","msgid":"<2a164497-2842-1efc-8dcc-f0567aecca15@ideasonboard.com>","date":"2023-06-19T08:31:33","subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: cam_helper: PDAF support\n\tfor IMX519","submitter":{"id":86,"url":"https://patchwork.libcamera.org/api/people/86/","name":"Umang Jain","email":"umang.jain@ideasonboard.com"},"content":"Hi,\n\nCC'ing John at Arducam,\n\nOn 6/19/23 1:57 PM, Kieran Bingham wrote:\n> Quoting Umang Jain via libcamera-devel (2023-06-18 11:03:56)\n>> Hi Laurent,\n>>\n>> On 6/17/23 8:20 PM, Laurent Pinchart wrote:\n>>> Hi Umang,\n>>>\n>>> On Thu, Jun 15, 2023 at 11:50:44PM +0530, Umang Jain via libcamera-devel wrote:\n>>>> From: sdfasdf <asdfasdfasdf@asdfasdf.com>\n>>>>\n>>>> Adds the PDAF support for IMX519 camera module by Arducam.\n>>>>\n>>>> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>\n>>>> ---\n>>>> Patch originally not authored by me, but we are missing main author's\n>>>> full-name and email.\n>>> That needs to be fixed. We can't merge code of unknown origin. The\n>>> original author has to be recorded, the origin of the code clearly\n>>> indicated, and the author should be CC'ed.\n>> There is,\n>>\n>> Author: john <john@arducam.com>\n>> Date:   Thu Mar 9 16:12:37 2023 +0800\n>>\n>> But no S-o-B tag when the commits are checked on [1]\n>>\n>> Does this suffice ? And should  I add an additional S-o-B ?\n>>\n>>       Signed-off-by: john <john@arducam.com>\n> No, you can't add someone elses 'signature' if they haven't provided it.\n>\n> We'll have to contact Arducam and get them to provide a Signed-off-by:\n> to certify they authored the code.\n\nThere's now a v2 on the list as well, and john@arducam.com is CC'ed. I \nwill wait for them to provide a S-o-B.\n>\n> --\n> Kieran\n>\n>\n>> [1]: https://github.com/ArduCAM/libcamera\n>>>> ---\n>>>>    src/ipa/rpi/cam_helper/cam_helper_imx519.cpp | 50 ++++++++++++++++++++\n>>>>    src/ipa/rpi/vc4/data/imx519.json             | 40 ++++++++++++++++\n>>>>    2 files changed, 90 insertions(+)\n>>>>\n>>>> diff --git a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n>>>> index c7262aa0..6d032082 100644\n>>>> --- a/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n>>>> +++ b/src/ipa/rpi/cam_helper/cam_helper_imx519.cpp\n>>>> @@ -15,9 +15,13 @@\n>>>>    \n>>>>    #include <libcamera/base/log.h>\n>>>>    \n>>>> +#include \"controller/pdaf_data.h\"\n>>>> +\n>>>>    #include \"cam_helper.h\"\n>>>>    #include \"md_parser.h\"\n>>>>    \n>>>> +#define ALIGN_UP(x, a) (((x) + (a)-1) & ~(a - 1))\n>>>> +\n>>>>    using namespace RPiController;\n>>>>    using namespace libcamera;\n>>>>    using libcamera::utils::Duration;\n>>>> @@ -66,8 +70,13 @@ private:\n>>>>       /* Largest long exposure scale factor given as a left shift on the frame length. */\n>>>>       static constexpr int longExposureShiftMax = 7;\n>>>>    \n>>>> +    static constexpr int pdafStatsRows = 12;\n>>>> +    static constexpr int pdafStatsCols = 16;\n>>>> +\n>>>>       void populateMetadata(const MdParser::RegisterMap &registers,\n>>>>                             Metadata &metadata) const override;\n>>>> +    static bool parsePdafData(const uint8_t *ptr, size_t len, unsigned bpp,\n>>>> +                              PdafRegions &pdaf);\n>>>>    };\n>>>>    \n>>>>    CamHelperImx519::CamHelperImx519()\n>>>> @@ -90,6 +99,11 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n>>>>       MdParser::RegisterMap registers;\n>>>>       DeviceStatus deviceStatus;\n>>>>    \n>>>> +    LOG(IPARPI, Debug) << \"Embedded buffer size: \" << buffer.size();\n>>>> +\n>>>> +    size_t bytesPerLine = (mode_.width * mode_.bitdepth) >> 3;\n>>>> +    bytesPerLine = ALIGN_UP(bytesPerLine, 16);\n>>>> +\n>>>>       if (metadata.get(\"device.status\", deviceStatus)) {\n>>>>               LOG(IPARPI, Error) << \"DeviceStatus not found from DelayedControls\";\n>>>>               return;\n>>>> @@ -97,6 +111,14 @@ void CamHelperImx519::prepare(libcamera::Span<const uint8_t> buffer, Metadata &m\n>>>>    \n>>>>       parseEmbeddedData(buffer, metadata);\n>>>>    \n>>>> +    if (buffer.size() > 2 * bytesPerLine) {\n>>>> +            PdafRegions pdaf;\n>>>> +            parsePdafData(&buffer[2 * bytesPerLine],\n>>>> +                          buffer.size() - 2 * bytesPerLine,\n>>>> +                          mode_.bitdepth, pdaf);\n>>>> +            metadata.set(\"pdaf.data\", pdaf);\n>>>> +    }\n>>>> +\n>>>>       /*\n>>>>        * The DeviceStatus struct is first populated with values obtained from\n>>>>        * DelayedControls. If this reports frame length is > frameLengthMax,\n>>>> @@ -188,6 +210,34 @@ void CamHelperImx519::populateMetadata(const MdParser::RegisterMap &registers,\n>>>>       metadata.set(\"device.status\", deviceStatus);\n>>>>    }\n>>>>    \n>>>> +bool CamHelperImx519::parsePdafData(const uint8_t *ptr, size_t len,\n>>>> +                                unsigned bpp, PdafRegions &pdaf)\n>>>> +{\n>>>> +    size_t step = bpp >> 1; /* bytes per PDAF grid entry */\n>>>> +\n>>>> +    if (bpp < 10 || bpp > 12 || len < 194 * step || ptr[0] != 0 || ptr[1] >= 0x40) {\n>>>> +            LOG(IPARPI, Error) << \"PDAF data in unsupported format\";\n>>>> +            return false;\n>>>> +    }\n>>>> +\n>>>> +    pdaf.init({ pdafStatsCols, pdafStatsRows });\n>>>> +\n>>>> +    ptr += 2 * step;\n>>>> +    for (unsigned i = 0; i < pdafStatsRows; ++i) {\n>>>> +            for (unsigned j = 0; j < pdafStatsCols; ++j) {\n>>>> +                    unsigned c = (ptr[0] << 3) | (ptr[1] >> 5);\n>>>> +                    int p = (((ptr[1] & 0x0F) - (ptr[1] & 0x10)) << 6) | (ptr[2] >> 2);\n>>>> +                    PdafData pdafData;\n>>>> +                    pdafData.conf = c;\n>>>> +                    pdafData.phase = c ? p : 0;\n>>>> +                    pdaf.set(libcamera::Point(j, i), { pdafData, 1, 0 });\n>>>> +                    ptr += step;\n>>>> +            }\n>>>> +    }\n>>>> +\n>>>> +    return true;\n>>>> +}\n>>>> +\n>>>>    static CamHelper *create()\n>>>>    {\n>>>>       return new CamHelperImx519();\n>>>> diff --git a/src/ipa/rpi/vc4/data/imx519.json b/src/ipa/rpi/vc4/data/imx519.json\n>>>> index 1b0a7747..0733d97e 100644\n>>>> --- a/src/ipa/rpi/vc4/data/imx519.json\n>>>> +++ b/src/ipa/rpi/vc4/data/imx519.json\n>>>> @@ -350,6 +350,46 @@\n>>>>                    ]\n>>>>                }\n>>>>            },\n>>>> +        {\n>>>> +            \"rpi.af\":\n>>>> +            {\n>>>> +                \"ranges\":\n>>>> +                {\n>>>> +                    \"normal\":\n>>>> +                    {\n>>>> +                        \"min\": 0.0,\n>>>> +                        \"max\": 12.0,\n>>>> +                        \"default\": 1.0\n>>>> +                    },\n>>>> +                    \"macro\":\n>>>> +                    {\n>>>> +                        \"min\": 3.0,\n>>>> +                        \"max\": 15.0,\n>>>> +                        \"default\": 4.0\n>>>> +                    }\n>>>> +                },\n>>>> +                \"speeds\":\n>>>> +                {\n>>>> +                    \"normal\":\n>>>> +                    {\n>>>> +                        \"step_coarse\": 1.0,\n>>>> +                        \"step_fine\": 0.25,\n>>>> +                        \"contrast_ratio\": 0.75,\n>>>> +                        \"pdaf_gain\": -0.02,\n>>>> +                        \"pdaf_squelch\": 0.125,\n>>>> +                        \"max_slew\": 2.0,\n>>>> +                        \"pdaf_frames\": 20,\n>>>> +                        \"dropout_frames\": 6,\n>>>> +                        \"step_frames\": 4\n>>>> +                    }\n>>>> +                },\n>>>> +                \"conf_epsilon\": 8,\n>>>> +                \"conf_thresh\": 16,\n>>>> +                \"conf_clip\": 512,\n>>>> +                \"skip_frames\": 5,\n>>>> +                \"map\": [ 0.0, 0.0, 15.0, 4095 ]\n>>>> +            }\n>>>> +        },\n>>>>            {\n>>>>                \"rpi.ccm\":\n>>>>                {","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id F2E87C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 19 Jun 2023 08:31:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 238D0628C3;\n\tMon, 19 Jun 2023 10:31:42 +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 DDD39614FD\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 19 Jun 2023 10:31:40 +0200 (CEST)","from [192.168.1.108] (unknown [103.86.18.208])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 75443547;\n\tMon, 19 Jun 2023 10:31:05 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1687163502;\n\tbh=e7ymgJEK93MSzSrLC7q3NRQRKQCv/51ODuHX43ksXd8=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=1YT9ueNiM3aHi+5Wl0yxtM1ROoc416oMOl4tmi41hqjP5Xxo8AOCtRV9WqUmRN/i7\n\teltfWO3UUy6iuzWft7yvoJRoCzv8Nli/fXBV16IwsiR0zsdFW74fqh/bHrBcw2DLET\n\tYMuurHZTH9NM3uLDk8xcuwfODfff7s7InY9vbXGFhygPQ3Si5Q6zZAeXs+i8vBHEZo\n\tymoYrRAMwNAG/y/IhgxPXmrXZxtTkaXeO/9+DyLNc+DicJAxVZgHUcoAJAQ+hh2PTF\n\thLomCA/esd0Xg21Y2XP77/DUdC6nwaNkXjX7Y+OsLKpGIt33fg5EyMLBPvxBDzEvSg\n\tXJmZHF5JuFZwQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1687163466;\n\tbh=e7ymgJEK93MSzSrLC7q3NRQRKQCv/51ODuHX43ksXd8=;\n\th=Date:Subject:To:References:Cc:From:In-Reply-To:From;\n\tb=t8eltomw5tHQKw44bmbKiOK5v7HSUMRJEgARHipMSY0yYocdQkoTouLT0Ct82Ay+/\n\t6aR+6wGH7wmTTnmB3bRdyh4wa6q3g9PtStYC/3oAWKNB8TityZtMjdCeVntNsOmV/v\n\ts8a3GIRa15viYwz4sSv35DY8ECW0N2f2VsDacwtc="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"t8eltomw\"; dkim-atps=neutral","Message-ID":"<2a164497-2842-1efc-8dcc-f0567aecca15@ideasonboard.com>","Date":"Mon, 19 Jun 2023 14:01:33 +0530","MIME-Version":"1.0","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101\n\tThunderbird/102.7.1","Content-Language":"en-US","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tUmang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","References":"<20230615182044.95347-1-umang.jain@ideasonboard.com>\n\t<20230617145019.GK14547@pendragon.ideasonboard.com>\n\t<feefc0e2-7a79-ee70-8a17-f0d5a62464b0@ideasonboard.com>\n\t<168716324724.3585053.11156992585955753457@Monstersaurus>","In-Reply-To":"<168716324724.3585053.11156992585955753457@Monstersaurus>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH] ipa: rpi: cam_helper: PDAF support\n\tfor IMX519","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":"Umang Jain via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Umang Jain <umang.jain@ideasonboard.com>","Cc":"john@arducam.com","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]