The CameraConfiguration::validateColorSpaces() function performs color space validation on a camera configuration, by validating the color space of each stream individually, and optionally ensuring that all streams share the same color space. The individual validation is very basic, limited to ensuring that raw formats use a raw color space. Color spaces are more constrained than that: - The Y'CbCr encoding and quantization range for RGB formats must be YcbcrEncoding::None and Range::Full respectively. - The Y'CbCr encoding for YUV formats must not be YcbcrEncoding::None. Instead of open-coding these constraints in the validateColorSpaces() function, create a new ColorSpace::adjust() function to centralize color space validation and adjustment, and use it in validateColorSpaces(). Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
76 lines
1.3 KiB
C++
76 lines
1.3 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2021, Raspberry Pi Ltd
|
|
*
|
|
* color_space.h - color space definitions
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
namespace libcamera {
|
|
|
|
class PixelFormat;
|
|
|
|
class ColorSpace
|
|
{
|
|
public:
|
|
enum class Primaries {
|
|
Raw,
|
|
Smpte170m,
|
|
Rec709,
|
|
Rec2020,
|
|
};
|
|
|
|
enum class TransferFunction {
|
|
Linear,
|
|
Srgb,
|
|
Rec709,
|
|
};
|
|
|
|
enum class YcbcrEncoding {
|
|
None,
|
|
Rec601,
|
|
Rec709,
|
|
Rec2020,
|
|
};
|
|
|
|
enum class Range {
|
|
Full,
|
|
Limited,
|
|
};
|
|
|
|
constexpr ColorSpace(Primaries p, TransferFunction t, YcbcrEncoding e, Range r)
|
|
: primaries(p), transferFunction(t), ycbcrEncoding(e), range(r)
|
|
{
|
|
}
|
|
|
|
static const ColorSpace Raw;
|
|
static const ColorSpace Srgb;
|
|
static const ColorSpace Sycc;
|
|
static const ColorSpace Smpte170m;
|
|
static const ColorSpace Rec709;
|
|
static const ColorSpace Rec2020;
|
|
|
|
Primaries primaries;
|
|
TransferFunction transferFunction;
|
|
YcbcrEncoding ycbcrEncoding;
|
|
Range range;
|
|
|
|
std::string toString() const;
|
|
static std::string toString(const std::optional<ColorSpace> &colorSpace);
|
|
|
|
static std::optional<ColorSpace> fromString(const std::string &str);
|
|
|
|
bool adjust(PixelFormat format);
|
|
};
|
|
|
|
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs);
|
|
static inline bool operator!=(const ColorSpace &lhs, const ColorSpace &rhs)
|
|
{
|
|
return !(lhs == rhs);
|
|
}
|
|
|
|
} /* namespace libcamera */
|