Show a patch.

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

{
    "id": 1164,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/1164/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/1164/",
    "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": "<20190506223430.3203-2-paul.elder@ideasonboard.com>",
    "date": "2019-05-06T22:34:30",
    "name": "[libcamera-devel,v3,2/2] qcam: format_converter: Add NV formats support",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "606f9a9e4b70298f0300cc64aa79061d729ea141",
    "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/1164/mbox/",
    "series": [
        {
            "id": 299,
            "url": "https://patchwork.libcamera.org/api/1.1/series/299/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=299",
            "date": "2019-05-06T22:34:29",
            "name": "[libcamera-devel,v3,1/2] qcam: format_converter: Add formatFamily enum",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/299/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/1164/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/1164/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<paul.elder@ideasonboard.com>",
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DA7BC60E66\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  7 May 2019 00:34:49 +0200 (CEST)",
            "from localhost.localdomain (unknown [96.44.9.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 273E555B;\n\tTue,  7 May 2019 00:34:49 +0200 (CEST)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1557182089;\n\tbh=tce0Sfelzwtn0mt7s4DH4jGRHdMIoOc4RooirapXIJQ=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=eImmZLDRIzM523lL4svwue2SCnqNeVTwGU2Dft3xD6lgMy6+a+62ujs1LJZ99kdsC\n\tpBhN1t4eI6A1fRl9ARv8lmy58uI4ReNbP4wJPhvVz6aez//Y0hj6cuZbKiTGvUn4xK\n\txneOwlpHA9RhxPQCliwgq6kcpdGi1Ii+z4nRt/0A=",
        "From": "Paul Elder <paul.elder@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon,  6 May 2019 18:34:30 -0400",
        "Message-Id": "<20190506223430.3203-2-paul.elder@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.20.1",
        "In-Reply-To": "<20190506223430.3203-1-paul.elder@ideasonboard.com>",
        "References": "<20190506223430.3203-1-paul.elder@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v3 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 22:34:50 -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 v3:\n- reorder the switch cases to match the order of the functions and enum\n- fix const -> non-const pointer cast in convertNV()\n- other minor syle changes\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 | 100 ++++++++++++++++++++++++++++++----\n src/qcam/format_converter.h   |   7 +++\n 2 files changed, 97 insertions(+), 10 deletions(-)",
    "diff": "diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp\nindex 192767c..d90f933 100644\n--- a/src/qcam/format_converter.cpp\n+++ b/src/qcam/format_converter.cpp\n@@ -31,6 +31,42 @@ int FormatConverter::configure(unsigned int format, unsigned int width,\n \t\t\t       unsigned int height)\n {\n \tswitch (format) {\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_BGR24:\n \t\tformatFamily_ = RGB;\n \t\tr_pos_ = 2;\n@@ -99,9 +135,63 @@ 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+\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+\tconst unsigned char *src_c = src + width_ * height_;\n+\n+\tfor (unsigned int y = 0; y < height_; y++) {\n+\t\tconst unsigned char *src_y = src + y * width_;\n+\t\tconst unsigned char *src_cb = src_c + (y / vertSubSample_) *\n+\t\t\t\t\t      c_stride + cb_pos;\n+\t\tconst unsigned char *src_cr = src_c + (y / vertSubSample_) *\n+\t\t\t\t\t      c_stride + cr_pos;\n+\n+\t\tfor (unsigned int 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 +214,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 bca44aa..391e6a4 100644\n--- a/src/qcam/format_converter.h\n+++ b/src/qcam/format_converter.h\n@@ -22,10 +22,12 @@ public:\n private:\n \tenum FormatFamily {\n \t\tMJPEG,\n+\t\tNV,\n \t\tRGB,\n \t\tYUV,\n \t};\n \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",
        "v3",
        "2/2"
    ]
}