From 6b392cef9c248a73ad1b3709217a0cccd2d68299 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Tue, 8 Nov 2022 03:24:30 -0600 Subject: [PATCH] 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. --- .../Libraries/LibVideo/Color/ColorConverter.cpp | 15 --------------- Userland/Libraries/LibVideo/PlaybackManager.cpp | 17 ++++++++++++++++- 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::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::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()));