Source files in libcamera start by a comment block header, which
includes the file name and a one-line description of the file contents.
While the latter is useful to get a quick overview of the file contents
at a glance, the former is mostly a source of inconvenience. The name in
the comments can easily get out of sync with the file name when files
are renamed, and copy & paste during development have often lead to
incorrect names being used to start with.
Readers of the source code are expected to know which file they're
looking it. Drop the file name from the header comment block.
The change was generated with the following script:
----------------------------------------
dirs="include/libcamera src test utils"
declare -rA patterns=(
['c']=' \* '
['cpp']=' \* '
['h']=' \* '
['py']='# '
['sh']='# '
)
for ext in ${!patterns[@]} ; do
files=$(for dir in $dirs ; do find $dir -name "*.${ext}" ; done)
pattern=${patterns[${ext}]}
for file in $files ; do
name=$(basename ${file})
sed -i "s/^\(${pattern}\)${name} - /\1/" "$file"
done
done
----------------------------------------
This misses several files that are out of sync with the comment block
header. Those will be addressed separately and manually.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
156 lines
3.9 KiB
C++
156 lines
3.9 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* libcamera Pixel Format
|
|
*/
|
|
|
|
#include <libcamera/formats.h>
|
|
#include <libcamera/pixel_format.h>
|
|
|
|
#include "libcamera/internal/formats.h"
|
|
|
|
/**
|
|
* \file pixel_format.h
|
|
* \brief libcamera pixel format
|
|
*/
|
|
|
|
namespace libcamera {
|
|
|
|
/**
|
|
* \class PixelFormat
|
|
* \brief libcamera image pixel format
|
|
*
|
|
* The PixelFormat type describes the format of images in the public libcamera
|
|
* API. It stores a FourCC value as a 32-bit unsigned integer and a modifier.
|
|
* The FourCC and modifier values are defined in the Linux kernel DRM/KMS API
|
|
* (see linux/drm_fourcc.h). Constant expressions for all pixel formats
|
|
* supported by libcamera are available in libcamera/formats.h.
|
|
*/
|
|
|
|
/**
|
|
* \fn PixelFormat::PixelFormat()
|
|
* \brief Construct a PixelFormat with an invalid format
|
|
*
|
|
* PixelFormat instances constructed with the default constructor are
|
|
* invalid, calling the isValid() function returns false.
|
|
*/
|
|
|
|
/**
|
|
* \fn PixelFormat::PixelFormat(uint32_t fourcc, uint64_t modifier)
|
|
* \brief Construct a PixelFormat from a DRM FourCC and a modifier
|
|
* \param[in] fourcc A DRM FourCC
|
|
* \param[in] modifier A DRM FourCC modifier
|
|
*/
|
|
|
|
/**
|
|
* \brief Compare pixel formats for equality
|
|
* \return True if the two pixel formats are equal, false otherwise
|
|
*/
|
|
bool PixelFormat::operator==(const PixelFormat &other) const
|
|
{
|
|
return fourcc_ == other.fourcc() && modifier_ == other.modifier_;
|
|
}
|
|
|
|
/**
|
|
* \fn bool PixelFormat::operator!=(const PixelFormat &other) const
|
|
* \brief Compare pixel formats for inequality
|
|
* \return True if the two pixel formats are not equal, false otherwise
|
|
*/
|
|
|
|
/**
|
|
* \brief Compare pixel formats for smaller than order
|
|
* \return True if \a this is smaller than \a other, false otherwise
|
|
*/
|
|
bool PixelFormat::operator<(const PixelFormat &other) const
|
|
{
|
|
if (fourcc_ < other.fourcc_)
|
|
return true;
|
|
if (fourcc_ > other.fourcc_)
|
|
return false;
|
|
return modifier_ < other.modifier_;
|
|
}
|
|
|
|
/**
|
|
* \fn bool PixelFormat::isValid() const
|
|
* \brief Check if the pixel format is valid
|
|
*
|
|
* PixelFormat instances constructed with the default constructor are
|
|
* invalid. Instances constructed with a FourCC defined in the DRM API
|
|
* are valid. The behaviour is undefined otherwise.
|
|
*
|
|
* \return True if the pixel format is valid, false otherwise
|
|
*/
|
|
|
|
/**
|
|
* \fn PixelFormat::operator uint32_t() const
|
|
* \brief Convert the the pixel format numerical value
|
|
* \return The pixel format numerical value
|
|
*/
|
|
|
|
/**
|
|
* \fn PixelFormat::fourcc() const
|
|
* \brief Retrieve the pixel format FourCC
|
|
* \return DRM FourCC
|
|
*/
|
|
|
|
/**
|
|
* \fn PixelFormat::modifier() const
|
|
* \brief Retrieve the pixel format modifier
|
|
* \return DRM modifier
|
|
*/
|
|
|
|
/**
|
|
* \brief Assemble and return a string describing the pixel format
|
|
* \return A string describing the pixel format
|
|
*/
|
|
std::string PixelFormat::toString() const
|
|
{
|
|
const PixelFormatInfo &info = PixelFormatInfo::info(*this);
|
|
|
|
if (!info.isValid()) {
|
|
if (*this == PixelFormat())
|
|
return "<INVALID>";
|
|
|
|
char fourcc[7] = { '<',
|
|
static_cast<char>(fourcc_),
|
|
static_cast<char>(fourcc_ >> 8),
|
|
static_cast<char>(fourcc_ >> 16),
|
|
static_cast<char>(fourcc_ >> 24),
|
|
'>' };
|
|
|
|
for (unsigned int i = 1; i < 5; i++) {
|
|
if (!isprint(fourcc[i]))
|
|
fourcc[i] = '.';
|
|
}
|
|
|
|
return fourcc;
|
|
}
|
|
|
|
return info.name;
|
|
}
|
|
|
|
/**
|
|
* \brief Create a PixelFormat from a string
|
|
* \return The PixelFormat represented by the \a name if known, or an
|
|
* invalid pixel format otherwise.
|
|
*/
|
|
PixelFormat PixelFormat::fromString(const std::string &name)
|
|
{
|
|
return PixelFormatInfo::info(name).format;
|
|
}
|
|
|
|
/**
|
|
* \brief Insert a text representation of a PixelFormat into an output stream
|
|
* \param[in] out The output stream
|
|
* \param[in] f The PixelFormat
|
|
* \return The output stream \a out
|
|
*/
|
|
std::ostream &operator<<(std::ostream &out, const PixelFormat &f)
|
|
{
|
|
out << f.toString();
|
|
return out;
|
|
}
|
|
|
|
} /* namespace libcamera */
|