]> git.sesse.net Git - kdenlive/blob - src/vectorscope.h
05a5b3394f6bb078a0241ba13ce3f14930f736a3
[kdenlive] / src / vectorscope.h
1 /***************************************************************************
2  *   Copyright (C) 2010 by Simon Andreas Eugster (simon.eu@gmail.com)      *
3  *   This file is part of kdenlive. See www.kdenlive.org.                  *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  ***************************************************************************/
10
11 #ifndef VECTORSCOPE_H
12 #define VECTORSCOPE_H
13
14 #include <QtCore>
15 #include "renderer.h"
16 #include "monitor.h"
17 #include "colorplaneexport.h"
18 #include "colortools.h"
19 #include "ui_vectorscope_ui.h"
20
21 class Render;
22 class Monitor;
23 class Vectorscope_UI;
24
25 enum PAINT_MODE { PAINT_GREEN = 0, PAINT_ORIG = 1, PAINT_CHROMA = 2, PAINT_YUV = 3, PAINT_BLACK = 4, PAINT_GREEN2 = 5 };
26 enum BACKGROUND_MODE { BG_NONE = 0, BG_YUV = 1, BG_CHROMA = 2 };
27
28 class Vectorscope : public QWidget, public Ui::Vectorscope_UI {
29     Q_OBJECT
30
31 public:
32     Vectorscope(Monitor *projMonitor, Monitor *clipMonitor, QWidget *parent = 0);
33     ~Vectorscope();
34
35 protected:
36     void paintEvent(QPaintEvent *);
37     void resizeEvent(QResizeEvent *event);
38     void mousePressEvent(QMouseEvent *);
39     void mouseMoveEvent(QMouseEvent *event);
40
41 private:
42     Monitor *m_projMonitor;
43     Monitor *m_clipMonitor;
44     Render *m_activeRender;
45
46     ColorTools *m_colorTools;
47     ColorPlaneExport *m_colorPlaneExport;
48
49     QAction *m_aExportBackground;
50     QAction *m_aAxisEnabled;
51     QAction *m_a75PBox;
52     QAction *m_aRealtime;
53
54     /** How to represent the pixels on the scope (green, original color, ...) */
55     int iPaintMode;
56
57     /** Custom scaling of the vectorscope */
58     float m_scaling;
59
60     /** Number of pixels to skip for getting realtime updates */
61     int m_skipPixels;
62
63     QPoint mapToCanvas(QRect inside, QPointF point);
64     QPoint centerPoint, pR75, pG75, pB75, pCy75, pMg75, pYl75;
65
66     bool circleEnabled;
67     QPoint mousePos;
68
69     /** Updates the dimension. Only necessary when the widget has been resized. */
70     void updateDimensions();
71     bool initialDimensionUpdateDone;
72     QRect m_scopeRect;
73     int cw;
74
75
76     /** The vectorscope color distribution.
77         Class variable as calculated by a thread. */
78     QImage m_scope;
79     QImage m_wheel;
80
81     void calculateScope();
82     QFuture<void> m_scopeCalcThread;
83     QFuture<QImage> m_wheelCalcThread;
84
85     /** This semaphore that guards QFuture m_scopeCalcThread is necessary for avoiding
86         deadlocks. If not present, then an incoming new frame might trigger a new thread
87         at the wrong point in time, causing a deadlock. Nasty ;) */
88     QSemaphore semaphore;
89
90     /** Prods the Scope calculation thread. If it is running, do nothing. If it is not,
91       run a new thread.
92       Returns true if a new thread has been started. */
93     bool prodCalcThread();
94     bool prodWheelThread();
95
96     /** Counts the number of frames that have been rendered in one of the monitors.
97       The frame number will be reset when the vectorscope starts calculating the
98       current frame. */
99     QAtomicInt newFrames;
100     /** Counts the number of other changes that should cause the vectorscope to be
101       recalculated. This is for example a resizeEvent. In this case, no new frames
102       are generated, but the scope has to be updated in any case (also if auto-update
103       is not enabled). */
104     QAtomicInt newChanges;
105     /** Counts the number of changes concerning the background wheel */
106     QAtomicInt newWheelChanges;
107
108 signals:
109     void signalScopeCalculationFinished(const unsigned int &mseconds, const unsigned int &skipPixels);
110
111 private slots:
112     void slotMagnifyChanged();
113     void slotBackgroundChanged();
114     void slotActiveMonitorChanged(bool isClipMonitor);
115     void slotRenderZoneUpdated();
116     void slotScopeCalculationFinished(unsigned int mseconds, unsigned int skipPixels);
117     void slotWheelCalculationFinished();
118     void slotUpdateScope();
119     void slotUpdateWheel();
120     void slotExportBackground();
121 };
122
123 #endif // VECTORSCOPE_H