Show a patch.

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

{
    "id": 16576,
    "url": "https://patchwork.libcamera.org/api/patches/16576/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16576/",
    "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": "<20220707155312.45807-1-ecurtin@redhat.com>",
    "date": "2022-07-07T15:53:13",
    "name": "[libcamera-devel] cam: sdl_sink: Use libjpeg over SDL2_image",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "4a3a417f56843ae4066252dfaa549433ac30a523",
    "submitter": {
        "id": 101,
        "url": "https://patchwork.libcamera.org/api/people/101/?format=api",
        "name": "Eric Curtin",
        "email": "ecurtin@redhat.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/16576/mbox/",
    "series": [
        {
            "id": 3265,
            "url": "https://patchwork.libcamera.org/api/series/3265/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3265",
            "date": "2022-07-07T15:53:13",
            "name": "[libcamera-devel] cam: sdl_sink: Use libjpeg over SDL2_image",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/3265/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16576/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16576/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 9EC3ABE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  7 Jul 2022 15:54:29 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id ECE786043F;\n\tThu,  7 Jul 2022 17:54:28 +0200 (CEST)",
            "from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.133.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id B848660400\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  7 Jul 2022 17:54:26 +0200 (CEST)",
            "from mail-wm1-f69.google.com (mail-wm1-f69.google.com\n\t[209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n\tus-mta-516-TADWGM5fO_6LoUbeKs_sRg-1; Thu, 07 Jul 2022 11:54:24 -0400",
            "by mail-wm1-f69.google.com with SMTP id\n\th186-20020a1c21c3000000b003a2cf5b5aabso937507wmh.8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 07 Jul 2022 08:54:24 -0700 (PDT)",
            "from p1.Home ([2001:8a0:6724:4500:a69c:e66f:828e:b340])\n\tby smtp.gmail.com with ESMTPSA id\n\tp17-20020a5d48d1000000b0021d63da245bsm14671644wrs.97.2022.07.07.08.54.21\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 07 Jul 2022 08:54:21 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1657209269;\n\tbh=8neRmBwpcfSDjY4GgPexpp1pG60zwX1JrtAyc4+VuSQ=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:Cc:From;\n\tb=UmWWLQbY+kLkOKv7vYKVVmMZQZRQNooXOgPx1kXVAAeGmZspvG8tIPQKnYe3JeTsm\n\to3xntG+qfezq64kDP5OMxIIyCvWxmc6bR7SyOLKL3fneQ6DOHMsgaZyUbxp/eegw6W\n\tnLt4sDnut+r+mU75DFy3nTHdIQPu30mebDmr2cYNANlVnYPg8xJ4ej+h8bD+4lh8wC\n\tB3TnaXRvAwglp/kgpcNjPXIsknyq/z/GQoEjoNR2N+iue8djTt9jkyibOMxOZxQJYk\n\tUXTjITJtck1PV1nvzmje+DLJJ9ctk8RqLQLu32tkfEoVnf7AoB2IFPxlX0SToXut+d\n\tgi/ReAqpLCi8A==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1657209265;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tcontent-transfer-encoding:content-transfer-encoding;\n\tbh=uERE4ERvMh4/idYtIiwu7IhQEtRUq0pijq9BreHoz1A=;\n\tb=JEgH8591IkIAaK2riEkQ2ufECsn2uOvTftrDSjtvu42sKC7crYUPOO0+w+CHC3L3qWoYO6\n\tk6XW9vYW34T2ChSUr8jIBp2hfZwn/EK1QkdkV3kxSW44vXcbCtp3SZjI7d1t93E1VATlTh\n\t/qn4e50Z++xrV2ONftVmmyrlixaQsug="
        ],
        "Authentication-Results": [
            "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"JEgH8591\"; \n\tdkim-atps=neutral",
            "relay.mimecast.com;\n\tauth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com"
        ],
        "X-MC-Unique": "TADWGM5fO_6LoUbeKs_sRg-1",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=uERE4ERvMh4/idYtIiwu7IhQEtRUq0pijq9BreHoz1A=;\n\tb=CyNuHfUSI1DtfJ5k/vDdjep4V/P7Z/W8XXJjGHtbtqMquCrzhawO4wV5uCiwwj1QXF\n\toJR/cafKH0XRGRf9YsytEPAyvEkZYw+N6AFn7ji9KarL3yAQT3Sz4JtENwf4nUsJ/WSJ\n\tCGWibVmDJY8vbE3DZv32NVOAzM3DZQr/2G73KYrYxYn13HVJBiaZ3oIpGHKoHbahHufx\n\tMUB28IYDkodi5eK7eamN4w0eZKxbDXZse4fakkj3y9N0izcRSgGhMnQc6dRWrV6wFN+F\n\tivJTUI85J18RPWKqBU9rHt/jB3P6YZzPAhydvXKa2KnFviGgikI1bvDRHUrFqMS/HDh6\n\tUMvQ==",
        "X-Gm-Message-State": "AJIora+8+b57LGyFIbV3j7JFj0JPJbbikXg2REzyMxQAZtwRyv9ZK8ue\n\ttxbmlM5Znb2WgipvStM3m6AzNm0FLtgTDvebu0nsqLwAbbPByiYvYCk8O/BS9H1NMipT37V+Gcp\n\tEBT/e92KyvON1Am8toGVLcbGRomQ5j4zLvmd3Arej66K7tkXKlUEEqF455G5m1a0kuTynN1CmNS\n\tT2a90V4VT2",
        "X-Received": [
            "by 2002:adf:d1c1:0:b0:21b:a5e9:b7b2 with SMTP id\n\tb1-20020adfd1c1000000b0021ba5e9b7b2mr45671754wrd.405.1657209262705; \n\tThu, 07 Jul 2022 08:54:22 -0700 (PDT)",
            "by 2002:adf:d1c1:0:b0:21b:a5e9:b7b2 with SMTP id\n\tb1-20020adfd1c1000000b0021ba5e9b7b2mr45671721wrd.405.1657209262242; \n\tThu, 07 Jul 2022 08:54:22 -0700 (PDT)"
        ],
        "X-Google-Smtp-Source": "AGRyM1uapbr/2YHCoewFawlzd6v7W10cXj3X2JKrXIcCXnl1xc9lHmT8adqvJnCPW+DCEpraj8hDLA==",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Thu,  7 Jul 2022 16:53:13 +0100",
        "Message-Id": "<20220707155312.45807-1-ecurtin@redhat.com>",
        "X-Mailer": "git-send-email 2.35.3",
        "MIME-Version": "1.0",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "Content-Type": "text/plain; charset=\"US-ASCII\"; x-default=true",
        "Subject": "[libcamera-devel] [PATCH] cam: sdl_sink: Use libjpeg over SDL2_image",
        "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>",
        "From": "Eric Curtin via libcamera-devel <libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Eric Curtin <ecurtin@redhat.com>",
        "Cc": "martijn@brixit.nl, jozef@mlich.cz",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "We were using the libjpeg functionality of SDL2_image only, instead just\nuse libjpeg directly to reduce our dependancy count, it is a more\ncommonly available library.\n\nSigned-off-by: Eric Curtin <ecurtin@redhat.com>\n---\n README.rst                   |  2 +-\n src/cam/meson.build          |  8 +++----\n src/cam/sdl_sink.cpp         |  4 ++--\n src/cam/sdl_texture.h        |  2 +-\n src/cam/sdl_texture_mjpg.cpp | 43 +++++++++++++++++++++++++++++++-----\n src/cam/sdl_texture_mjpg.h   |  5 +++++\n 6 files changed, 51 insertions(+), 13 deletions(-)",
    "diff": "diff --git a/README.rst b/README.rst\nindex b9e72d81..5e8bc1cc 100644\n--- a/README.rst\n+++ b/README.rst\n@@ -93,7 +93,7 @@ for cam: [optional]\n \n         - libdrm-dev: Enables the KMS sink\n         - libsdl2-dev: Enables the SDL sink\n-        - libsdl2-image-dev: Supports MJPEG on the SDL sink\n+        - libjpeg-dev: Supports MJPEG on the SDL sink\n \n for qcam: [optional]\n         qtbase5-dev libqt5core5a libqt5gui5 libqt5widgets5 qttools5-dev-tools libtiff-dev\ndiff --git a/src/cam/meson.build b/src/cam/meson.build\nindex 5957ce14..27cbd0de 100644\n--- a/src/cam/meson.build\n+++ b/src/cam/meson.build\n@@ -25,7 +25,7 @@ cam_cpp_args = []\n \n libdrm = dependency('libdrm', required : false)\n libsdl2 = dependency('SDL2', required : false)\n-libsdl2_image = dependency('SDL2_image', required : false)\n+libjpeg = dependency('libjpeg', required : false)\n \n if libdrm.found()\n     cam_cpp_args += [ '-DHAVE_KMS' ]\n@@ -43,8 +43,8 @@ if libsdl2.found()\n         'sdl_texture_yuyv.cpp'\n     ])\n \n-    if libsdl2_image.found()\n-        cam_cpp_args += ['-DHAVE_SDL_IMAGE']\n+    if libjpeg.found()\n+        cam_cpp_args += ['-DHAVE_LIBJPEG']\n         cam_sources += files([\n             'sdl_texture_mjpg.cpp'\n         ])\n@@ -58,7 +58,7 @@ cam  = executable('cam', cam_sources,\n                       libdrm,\n                       libevent,\n                       libsdl2,\n-                      libsdl2_image,\n+                      libjpeg,\n                       libyaml,\n                   ],\n                   cpp_args : cam_cpp_args,\ndiff --git a/src/cam/sdl_sink.cpp b/src/cam/sdl_sink.cpp\nindex f8e3e95d..19fdfd6d 100644\n--- a/src/cam/sdl_sink.cpp\n+++ b/src/cam/sdl_sink.cpp\n@@ -21,7 +21,7 @@\n \n #include \"event_loop.h\"\n #include \"image.h\"\n-#ifdef HAVE_SDL_IMAGE\n+#ifdef HAVE_LIBJPEG\n #include \"sdl_texture_mjpg.h\"\n #endif\n #include \"sdl_texture_yuyv.h\"\n@@ -62,7 +62,7 @@ int SDLSink::configure(const libcamera::CameraConfiguration &config)\n \trect_.h = cfg.size.height;\n \n \tswitch (cfg.pixelFormat) {\n-#ifdef HAVE_SDL_IMAGE\n+#ifdef HAVE_LIBJPEG\n \tcase libcamera::formats::MJPEG:\n \t\ttexture_ = std::make_unique<SDLTextureMJPG>(rect_);\n \t\tbreak;\ndiff --git a/src/cam/sdl_texture.h b/src/cam/sdl_texture.h\nindex 90974798..42c906f2 100644\n--- a/src/cam/sdl_texture.h\n+++ b/src/cam/sdl_texture.h\n@@ -25,5 +25,5 @@ protected:\n \tSDL_Texture *ptr_;\n \tconst SDL_Rect rect_;\n \tconst SDL_PixelFormatEnum pixelFormat_;\n-\tconst int pitch_;\n+\tint pitch_;\n };\ndiff --git a/src/cam/sdl_texture_mjpg.cpp b/src/cam/sdl_texture_mjpg.cpp\nindex 69e99ad3..232af673 100644\n--- a/src/cam/sdl_texture_mjpg.cpp\n+++ b/src/cam/sdl_texture_mjpg.cpp\n@@ -7,19 +7,52 @@\n \n #include \"sdl_texture_mjpg.h\"\n \n-#include <SDL2/SDL_image.h>\n+#include <jpeglib.h>\n \n using namespace libcamera;\n \n SDLTextureMJPG::SDLTextureMJPG(const SDL_Rect &rect)\n \t: SDLTexture(rect, SDL_PIXELFORMAT_RGB24, 0)\n {\n+\tpitch_ = rect_.w * 3;\n+\trgbdata_ = (unsigned char *)malloc(pitch_ * rect_.h);\n+}\n+\n+SDLTextureMJPG::~SDLTextureMJPG()\n+{\n+\tfree(rgbdata_);\n+}\n+\n+void SDLTextureMJPG::decompress(const unsigned char *jpeg,\n+\t\t\t\tunsigned long jpeg_size)\n+{\n+\tstruct jpeg_error_mgr jerr;\n+\tstruct jpeg_decompress_struct cinfo;\n+\tcinfo.err = jpeg_std_error(&jerr);\n+\n+\tjpeg_create_decompress(&cinfo);\n+\n+\tjpeg_mem_src(&cinfo, jpeg, jpeg_size);\n+\n+\tjpeg_read_header(&cinfo, TRUE);\n+\n+\tjpeg_start_decompress(&cinfo);\n+\n+\tint row_stride = cinfo.output_width * cinfo.output_components;\n+\tunsigned char *buffer = (unsigned char *)malloc(row_stride);\n+\tfor (int i = 0; cinfo.output_scanline < cinfo.output_height; ++i) {\n+\t\tjpeg_read_scanlines(&cinfo, &buffer, 1);\n+\t\tmemcpy(rgbdata_ + i * pitch_, buffer, row_stride);\n+\t}\n+\n+\tfree(buffer);\n+\tjpeg_finish_decompress(&cinfo);\n+\n+\tjpeg_destroy_decompress(&cinfo);\n }\n \n void SDLTextureMJPG::update(const Span<uint8_t> &data)\n {\n-\tSDL_RWops *bufferStream = SDL_RWFromMem(data.data(), data.size());\n-\tSDL_Surface *frame = IMG_Load_RW(bufferStream, 0);\n-\tSDL_UpdateTexture(ptr_, nullptr, frame->pixels, frame->pitch);\n-\tSDL_FreeSurface(frame);\n+\tdecompress(data.data(), data.size());\n+\tSDL_UpdateTexture(ptr_, nullptr, rgbdata_, pitch_);\n }\ndiff --git a/src/cam/sdl_texture_mjpg.h b/src/cam/sdl_texture_mjpg.h\nindex b103f801..73c7fb68 100644\n--- a/src/cam/sdl_texture_mjpg.h\n+++ b/src/cam/sdl_texture_mjpg.h\n@@ -13,5 +13,10 @@ class SDLTextureMJPG : public SDLTexture\n {\n public:\n \tSDLTextureMJPG(const SDL_Rect &rect);\n+\tvirtual ~SDLTextureMJPG();\n \tvoid update(const libcamera::Span<uint8_t> &data) override;\n+\n+private:\n+\tunsigned char *rgbdata_ = 0;\n+\tvoid decompress(const unsigned char *jpeg, unsigned long jpeg_size);\n };\n",
    "prefixes": [
        "libcamera-devel"
    ]
}