summaryrefslogtreecommitdiff
path: root/include/libcamera/transform.h
blob: 44cb4c6fc974cb0f4fd6c3a4b292e442cb76a9d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2020, Raspberry Pi Ltd
 *
 * transform.h - 2D plane transforms
 */

#pragma once

#include <string>

namespace libcamera {

enum class Orientation;

enum class Transform : int {
	Identity = 0,
	Rot0 = Identity,
	HFlip = 1,
	VFlip = 2,
	HVFlip = HFlip | VFlip,
	Rot180 = HVFlip,
	Transpose = 4,
	Rot270 = HFlip | Transpose,
	Rot90 = VFlip | Transpose,
	Rot180Transpose = HFlip | VFlip | Transpose
};

constexpr Transform operator&(Transform t0, Transform t1)
{
	return static_cast<Transform>(static_cast<int>(t0) & static_cast<int>(t1));
}

constexpr Transform operator|(Transform t0, Transform t1)
{
	return static_cast<Transform>(static_cast<int>(t0) | static_cast<int>(t1));
}

constexpr Transform operator^(Transform t0, Transform t1)
{
	return static_cast<Transform>(static_cast<int>(t0) ^ static_cast<int>(t1));
}

constexpr Transform &operator&=(Transform &t0, Transform t1)
{
	return t0 = t0 & t1;
}

constexpr Transform &operator|=(Transform &t0, Transform t1)
{
	return t0 = t0 | t1;
}

constexpr Transform &operator^=(Transform &t0, Transform t1)
{
	return t0 = t0 ^ t1;
}

Transform operator*(Transform t0, Transform t1);

Transform operator-(Transform t);

constexpr bool operator!(Transform t)
{
	return t == Transform::Identity;
}

constexpr Transform operator~(Transform t)
{
	return static_cast<Transform>(~static_cast<int>(t) & 7);
}

Transform transformFromRotation(int angle, bool *success = nullptr);

Transform operator/(const Orientation &o1, const Orientation &o2);
Orientation operator*(const Orientation &o, const Transform &t);

const char *transformToString(Transform t);

} /* namespace libcamera */