Loading...
Searching...
No Matches
color_space.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2021, Raspberry Pi Ltd
*
* 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 */
libcamera::ColorSpace
Class to describe a color space.
Definition color_space.h:18
libcamera::ColorSpace::Primaries
Primaries
The color primaries for this color space.
Definition color_space.h:20
libcamera::ColorSpace::fromString
static std::optional< ColorSpace > fromString(const std::string &str)
Construct a color space from a string.
Definition color_space.cpp:338
libcamera::ColorSpace::ColorSpace
constexpr ColorSpace(Primaries p, TransferFunction t, YcbcrEncoding e, Range r)
Construct a ColorSpace from explicit values.
Definition color_space.h:45
libcamera::ColorSpace::TransferFunction
TransferFunction
The transfer function used for this color space.
Definition color_space.h:27
libcamera::ColorSpace::TransferFunction::Linear
@ Linear
This color space uses a linear (identity) transfer function.
Definition color_space.h:28
libcamera::ColorSpace::range
Range range
The pixel range used with by color space.
Definition color_space.h:60
libcamera::ColorSpace::ycbcrEncoding
YcbcrEncoding ycbcrEncoding
The Y'CbCr encoding used by this color space.
Definition color_space.h:59
libcamera::ColorSpace::Rec2020
static const ColorSpace Rec2020
A constant representing the Rec.2020 color space.
Definition color_space.h:55
libcamera::ColorSpace::YcbcrEncoding
YcbcrEncoding
The Y'CbCr encoding.
Definition color_space.h:33
libcamera::ColorSpace::YcbcrEncoding::None
@ None
There is no defined Y'CbCr encoding (used for non-YUV formats).
Definition color_space.h:34
libcamera::ColorSpace::YcbcrEncoding::Rec601
@ Rec601
Rec.601 Y'CbCr encoding.
Definition color_space.h:35
libcamera::ColorSpace::Rec709
static const ColorSpace Rec709
A constant representing the Rec.709 color space.
Definition color_space.h:54
libcamera::ColorSpace::primaries
Primaries primaries
The color primaries of this color space.
Definition color_space.h:57
libcamera::ColorSpace::Smpte170m
static const ColorSpace Smpte170m
A constant representing the SMPTE170M color space.
Definition color_space.h:53
libcamera::ColorSpace::Raw
static const ColorSpace Raw
A constant representing a raw color space (from a sensor).
Definition color_space.h:50
libcamera::ColorSpace::adjust
bool adjust(PixelFormat format)
Adjust the color space to match a pixel format.
Definition color_space.cpp:423
libcamera::ColorSpace::Range
Range
The range (sometimes "quantisation") for this color space.
Definition color_space.h:40
libcamera::ColorSpace::Range::Limited
@ Limited
This color space uses limited range pixel values, being 16 to 235 for Y' and 16 to 240 for Cb and Cr ...
Definition color_space.h:42
libcamera::ColorSpace::Range::Full
@ Full
This color space uses full range pixel values.
Definition color_space.h:41
libcamera::ColorSpace::Srgb
static const ColorSpace Srgb
A constant representing the sRGB color space (RGB formats only).
Definition color_space.h:51
libcamera::ColorSpace::transferFunction
TransferFunction transferFunction
The transfer function used by this color space.
Definition color_space.h:58
libcamera::ColorSpace::toString
std::string toString() const
Assemble and return a readable string representation of the ColorSpace.
Definition color_space.cpp:267
libcamera::ColorSpace::Sycc
static const ColorSpace Sycc
A constant representing the sYCC color space, typically used for encoding JPEG images.
Definition color_space.h:52
libcamera::PixelFormat
libcamera image pixel format
Definition pixel_format.h:17
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17