mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
LibMedia: Remove reserved values from CICP enums
These served no purpose, instead we should determine validity with a full switch statement.
This commit is contained in:
committed by
Gregory Bertilson
parent
3cfe1f7542
commit
e42d9efcb6
Notes:
github-actions[bot]
2026-04-18 06:25:54 +00:00
Author: https://github.com/Zaggy1024 Commit: https://github.com/LadybirdBrowser/ladybird/commit/e42d9efcb6c
@@ -57,8 +57,6 @@ ErrorOr<ColorSpace> ColorSpace::from_cicp(Media::CodingIndependentCodePoints cic
|
||||
|
||||
auto primaries = TRY([&] -> ErrorOr<SkColorSpacePrimaries> {
|
||||
switch (cicp.color_primaries()) {
|
||||
case Media::ColorPrimaries::Reserved:
|
||||
break;
|
||||
case Media::ColorPrimaries::BT709:
|
||||
case Media::ColorPrimaries::Unspecified:
|
||||
return SkNamedPrimaries::kRec709;
|
||||
@@ -92,8 +90,6 @@ ErrorOr<ColorSpace> ColorSpace::from_cicp(Media::CodingIndependentCodePoints cic
|
||||
|
||||
auto transfer_function = TRY([&] -> ErrorOr<skcms_TransferFunction> {
|
||||
switch (cicp.transfer_characteristics()) {
|
||||
case Media::TransferCharacteristics::Reserved:
|
||||
break;
|
||||
case Media::TransferCharacteristics::BT709:
|
||||
case Media::TransferCharacteristics::Unspecified:
|
||||
return SkNamedTransferFn::kRec709;
|
||||
|
||||
@@ -17,9 +17,10 @@ namespace Media {
|
||||
// Current edition is from 07/21.
|
||||
|
||||
enum class ColorPrimaries : u8 {
|
||||
Reserved = 0,
|
||||
// Reserved
|
||||
BT709 = 1,
|
||||
Unspecified = 2, // Used by codecs to indicate that an alternative value may be used
|
||||
Unspecified = 2, // Used by codecs to indicate that an alternative value may be used.
|
||||
// Reserved
|
||||
BT470M = 4,
|
||||
BT470BG = 5,
|
||||
BT601 = 6,
|
||||
@@ -30,13 +31,13 @@ enum class ColorPrimaries : u8 {
|
||||
SMPTE431 = 11,
|
||||
SMPTE432 = 12,
|
||||
EBU3213 = 22,
|
||||
// All other values are also Reserved for later use.
|
||||
};
|
||||
|
||||
enum class TransferCharacteristics : u8 {
|
||||
Reserved = 0,
|
||||
// Reserved
|
||||
BT709 = 1,
|
||||
Unspecified = 2, // Used by codecs to indicate that an alternative value may be used
|
||||
// Reserved
|
||||
BT470M = 4,
|
||||
BT470BG = 5,
|
||||
BT601 = 6, // BT.601 or Rec. 601
|
||||
@@ -52,13 +53,13 @@ enum class TransferCharacteristics : u8 {
|
||||
SMPTE2084 = 16, // Also known as PQ
|
||||
SMPTE428 = 17,
|
||||
HLG = 18,
|
||||
// All other values are also Reserved for later use.
|
||||
};
|
||||
|
||||
enum class MatrixCoefficients : u8 {
|
||||
Identity = 0, // Applies no transformation to input values
|
||||
Identity = 0,
|
||||
BT709 = 1,
|
||||
Unspecified = 2, // Used by codecs to indicate that an alternative value may be used
|
||||
Unspecified = 2, // Used by codecs to indicate that an alternative value may be used.
|
||||
// Reserved
|
||||
FCC = 4,
|
||||
BT470BG = 5,
|
||||
BT601 = 6,
|
||||
@@ -70,15 +71,96 @@ enum class MatrixCoefficients : u8 {
|
||||
ChromaticityDerivedNonConstantLuminance = 12,
|
||||
ChromaticityDerivedConstantLuminance = 13,
|
||||
ICtCp = 14,
|
||||
// All other values are Reserved for later use.
|
||||
};
|
||||
|
||||
enum class VideoFullRangeFlag : u8 {
|
||||
Studio = 0, // Y range 16..235, UV range 16..240
|
||||
Full = 1, // 0..255
|
||||
Unspecified = 2, // Not part of the spec, serenity-specific addition for convenience.
|
||||
Unspecified = 2, // Used by codecs to indicate that an alternative value may be used.
|
||||
};
|
||||
|
||||
static constexpr bool color_primaries_valid(ColorPrimaries color_primaries)
|
||||
{
|
||||
switch (color_primaries) {
|
||||
case ColorPrimaries::Unspecified:
|
||||
return false;
|
||||
case ColorPrimaries::BT709:
|
||||
case ColorPrimaries::BT470M:
|
||||
case ColorPrimaries::BT470BG:
|
||||
case ColorPrimaries::BT601:
|
||||
case ColorPrimaries::SMPTE240:
|
||||
case ColorPrimaries::GenericFilm:
|
||||
case ColorPrimaries::BT2020:
|
||||
case ColorPrimaries::XYZ:
|
||||
case ColorPrimaries::SMPTE431:
|
||||
case ColorPrimaries::SMPTE432:
|
||||
case ColorPrimaries::EBU3213:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static constexpr bool transfer_characteristics_valid(TransferCharacteristics transfer_characteristics)
|
||||
{
|
||||
switch (transfer_characteristics) {
|
||||
case TransferCharacteristics::Unspecified:
|
||||
return false;
|
||||
case TransferCharacteristics::BT709:
|
||||
case TransferCharacteristics::BT470M:
|
||||
case TransferCharacteristics::BT470BG:
|
||||
case TransferCharacteristics::BT601:
|
||||
case TransferCharacteristics::SMPTE240:
|
||||
case TransferCharacteristics::Linear:
|
||||
case TransferCharacteristics::Log100:
|
||||
case TransferCharacteristics::Log100Sqrt10:
|
||||
case TransferCharacteristics::IEC61966:
|
||||
case TransferCharacteristics::BT1361:
|
||||
case TransferCharacteristics::SRGB:
|
||||
case TransferCharacteristics::BT2020BitDepth10:
|
||||
case TransferCharacteristics::BT2020BitDepth12:
|
||||
case TransferCharacteristics::SMPTE2084:
|
||||
case TransferCharacteristics::SMPTE428:
|
||||
case TransferCharacteristics::HLG:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static constexpr bool matrix_coefficients_valid(MatrixCoefficients matrix_coefficients)
|
||||
{
|
||||
switch (matrix_coefficients) {
|
||||
case MatrixCoefficients::Unspecified:
|
||||
return false;
|
||||
case MatrixCoefficients::Identity:
|
||||
case MatrixCoefficients::BT709:
|
||||
case MatrixCoefficients::FCC:
|
||||
case MatrixCoefficients::BT470BG:
|
||||
case MatrixCoefficients::BT601:
|
||||
case MatrixCoefficients::SMPTE240:
|
||||
case MatrixCoefficients::YCgCo:
|
||||
case MatrixCoefficients::BT2020NonConstantLuminance:
|
||||
case MatrixCoefficients::BT2020ConstantLuminance:
|
||||
case MatrixCoefficients::SMPTE2085:
|
||||
case MatrixCoefficients::ChromaticityDerivedNonConstantLuminance:
|
||||
case MatrixCoefficients::ChromaticityDerivedConstantLuminance:
|
||||
case MatrixCoefficients::ICtCp:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static constexpr bool video_full_range_flag_valid(VideoFullRangeFlag video_full_range_flag)
|
||||
{
|
||||
switch (video_full_range_flag) {
|
||||
case VideoFullRangeFlag::Unspecified:
|
||||
return false;
|
||||
case VideoFullRangeFlag::Studio:
|
||||
case VideoFullRangeFlag::Full:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/Coding-independent_code_points
|
||||
struct CodingIndependentCodePoints {
|
||||
public:
|
||||
@@ -103,13 +185,13 @@ public:
|
||||
|
||||
constexpr void adopt_specified_values(CodingIndependentCodePoints cicp)
|
||||
{
|
||||
if (cicp.color_primaries() != ColorPrimaries::Unspecified && cicp.color_primaries() != ColorPrimaries::Reserved)
|
||||
if (color_primaries_valid(cicp.color_primaries()))
|
||||
set_color_primaries(cicp.color_primaries());
|
||||
if (cicp.transfer_characteristics() != TransferCharacteristics::Unspecified && cicp.transfer_characteristics() != TransferCharacteristics::Reserved)
|
||||
if (transfer_characteristics_valid(cicp.transfer_characteristics()))
|
||||
set_transfer_characteristics(cicp.transfer_characteristics());
|
||||
if (cicp.matrix_coefficients() != MatrixCoefficients::Unspecified)
|
||||
if (matrix_coefficients_valid(cicp.matrix_coefficients()))
|
||||
set_matrix_coefficients(cicp.matrix_coefficients());
|
||||
if (cicp.video_full_range_flag() != VideoFullRangeFlag::Unspecified)
|
||||
if (video_full_range_flag_valid(cicp.video_full_range_flag()))
|
||||
set_video_full_range_flag(cicp.video_full_range_flag());
|
||||
}
|
||||
|
||||
@@ -123,8 +205,6 @@ private:
|
||||
constexpr StringView color_primaries_to_string(ColorPrimaries color_primaries)
|
||||
{
|
||||
switch (color_primaries) {
|
||||
case ColorPrimaries::Reserved:
|
||||
return "Reserved"sv;
|
||||
case ColorPrimaries::BT709:
|
||||
return "BT.709"sv;
|
||||
case ColorPrimaries::Unspecified:
|
||||
@@ -156,8 +236,6 @@ constexpr StringView color_primaries_to_string(ColorPrimaries color_primaries)
|
||||
constexpr StringView transfer_characteristics_to_string(TransferCharacteristics transfer_characteristics)
|
||||
{
|
||||
switch (transfer_characteristics) {
|
||||
case TransferCharacteristics::Reserved:
|
||||
return "Reserved"sv;
|
||||
case TransferCharacteristics::BT709:
|
||||
return "BT.709"sv;
|
||||
case TransferCharacteristics::Unspecified:
|
||||
@@ -238,7 +316,7 @@ constexpr StringView video_full_range_flag_to_string(VideoFullRangeFlag video_fu
|
||||
return "Studio"sv;
|
||||
case VideoFullRangeFlag::Full:
|
||||
return "Full"sv;
|
||||
case VideoFullRangeFlag::Unspecified: // Not part of the spec, serenity-specific addition for convenience.
|
||||
case VideoFullRangeFlag::Unspecified:
|
||||
return "Unspecified"sv;
|
||||
}
|
||||
return "Unknown"sv;
|
||||
|
||||
@@ -14,7 +14,7 @@ TEST_CASE(adopt_specified_values_ignores_reserved_and_unspecified_values)
|
||||
Media::MatrixCoefficients::BT709, Media::VideoFullRangeFlag::Studio
|
||||
};
|
||||
|
||||
cicp.adopt_specified_values({ Media::ColorPrimaries::Reserved, Media::TransferCharacteristics::Reserved,
|
||||
cicp.adopt_specified_values({ static_cast<Media::ColorPrimaries>(0), static_cast<Media::TransferCharacteristics>(0),
|
||||
Media::MatrixCoefficients::Unspecified, Media::VideoFullRangeFlag::Unspecified });
|
||||
|
||||
EXPECT(cicp.color_primaries() == Media::ColorPrimaries::BT709);
|
||||
|
||||
Reference in New Issue
Block a user