[{"id":20382,"web_url":"https://patchwork.libcamera.org/comment/20382/","msgid":"<CAHW6GY+JniLjJFQ=-AjM85ts4pGbJW8jx1k2yy0Hv_dRDYEpHQ@mail.gmail.com>","date":"2021-10-22T12:53:18","subject":"Re: [libcamera-devel] [PATCH 1/6] libcamera: bayer_format: Add\n\tconversion helpers to the BayerFormat class","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"content":"Hi Naush\n\nThanks for this patch!\n\nOn Fri, 22 Oct 2021 at 12:55, Naushir Patuck <naush@raspberrypi.com> wrote:\n>\n> Add a BayerFormat::toMbusCode() member function to convert a BayerFormat to an\n> mbus code defined by the V4L2 specification.\n>\n> Add a BayerFormat::toPixelFormat() member function to convert a BayerFormat to a\n> PixelFormat type. This conversion uses the existing bayerToV4l2 conversion\n> table.\n>\n> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>\n> ---\n>  include/libcamera/internal/bayer_format.h |  4 +++\n>  src/libcamera/bayer_format.cpp            | 31 +++++++++++++++++++++++\n>  2 files changed, 35 insertions(+)\n>\n> diff --git a/include/libcamera/internal/bayer_format.h b/include/libcamera/internal/bayer_format.h\n> index 723382d4168d..217da54e90a2 100644\n> --- a/include/libcamera/internal/bayer_format.h\n> +++ b/include/libcamera/internal/bayer_format.h\n> @@ -10,6 +10,8 @@\n>  #include <stdint.h>\n>  #include <string>\n>\n> +#include <libcamera/pixel_format.h>\n> +\n>  #include \"libcamera/internal/v4l2_pixelformat.h\"\n>\n>  namespace libcamera {\n> @@ -43,6 +45,7 @@ public:\n>         {\n>         }\n>\n> +       unsigned int toMbusCode() const;\n>         static const BayerFormat &fromMbusCode(unsigned int mbusCode);\n>         bool isValid() const { return bitDepth != 0; }\n>\n> @@ -50,6 +53,7 @@ public:\n>\n>         V4L2PixelFormat toV4L2PixelFormat() const;\n>         static BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format);\n> +       PixelFormat toPixelFormat() const;\n>         BayerFormat transform(Transform t) const;\n>\n>         Order order;\n> diff --git a/src/libcamera/bayer_format.cpp b/src/libcamera/bayer_format.cpp\n> index 11355f144f66..c138e7a09597 100644\n> --- a/src/libcamera/bayer_format.cpp\n> +++ b/src/libcamera/bayer_format.cpp\n> @@ -169,6 +169,24 @@ const std::unordered_map<unsigned int, BayerFormat> mbusCodeToBayer{\n>   * \\param[in] p The type of packing applied to the pixel values\n>   */\n>\n> +/**\n> + * \\brief Retrieve the media bus code associated with a BayerFormat\n> + *\n> + * The media bus code numeric identifiers are defined by the V4L2 specification.\n> + */\n> +unsigned int BayerFormat::toMbusCode() const\n> +{\n> +       const auto it = std::find_if(mbusCodeToBayer.begin(), mbusCodeToBayer.end(),\n> +                                    [this](const auto &p) {\n> +                                            return p.second == *this;\n> +                                    });\n> +\n> +       if (it == mbusCodeToBayer.end())\n> +               return it->first;\n> +\n> +       return 0;\n\nI assume media bus codes are defined such that zero can't be a valid one!\n\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\n\nBest regards\n\nDavid\n\n> +}\n> +\n>  /**\n>   * \\brief Retrieve the BayerFormat associated with a media bus code\n>   * \\param[in] mbusCode The media bus code to convert into a BayerFormat\n> @@ -269,6 +287,19 @@ BayerFormat BayerFormat::fromV4L2PixelFormat(V4L2PixelFormat v4l2Format)\n>         return BayerFormat();\n>  }\n>\n> +/**\n> + * \\brief Convert a BayerFormat into the corresponding PixelFormat\n> + * \\return The PixelFormat corresponding to this BayerFormat\n> + */\n> +PixelFormat BayerFormat::toPixelFormat() const\n> +{\n> +       const auto it = bayerToV4l2.find(*this);\n> +       if (it != bayerToV4l2.end())\n> +               return PixelFormat(it->second);\n> +\n> +       return PixelFormat();\n> +}\n> +\n>  /**\n>   * \\brief Apply a transform to this BayerFormat\n>   * \\param[in] t The transform to apply\n> --\n> 2.25.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 3F2DCBF415\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 22 Oct 2021 12:53:32 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8879668F59;\n\tFri, 22 Oct 2021 14:53:31 +0200 (CEST)","from mail-wr1-x430.google.com (mail-wr1-x430.google.com\n\t[IPv6:2a00:1450:4864:20::430])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E60726012A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Oct 2021 14:53:29 +0200 (CEST)","by mail-wr1-x430.google.com with SMTP id d13so112521wrf.11\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 22 Oct 2021 05:53:29 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"TIgRSpbz\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=hZQ116rpIeCOoJF5Z4M81wX6jwQwfWNiqSVgAbb+IUk=;\n\tb=TIgRSpbzGz1e8qsE/JcyiR3Ie9dLYmvCkYfcoVxkNz7mOfLwKl3aL4oHIkgIXensFb\n\trBM1x7CNQ2nhFdrJ0MAjk+B2y0d41MFjIcaj2PT7wzTcc5WzWsy64zKlC31txBXDldPB\n\tRkTDnQNv94jXvQaKb6S0k+KOgx8DKVWfEggJuyKJHetNPj6aJZJcPUU4jLC+h+7ZKqqr\n\tfqlqRhpe0eN3DF4IewgzBbL06/5NEGZeF83rPs2rj00fu717udynvsKK9W8pbUc0C7z0\n\tlKoZ6/UpU/CPWCXOiUOH3i3hd+fB+NOy8dibDy5EeXz9G1KfTwNjdt3GO4tJHl1XI5qf\n\tJkpg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=hZQ116rpIeCOoJF5Z4M81wX6jwQwfWNiqSVgAbb+IUk=;\n\tb=AWXvnTVsISO9MpSJE+gZNyCe2TCqITp0tMVmpP+dBTXrux/MnglfyKy1qM5BaehbD0\n\tzvYn9eIHEoOjjnMuHtW98iH+gDbSwpdbhoV0AL59tKA8UXk53tVcvVp9vsltMidqaliu\n\tLET325iptOsBBGIqZpUqu5C/ekPFlxs2fQoDaaGWYL2aKo93VCpEIOj33CQzcObVO3O7\n\toaEMxfzFPiwcmMxStJTQVqH0f16R1tAGXwQQlBpdTAp+6DyLamKuF5zPNS0qx0KcKL+j\n\t50ka495roUbSBOFZwBKa6lw5qXUPVBmupJ5ZAEfXC4c8ncoMzS+U0tUf9LGdwhXWF8Qm\n\tWcBQ==","X-Gm-Message-State":"AOAM531MnW1c3TTGgmTXssfzZ/bFIZv6gE4htMqs1Ap7xBq360AZ/C0k\n\tZ12isNt2iJ/HzjYA/OglwVjwlNH5zq96xwbGGmhUpw==","X-Google-Smtp-Source":"ABdhPJyIQPxAjpOOwt7v6+cJf53/zgqPEFVESAuFIxzoHOxd2RDm7l0mv77xucgkscDRZrPbvM4F4OJPNz8ZhuMjIbY=","X-Received":"by 2002:a05:6000:90:: with SMTP id\n\tm16mr10893453wrx.354.1634907209533; \n\tFri, 22 Oct 2021 05:53:29 -0700 (PDT)","MIME-Version":"1.0","References":"<20211022115537.2964533-1-naush@raspberrypi.com>\n\t<20211022115537.2964533-2-naush@raspberrypi.com>","In-Reply-To":"<20211022115537.2964533-2-naush@raspberrypi.com>","From":"David Plowman <david.plowman@raspberrypi.com>","Date":"Fri, 22 Oct 2021 13:53:18 +0100","Message-ID":"<CAHW6GY+JniLjJFQ=-AjM85ts4pGbJW8jx1k2yy0Hv_dRDYEpHQ@mail.gmail.com>","To":"Naushir Patuck <naush@raspberrypi.com>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH 1/6] libcamera: bayer_format: Add\n\tconversion helpers to the BayerFormat class","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera devel <libcamera-devel@lists.libcamera.org>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]