libcamera v0.1.0+127-8e215127-dirty (2023-12-02T01:06:12+00:00)
Supporting cameras in Linux since 2019
color_space.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2021, Raspberry Pi Ltd
4 *
5 * color_space.h - color space definitions
6 */
7
8#pragma once
9
10#include <optional>
11#include <string>
12
13namespace libcamera {
14
15class PixelFormat;
16
18{
19public:
20 enum class Primaries {
21 Raw,
23 Rec709,
24 Rec2020,
25 };
26
27 enum class TransferFunction {
28 Linear,
29 Srgb,
30 Rec709,
31 };
32
33 enum class YcbcrEncoding {
34 None,
35 Rec601,
36 Rec709,
37 Rec2020,
38 };
39
40 enum class Range {
41 Full,
42 Limited,
43 };
44
47 {
48 }
49
50 static const ColorSpace Raw;
51 static const ColorSpace Srgb;
52 static const ColorSpace Sycc;
53 static const ColorSpace Smpte170m;
54 static const ColorSpace Rec709;
55 static const ColorSpace Rec2020;
56
61
62 std::string toString() const;
63 static std::string toString(const std::optional<ColorSpace> &colorSpace);
64
65 static std::optional<ColorSpace> fromString(const std::string &str);
66
67 bool adjust(PixelFormat format);
68};
69
70bool operator==(const ColorSpace &lhs, const ColorSpace &rhs);
71static inline bool operator!=(const ColorSpace &lhs, const ColorSpace &rhs)
72{
73 return !(lhs == rhs);
74}
75
76} /* namespace libcamera */
Class to describe a color space.
Definition: color_space.h:18
Primaries
The color primaries for this color space.
Definition: color_space.h:20
@ Raw
These are raw colors directly from a sensor, the primaries are unspecified.
@ Smpte170m
SMPTE 170M color primaries.
@ Rec2020
Rec.2020 color primaries.
@ Rec709
Rec.709 color primaries.
static std::optional< ColorSpace > fromString(const std::string &str)
Construct a color space from a string.
Definition: color_space.cpp:338
Range range
The pixel range used with by color space.
Definition: color_space.h:60
TransferFunction
The transfer function used for this color space.
Definition: color_space.h:27
@ Linear
This color space uses a linear (identity) transfer function.
@ Rec709
Rec.709 transfer function.
YcbcrEncoding ycbcrEncoding
The Y'CbCr encoding used by this color space.
Definition: color_space.h:59
static const ColorSpace Rec2020
A constant representing the Rec.2020 color space.
Definition: color_space.h:55
YcbcrEncoding
The Y'CbCr encoding.
Definition: color_space.h:33
@ None
There is no defined Y'CbCr encoding (used for non-YUV formats)
@ Rec601
Rec.601 Y'CbCr encoding.
@ Rec2020
Rec.2020 Y'CbCr encoding.
@ Rec709
Rec.709 Y'CbCr encoding.
static const ColorSpace Rec709
A constant representing the Rec.709 color space.
Definition: color_space.h:54
constexpr ColorSpace(Primaries p, TransferFunction t, YcbcrEncoding e, Range r)
Construct a ColorSpace from explicit values.
Definition: color_space.h:45
static const ColorSpace Smpte170m
A constant representing the SMPTE170M color space.
Definition: color_space.h:53
TransferFunction transferFunction
The transfer function used by this color space.
Definition: color_space.h:58
Primaries primaries
The color primaries of this color space.
Definition: color_space.h:57
static const ColorSpace Raw
A constant representing a raw color space (from a sensor)
Definition: color_space.h:50
bool adjust(PixelFormat format)
Adjust the color space to match a pixel format.
Definition: color_space.cpp:423
Range
The range (sometimes "quantisation") for this color space.
Definition: color_space.h:40
@ Limited
This color space uses limited range pixel values, being 16 to 235 for Y' and 16 to 240 for Cb and Cr ...
@ Full
This color space uses full range pixel values.
static const ColorSpace Srgb
A constant representing the sRGB color space (RGB formats only)
Definition: color_space.h:51
std::string toString() const
Assemble and return a readable string representation of the ColorSpace.
Definition: color_space.cpp:267
static const ColorSpace Sycc
A constant representing the sYCC color space, typically used for encoding JPEG images.
Definition: color_space.h:52
libcamera image pixel format
Definition: pixel_format.h:18
Top-level libcamera namespace.
Definition: backtrace.h:17
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs)
Compare color spaces for equality.
Definition: color_space.cpp:506