1 | // Copyright (C) 2024 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QVIDEOTRANSFORMATION_P_H |
5 | #define QVIDEOTRANSFORMATION_P_H |
6 | |
7 | #include <qtvideo.h> |
8 | #include <optional> |
9 | |
10 | // |
11 | // W A R N I N G |
12 | // ------------- |
13 | // |
14 | // This file is not part of the Qt API. It exists purely as an |
15 | // implementation detail. This header file may change from version to |
16 | // version without notice, or even be removed. |
17 | // |
18 | // We mean it. |
19 | // |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | struct VideoTransformation |
24 | { |
25 | QtVideo::Rotation rotation = QtVideo::Rotation::None; |
26 | bool mirrorredHorizontallyAfterRotation = false; |
27 | |
28 | void rotate(QtVideo::Rotation rotation) |
29 | { |
30 | if (rotation != QtVideo::Rotation::None) { |
31 | int angle = qToUnderlying(e: rotation); |
32 | if (mirrorredHorizontallyAfterRotation && angle % 180 != 0) |
33 | angle += 180; |
34 | |
35 | appendRotation(angle); |
36 | } |
37 | } |
38 | |
39 | void mirrorHorizontally(bool mirror = true) { mirrorredHorizontallyAfterRotation ^= mirror; } |
40 | |
41 | void mirrorVertically(bool mirror = true) |
42 | { |
43 | if (mirror) { |
44 | mirrorredHorizontallyAfterRotation ^= true; |
45 | appendRotation(angle: 180); |
46 | } |
47 | } |
48 | |
49 | int rotationIndex() const { return qToUnderlying(e: rotation) / 90; } |
50 | |
51 | private: |
52 | void appendRotation(quint32 angle) |
53 | { |
54 | rotation = QtVideo::Rotation((angle + qToUnderlying(e: rotation)) % 360); |
55 | } |
56 | }; |
57 | |
58 | using VideoTransformationOpt = std::optional<VideoTransformation>; |
59 | |
60 | inline bool operator==(const VideoTransformation &lhs, const VideoTransformation &rhs) |
61 | { |
62 | return lhs.rotation == rhs.rotation |
63 | && lhs.mirrorredHorizontallyAfterRotation == rhs.mirrorredHorizontallyAfterRotation; |
64 | } |
65 | |
66 | inline bool operator!=(const VideoTransformation &lhs, const VideoTransformation &rhs) |
67 | { |
68 | return !(lhs == rhs); |
69 | } |
70 | |
71 | Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug dbg, const VideoTransformation &transform); |
72 | |
73 | QT_END_NAMESPACE |
74 | |
75 | #endif // QVIDEOTRANSFORMATION_P_H |
76 |