1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:37:34 +00:00

LibVideo: Rename "ColorRange" to "VideoFullRangeFlag"

That matches the terminology used in ITU-T Rec. H.273,
PNG's cICP chunk, and the ICC cicpTag.

Also change the enum values to match the values in the spec --
0 means "not full range" and 1 means "full range".

(For now, keep the "Unspecified" entry around, and give it value 2.
This value is not in the spec.)

No intended behavior change.
This commit is contained in:
Nico Weber 2023-02-08 14:16:37 -05:00 committed by Linus Groh
parent 49474d8718
commit 89b98830f6
7 changed files with 29 additions and 29 deletions

View file

@ -72,20 +72,20 @@ enum class MatrixCoefficients : u8 {
// All other values are Reserved for later use.
};
enum class ColorRange : u8 {
Unspecified,
Studio, // Y range 16..235, UV range 16..240
Full, // 0..255
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.
};
// https://en.wikipedia.org/wiki/Coding-independent_code_points
struct CodingIndependentCodePoints {
public:
constexpr CodingIndependentCodePoints(ColorPrimaries color_primaries, TransferCharacteristics transfer_characteristics, MatrixCoefficients matrix_coefficients, ColorRange color_range)
constexpr CodingIndependentCodePoints(ColorPrimaries color_primaries, TransferCharacteristics transfer_characteristics, MatrixCoefficients matrix_coefficients, VideoFullRangeFlag video_full_range_flag)
: m_color_primaries(color_primaries)
, m_transfer_characteristics(transfer_characteristics)
, m_matrix_coefficients(matrix_coefficients)
, m_color_range(color_range)
, m_video_full_range_flag(video_full_range_flag)
{
}
@ -95,8 +95,8 @@ public:
constexpr void set_transfer_characteristics(TransferCharacteristics value) { m_transfer_characteristics = value; }
constexpr MatrixCoefficients matrix_coefficients() const { return m_matrix_coefficients; }
constexpr void set_matrix_coefficients(MatrixCoefficients value) { m_matrix_coefficients = value; }
constexpr ColorRange color_range() const { return m_color_range; }
constexpr void set_color_range(ColorRange value) { m_color_range = value; }
constexpr VideoFullRangeFlag video_full_range_flag() const { return m_video_full_range_flag; }
constexpr void set_video_full_range_flag(VideoFullRangeFlag value) { m_video_full_range_flag = value; }
constexpr void default_code_points_if_unspecified(CodingIndependentCodePoints cicp)
{
@ -106,8 +106,8 @@ public:
set_transfer_characteristics(cicp.transfer_characteristics());
if (matrix_coefficients() == MatrixCoefficients::Unspecified)
set_matrix_coefficients(cicp.matrix_coefficients());
if (color_range() == ColorRange::Unspecified)
set_color_range(cicp.color_range());
if (video_full_range_flag() == VideoFullRangeFlag::Unspecified)
set_video_full_range_flag(cicp.video_full_range_flag());
}
constexpr void adopt_specified_values(CodingIndependentCodePoints cicp)
@ -118,15 +118,15 @@ public:
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());
if (cicp.video_full_range_flag() != VideoFullRangeFlag::Unspecified)
set_video_full_range_flag(cicp.video_full_range_flag());
}
private:
ColorPrimaries m_color_primaries;
TransferCharacteristics m_transfer_characteristics;
MatrixCoefficients m_matrix_coefficients;
ColorRange m_color_range;
VideoFullRangeFlag m_video_full_range_flag;
};
constexpr StringView color_primaries_to_string(ColorPrimaries color_primaries)

View file

