From patchwork Mon Jul 4 18:07:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Machek X-Patchwork-Id: 16535 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E6B21BE173 for ; Mon, 4 Jul 2022 18:07:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 470A06564A; Mon, 4 Jul 2022 20:07:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656958043; bh=jRJzs6mlEQxfLdqdeAP6Msdx90cfLMjuKjIIN7QIqko=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=WblOXq7LJJX1bQBm5i77QHR2ZNQcBB1tIlpGjTdSre6nuiM4sVPiexvDGRiw8BO70 AV7FjBcaOarxhL9N/WDMceuHFszdCHSGZrLgyG6lvmF/5t8y/iQ+l8D2r35H3eibi5 aMnGmHCh9l6THlDaD4G3KLedHDOWqJTuLORUxHbHc8RlChv3LBqtCxw781Vch1+05g yMfQ4ZTGHlXiZXCmUGivotsFSezIKsEBXDV8qHD5g2e023ffONPYb895EAdh7akMXT AIVPRUyEOGlaeHZdf2kAetNhonQPCRSz2xOqSL+7iE0qOskNp8eMQz+yDfUxY/Z8iT olzWrpZkxc5cw== Received: from jabberwock.ucw.cz (jabberwock.ucw.cz [46.255.230.98]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B01961FB1 for ; Mon, 4 Jul 2022 20:07:21 +0200 (CEST) Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id C046D1C0D7F; Mon, 4 Jul 2022 20:07:20 +0200 (CEST) Date: Mon, 4 Jul 2022 20:07:20 +0200 To: Rafael Diniz Message-ID: <20220704180719.GA30565@amd> References: <20220620120711.GA12286@duo.ucw.cz> <20220701211120.GB18840@duo.ucw.cz> <279b87a6-2209-e4d1-6342-12253258b59f@riseup.net> <9a63e90b-5da6-2915-462e-70b2f61d1867@riseup.net> <20220703155800.GA11658@amd> <70821a87-8ea5-1583-daa3-ce1531977ce7@riseup.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Subject: [libcamera-devel] JPEG support for libcamera X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Pavel Machek via libcamera-devel From: Pavel Machek Reply-To: Pavel Machek Cc: martijn@brixit.nl, libcamera-devel@lists.libcamera.org, jozef@mlich.cz Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" JPEG is very similar to MJPEG format (AFAICT, it may contain extra EXIF headers). Add support for it. Tested with PinePhone and command line cam utility. Signed-off-by: Pavel Machek diff --git a/include/linux/drm_fourcc.h b/include/linux/drm_fourcc.h index ea11dcb4..b30a705d 100644 --- a/include/linux/drm_fourcc.h +++ b/include/linux/drm_fourcc.h @@ -352,6 +352,7 @@ extern "C" { /* Compressed formats */ #define DRM_FORMAT_MJPEG fourcc_code('M', 'J', 'P', 'G') /* Motion-JPEG */ +#define DRM_FORMAT_JPEG fourcc_code('J', 'P', 'E', 'G') /* JFIF JPEG */ /* * Bayer formats diff --git a/src/cam/sdl_sink.cpp b/src/cam/sdl_sink.cpp index f8e3e95d..673bd642 100644 --- a/src/cam/sdl_sink.cpp +++ b/src/cam/sdl_sink.cpp @@ -63,6 +63,7 @@ int SDLSink::configure(const libcamera::CameraConfiguration &config) switch (cfg.pixelFormat) { #ifdef HAVE_SDL_IMAGE + case libcamera::formats::JPEG: case libcamera::formats::MJPEG: texture_ = std::make_unique(rect_); break; diff --git a/src/gstreamer/gstlibcamera-utils.cpp b/src/gstreamer/gstlibcamera-utils.cpp index 3f242286..fd5689d9 100644 --- a/src/gstreamer/gstlibcamera-utils.cpp +++ b/src/gstreamer/gstlibcamera-utils.cpp @@ -80,6 +80,7 @@ bare_structure_from_format(const PixelFormat &format) gst_video_format_to_string(gst_format), nullptr); switch (format) { + case formats::JPEG: case formats::MJPEG: return gst_structure_new_empty("image/jpeg"); default: diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp index 283ecb3d..c5e97198 100644 --- a/src/libcamera/formats.cpp +++ b/src/libcamera/formats.cpp @@ -944,6 +944,19 @@ const std::map pixelFormatInfo{ } }, /* Compressed formats. */ + { formats::JPEG, { + .name = "JPEG", + .format = formats::JPEG, + .v4l2Formats = { + .single = V4L2PixelFormat(V4L2_PIX_FMT_JPEG), + .multi = V4L2PixelFormat(), + }, + .bitsPerPixel = 0, + .colourEncoding = PixelFormatInfo::ColourEncodingYUV, + .packed = false, + .pixelsPerGroup = 1, + .planes = {{ { 1, 1 }, { 0, 0 }, { 0, 0 } }}, + } }, { formats::MJPEG, { .name = "MJPEG", .format = formats::MJPEG, diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml index 7dda0132..6b931c34 100644 --- a/src/libcamera/formats.yaml +++ b/src/libcamera/formats.yaml @@ -76,6 +76,8 @@ formats: - YVU444: fourcc: DRM_FORMAT_YVU444 + - JPEG: + fourcc: DRM_FORMAT_JPEG - MJPEG: fourcc: DRM_FORMAT_MJPEG diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp index 58fc4e9d..82dfbd1e 100644 --- a/src/libcamera/v4l2_pixelformat.cpp +++ b/src/libcamera/v4l2_pixelformat.cpp @@ -183,6 +183,8 @@ const std::map vpf2pf{ /* Compressed formats. */ { V4L2PixelFormat(V4L2_PIX_FMT_MJPEG), { formats::MJPEG, "Motion-JPEG" } }, + { V4L2PixelFormat(V4L2_PIX_FMT_JPEG), + { formats::JPEG, "JPEG" } }, }; } /* namespace */