[libcamera-devel] JPEG support for libcamera
Rafael Diniz
rafael at riseup.net
Tue Jul 5 08:55:34 CEST 2022
Hi Pavel,
Thanks! It worked! There was one more place to add a "JPEG". Here is an
updated patch:
https://github.com/maemo-leste-upstream-forks/libcamera/commit/f6fabd191f6bc8f66cfddd8caf8c49759fd55a87
diff --git a/include/linux/drm_fourcc.h b/include/linux/drm_fourcc.h
index ea11dcb4..d20fd1ae 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..0c328e88 100644
--- a/src/cam/sdl_sink.cpp
+++ b/src/cam/sdl_sink.cpp
@@ -64,6 +64,7 @@ int SDLSink::configure(const
libcamera::CameraConfiguration &config)
switch (cfg.pixelFormat) {
#ifdef HAVE_SDL_IMAGE
case libcamera::formats::MJPEG:
+ case libcamera::formats::JPEG:
texture_ = std::make_unique<SDLTextureMJPG>(rect_);
break;
#endif
diff --git a/src/gstreamer/gstlibcamera-utils.cpp
b/src/gstreamer/gstlibcamera-utils.cpp
index 3f242286..dd6836c1 100644
--- a/src/gstreamer/gstlibcamera-utils.cpp
+++ b/src/gstreamer/gstlibcamera-utils.cpp
@@ -18,6 +18,7 @@ static struct {
} format_map[] = {
/* Compressed */
{ GST_VIDEO_FORMAT_ENCODED, formats::MJPEG },
+ { GST_VIDEO_FORMAT_ENCODED, formats::JPEG },
/* RGB */
{ GST_VIDEO_FORMAT_RGB, formats::BGR888 },
@@ -81,6 +82,7 @@ bare_structure_from_format(const PixelFormat &format)
switch (format) {
case formats::MJPEG:
+ case formats::JPEG:
return gst_structure_new_empty("image/jpeg");
default:
return nullptr;
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<PixelFormat, PixelFormatInfo>
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..e5737323 100644
--- a/src/libcamera/v4l2_pixelformat.cpp
+++ b/src/libcamera/v4l2_pixelformat.cpp
@@ -181,6 +181,8 @@ const std::map<V4L2PixelFormat,
V4L2PixelFormat::Info> vpf2pf{
{ formats::SRGGB16, "16-bit Bayer RGRG/GBGB" } },
/* Compressed formats. */
+ { V4L2PixelFormat(V4L2_PIX_FMT_JPEG),
+ { formats::JPEG, "JPEG" } },
{ V4L2PixelFormat(V4L2_PIX_FMT_MJPEG),
{ formats::MJPEG, "Motion-JPEG" } },
};
Cheers,
Rafael
On 7/4/22 15:07, Pavel Machek wrote:
> 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 <pavel at ucw.cz>
>
> 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<SDLTextureMJPG>(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<PixelFormat, PixelFormatInfo> 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<V4L2PixelFormat, V4L2PixelFormat::Info> vpf2pf{
> /* Compressed formats. */
> { V4L2PixelFormat(V4L2_PIX_FMT_MJPEG),
> { formats::MJPEG, "Motion-JPEG" } },
> + { V4L2PixelFormat(V4L2_PIX_FMT_JPEG),
> + { formats::JPEG, "JPEG" } },
> };
>
> } /* namespace */
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20220705/9f6fe183/attachment.sig>
More information about the libcamera-devel
mailing list