summaryrefslogtreecommitdiff
path: root/src/wx
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-10-18 20:26:05 +0200
committerCarl Hetherington <cth@carlh.net>2022-10-18 20:26:05 +0200
commit94eff17bdb94c170d456c7dab5ad3d4c00af4b14 (patch)
tree54281a554d800b49c149a69fe037035f903498ad /src/wx
parent053bf81d7ef24843cc2eea62e24c2296fed48950 (diff)
parentc9a1e2040bf5600aeafdefe56a3bf46e15419a16 (diff)
Hopefully fix colour of Rec.2020 sources in the preview.
Diffstat (limited to 'src/wx')
-rw-r--r--src/wx/colour_conversion_editor.cc1
-rw-r--r--src/wx/gl_video_view.cc79
-rw-r--r--src/wx/gl_video_view.h1
-rw-r--r--src/wx/simple_video_view.cc10
-rw-r--r--src/wx/simple_video_view.h7
5 files changed, 80 insertions, 18 deletions
diff --git a/src/wx/colour_conversion_editor.cc b/src/wx/colour_conversion_editor.cc
index b7c054e27..4cc9aaa9e 100644
--- a/src/wx/colour_conversion_editor.cc
+++ b/src/wx/colour_conversion_editor.cc
@@ -118,6 +118,7 @@ ColourConversionEditor::ColourConversionEditor (wxWindow* parent, bool yuv)
_yuv_to_rgb = new wxChoice (this, wxID_ANY);
_yuv_to_rgb->Append (_("Rec. 601"));
_yuv_to_rgb->Append (_("Rec. 709"));
+ _yuv_to_rgb->Append (_("Rec. 2020"));
table->Add (_yuv_to_rgb, wxGBPosition (r, 1));
++r;
diff --git a/src/wx/gl_video_view.cc b/src/wx/gl_video_view.cc
index 1f60af69d..4fc620936 100644
--- a/src/wx/gl_video_view.cc
+++ b/src/wx/gl_video_view.cc
@@ -197,13 +197,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 colour_conversion;\n"
+"uniform mat4 xyz_rec709_colour_conversion;\n"
+"uniform mat4 rec2020_rec709_colour_conversion;\n"
"\n"
"out vec4 FragColor;\n"
"\n"
@@ -271,13 +273,17 @@ static constexpr char fragment_source[] =
" FragColor.x = pow(FragColor.x, IN_GAMMA) / DCI_COEFFICIENT;\n"
" FragColor.y = pow(FragColor.y, IN_GAMMA) / DCI_COEFFICIENT;\n"
" FragColor.z = pow(FragColor.z, IN_GAMMA) / DCI_COEFFICIENT;\n"
-" FragColor = colour_conversion * FragColor;\n"
+" FragColor = xyz_rec709_colour_conversion * FragColor;\n"
" FragColor.x = pow(FragColor.x, OUT_GAMMA);\n"
" FragColor.y = pow(FragColor.y, OUT_GAMMA);\n"
" FragColor.z = pow(FragColor.z, OUT_GAMMA);\n"
" 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 +294,8 @@ enum class FragmentType
OUTLINE_CONTENT = 0,
CROP_GUESS = 1,
XYZ_IMAGE = 2,
- RGB_IMAGE = 3,
+ REC709_IMAGE = 3,
+ REC2020_IMAGE = 4,
};
@@ -453,18 +460,48 @@ GLVideoView::setup_shaders ()
set_outline_content_colour (program);
set_crop_guess_colour (program);
- auto conversion = dcp::ColourConversion::rec709_to_xyz();
- boost::numeric::ublas::matrix<double> matrix = conversion.xyz_to_rgb ();
- GLfloat gl_matrix[] = {
- static_cast<float>(matrix(0, 0)), static_cast<float>(matrix(0, 1)), static_cast<float>(matrix(0, 2)), 0.0f,
- static_cast<float>(matrix(1, 0)), static_cast<float>(matrix(1, 1)), static_cast<float>(matrix(1, 2)), 0.0f,
- static_cast<float>(matrix(2, 0)), static_cast<float>(matrix(2, 1)), static_cast<float>(matrix(2, 2)), 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f
- };
+ auto ublas_to_gl = [](boost::numeric::ublas::matrix<double> const& ublas, GLfloat* gl) {
+ gl[0] = static_cast<float>(ublas(0, 0));
+ gl[1] = static_cast<float>(ublas(0, 1));
+ gl[2] = static_cast<float>(ublas(0, 2));
+ gl[3] = 0.0f;
+ gl[4] = static_cast<float>(ublas(1, 0));
+ gl[5] = static_cast<float>(ublas(1, 1));
+ gl[6] = static_cast<float>(ublas(1, 2));
+ gl[7] = 0.0f;
+ gl[8] = static_cast<float>(ublas(2, 0));
+ gl[9] = static_cast<float>(ublas(2, 1));
+ gl[10] = static_cast<float>(ublas(2, 2));
+ gl[11] = 0.0f;
+ gl[12] = 0.0f;
+ gl[13] = 0.0f;
+ gl[14] = 0.0f;
+ gl[15] = 1.0f;
+ };
- auto colour_conversion = glGetUniformLocation (program, "colour_conversion");
- check_gl_error ("glGetUniformLocation");
- glUniformMatrix4fv (colour_conversion, 1, GL_TRUE, gl_matrix);
+ {
+ auto conversion = dcp::ColourConversion::rec709_to_xyz();
+ boost::numeric::ublas::matrix<double> matrix = conversion.xyz_to_rgb ();
+ GLfloat gl_matrix[16];
+ ublas_to_gl(matrix, gl_matrix);
+
+ auto xyz_rec709_colour_conversion = glGetUniformLocation(program, "xyz_rec709_colour_conversion");
+ check_gl_error ("glGetUniformLocation");
+ 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");
@@ -522,11 +559,17 @@ GLVideoView::draw ()
glBindVertexArray(_vao);
check_gl_error ("glBindVertexArray");
- glUniform1i(_fragment_type, static_cast<GLint>(_optimise_for_j2k ? FragmentType::XYZ_IMAGE : FragmentType::RGB_IMAGE));
+ if (_optimise_for_j2k) {
+ glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::XYZ_IMAGE));
+ } else if (_rec2020) {
+ glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::REC2020_IMAGE));
+ } else {
+ glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::REC709_IMAGE));
+ }
_video_texture->bind();
glDrawElements (GL_TRIANGLES, indices_video_texture_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_video_texture_offset * sizeof(int)));
if (_have_subtitle_to_render) {
- glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::RGB_IMAGE));
+ glUniform1i(_fragment_type, static_cast<GLint>(FragmentType::REC709_IMAGE));
_subtitle_texture->bind();
glDrawElements (GL_TRIANGLES, indices_subtitle_texture_number, GL_UNSIGNED_INT, reinterpret_cast<void*>(indices_subtitle_texture_offset * sizeof(int)));
}
@@ -692,6 +735,8 @@ GLVideoView::set_image (shared_ptr<const PlayerVideo> 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);
diff --git a/src/wx/gl_video_view.h b/src/wx/gl_video_view.h
index fd9154a73..964f6f1ab 100644
--- a/src/wx/gl_video_view.h
+++ b/src/wx/gl_video_view.h
@@ -134,6 +134,7 @@ private:
Last<boost::optional<dcpomatic::Rect<float>>> _last_crop_guess;
boost::atomic<wxSize> _canvas_size;
+ boost::atomic<bool> _rec2020;
std::unique_ptr<Texture> _video_texture;
std::unique_ptr<Texture> _subtitle_texture;
bool _have_subtitle_to_render = false;
diff --git a/src/wx/simple_video_view.cc b/src/wx/simple_video_view.cc
index 00d81ab47..09c172171 100644
--- a/src/wx/simple_video_view.cc
+++ b/src/wx/simple_video_view.cc
@@ -26,6 +26,8 @@
#include "lib/butler.h"
#include "lib/dcpomatic_log.h"
#include "lib/image.h"
+#include "lib/video_filter_graph.h"
+#include "lib/video_filter_graph_set.h"
#include <dcp/util.h>
#include <dcp/warnings.h>
LIBDCP_DISABLE_WARNINGS
@@ -46,6 +48,8 @@ using namespace dcpomatic;
SimpleVideoView::SimpleVideoView (FilmViewer* viewer, wxWindow* parent)
: VideoView (viewer)
+ , _rec2020_filter("convert", "convert", "", "colorspace=all=bt709:iall=bt2020")
+ , _rec2020_filter_graph({ &_rec2020_filter }, dcp::Fraction(24, 1))
{
_panel = new wxPanel (parent);
@@ -241,7 +245,11 @@ SimpleVideoView::update ()
_state_timer.set ("get image");
- _image = player_video().first->image(boost::bind(&PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, true);
+ auto const pv = player_video();
+ _image = pv.first->image(boost::bind(&PlayerVideo::force, AV_PIX_FMT_RGB24), VideoRange::FULL, true);
+ if (pv.first->colour_conversion() && pv.first->colour_conversion()->about_equal(dcp::ColourConversion::rec2020_to_xyz(), 1e-6)) {
+ _image = Image::ensure_alignment(_rec2020_filter_graph.get(_image->size(), _image->pixel_format())->process(_image).front(), Image::Alignment::COMPACT);
+ }
_state_timer.set ("ImageChanged");
_viewer->image_changed (player_video().first);
diff --git a/src/wx/simple_video_view.h b/src/wx/simple_video_view.h
index 7a48f8ef8..e19068979 100644
--- a/src/wx/simple_video_view.h
+++ b/src/wx/simple_video_view.h
@@ -20,14 +20,18 @@
#include "video_view.h"
+#include "lib/filter.h"
#include "lib/position.h"
+#include "lib/video_filter_graph_set.h"
#include <dcp/types.h>
#include <dcp/warnings.h>
LIBDCP_DISABLE_WARNINGS
#include <wx/wx.h>
LIBDCP_ENABLE_WARNINGS
+
class FilmViewer;
+class Filter;
class SimpleVideoView : public VideoView
@@ -53,4 +57,7 @@ private:
wxTimer _timer;
Position<int> _inter_position;
dcp::Size _inter_size;
+
+ Filter _rec2020_filter;
+ VideoFilterGraphSet _rec2020_filter_graph;
};