libcamera: bayer_format: Add operator<<()
Implement the stream output operator<<() for the BayerFormat class to simplify printing them. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
2efd8ab36a
commit
08d6133113
2 changed files with 39 additions and 21 deletions
|
@ -7,6 +7,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <ostream>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
|
@ -68,4 +69,6 @@ static inline bool operator!=(const BayerFormat &lhs, const BayerFormat &rhs)
|
|||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const BayerFormat &f);
|
||||
|
||||
} /* namespace libcamera */
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <linux/media-bus-format.h>
|
||||
|
@ -236,28 +237,10 @@ const BayerFormat &BayerFormat::fromMbusCode(unsigned int mbusCode)
|
|||
*/
|
||||
std::string BayerFormat::toString() const
|
||||
{
|
||||
std::string result;
|
||||
std::stringstream ss;
|
||||
ss << *this;
|
||||
|
||||
static const char *orderStrings[] = {
|
||||
"BGGR",
|
||||
"GBRG",
|
||||
"GRBG",
|
||||
"RGGB",
|
||||
"MONO"
|
||||
};
|
||||
if (isValid() && order <= MONO)
|
||||
result = orderStrings[order];
|
||||
else
|
||||
return "INVALID";
|
||||
|
||||
result += "-" + std::to_string(bitDepth);
|
||||
|
||||
if (packing == Packing::CSI2)
|
||||
result += "-CSI2P";
|
||||
else if (packing == Packing::IPU3)
|
||||
result += "-IPU3P";
|
||||
|
||||
return result;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -270,6 +253,38 @@ bool operator==(const BayerFormat &lhs, const BayerFormat &rhs)
|
|||
lhs.packing == rhs.packing;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Insert a text representation of a BayerFormats into an output stream
|
||||
* \param[in] out The output stream
|
||||
* \param[in] f The BayerFormat
|
||||
* \return The output stream \a out
|
||||
*/
|
||||
std::ostream &operator<<(std::ostream &out, const BayerFormat &f)
|
||||
{
|
||||
static const char *orderStrings[] = {
|
||||
"BGGR-",
|
||||
"GBRG-",
|
||||
"GRBG-",
|
||||
"RGGB-",
|
||||
"MONO-"
|
||||
};
|
||||
|
||||
if (!f.isValid() || f.order > BayerFormat::MONO) {
|
||||
out << "INVALID";
|
||||
return out;
|
||||
}
|
||||
|
||||
/* The cast is required to avoid bitDepth being interpreted as a char. */
|
||||
out << orderStrings[f.order] << static_cast<unsigned int>(f.bitDepth);
|
||||
|
||||
if (f.packing == BayerFormat::Packing::CSI2)
|
||||
out << "-CSI2P";
|
||||
else if (f.packing == BayerFormat::Packing::IPU3)
|
||||
out << "-IPU3P";
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* \fn bool operator!=(const BayerFormat &lhs, const BayerFormat &rhs)
|
||||
* \brief Compare two BayerFormats for inequality
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue