summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibVideo
diff options
context:
space:
mode:
authorZaggy1024 <zaggy1024@gmail.com>2022-11-08 03:24:30 -0600
committerAndreas Kling <kling@serenityos.org>2022-11-11 11:34:03 +0100
commit6b392cef9c248a73ad1b3709217a0cccd2d68299 (patch)
tree2991b4bbe482822704bc0322fa25798a4ca8b19e /Userland/Libraries/LibVideo
parenta2cd61d19d4e47608de319398bbd9deb1b259c49 (diff)
downloadserenity-6b392cef9c248a73ad1b3709217a0cccd2d68299.zip
LibVideo: Treat BT.601/709/2020 input transfer characteristics as sRGB
I've realized that it probably makes more sense to change the input transfer characteristics to treat these as sRGB since color conversion in linear converted from BT.709 doesn't really make sense. If content creation applications expect media players to display BT.709 without conversions, this means they expect applications to treat it as sRGB, since that's what most displays use. That most likely also means they process it as sRGB internally, meaning we should do the same for our color primaries conversion.
Diffstat (limited to 'Userland/Libraries/LibVideo')
-rw-r--r--Userland/Libraries/LibVideo/Color/ColorConverter.cpp15
-rw-r--r--Userland/Libraries/LibVideo/PlaybackManager.cpp17
2 files changed, 16 insertions, 16 deletions
diff --git a/Userland/Libraries/LibVideo/Color/ColorConverter.cpp b/Userland/Libraries/LibVideo/Color/ColorConverter.cpp
index 4a80b014d8..2026c040d6 100644
--- a/Userland/Libraries/LibVideo/Color/ColorConverter.cpp
+++ b/Userland/Libraries/LibVideo/Color/ColorConverter.cpp
@@ -165,21 +165,6 @@ DecoderErrorOr<ColorConverter> ColorConverter::create(u8 bit_depth, CodingIndepe
// should apply tonemapping as well.
// Use a lookup table as with step 3.
TransferCharacteristics output_tc = TransferCharacteristics::SRGB;
- switch (cicp.transfer_characteristics()) {
- case TransferCharacteristics::Unspecified:
- break;
- case TransferCharacteristics::BT709:
- case TransferCharacteristics::BT601:
- case TransferCharacteristics::BT2020BitDepth10:
- case TransferCharacteristics::BT2020BitDepth12:
- // BT.601, BT.709 and BT.2020 have a similar transfer function to sRGB, and other applications
- // (Chromium, VLC) seem to keep video output in those transfer characteristics.
- output_tc = TransferCharacteristics::BT709;
- break;
- default:
- break;
- }
-
auto to_non_linear_lookup_table = InterpolatedLookupTable<to_non_linear_size>::create(
[&](float value) {
return TransferCharacteristicsConversion::to_non_linear_luminance(value, output_tc);
diff --git a/Userland/Libraries/LibVideo/PlaybackManager.cpp b/Userland/Libraries/LibVideo/PlaybackManager.cpp
index 244c66e6c3..7d6ca6adc0 100644
--- a/Userland/Libraries/LibVideo/PlaybackManager.cpp
+++ b/Userland/Libraries/LibVideo/PlaybackManager.cpp
@@ -221,7 +221,22 @@ 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({ Video::ColorPrimaries::BT709, Video::TransferCharacteristics::BT709, Video::MatrixCoefficients::BT709, Video::ColorRange::Studio });
+ cicp.default_code_points_if_unspecified({ ColorPrimaries::BT709, TransferCharacteristics::BT709, MatrixCoefficients::BT709, ColorRange::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
+ // handling those as sRGB instead, which causes no transfer function change in the output,
+ // unless display color management is later implemented.
+ switch (cicp.transfer_characteristics()) {
+ case TransferCharacteristics::BT601:
+ case TransferCharacteristics::BT709:
+ case TransferCharacteristics::BT2020BitDepth10:
+ case TransferCharacteristics::BT2020BitDepth12:
+ cicp.set_transfer_characteristics(TransferCharacteristics::SRGB);
+ break;
+ default:
+ break;
+ }
auto bitmap = TRY_OR_ENQUEUE_ERROR(decoded_frame->to_bitmap());
m_frame_queue->enqueue(FrameQueueItem::frame(bitmap, frame_sample->timestamp()));