Show a patch.

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

{
    "id": 16676,
    "url": "https://patchwork.libcamera.org/api/patches/16676/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/16676/",
    "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": "<20220718115128.22437-1-ecurtin@redhat.com>",
    "date": "2022-07-18T11:51:29",
    "name": "[libcamera-devel,v3] cam: sdl_sink: Use libjpeg over SDL2_image",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "adef53663835524383d8135225e3415e07101e00",
    "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/16676/mbox/",
    "series": [
        {
            "id": 3294,
            "url": "https://patchwork.libcamera.org/api/series/3294/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3294",
            "date": "2022-07-18T11:51:29",
            "name": "[libcamera-devel,v3] cam: sdl_sink: Use libjpeg over SDL2_image",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/3294/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/16676/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/16676/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 1C0C6BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 18 Jul 2022 11:54:18 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7774A63312;\n\tMon, 18 Jul 2022 13:54:17 +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 77E4E6048B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Jul 2022 13:54:16 +0200 (CEST)",
            "from mail-wr1-f70.google.com (mail-wr1-f70.google.com\n\t[209.85.221.70]) 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-454-oPOeMLwoP7m_WIgQKnX9rQ-1; Mon, 18 Jul 2022 07:54:14 -0400",
            "by mail-wr1-f70.google.com with SMTP id\n\tk26-20020adfb35a000000b0021d6c3b9363so1931589wrd.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Jul 2022 04:54:14 -0700 (PDT)",
            "from p1.Home ([2001:8a0:6724:4500:a69c:e66f:828e:b340])\n\tby smtp.gmail.com with ESMTPSA id\n\tg20-20020a05600c4ed400b003a2cfb9f5basm21114471wmq.16.2022.07.18.04.54.11\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 18 Jul 2022 04:54:12 -0700 (PDT)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1658145257;\n\tbh=8ikKDZdNm1sMQsuvMyik1hVl0obCVDLUH5ZQHKRH2AU=;\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=RXSp/PBVvInnmyBzbNMi8+NPypVRP4wj0drpdDtRCcDoHZCOLEylAjERJlYZDGDlW\n\tZFtr2QVcij0SvBO+YXIYW1QmlHNiJGlr8PKZeI3MDGts+/nMCQk/zyYARguuWKgAJz\n\t2Gi4omvpLzZACCRee1W6AKLgqF9W66ZxXLrUsSjFub9kIg2CVudo+kpSoCnH9Ao7ut\n\tygUaw/05SaucL7PesOIu6MdIMZb0pKGPsV/Vg6sx4F7rgAhMSkUyTSTMq5fQ5ORXCF\n\tpHk3CfQiwOq0J8kFsRbcy9uG9R3ziPLR3Dvz3VstUviN95oOep6D57GkDfkv/Zjr6o\n\t+Q/lA9iHm56uw==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1658145255;\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=1CqFCwRwfGZ6wUjAuCgGdxoC1sKD43hr0CFFDVZlqTg=;\n\tb=P5BobyXaO1BcJzLbRQe8ZPOHTHCfcGtK1TaxL5VHoB1zCI3JT2gXK3tVY/UVeYMIfgoUDZ\n\tOpSayZi37lfaAwj0TR5X8g2yZOjxHm9LpD+DwdlN+twXlRLJ4+iXxz2OahKyHytWF1sOHp\n\t0h6X7d5LUGt55PMpE92A/BmRJn7YQas="
        ],
        "Authentication-Results": [
            "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=redhat.com\n\theader.i=@redhat.com header.b=\"P5BobyXa\"; \n\tdkim-atps=neutral",
            "relay.mimecast.com;\n\tauth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ecurtin@redhat.com"
        ],
        "X-MC-Unique": "oPOeMLwoP7m_WIgQKnX9rQ-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=1CqFCwRwfGZ6wUjAuCgGdxoC1sKD43hr0CFFDVZlqTg=;\n\tb=FDSvRkDGZuPGr4eimTnnrMxRt1AOzbMlwovwV5pGO5B37D0tbQ+0DmrT/9JJ9sws6M\n\thVWgtZGcVbw6kPxybpgq5Qet5TqU42zkW1/2QTW6zuifLdAuMPa1EMDiAWe4gh73cocZ\n\tg27GW1Mo9RbOCsRHHksauqTJsiPXc++AGDYCvBXv6iHRNz0Su/iU1Ux7C8CYrNQ7+Sav\n\tcxd+7w1/GtBkPt8STd8teSE3oBofyoPh0GqEOMIcOEio6jj8c58TF5prSkd3cG3bEdCy\n\tdzZayhblZVm6E5Oa9NEgkCDxBWl+dGz9SjOxR8ZgiO6tuQFFHAuYd/RwyX2KvIoGXC3Z\n\tcvBA==",
        "X-Gm-Message-State": "AJIora/m/snCJU8gz6uFXfHCuuep7ugLafdYf2txQ7CGmhQSS1d6mtsN\n\tLrbWx5tZqHmEozt/2dqGdqTJ7aEL/Dgylb+dnP/0DXZ3wTSUobcedDDqJZDCG+gJ1PYm6TeIfqk\n\tpkBwq7khHAbHMeDDd/31FGrk0LcTPx4lAhzoq9l6t+P2J3ogtDwfqfxQX/juWNfvGaaHatPxyjy\n\tsX5hUz1pph",
        "X-Received": [
            "by 2002:a5d:5952:0:b0:21d:7c9b:e444 with SMTP id\n\te18-20020a5d5952000000b0021d7c9be444mr22861355wri.75.1658145252940; \n\tMon, 18 Jul 2022 04:54:12 -0700 (PDT)",
            "by 2002:a5d:5952:0:b0:21d:7c9b:e444 with SMTP id\n\te18-20020a5d5952000000b0021d7c9be444mr22861328wri.75.1658145252576; \n\tMon, 18 Jul 2022 04:54:12 -0700 (PDT)"
        ],
        "X-Google-Smtp-Source": "AGRyM1uKsa2epwXbNe7rSA2MNUXcH1uVlGae+IS1FfqZHRmPNO3W/B7adXsVVFfBHe5tRrPl+pLNuQ==",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 18 Jul 2022 12:51:29 +0100",
        "Message-Id": "<20220718115128.22437-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 v3] cam: sdl_sink: Use libjpeg over\n\tSDL2_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": "Ian Mullins <imullins@redhat.com>, 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---\nChanges in v3:\n- create JpegErrorManager struct\n- change c cast to reinterpret_cast\n\nChanges in v2:\n- alphabetically sorted various orderings\n- pitch_ is const again\n- added setjmp logic for error handling in libjpeg\n- rgbdata_ to unique_ptr and renamed to rgb_\n- removed a copy from buffer to rgb_\n- removed a destructor\n---\n README.rst                     |  2 +-\n src/cam/jpeg_error_manager.cpp | 26 ++++++++++++++++++++\n src/cam/jpeg_error_manager.h   | 21 ++++++++++++++++\n src/cam/meson.build            |  9 ++++---\n src/cam/sdl_sink.cpp           |  4 +--\n src/cam/sdl_texture_mjpg.cpp   | 45 +++++++++++++++++++++++++++++-----\n src/cam/sdl_texture_mjpg.h     |  6 +++++\n 7 files changed, 100 insertions(+), 13 deletions(-)\n create mode 100644 src/cam/jpeg_error_manager.cpp\n create mode 100644 src/cam/jpeg_error_manager.h",
    "diff": "diff --git a/README.rst b/README.rst\nindex b9e72d81..47b914f0 100644\n--- a/README.rst\n+++ b/README.rst\n@@ -92,8 +92,8 @@ for cam: [optional]\n         tool:\n \n         - libdrm-dev: Enables the KMS sink\n+        - libjpeg-dev: Enables MJPEG on the SDL sink\n         - libsdl2-dev: Enables the SDL sink\n-        - libsdl2-image-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/jpeg_error_manager.cpp b/src/cam/jpeg_error_manager.cpp\nnew file mode 100644\nindex 00000000..7e45e577\n--- /dev/null\n+++ b/src/cam/jpeg_error_manager.cpp\n@@ -0,0 +1,26 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2022, Ideas on Board Oy\n+ *\n+ * jpeg_error_manager.cpp - JPEG Error Manager\n+ */\n+\n+#include \"jpeg_error_manager.h\"\n+\n+static void errorExit(j_common_ptr cinfo)\n+{\n+\tJpegErrorManager *self =\n+\t\treinterpret_cast<JpegErrorManager *>(cinfo->err);\n+\tlongjmp(self->escape_, 1);\n+}\n+\n+static void outputMessage([[maybe_unused]] j_common_ptr cinfo)\n+{\n+}\n+\n+JpegErrorManager::JpegErrorManager(struct jpeg_decompress_struct &cinfo)\n+{\n+\tcinfo.err = jpeg_std_error(&errmgr_);\n+\terrmgr_.error_exit = errorExit;\n+\terrmgr_.output_message = outputMessage;\n+}\ndiff --git a/src/cam/jpeg_error_manager.h b/src/cam/jpeg_error_manager.h\nnew file mode 100644\nindex 00000000..0af28da1\n--- /dev/null\n+++ b/src/cam/jpeg_error_manager.h\n@@ -0,0 +1,21 @@\n+/* SPDX-License-Identifier: GPL-2.0-or-later */\n+/*\n+ * Copyright (C) 2022, Ideas on Board Oy\n+ *\n+ * jpeg_error_manager.h - JPEG Error Manager\n+ */\n+\n+#pragma once\n+\n+#include <setjmp.h>\n+#include <stdio.h>\n+\n+#include <jpeglib.h>\n+\n+struct JpegErrorManager {\n+\tJpegErrorManager(struct jpeg_decompress_struct &cinfo);\n+\n+\t/* Order very important for reinterpret_cast */\n+\tstruct jpeg_error_mgr errmgr_;\n+\tjmp_buf escape_;\n+};\ndiff --git a/src/cam/meson.build b/src/cam/meson.build\nindex 5957ce14..86cef683 100644\n--- a/src/cam/meson.build\n+++ b/src/cam/meson.build\n@@ -24,8 +24,8 @@ cam_sources = files([\n cam_cpp_args = []\n \n libdrm = dependency('libdrm', required : false)\n+libjpeg = dependency('libjpeg', required : false)\n libsdl2 = dependency('SDL2', required : false)\n-libsdl2_image = dependency('SDL2_image', required : false)\n \n if libdrm.found()\n     cam_cpp_args += [ '-DHAVE_KMS' ]\n@@ -43,9 +43,10 @@ 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+            'jpeg_error_manager.cpp',\n             'sdl_texture_mjpg.cpp'\n         ])\n     endif\n@@ -57,8 +58,8 @@ cam  = executable('cam', cam_sources,\n                       libcamera_public,\n                       libdrm,\n                       libevent,\n+                      libjpeg,\n                       libsdl2,\n-                      libsdl2_image,\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_mjpg.cpp b/src/cam/sdl_texture_mjpg.cpp\nindex 69e99ad3..e3fd1a35 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 \"jpeg_error_manager.h\"\n+\n+#include <iostream>\n \n using namespace libcamera;\n \n SDLTextureMJPG::SDLTextureMJPG(const SDL_Rect &rect)\n-\t: SDLTexture(rect, SDL_PIXELFORMAT_RGB24, 0)\n+\t: SDLTexture(rect, SDL_PIXELFORMAT_RGB24, rect.w * 3),\n+\t  rgb_(std::make_unique<unsigned char[]>(pitch_ * rect.h))\n+{\n+}\n+\n+int SDLTextureMJPG::decompress(const unsigned char *jpeg,\n+\t\t\t       unsigned long jpeg_size)\n {\n+\tstruct jpeg_decompress_struct cinfo;\n+\tJpegErrorManager jpegErrorManager(cinfo);\n+\tif (setjmp(jpegErrorManager.escape_)) {\n+\t\t/* libjpeg found an error */\n+\t\tjpeg_destroy_decompress(&cinfo);\n+\t\tstd::cerr << \"JPEG decompression error\" << std::endl;\n+\t\treturn -EINVAL;\n+\t}\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+\tfor (int i = 0; cinfo.output_scanline < cinfo.output_height; ++i) {\n+\t\tJSAMPROW rowptr = rgb_.get() + i * pitch_;\n+\t\tjpeg_read_scanlines(&cinfo, &rowptr, 1);\n+\t}\n+\n+\tjpeg_finish_decompress(&cinfo);\n+\n+\tjpeg_destroy_decompress(&cinfo);\n+\n+\treturn 0;\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, rgb_.get(), pitch_);\n }\ndiff --git a/src/cam/sdl_texture_mjpg.h b/src/cam/sdl_texture_mjpg.h\nindex b103f801..332c43d7 100644\n--- a/src/cam/sdl_texture_mjpg.h\n+++ b/src/cam/sdl_texture_mjpg.h\n@@ -13,5 +13,11 @@ class SDLTextureMJPG : public SDLTexture\n {\n public:\n \tSDLTextureMJPG(const SDL_Rect &rect);\n+\n \tvoid update(const libcamera::Span<uint8_t> &data) override;\n+\n+private:\n+\tint decompress(const unsigned char *jpeg, unsigned long jpeg_size);\n+\n+\tstd::unique_ptr<unsigned char[]> rgb_;\n };\n",
    "prefixes": [
        "libcamera-devel",
        "v3"
    ]
}