X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fgl_video_view.cc;h=397693f51f1fbd7afe26a5fb796f788e60488564;hb=5ee919f413a6c1048aecf83676d42ab3fd94e06e;hp=f8c97ba14013247cf5844c8f82ce68dae1820495;hpb=1d6fbc1db119e69cbe72a56acc82884b623079c1;p=dcpomatic.git diff --git a/src/wx/gl_video_view.cc b/src/wx/gl_video_view.cc index f8c97ba14..397693f51 100644 --- a/src/wx/gl_video_view.cc +++ b/src/wx/gl_video_view.cc @@ -79,6 +79,7 @@ check_gl_error (char const * last) GLVideoView::GLVideoView (FilmViewer* viewer, wxWindow *parent) : VideoView (viewer) , _context (nullptr) + , _rec2020(false) , _vsync_enabled (false) , _playing (false) , _one_shot (false) @@ -197,13 +198,15 @@ static constexpr char fragment_source[] = /* type = 0: draw outline content rectangle * type = 1: draw crop guess rectangle * type = 2: draw XYZ image - * type = 3: draw RGB image + * type = 3: draw RGB image (with sRGB/Rec709 primaries) + * type = 4: draw RGB image (converting from Rec2020 primaries) * See FragmentType enum below. */ "uniform int type = 0;\n" "uniform vec4 outline_content_colour;\n" "uniform vec4 crop_guess_colour;\n" "uniform mat4 xyz_rec709_colour_conversion;\n" +"uniform mat4 rec2020_rec709_colour_conversion;\n" "\n" "out vec4 FragColor;\n" "\n" @@ -278,6 +281,10 @@ static constexpr char fragment_source[] = " break;\n" " case 3:\n" " FragColor = texture_bicubic(texture_sampler, TexCoord);\n" +" break;\n" +" case 4:\n" +" FragColor = texture_bicubic(texture_sampler, TexCoord);\n" +" FragColor = rec2020_rec709_colour_conversion * FragColor;\n" " break;\n" " }\n" "}\n"; @@ -288,7 +295,8 @@ enum class FragmentType OUTLINE_CONTENT = 0, CROP_GUESS = 1, XYZ_IMAGE = 2, - RGB_IMAGE = 3, + REC709_IMAGE = 3, + REC2020_IMAGE = 4, }; @@ -483,6 +491,19 @@ GLVideoView::setup_shaders () glUniformMatrix4fv(xyz_rec709_colour_conversion, 1, GL_TRUE, gl_matrix); } + { + auto xyz_rec709 = dcp::ColourConversion::rec709_to_xyz().xyz_to_rgb(); + auto rec2020_xyz = dcp::ColourConversion::rec2020_to_xyz().rgb_to_xyz(); + auto product = boost::numeric::ublas::prod(xyz_rec709, rec2020_xyz); + + GLfloat gl_matrix[16]; + ublas_to_gl(product, gl_matrix); + + auto rec2020_rec709_colour_conversion = glGetUniformLocation(program, "rec2020_rec709_colour_conversion"); + check_gl_error("glGetUniformLocation"); + glUniformMatrix4fv(rec2020_rec709_colour_conversion, 1, GL_TRUE, gl_matrix); + } + glLineWidth (1.0f); check_gl_error ("glLineWidth"); glEnable (GL_BLEND); @@ -539,11 +560,17 @@ GLVideoView::draw () glBindVertexArray(_vao); check_gl_error ("glBindVertexArray"); - glUniform1i(_fragment_type, static_cast(_optimise_for_j2k ? FragmentType::XYZ_IMAGE : FragmentType::RGB_IMAGE)); + if (_optimise_for_j2k) { + glUniform1i(_fragment_type, static_cast(FragmentType::XYZ_IMAGE)); + } else if (_rec2020) { + glUniform1i(_fragment_type, static_cast(FragmentType::REC2020_IMAGE)); + } else { + glUniform1i(_fragment_type, static_cast(FragmentType::REC709_IMAGE)); + } _video_texture->bind(); glDrawElements (GL_TRIANGLES, indices_video_texture_number, GL_UNSIGNED_INT, reinterpret_cast(indices_video_texture_offset * sizeof(int))); if (_have_subtitle_to_render) { - glUniform1i(_fragment_type, static_cast(FragmentType::RGB_IMAGE)); + glUniform1i(_fragment_type, static_cast(FragmentType::REC709_IMAGE)); _subtitle_texture->bind(); glDrawElements (GL_TRIANGLES, indices_subtitle_texture_number, GL_UNSIGNED_INT, reinterpret_cast(indices_subtitle_texture_offset * sizeof(int))); } @@ -709,6 +736,8 @@ GLVideoView::set_image (shared_ptr pv) check_gl_error ("glBufferSubData (subtitle)"); } + _rec2020 = pv->colour_conversion() && pv->colour_conversion()->about_equal(dcp::ColourConversion::rec2020_to_xyz(), 1e-6); + /* opt: where should these go? */ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);