Show a patch.

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

{
    "id": 1162,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1162/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1162/",
    "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": "<20190506201528.24445-2-paul.elder@ideasonboard.com>",
    "date": "2019-05-06T20:15:28",
    "name": "[libcamera-devel,v2,2/2] qcam: format_converter: Add NV formats support",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "159d5940d655c63b0c845ded9392616dc4cf7e1c",
    "submitter": {
        "id": 17,
        "url": "https://patchwork.libcamera.org/api/1.1/people/17/?format=api",
        "name": "Paul Elder",
        "email": "paul.elder@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/1162/mbox/",
    "series": [
        {
            "id": 298,
            "url": "https://patchwork.libcamera.org/api/1.1/series/298/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=298",
            "date": "2019-05-06T20:15:27",
            "name": "[libcamera-devel,v2,1/2] qcam: format_converter: Add formatFamily enum",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/298/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1162/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1162/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<paul.elder@ideasonboard.com>",
        "Received": [
            "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 3B6AE60E63\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  6 May 2019 22:15:37 +0200 (CEST)",
            "from localhost.localdomain (unknown [96.44.9.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 72728124B;\n\tMon,  6 May 2019 22:15:36 +0200 (CEST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1557173736;\n\tbh=0B7HvSx2+neaInLbb2VQ84YrUHw4F2cT4TAgIGFQA1A=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Ifdymx7ThuNETCx/sFI3swMErBxH3R2mN/c4BoddVoILxZUb7VUQi3MJuM28OpWNc\n\t5aXsl8TpD30aOxufksQrGwHZ7DVWiJFQb02NKl9TtWXGyuYELDtpVKNZAMJT7224cE\n\tCdoRliBabudlGVcTFnx2VAYpZkHALNNnzAp1eHMo=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon,  6 May 2019 16:15:28 -0400",
        "Message-Id": "<20190506201528.24445-2-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20190506201528.24445-1-paul.elder@ideasonboard.com>",
        "References": "<20190506201528.24445-1-paul.elder@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 2/2] qcam: format_converter: Add NV\n\tformats support",
        "X-BeenThere": "libcamera-devel@lists.libcamera.org",
        "X-Mailman-Version": "2.1.23",
        "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>",
        "X-List-Received-Date": "Mon, 06 May 2019 20:15:37 -0000"
    },
    "content": "Add support for some NV formats:\n- V4L2_PIX_FMT_NV12, V4L2_PIX_FMT_NV21\n- V4L2_PIX_FMT_NV16, V4L2_PIX_FMT_NV61\n- V4L2_PIX_FMT_NV24, V4L2_PIX_FMT_NV42\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\nChanges in v2:\n- reorder functions in format_converter.cpp to match format_converter.h\n  (move yuv_to_rgb() to be before all specialized convert functions)\n- renamed NV conversion parameters from xDownSample_ and yDownSample_ to\n  horzSubSample_ and vertSubSample_, respectively\n- unrolled the loop and simplify some of the calculations in convertNV()\n  and achieved a 1.67 speedup compared to v1\n\n src/qcam/format_converter.cpp | 99 +++++++++++++++++++++++++++++++----\n src/qcam/format_converter.h   |  7 +++\n 2 files changed, 96 insertions(+), 10 deletions(-)",
    "diff": "diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp\nindex 192767c..eab222f 100644\n--- a/src/qcam/format_converter.cpp\n+++ b/src/qcam/format_converter.cpp\n@@ -72,6 +72,42 @@ int FormatConverter::configure(unsigned int format, unsigned int width,\n \t\ty_pos_ = 0;\n \t\tcb_pos_ = 1;\n \t\tbreak;\n+\tcase V4L2_PIX_FMT_NV12:\n+\t\tformatFamily_ = NV;\n+\t\thorzSubSample_ = 2;\n+\t\tvertSubSample_ = 2;\n+\t\tnvSwap_ = false;\n+\t\tbreak;\n+\tcase V4L2_PIX_FMT_NV21:\n+\t\tformatFamily_ = NV;\n+\t\thorzSubSample_ = 2;\n+\t\tvertSubSample_ = 2;\n+\t\tnvSwap_ = true;\n+\t\tbreak;\n+\tcase V4L2_PIX_FMT_NV16:\n+\t\tformatFamily_ = NV;\n+\t\thorzSubSample_ = 2;\n+\t\tvertSubSample_ = 1;\n+\t\tnvSwap_ = false;\n+\t\tbreak;\n+\tcase V4L2_PIX_FMT_NV61:\n+\t\tformatFamily_ = NV;\n+\t\thorzSubSample_ = 2;\n+\t\tvertSubSample_ = 1;\n+\t\tnvSwap_ = true;\n+\t\tbreak;\n+\tcase V4L2_PIX_FMT_NV24:\n+\t\tformatFamily_ = NV;\n+\t\thorzSubSample_ = 1;\n+\t\tvertSubSample_ = 1;\n+\t\tnvSwap_ = false;\n+\t\tbreak;\n+\tcase V4L2_PIX_FMT_NV42:\n+\t\tformatFamily_ = NV;\n+\t\thorzSubSample_ = 1;\n+\t\tvertSubSample_ = 1;\n+\t\tnvSwap_ = true;\n+\t\tbreak;\n \tcase V4L2_PIX_FMT_MJPEG:\n \t\tformatFamily_ = MJPEG;\n \t\tbreak;\n@@ -99,9 +135,62 @@ void FormatConverter::convert(const unsigned char *src, size_t size,\n \tcase RGB:\n \t\tconvertRGB(src, dst->bits());\n \t\tbreak;\n+\tcase NV:\n+\t\tconvertNV(src, dst->bits());\n+\t\tbreak;\n \t};\n }\n \n+static void yuv_to_rgb(int y, int u, int v, int *r, int *g, int *b)\n+{\n+\tint c = y - 16;\n+\tint d = u - 128;\n+\tint e = v - 128;\n+\t*r = CLIP(( 298 * c           + 409 * e + 128) >> RGBSHIFT);\n+\t*g = CLIP(( 298 * c - 100 * d - 208 * e + 128) >> RGBSHIFT);\n+\t*b = CLIP(( 298 * c + 516 * d           + 128) >> RGBSHIFT);\n+}\n+\n+void FormatConverter::convertNV(const unsigned char *src, unsigned char *dst)\n+{\n+\tunsigned int x, y;\n+\tint r, g, b;\n+\n+\tunsigned int c_stride = width_ * (2 / horzSubSample_);\n+\tunsigned int c_inc = horzSubSample_ == 1 ? 2 : 0;\n+\tunsigned int cb_pos = nvSwap_ ? 1 : 0;\n+\tunsigned int cr_pos = nvSwap_ ? 0 : 1;\n+\tunsigned int base = width_ * height_;\n+\n+\tfor (y = 0; y < height_; y++) {\n+\t\tunsigned char *src_y = (unsigned char *)src + y * width_;\n+\t\tunsigned char *src_cb = (unsigned char *)src + base + (y / vertSubSample_) * c_stride + cb_pos;\n+\t\tunsigned char *src_cr = (unsigned char *)src + base + (y / vertSubSample_) * c_stride + cr_pos;\n+\n+\t\tfor (x = 0; x < width_; x += 2) {\n+\t\t\tyuv_to_rgb(*src_y, *src_cb, *src_cr, &r, &g, &b);\n+\t\t\tdst[0] = b;\n+\t\t\tdst[1] = g;\n+\t\t\tdst[2] = r;\n+\t\t\tdst[3] = 0xff;\n+\t\t\tsrc_y++;\n+\t\t\tsrc_cb += c_inc;\n+\t\t\tsrc_cr += c_inc;\n+\t\t\tdst += 4;\n+\n+\t\t\tyuv_to_rgb(*src_y, *src_cb, *src_cr, &r, &g, &b);\n+\t\t\tdst[0] = b;\n+\t\t\tdst[1] = g;\n+\t\t\tdst[2] = r;\n+\t\t\tdst[3] = 0xff;\n+\t\t\tsrc_y++;\n+\t\t\tsrc_cb += 2;\n+\t\t\tsrc_cr += 2;\n+\t\t\tdst += 4;\n+\t\t}\n+\t}\n+}\n+\n void FormatConverter::convertRGB(const unsigned char *src, unsigned char *dst)\n {\n \tunsigned int x, y;\n@@ -124,16 +213,6 @@ void FormatConverter::convertRGB(const unsigned char *src, unsigned char *dst)\n \t}\n }\n \n-static void yuv_to_rgb(int y, int u, int v, int *r, int *g, int *b)\n-{\n-\tint c = y - 16;\n-\tint d = u - 128;\n-\tint e = v - 128;\n-\t*r = CLIP(( 298 * c           + 409 * e + 128) >> RGBSHIFT);\n-\t*g = CLIP(( 298 * c - 100 * d - 208 * e + 128) >> RGBSHIFT);\n-\t*b = CLIP(( 298 * c + 516 * d           + 128) >> RGBSHIFT);\n-}\n-\n void FormatConverter::convertYUV(const unsigned char *src, unsigned char *dst)\n {\n \tunsigned int src_x, src_y, dst_x, dst_y;\ndiff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h\nindex c18871e..ad67081 100644\n--- a/src/qcam/format_converter.h\n+++ b/src/qcam/format_converter.h\n@@ -16,6 +16,7 @@ class FormatConverter\n public:\n \tenum FormatFamily {\n \t\tMJPEG,\n+\t\tNV,\n \t\tRGB,\n \t\tYUV,\n \t};\n@@ -26,6 +27,7 @@ public:\n \tvoid convert(const unsigned char *src, size_t size, QImage *dst);\n \n private:\n+\tvoid convertNV(const unsigned char *src, unsigned char *dst);\n \tvoid convertRGB(const unsigned char *src, unsigned char *dst);\n \tvoid convertYUV(const unsigned char *src, unsigned char *dst);\n \n@@ -35,6 +37,11 @@ private:\n \n \tenum FormatFamily formatFamily_;\n \n+\t/* NV parameters */\n+\tunsigned int horzSubSample_;\n+\tunsigned int vertSubSample_;\n+\tbool nvSwap_;\n+\n \t/* RGB parameters */\n \tunsigned int bpp_;\n \tunsigned int r_pos_;\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "2/2"
    ]
}