+ if (current_wb_pick_display == channel_number) {
+ // The picking was already done from eventFilter(), since we don't get
+ // the mouse pointer here.
+ } else {
+ global_mixer->channel_clicked(channel_number);
+ }
+}
+
+void MainWindow::wb_button_clicked(int channel_number)
+{
+ current_wb_pick_display = channel_number;
+ QApplication::setOverrideCursor(Qt::CrossCursor);
+}
+
+bool MainWindow::eventFilter(QObject *watched, QEvent *event)
+{
+ if (current_wb_pick_display != -1 &&
+ event->type() == QEvent::MouseButtonRelease &&
+ watched->isWidgetType()) {
+ QApplication::restoreOverrideCursor();
+ if (watched == previews[current_wb_pick_display]->display) {
+ const QMouseEvent *mouse_event = (QMouseEvent *)event;
+ set_white_balance(current_wb_pick_display, mouse_event->x(), mouse_event->y());
+ } else {
+ // The user clicked on something else, give up.
+ // (The click goes through, which might not be ideal, but, yes.)
+ current_wb_pick_display = -1;
+ }
+ }
+ return false;
+}
+
+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
+
+void MainWindow::set_white_balance(int channel_number, int x, int 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(Mixer::OUTPUT_INPUT0 + channel_number, 0.5, 0.5, 0.5);
+ previews[channel_number]->display->updateGL();
+ QRgb reference_color = previews[channel_number]->display->grabFrameBuffer().pixel(x, y);
+
+ double r = srgb_to_linear(qRed(reference_color) / 255.0);
+ double g = srgb_to_linear(qGreen(reference_color) / 255.0);
+ double b = srgb_to_linear(qBlue(reference_color) / 255.0);
+ global_mixer->set_wb(Mixer::OUTPUT_INPUT0 + channel_number, r, g, b);
+ previews[channel_number]->display->updateGL();