libcamera  v0.4.0
Supporting cameras in Linux since 2019
Classes | Public Member Functions | Static Public Member Functions | List of all members
libcamera::V4L2PixelFormat Class Reference

V4L2 pixel format FourCC wrapper. More...

Classes

struct  Info
 Information about a V4L2 pixel format. More...
 

Public Member Functions

 V4L2PixelFormat ()
 Construct a V4L2PixelFormat with an invalid format. More...
 
 V4L2PixelFormat (uint32_t fourcc)
 Construct a V4L2PixelFormat from a FourCC value. More...
 
bool isValid () const
 Check if the pixel format is valid. More...
 
uint32_t fourcc () const
 Retrieve the pixel format FourCC numerical value. More...
 
 operator uint32_t () const
 Convert to the pixel format FourCC numerical value. More...
 
std::string toString () const
 Assemble and return a string describing the pixel format. More...
 
const char * description () const
 Retrieve the V4L2 description for the format. More...
 
PixelFormat toPixelFormat (bool warn=true) const
 Convert the V4L2 pixel format to the corresponding PixelFormat. More...
 

Static Public Member Functions

static const std::vector< V4L2PixelFormat > & fromPixelFormat (const PixelFormat &pixelFormat)
 Retrieve the list of V4L2PixelFormat associated with pixelFormat. More...
 

Detailed Description

V4L2 pixel format FourCC wrapper.

The V4L2PixelFormat class describes the pixel format of a V4L2 buffer. It wraps the V4L2 numerical FourCC, and shall be used in all APIs that deal with V4L2 pixel formats. Its purpose is to prevent unintentional confusion of V4L2 and DRM FourCCs in code by catching implicit conversion attempts at compile time.

To achieve this goal, construction of a V4L2PixelFormat from an integer value is explicit. To retrieve the integer value of a V4L2PixelFormat, both the explicit value() and implicit uint32_t conversion operators may be used.

Constructor & Destructor Documentation

◆ V4L2PixelFormat() [1/2]

libcamera::V4L2PixelFormat::V4L2PixelFormat ( )
inline

Construct a V4L2PixelFormat with an invalid format.

V4L2PixelFormat instances constructed with the default constructor are invalid, calling the isValid() function returns false.

◆ V4L2PixelFormat() [2/2]

libcamera::V4L2PixelFormat::V4L2PixelFormat ( uint32_t  fourcc)
inlineexplicit

Construct a V4L2PixelFormat from a FourCC value.

Parameters
[in]fourccThe pixel format FourCC numerical value

Member Function Documentation

◆ description()

const char * libcamera::V4L2PixelFormat::description ( ) const

Retrieve the V4L2 description for the format.

The description matches the value used by the kernel, as would be reported by the VIDIOC_ENUM_FMT ioctl.

Returns
The V4L2 description corresponding to the V4L2 format, or a placeholder description if not found

◆ fourcc()

uint32_t libcamera::V4L2PixelFormat::fourcc ( ) const
inline

Retrieve the pixel format FourCC numerical value.

Returns
The pixel format FourCC numerical value

◆ fromPixelFormat()

const std::vector< V4L2PixelFormat > & libcamera::V4L2PixelFormat::fromPixelFormat ( const PixelFormat pixelFormat)
static

Retrieve the list of V4L2PixelFormat associated with pixelFormat.

Parameters
[in]pixelFormatThe PixelFormat to convert

Multiple V4L2 formats may exist for one PixelFormat as V4L2 defines separate 4CCs for contiguous and non-contiguous versions of the same image format.

Returns
The list of V4L2PixelFormat corresponding to pixelFormat

◆ isValid()

bool libcamera::V4L2PixelFormat::isValid ( ) const
inline

Check if the pixel format is valid.

V4L2PixelFormat instances constructed with the default constructor are invalid. Instances constructed with a FourCC defined in the V4L2 API are valid. The behaviour is undefined otherwise.

Returns
True if the pixel format is valid, false otherwise

◆ operator uint32_t()

libcamera::V4L2PixelFormat::operator uint32_t ( ) const
inline

Convert to the pixel format FourCC numerical value.

Returns
The pixel format FourCC numerical value

◆ toPixelFormat()

PixelFormat libcamera::V4L2PixelFormat::toPixelFormat ( bool  warn = true) const

Convert the V4L2 pixel format to the corresponding PixelFormat.

Parameters
[in]warnWhen true, log a warning message if the V4L2 pixel format isn't known

Users of this function might try to convert a V4L2PixelFormat to a PixelFormat just to check if the format is supported or not. In that case, they can suppress the warning message by setting the warn argument to false to not pollute the log with unnecessary messages.

Returns
The PixelFormat corresponding to the V4L2 pixel format

◆ toString()

std::string libcamera::V4L2PixelFormat::toString ( ) const

Assemble and return a string describing the pixel format.

Returns
A string describing the pixel format

The documentation for this class was generated from the following files: