Show a patch.

GET /api/patches/11031/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 11031,
    "url": "https://patchwork.libcamera.org/api/patches/11031/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/11031/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20210127044425.2193480-3-hiroh@chromium.org>",
    "date": "2021-01-27T04:44:25",
    "name": "[libcamera-devel,v2,2/2] android: libyuv: Introduce PostProcessorLibyuv",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "41ecc69c80d20dbb2a50cab19aa3075ade745a7d",
    "submitter": {
        "id": 63,
        "url": "https://patchwork.libcamera.org/api/people/63/?format=api",
        "name": "Hirokazu Honda",
        "email": "hiroh@chromium.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/11031/mbox/",
    "series": [
        {
            "id": 1614,
            "url": "https://patchwork.libcamera.org/api/series/1614/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1614",
            "date": "2021-01-27T04:44:23",
            "name": "Introduce Post processor using libyuv",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/1614/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/11031/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/11031/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 E2848C0F2B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 27 Jan 2021 04:44:38 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B05B568348;\n\tWed, 27 Jan 2021 05:44:38 +0100 (CET)",
            "from mail-pf1-x432.google.com (mail-pf1-x432.google.com\n\t[IPv6:2607:f8b0:4864:20::432])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 64AC768344\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 27 Jan 2021 05:44:36 +0100 (CET)",
            "by mail-pf1-x432.google.com with SMTP id w14so408815pfi.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 26 Jan 2021 20:44:36 -0800 (PST)",
            "from hiroh.c.googlers.com.com\n\t(128.141.236.35.bc.googleusercontent.com. [35.236.141.128])\n\tby smtp.gmail.com with ESMTPSA id\n\tz3sm645920pfb.157.2021.01.26.20.44.33\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 26 Jan 2021 20:44:34 -0800 (PST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"GWBafH3M\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=h+BnWovUvPMa/lZlazdSEmTYiy9CcnlwWIlxHpOF7/s=;\n\tb=GWBafH3MmRfaaAG/goSDT8Lin2mdmZ8r5tP2wUVzNHoIzhUGEh4lvMAD9ZA4xnHJkD\n\tZ5H7iN8XsU0BmtRE7z6o+YDZer3c81qa2mFnIeu+MSQ/9fxBCgDuZkhpGAmpBcV4wo/k\n\tXySsYBmkxJ+SOhZn7Pwc1dKZsqICSHhDeCnyU=",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=h+BnWovUvPMa/lZlazdSEmTYiy9CcnlwWIlxHpOF7/s=;\n\tb=F14jpvlg9ieqc965uHez5nqAAA/0mB/LZ5V4sDyiKLQMAg/y5xpMaRbmbgm/rs10Qc\n\tewoWXvPa7i0boTrUPh6eMwjSbXjA/UnwJZo0JD5IwFtGZVs2+90dOK1SzwWQPmiro0Ak\n\tAhqMvup6NegiJoqT/ts8Q8NReXfrdDwGUEANZnLuzcw5RzDTYnT3X06SjV6r77lV53kd\n\toHknWHOOoCpdtIRYxklpAWTpKURQQMZk2A6biQMiEoxJiBK2rBe/mdjH3wSushMfYHFo\n\taci7evj2Q8MjaVomuK6mn6fV8Wdu5uk/R2PcNa6Qq9yw1JJn5INwQ+foeYvUaac6cvRr\n\tt+Uw==",
        "X-Gm-Message-State": "AOAM530cwKmDoXWoX6eq3x5fCMrwXqpXFAdwpN1OWpYcb/y2+n2CF9Na\n\tQcgOHyer7P0E0yfFSO8QdBvbrBz7o4cCRZQg",
        "X-Google-Smtp-Source": "ABdhPJxhue4yleM35Q2qfcKt2XG/nv1wYerDgrl8655V+OoxH4ljDc3ZibJW3iH2/EdOWwecQVqmmA==",
        "X-Received": "by 2002:a62:f207:0:b029:1c0:434b:cc14 with SMTP id\n\tm7-20020a62f2070000b02901c0434bcc14mr8685017pfh.11.1611722674764; \n\tTue, 26 Jan 2021 20:44:34 -0800 (PST)",
        "From": "Hirokazu Honda <hiroh@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Wed, 27 Jan 2021 04:44:25 +0000",
        "Message-Id": "<20210127044425.2193480-3-hiroh@chromium.org>",
        "X-Mailer": "git-send-email 2.30.0.280.ga3ce27912f-goog",
        "In-Reply-To": "<20210127044425.2193480-1-hiroh@chromium.org>",
        "References": "<20210127044425.2193480-1-hiroh@chromium.org>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v2 2/2] android: libyuv: Introduce\n\tPostProcessorLibyuv",
        "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>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "This adds PostProcessorLibyuv. It supports NV12 buffer scaling.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n\n---\n src/android/libyuv/post_processor_libyuv.cpp | 126 +++++++++++++++++++\n src/android/libyuv/post_processor_libyuv.h   |  38 ++++++\n src/android/meson.build                      |   1 +\n 3 files changed, 165 insertions(+)\n create mode 100644 src/android/libyuv/post_processor_libyuv.cpp\n create mode 100644 src/android/libyuv/post_processor_libyuv.h\n\n--\n2.30.0.280.ga3ce27912f-goog",
    "diff": "diff --git a/src/android/libyuv/post_processor_libyuv.cpp b/src/android/libyuv/post_processor_libyuv.cpp\nnew file mode 100644\nindex 00000000..5f40fd25\n--- /dev/null\n+++ b/src/android/libyuv/post_processor_libyuv.cpp\n@@ -0,0 +1,126 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * post_processor_libyuv.cpp - Post Processor using libyuv\n+ */\n+\n+#include \"post_processor_libyuv.h\"\n+\n+#include <libyuv/scale.h>\n+\n+#include <libcamera/formats.h>\n+#include <libcamera/geometry.h>\n+#include <libcamera/internal/formats.h>\n+#include <libcamera/internal/log.h>\n+#include <libcamera/pixel_format.h>\n+\n+using namespace libcamera;\n+\n+LOG_DEFINE_CATEGORY(LIBYUV)\n+\n+namespace {\n+void getNV12LengthAndStride(Size size, unsigned int length[2],\n+\t\t\t    unsigned int stride[2])\n+{\n+\tconst auto nv12Info = PixelFormatInfo::info(PixelFormat(formats::NV12));\n+\tfor (unsigned int i = 0; i < 2; i++) {\n+\t\tconst unsigned int vertSubSample =\n+\t\t\tnv12Info.planes[i].verticalSubSampling;\n+\t\tlength[i] = nv12Info.stride(size.width, i, /*align=*/1) *\n+\t\t\t    ((size.height + vertSubSample - 1) / vertSubSample);\n+\t\tstride[i] = nv12Info.stride(size.width, i, 1);\n+\t}\n+}\n+} // namespace\n+\n+PostProcessorLibyuv::PostProcessorLibyuv() = default;\n+\n+int PostProcessorLibyuv::configure(const StreamConfiguration &inCfg,\n+\t\t\t\t   const StreamConfiguration &outCfg)\n+{\n+\tif (inCfg.pixelFormat != outCfg.pixelFormat) {\n+\t\tLOG(LIBYUV, Error)\n+\t\t\t<< \"Pixel format conversion is not supported\"\n+\t\t\t<< \"-In: \" << inCfg.toString()\n+\t\t\t<< \"-Out: \" << outCfg.toString();\n+\t\treturn -EINVAL;\n+\t}\n+\tif (inCfg.size < outCfg.size) {\n+\t\tLOG(LIBYUV, Error) << \"Up-scaling is not supported\"\n+\t\t\t\t   << \", -In: \" << inCfg.toString()\n+\t\t\t\t   << \", -Out: \" << outCfg.toString();\n+\t\treturn -EINVAL;\n+\t}\n+\tif (inCfg.pixelFormat == formats::NV12) {\n+\t\tLOG(LIBYUV, Error) << \"Only NV12 is supported\"\n+\t\t\t\t   << \", -In: \" << inCfg.toString()\n+\t\t\t\t   << \", -Out: \" << outCfg.toString();\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tgetNV12LengthAndStride(inCfg.size, sourceLength_, sourceStride_);\n+\tgetNV12LengthAndStride(outCfg.size, destinationLength_,\n+\t\t\t       destinationStride_);\n+\treturn 0;\n+}\n+\n+int PostProcessorLibyuv::process(const FrameBuffer &source,\n+\t\t\t\t libcamera::MappedBuffer *destination,\n+\t\t\t\t const CameraMetadata & /*requestMetadata*/,\n+\t\t\t\t CameraMetadata * /*metadata*/)\n+{\n+\tif (!IsValidNV12Buffers(source, *destination)) {\n+\t\tLOG(LIBYUV, Error) << \"Invalid source and destination\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tconst MappedFrameBuffer sourceMapped(&source, PROT_READ);\n+\tif (!sourceMapped.isValid()) {\n+\t\tLOG(LIBYUV, Error) << \"Failed to mmap camera frame buffer\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0 == libyuv::NV12Scale(sourceMapped.maps()[0].data(),\n+\t\t\t\t      sourceStride_[0],\n+\t\t\t\t      sourceMapped.maps()[1].data(),\n+\t\t\t\t      sourceStride_[1],\n+\t\t\t\t      sourceSize_.width, sourceSize_.height,\n+\t\t\t\t      destination->maps()[0].data(),\n+\t\t\t\t      destinationStride_[0],\n+\t\t\t\t      destination->maps()[1].data(),\n+\t\t\t\t      destinationStride_[1],\n+\t\t\t\t      destinationSize_.width,\n+\t\t\t\t      destinationSize_.height,\n+\t\t\t\t      libyuv::FilterMode::kFilterBilinear);\n+}\n+\n+bool PostProcessorLibyuv::IsValidNV12Buffers(\n+\tconst FrameBuffer &source,\n+\tconst libcamera::MappedBuffer &destination) const\n+{\n+\tif (source.planes().size() != 2u) {\n+\t\tLOG(LIBYUV, Error) << \"The number of source planes is not 2\";\n+\t\treturn false;\n+\t}\n+\tif (destination.maps().size() != 2u) {\n+\t\tLOG(LIBYUV, Error)\n+\t\t\t<< \"The number of destination planes is not 2\";\n+\t\treturn false;\n+\t}\n+\n+\tif (source.planes()[0].length < sourceLength_[0] ||\n+\t    source.planes()[1].length < sourceLength_[1]) {\n+\t\tLOG(LIBYUV, Error)\n+\t\t\t<< \"The source planes lengths are too small\";\n+\t\treturn false;\n+\t}\n+\tif (destination.maps()[0].size() < destinationLength_[0] ||\n+\t    destination.maps()[1].size() < destinationLength_[1]) {\n+\t\tLOG(LIBYUV, Error)\n+\t\t\t<< \"The destination planes lengths are too small\";\n+\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\ndiff --git a/src/android/libyuv/post_processor_libyuv.h b/src/android/libyuv/post_processor_libyuv.h\nnew file mode 100644\nindex 00000000..40c635a1\n--- /dev/null\n+++ b/src/android/libyuv/post_processor_libyuv.h\n@@ -0,0 +1,38 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2021, Google Inc.\n+ *\n+ * post_processor_libyuv.h - Post Processor using libyuv\n+ */\n+#ifndef __ANDROID_POST_PROCESSOR_LIBYUV_H__\n+#define __ANDROID_POST_PROCESSOR_LIBYUV_H__\n+\n+#include \"../post_processor.h\"\n+\n+class CameraDevice;\n+\n+class PostProcessorLibyuv : public PostProcessor\n+{\n+public:\n+\tPostProcessorLibyuv();\n+\n+\tint configure(const libcamera::StreamConfiguration &incfg,\n+\t\t      const libcamera::StreamConfiguration &outcfg) override;\n+\tint process(const libcamera::FrameBuffer &source,\n+\t\t    libcamera::MappedBuffer *destination,\n+\t\t    const CameraMetadata & /*requestMetadata*/,\n+\t\t    CameraMetadata *metadata) override;\n+\n+private:\n+\tbool IsValidNV12Buffers(const libcamera::FrameBuffer &source,\n+\t\t\t\tconst libcamera::MappedBuffer &destination) const;\n+\n+\tlibcamera::Size sourceSize_;\n+\tlibcamera::Size destinationSize_;\n+\tunsigned int sourceLength_[2] = {};\n+\tunsigned int destinationLength_[2] = {};\n+\tunsigned int sourceStride_[2] = {};\n+\tunsigned int destinationStride_[2] = {};\n+};\n+\n+#endif /* __ANDROID_POST_PROCESSOR_LIBYUV_H__ */\ndiff --git a/src/android/meson.build b/src/android/meson.build\nindex 3d4d3be4..ff067d12 100644\n--- a/src/android/meson.build\n+++ b/src/android/meson.build\n@@ -26,6 +26,7 @@ android_hal_sources = files([\n     'jpeg/exif.cpp',\n     'jpeg/post_processor_jpeg.cpp',\n     'jpeg/thumbnailer.cpp',\n+    'libyuv/post_processor_libyuv.cpp'\n ])\n\n android_camera_metadata_sources = files([\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "2/2"
    ]
}