@ -87,7 +87,7 @@ DecoderErrorOr<ColorConverter> ColorConverter::create(u8 bit_depth, CodingIndepe
float y_max;
float uv_min;
float uv_max;
if (cicp.color_range() == ColorRange::Studio) {
if (cicp.video_full_range_flag() == VideoFullRangeFlag::Studio) {
y_min = 16.0f / 255.0f;
y_max = 235.0f / 255.0f;
uv_min = y_min;

View file

@ -77,24 +77,24 @@ public:
CodingIndependentCodePoints to_cicp() const
{
Video::ColorRange color_range;
Video::VideoFullRangeFlag video_full_range_flag;
switch (range) {
case ColorRange::Full:
color_range = Video::ColorRange::Full;
video_full_range_flag = Video::VideoFullRangeFlag::Full;
break;
case ColorRange::Broadcast:
color_range = Video::ColorRange::Studio;
video_full_range_flag = Video::VideoFullRangeFlag::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;
video_full_range_flag = Video::VideoFullRangeFlag::Unspecified;
break;
}
return { color_primaries, transfer_characteristics, matrix_coefficients, color_range };
return { color_primaries, transfer_characteristics, matrix_coefficients, video_full_range_flag };
}
};

View file

@ -190,7 +190,7 @@ bool PlaybackManager::decode_and_queue_one_sample()
auto& cicp = decoded_frame->cicp();
cicp.adopt_specified_values(frame_sample->container_cicp());
cicp.default_code_points_if_unspecified({ ColorPrimaries::BT709, TransferCharacteristics::BT709, MatrixCoefficients::BT709, ColorRange::Studio });
cicp.default_code_points_if_unspecified({ ColorPrimaries::BT709, TransferCharacteristics::BT709, MatrixCoefficients::BT709, VideoFullRangeFlag::Studio });
// BT.601, BT.709 and BT.2020 have a similar transfer function to sRGB, so other applications
// (Chromium, VLC) forgo transfer characteristics conversion. We will emulate that behavior by

View file

@ -241,7 +241,7 @@ struct SegmentFeature {
struct ColorConfig {
u8 bit_depth { 8 };
ColorSpace color_space { ColorSpace::Bt601 };
ColorRange color_range { ColorRange::Studio };
VideoFullRangeFlag color_range { VideoFullRangeFlag::Studio };
bool subsampling_x { true };
bool subsampling_y { true };
};

View file

@ -143,11 +143,11 @@ DecoderErrorOr<void> Parser::refresh_probs(FrameContext const& frame_context)
return {};
}
DecoderErrorOr<ColorRange> Parser::read_color_range()
DecoderErrorOr<VideoFullRangeFlag> Parser::read_video_full_range_flag()
{
if (TRY_READ(m_bit_stream->read_bit()))
return ColorRange::Full;
return ColorRange::Studio;
return VideoFullRangeFlag::Full;
return VideoFullRangeFlag::Studio;
}
/* (6.2) */
@ -303,11 +303,11 @@ DecoderErrorOr<ColorConfig> Parser::parse_color_config(FrameContext const& frame
auto color_space = static_cast<ColorSpace>(TRY_READ(m_bit_stream->read_bits(3)));
VERIFY(color_space <= ColorSpace::RGB);
ColorRange color_range;
VideoFullRangeFlag video_full_range_flag;
bool subsampling_x, subsampling_y;
if (color_space != ColorSpace::RGB) {
color_range = TRY(read_color_range());
video_full_range_flag = TRY(read_video_full_range_flag());
if (frame_context.profile == 1 || frame_context.profile == 3) {
subsampling_x = TRY_READ(m_bit_stream->read_bit());
subsampling_y = TRY_READ(m_bit_stream->read_bit());
@ -318,7 +318,7 @@ DecoderErrorOr<ColorConfig> Parser::parse_color_config(FrameContext const& frame
subsampling_y = true;
}
} else {
color_range = ColorRange::Full;
video_full_range_flag = VideoFullRangeFlag::Full;
if (frame_context.profile == 1 || frame_context.profile == 3) {
subsampling_x = false;
subsampling_y = false;
@ -330,7 +330,7 @@ DecoderErrorOr<ColorConfig> Parser::parse_color_config(FrameContext const& frame
}
}
return ColorConfig { bit_depth, color_space, color_range, subsampling_x, subsampling_y };
return ColorConfig { bit_depth, color_space, video_full_range_flag, subsampling_x, subsampling_y };
}
DecoderErrorOr<Gfx::Size<u32>> Parser::parse_frame_size()

View file

@ -45,7 +45,7 @@ private:
* See also section 5.26. */
Vector<size_t> parse_superframe_sizes(ReadonlyBytes);
DecoderErrorOr<ColorRange> read_color_range();
DecoderErrorOr<VideoFullRangeFlag> read_video_full_range_flag();
/* (6.1) Frame Syntax */
bool trailing_bits();