diff options
Diffstat (limited to 'Userland/Applications/VideoPlayer/main.cpp')
-rw-r--r-- | Userland/Applications/VideoPlayer/main.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/Userland/Applications/VideoPlayer/main.cpp b/Userland/Applications/VideoPlayer/main.cpp index 9e129e2c7f..fb56803a05 100644 --- a/Userland/Applications/VideoPlayer/main.cpp +++ b/Userland/Applications/VideoPlayer/main.cpp @@ -12,6 +12,7 @@ #include <LibGUI/Window.h> #include <LibGfx/Bitmap.h> #include <LibMain/Main.h> +#include <LibVideo/Color/ColorConverter.h> #include <LibVideo/MatroskaReader.h> #include <LibVideo/VP9/Decoder.h> @@ -91,6 +92,15 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) auto uv_subsampling_y = vp9_decoder.get_uv_subsampling_y(); auto uv_subsampling_x = vp9_decoder.get_uv_subsampling_x(); Gfx::IntSize uv_size { y_size.width() >> uv_subsampling_x, y_size.height() >> uv_subsampling_y }; + auto cicp = vp9_decoder.get_cicp_color_space(); + cicp.default_code_points_if_unspecified(Video::ColorPrimaries::BT709, Video::TransferCharacteristics::BT709, Video::MatrixCoefficients::BT709); + + auto color_converter_result = Video::ColorConverter::create(vp9_decoder.get_bit_depth(), cicp); + if (color_converter_result.is_error()) { + outln("Cannot convert video colors: {}", color_converter_result.release_error().string_literal()); + return; + } + auto color_converter = color_converter_result.release_value(); for (auto y_row = 0u; y_row < video_track.pixel_height; y_row++) { auto uv_row = y_row >> uv_subsampling_y; @@ -99,17 +109,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) auto uv_column = y_column >> uv_subsampling_x; auto y = output_y[y_row * y_size.width() + y_column]; - auto cb = output_u[uv_row * uv_size.width() + uv_column]; - auto cr = output_v[uv_row * uv_size.width() + uv_column]; - // Convert from Rec.709 YCbCr to RGB. - auto r_float = floorf(clamp(y + (cr - 128) * 219.0f / 224.0f * 1.5748f, 0, 255)); - auto g_float = floorf(clamp(y + (cb - 128) * 219.0f / 224.0f * -0.0722f * 1.8556f / 0.7152f + (cr - 128) * 219.0f / 224.0f * -0.2126f * 1.5748f / 0.7152f, 0, 255)); - auto b_float = floorf(clamp(y + (cb - 128) * 219.0f / 224.0f * 1.8556f, 0, 255)); - auto r = static_cast<u8>(r_float); - auto g = static_cast<u8>(g_float); - auto b = static_cast<u8>(b_float); - - image->set_pixel(y_column, y_row, Gfx::Color(r, g, b)); + auto u = output_u[uv_row * uv_size.width() + uv_column]; + auto v = output_v[uv_row * uv_size.width() + uv_column]; + + image->set_pixel(y_column, y_row, color_converter.convert_yuv_to_full_range_rgb(y, u, v)); } } |