Show a patch.

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

{
    "id": 11047,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/11047/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/11047/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20210128224217.2919790-3-hiroh@chromium.org>",
    "date": "2021-01-28T22:42:16",
    "name": "[libcamera-devel,v3,2/2] android: libyuv: Introduce PostProcessorLibyuv",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "9264a32755575c121352deca9d5a4d0753a4410a",
    "submitter": {
        "id": 63,
        "url": "https://patchwork.libcamera.org/api/1.1/people/63/?format=api",
        "name": "Hirokazu Honda",
        "email": "hiroh@chromium.org"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/11047/mbox/",
    "series": [
        {
            "id": 1622,
            "url": "https://patchwork.libcamera.org/api/1.1/series/1622/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1622",
            "date": "2021-01-28T22:42:14",
            "name": "Introduce post processor using libyuv",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/1622/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/11047/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/11047/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 0D5E5BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 28 Jan 2021 22:42:30 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CFFA968396;\n\tThu, 28 Jan 2021 23:42:29 +0100 (CET)",
            "from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com\n\t[IPv6:2607:f8b0:4864:20::1034])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B47856838E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Jan 2021 23:42:27 +0100 (CET)",
            "by mail-pj1-x1034.google.com with SMTP id l18so5250978pji.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Jan 2021 14:42:27 -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\tmd7sm5866288pjb.52.2021.01.28.14.42.24\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 28 Jan 2021 14:42:25 -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=\"VYv5JfnV\"; 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=Sb/64puLYPXfOeUQQBdbMmKpH6LeVFA1Wk43ULvbUFg=;\n\tb=VYv5JfnVKEBJdW3At7mTNS8N4QszW2VvwqTvWHr7w71gdUdNHBVVpsrEuFyG18DMTs\n\tWGfGdAyR4u3RSsgnXLwm3b/eO/mqGSMwg1N0Yse+jhNh4G0VrbyA2nUfvud11BZpDt/H\n\twPSLlUz72WMxQZERv77HU5hFBhG4gTWaEkxLA=",
        "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=Sb/64puLYPXfOeUQQBdbMmKpH6LeVFA1Wk43ULvbUFg=;\n\tb=ulSd4yO3O9IrxBRdfPpS/aF1g25u30lX8ayayn6HNZE9Urp7K6HeZ+qFqLHed2Is0b\n\tF5kSPNsb2PjDa7J7lIKdnHLXeb7M6jSDoyXIW8DvqVVAdDJ4YzbIyOCClcPNTE3Rgyz2\n\tJDtfY3nH5SqZzXtV17ipY61VPIbdesIs7kfMu0M/iVUhVL9IjlBWbCMAqqqLQrlZevF9\n\te1uwOftHA29cVaXHErGI3v9XVGGyQ17Pc/KH0Ef8s72yJXC0+2v+Dw6aV39HhkLSsbFj\n\tumFek8dguGH2qYIXhQx+DpqWzzl8OKQo5CZbmDcHRXNFJhAZcHnYsarA5e81ip4y5MnY\n\txXFw==",
        "X-Gm-Message-State": "AOAM5312rlTuIB7/PZhgWDJSIcOk/hcvXNhRaockFCZLNqD32ukUkES8\n\t8ZpHWH2zHXUAMqbcGHB6pgLJGBEC+N+MLoc+",
        "X-Google-Smtp-Source": "ABdhPJyaGOKiD0F++j5MGT0kjVZTAsEBMCN4Af8LLe34KwEuWCs9Qwz3m+k7xPP9rhvXpAdRxqNnpg==",
        "X-Received": "by 2002:a17:902:bb90:b029:df:bdbb:be99 with SMTP id\n\tm16-20020a170902bb90b02900dfbdbbbe99mr1358500pls.52.1611873745957; \n\tThu, 28 Jan 2021 14:42:25 -0800 (PST)",
        "From": "Hirokazu Honda <hiroh@chromium.org>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu, 28 Jan 2021 22:42:16 +0000",
        "Message-Id": "<20210128224217.2919790-3-hiroh@chromium.org>",
        "X-Mailer": "git-send-email 2.30.0.365.g02bc693789-goog",
        "In-Reply-To": "<20210128224217.2919790-1-hiroh@chromium.org>",
        "References": "<20210128224217.2919790-1-hiroh@chromium.org>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v3 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 | 123 +++++++++++++++++++\n src/android/libyuv/post_processor_libyuv.h   |  44 +++++++\n src/android/meson.build                      |   1 +\n 3 files changed, 168 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.365.g02bc693789-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..81f237e0\n--- /dev/null\n+++ b/src/android/libyuv/post_processor_libyuv.cpp\n@@ -0,0 +1,123 @@\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+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<< \" (from \" << inCfg.toString()\n+\t\t\t<< \" to \" << outCfg.toString() << \")\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (inCfg.size < outCfg.size) {\n+\t\tLOG(LIBYUV, Error) << \"Up-scaling is not supported\"\n+\t\t\t\t   << \" (from \" << inCfg.toString()\n+\t\t\t\t   << \" to \" << outCfg.toString() << \")\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (inCfg.pixelFormat == formats::NV12) {\n+\t\tLOG(LIBYUV, Error) << \"Unsupported format \" << inCfg.pixelFormat\n+\t\t\t\t   << \" (only NV12 is supported)\";\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 [[maybe_unused]] const CameraMetadata &requestMetadata,\n+\t\t\t\t [[maybe_unused]] CameraMetadata *metadata)\n+{\n+\tif (!isValidNV12Buffers(source, *destination))\n+\t\treturn -EINVAL;\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+}\n+\n+// static\n+void PostProcessorLibyuv::getNV12LengthAndStride(Size size,\n+\t\t\t\t\t\t unsigned int length[2],\n+\t\t\t\t\t\t unsigned int stride[2])\n+{\n+\tconst PixelFormatInfo &nv12Info = PixelFormatInfo::info(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+}\ndiff --git a/src/android/libyuv/post_processor_libyuv.h b/src/android/libyuv/post_processor_libyuv.h\nnew file mode 100644\nindex 00000000..a65a16b3\n--- /dev/null\n+++ b/src/android/libyuv/post_processor_libyuv.h\n@@ -0,0 +1,44 @@\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 <libcamera/geometry.h>\n+\n+#include \"../post_processor.h\"\n+\n+class CameraDevice;\n+\n+class PostProcessorLibyuv : public PostProcessor\n+{\n+public:\n+\tPostProcessorLibyuv() = default;\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+\tstatic void getNV12LengthAndStride(libcamera::Size size,\n+\t\t\t\t\t   unsigned int length[2],\n+\t\t\t\t\t   unsigned int stride[2]);\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 e1533d7c..cbe09200 100644\n--- a/src/android/meson.build\n+++ b/src/android/meson.build\n@@ -44,6 +44,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",
        "v3",
        "2/2"
    ]
}