summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibVideo
diff options
context:
space:
mode:
authorZaggy1024 <zaggy1024@gmail.com>2022-10-29 17:39:45 -0500
committerAndreas Kling <kling@serenityos.org>2022-10-31 14:47:13 +0100
commit3720f66bb1ce9ffb7fe9c4e32893054f3f1749a8 (patch)
tree8e998ee322f49eebb8aa4b0ac7133cf17782465b /Userland/Libraries/LibVideo
parent074f771b596d0275c818184f24036ba9d3e3af0a (diff)
downloadserenity-3720f66bb1ce9ffb7fe9c4e32893054f3f1749a8.zip
LibVideo: Set CodingIndependentCodePoints in its member functions
This moves the setting of code points in CICP structs to member functions completely so that the code having to set these code points can be much cleaner.
Diffstat (limited to 'Userland/Libraries/LibVideo')
-rw-r--r--Userland/Libraries/LibVideo/Color/CodingIndependentCodePoints.h27
-rw-r--r--Userland/Libraries/LibVideo/MatroskaDocument.h39
2 files changed, 40 insertions, 26 deletions
diff --git a/Userland/Libraries/LibVideo/Color/CodingIndependentCodePoints.h b/Userland/Libraries/LibVideo/Color/CodingIndependentCodePoints.h
index e393406c91..5d42ace027 100644
--- a/Userland/Libraries/LibVideo/Color/CodingIndependentCodePoints.h
+++ b/Userland/Libraries/LibVideo/Color/CodingIndependentCodePoints.h
@@ -73,8 +73,9 @@ enum class MatrixCoefficients : u8 {
};
enum class ColorRange : u8 {
- Studio = 0, // Y range 16..235, UV range 16..240
- Full = 1, // 0..255
+ Unspecified,
+ Studio, // Y range 16..235, UV range 16..240
+ Full, // 0..255
};
// https://en.wikipedia.org/wiki/Coding-independent_code_points
@@ -97,14 +98,28 @@ public:
constexpr ColorRange color_range() const { return m_color_range; }
constexpr void set_color_range(ColorRange value) { m_color_range = value; }
- constexpr void default_code_points_if_unspecified(ColorPrimaries cp, TransferCharacteristics tc, MatrixCoefficients mc)
+ constexpr void default_code_points_if_unspecified(CodingIndependentCodePoints cicp)
{
if (color_primaries() == ColorPrimaries::Unspecified)
- set_color_primaries(cp);
+ set_color_primaries(cicp.color_primaries());
if (transfer_characteristics() == TransferCharacteristics::Unspecified)
- set_transfer_characteristics(tc);
+ set_transfer_characteristics(cicp.transfer_characteristics());
if (matrix_coefficients() == MatrixCoefficients::Unspecified)
- set_matrix_coefficients(mc);
+ set_matrix_coefficients(cicp.matrix_coefficients());
+ if (color_range() == ColorRange::Unspecified)
+ set_color_range(cicp.color_range());
+ }
+
+ constexpr void adopt_specified_values(CodingIndependentCodePoints cicp)
+ {
+ if (cicp.color_primaries() != ColorPrimaries::Unspecified)
+ set_color_primaries(cicp.color_primaries());
+ if (cicp.transfer_characteristics() != TransferCharacteristics::Unspecified)
+ set_transfer_characteristics(cicp.transfer_characteristics());
+ if (cicp.matrix_coefficients() != MatrixCoefficients::Unspecified)
+ set_matrix_coefficients(cicp.matrix_coefficients());
+ if (cicp.color_range() != ColorRange::Unspecified)
+ set_color_range(cicp.color_range());
}
private:
diff --git a/Userland/Libraries/LibVideo/MatroskaDocument.h b/Userland/Libraries/LibVideo/MatroskaDocument.h
index fbe7faf061..daa25378f9 100644
--- a/Userland/Libraries/LibVideo/MatroskaDocument.h
+++ b/Userland/Libraries/LibVideo/MatroskaDocument.h
@@ -65,27 +65,26 @@ public:
u64 bits_per_channel = 0;
ColorRange range = ColorRange::Unspecified;
- Video::ColorRange full_or_studio_range() const
+ CodingIndependentCodePoints to_cicp() const
{
- // FIXME: Figure out what UseCICP should do here. Matroska specification did not
- // seem to explain in the 'colour' section. When this is fixed, change
- // replace_code_points_if_specified to match.
- VERIFY(range == ColorRange::Full || range == ColorRange::Broadcast);
- if (range == ColorRange::Full)
- return Video::ColorRange::Full;
- return Video::ColorRange::Studio;
- }
-
- void replace_code_points_if_specified(CodingIndependentCodePoints& cicp) const
- {
- if (color_primaries != ColorPrimaries::Unspecified)
- cicp.set_color_primaries(color_primaries);
- if (transfer_characteristics != TransferCharacteristics::Unspecified)
- cicp.set_transfer_characteristics(transfer_characteristics);
- if (matrix_coefficients != MatrixCoefficients::Unspecified)
- cicp.set_matrix_coefficients(matrix_coefficients);
- if (range != ColorRange::Unspecified && range != ColorRange::UseCICP)
- cicp.set_color_range(full_or_studio_range());
+ Video::ColorRange color_range;
+ switch (range) {
+ case ColorRange::Full:
+ color_range = Video::ColorRange::Full;
+ break;
+ case ColorRange::Broadcast:
+ color_range = Video::ColorRange::Studio;
+ break;
+ case ColorRange::Unspecified:
+ case ColorRange::UseCICP:
+ // FIXME: Figure out what UseCICP should do here. Matroska specification did not
+ // seem to explain in the 'colour' section. When this is fixed, change
+ // replace_code_points_if_specified to match.
+ color_range = Video::ColorRange::Unspecified;
+ break;
+ }
+
+ return { color_primaries, transfer_characteristics, matrix_coefficients, color_range };
}
};