]> git.sesse.net Git - nageru/blobdiff - glwidget.cpp
Release Nageru 1.7.2.
[nageru] / glwidget.cpp
index ca9416bc4f38a14e26566696642a1ba7491fd8f9..bf537de2dbdb0806d2c41fec0b8ebf3fcd74d8e7 100644 (file)
@@ -33,11 +33,23 @@ class QMouseEvent;
 #include <movit/util.h>
 #include <string>
 
-
 using namespace movit;
 using namespace std;
 using namespace std::placeholders;
 
+namespace {
+
+double srgb_to_linear(double x)
+{
+       if (x < 0.04045) {
+               return x / 12.92;
+       } else {
+               return pow((x + 0.055) / 1.055, 2.4);
+       }
+}
+
+}  // namespace
+
 GLWidget::GLWidget(QWidget *parent)
     : QGLWidget(parent, global_share_widget)
 {
@@ -56,6 +68,22 @@ void GLWidget::shutdown()
        global_mixer->remove_frame_ready_callback(output, this);
 }
 
+void GLWidget::grab_white_balance(unsigned channel, unsigned x, unsigned y)
+{
+       // Set the white balance to neutral for the grab. It's probably going to
+       // flicker a bit, but hopefully this display is not live anyway.
+       global_mixer->set_wb(output, 0.5, 0.5, 0.5);
+       global_mixer->wait_for_next_frame();
+
+       // Mark that the next paintGL() should grab the given pixel.
+       grab_x = x;
+       grab_y = y;
+       grab_output = Mixer::Output(Mixer::OUTPUT_INPUT0 + channel);
+       should_grab = true;
+
+       updateGL();
+}
+
 void GLWidget::initializeGL()
 {
        static once_flag flag;
@@ -122,6 +150,17 @@ void GLWidget::paintGL()
        } else {
                assert(resource_pool == frame.chain->get_resource_pool());
        }
+
+       if (should_grab) {
+               GLfloat reference_color[4];
+               glReadPixels(grab_x, current_height - grab_y - 1, 1, 1, GL_BGRA, GL_FLOAT, reference_color);
+
+               double r = srgb_to_linear(reference_color[2]);
+               double g = srgb_to_linear(reference_color[1]);
+               double b = srgb_to_linear(reference_color[0]);
+               global_mixer->set_wb(grab_output, r, g, b);
+               should_grab = false;
+       }
 }
 
 void GLWidget::mousePressEvent(QMouseEvent *event)