summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Plowman <david.plowman@raspberrypi.com>2020-06-17 17:44:42 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-06-23 01:39:28 +0300
commitc3ed943c992a09c5fc19e25328dca7aa52691c36 (patch)
tree83b9846e4f2886d38c7d57b3662f02b5c83ff593
parent405ba5fd4ab7a53e57eeafe4a458e6db3edf042b (diff)
libcamera: Add support for planar YUV422 and YUV420 formats
These formats can be helpful when downstream applications or libraries support them natively (avoiding a costly conversion). Signed-off-by: David Plowman <david.plowman@raspberrypi.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: David Plowman <david.plowman@raspberrypi.com> Tested-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rw-r--r--src/libcamera/formats.cpp14
-rw-r--r--src/libcamera/formats.yaml5
-rw-r--r--src/libcamera/v4l2_pixelformat.cpp2
-rw-r--r--src/v4l2/v4l2_camera_proxy.cpp4
4 files changed, 24 insertions, 1 deletions
diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
index 97e98678..c0b53ce7 100644
--- a/src/libcamera/formats.cpp
+++ b/src/libcamera/formats.cpp
@@ -270,6 +270,20 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
.packed = false,
} },
+ { formats::YUV420, {
+ .format = PixelFormat(formats::YUV420),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV420),
+ .bitsPerPixel = 12,
+ .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
+ .packed = false,
+ } },
+ { formats::YUV422, {
+ .format = PixelFormat(formats::YUV422),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV422P),
+ .bitsPerPixel = 16,
+ .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
+ .packed = false,
+ } },
/* Greyscale formats. */
{ formats::R8, {
diff --git a/src/libcamera/formats.yaml b/src/libcamera/formats.yaml
index a6841c61..ce06dbc4 100644
--- a/src/libcamera/formats.yaml
+++ b/src/libcamera/formats.yaml
@@ -53,6 +53,11 @@ formats:
- NV42:
fourcc: DRM_FORMAT_NV42
+ - YUV420:
+ fourcc: DRM_FORMAT_YUV420
+ - YUV422:
+ fourcc: DRM_FORMAT_YUV422
+
- MJPEG:
fourcc: DRM_FORMAT_MJPEG
diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
index 741f6c26..6745d17d 100644
--- a/src/libcamera/v4l2_pixelformat.cpp
+++ b/src/libcamera/v4l2_pixelformat.cpp
@@ -63,6 +63,8 @@ const std::map<V4L2PixelFormat, PixelFormat> vpf2pf{
{ V4L2PixelFormat(V4L2_PIX_FMT_NV61), formats::NV61 },
{ V4L2PixelFormat(V4L2_PIX_FMT_NV12), formats::NV12 },
{ V4L2PixelFormat(V4L2_PIX_FMT_NV21), formats::NV21 },
+ { V4L2PixelFormat(V4L2_PIX_FMT_YUV420), formats::YUV420 },
+ { V4L2PixelFormat(V4L2_PIX_FMT_YUV422P), formats::YUV422 },
/* Greyscale formats. */
{ V4L2PixelFormat(V4L2_PIX_FMT_GREY), formats::R8 },
diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index bf47aa7e..86b87e37 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -560,7 +560,7 @@ struct PixelFormatInfo {
namespace {
-static const std::array<PixelFormatInfo, 14> pixelFormatInfo = {{
+static const std::array<PixelFormatInfo, 16> pixelFormatInfo = {{
/* RGB formats. */
{ formats::RGB888, V4L2_PIX_FMT_BGR24, 1, {{ { 24, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} },
{ formats::BGR888, V4L2_PIX_FMT_RGB24, 1, {{ { 24, 1, 1 }, { 0, 0, 0 }, { 0, 0, 0 } }} },
@@ -577,6 +577,8 @@ static const std::array<PixelFormatInfo, 14> pixelFormatInfo = {{
{ formats::NV61, V4L2_PIX_FMT_NV61, 2, {{ { 8, 1, 1 }, { 16, 2, 1 }, { 0, 0, 0 } }} },
{ formats::NV24, V4L2_PIX_FMT_NV24, 2, {{ { 8, 1, 1 }, { 16, 1, 1 }, { 0, 0, 0 } }} },
{ formats::NV42, V4L2_PIX_FMT_NV42, 2, {{ { 8, 1, 1 }, { 16, 1, 1 }, { 0, 0, 0 } }} },
+ { formats::YUV420, V4L2_PIX_FMT_YUV420, 3, {{ { 8, 1, 1 }, { 8, 2, 2 }, { 8, 2, 2 } }} },
+ { formats::YUV422, V4L2_PIX_FMT_YUV422P, 3, {{ { 8, 1, 1 }, { 8, 2, 1 }, { 8, 2, 1 } }} },
/* Compressed formats. */
/*
* \todo Get a better image size estimate for MJPEG, via
ontroller; using namespace libcamera; using libcamera::utils::Duration; namespace libcamera { LOG_DECLARE_CATEGORY(IPARPI) } static std::map<std::string, CamHelperCreateFunc> camHelpers; CamHelper *CamHelper::create(std::string const &camName) { /* * CamHelpers get registered by static RegisterCamHelper * initialisers. */ for (auto &p : camHelpers) { if (camName.find(p.first) != std::string::npos) return p.second(); } return nullptr; } CamHelper::CamHelper(std::unique_ptr<MdParser> parser, unsigned int frameIntegrationDiff) : parser_(std::move(parser)), initialized_(false), frameIntegrationDiff_(frameIntegrationDiff) { } CamHelper::~CamHelper() { } void CamHelper::prepare(Span<const uint8_t> buffer, Metadata &metadata) { parseEmbeddedData(buffer, metadata); } void CamHelper::process([[maybe_unused]] StatisticsPtr &stats, [[maybe_unused]] Metadata &metadata) { } uint32_t CamHelper::exposureLines(const Duration exposure) const { assert(initialized_); return exposure / mode_.lineLength; } Duration CamHelper::exposure(uint32_t exposureLines) const { assert(initialized_); return exposureLines * mode_.lineLength; } uint32_t CamHelper::getVBlanking(Duration &exposure, Duration minFrameDuration, Duration maxFrameDuration) const { uint32_t frameLengthMin, frameLengthMax, vblank; uint32_t exposureLines = CamHelper::exposureLines(exposure); assert(initialized_); /* * minFrameDuration and maxFrameDuration are clamped by the caller * based on the limits for the active sensor mode. */ frameLengthMin = minFrameDuration / mode_.lineLength; frameLengthMax = maxFrameDuration / mode_.lineLength; /* * Limit the exposure to the maximum frame duration requested, and * re-calculate if it has been clipped. */ exposureLines = std::min(frameLengthMax - frameIntegrationDiff_, exposureLines); exposure = CamHelper::exposure(exposureLines); /* Limit the vblank to the range allowed by the frame length limits. */ vblank = std::clamp(exposureLines + frameIntegrationDiff_, frameLengthMin, frameLengthMax) - mode_.height; return vblank; } void CamHelper::setCameraMode(const CameraMode &mode) { mode_ = mode; if (parser_) { parser_->setBitsPerPixel(mode.bitdepth); parser_->setLineLengthBytes(0); /* We use SetBufferSize. */ } initialized_ = true; } void CamHelper::getDelays(int &exposureDelay, int &gainDelay, int &vblankDelay) const { /* * These values are correct for many sensors. Other sensors will * need to over-ride this function. */ exposureDelay = 2; gainDelay = 1; vblankDelay = 2; } bool CamHelper::sensorEmbeddedDataPresent() const { return false; } double CamHelper::getModeSensitivity([[maybe_unused]] const CameraMode &mode) const { /* * Most sensors have the same sensitivity in every mode, but this * function can be overridden for those that do not. Note that it is * called before mode_ is set, so it must return the sensitivity * of the mode that is passed in. */ return 1.0; } unsigned int CamHelper::hideFramesStartup() const { /* * The number of frames when a camera first starts that shouldn't be * displayed as they are invalid in some way. */ return 0; } unsigned int CamHelper::hideFramesModeSwitch() const { /* After a mode switch, many sensors return valid frames immediately. */ return 0; } unsigned int CamHelper::mistrustFramesStartup() const { /* Many sensors return a single bad frame on start-up. */ return 1; } unsigned int CamHelper::mistrustFramesModeSwitch() const { /* Many sensors return valid metadata immediately. */ return 0; } void CamHelper::parseEmbeddedData(Span<const uint8_t> buffer, Metadata &metadata) { MdParser::RegisterMap registers; Metadata parsedMetadata; if (buffer.empty()) return; if (parser_->parse(buffer, registers) != MdParser::Status::OK) {