mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
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.
This commit is contained in:
parent
074f771b59
commit
3720f66bb1
Notes:
sideshowbarker
2024-07-17 05:02:35 +09:00
Author: https://github.com/Zaggy1024 Commit: https://github.com/SerenityOS/serenity/commit/3720f66bb1 Pull-request: https://github.com/SerenityOS/serenity/pull/15851
3 changed files with 42 additions and 27 deletions
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "LibVideo/Color/CodingIndependentCodePoints.h"
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/ElapsedTimer.h>
|
||||
#include <LibGUI/Application.h>
|
||||
|
@ -90,8 +91,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto frame = frame_result.release_value();
|
||||
|
||||
auto& cicp = frame->cicp();
|
||||
video_track.color_format.replace_code_points_if_specified(cicp);
|
||||
cicp.default_code_points_if_unspecified(Video::ColorPrimaries::BT709, Video::TransferCharacteristics::BT709, Video::MatrixCoefficients::BT709);
|
||||
cicp.adopt_specified_values(video_track.color_format.to_cicp());
|
||||
cicp.default_code_points_if_unspecified({ Video::ColorPrimaries::BT709, Video::TransferCharacteristics::BT709, Video::MatrixCoefficients::BT709, Video::ColorRange::Studio });
|
||||
|
||||
auto convert_result = frame->output_to_bitmap(image);
|
||||
if (convert_result.is_error()) {
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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());
|
||||
return { color_primaries, transfer_characteristics, matrix_coefficients, color_range };
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue