FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
TCSystemCS/MetaData/Orientation.cs at develop · tgoessler/TCSystemCS · GitHub
tgoessler
TCSystemCS
Repository navigation
Code
Pull requests
6
(6)
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
TCSystemCS
/
MetaData
/
Orientation.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
205 lines (173 loc) · 7.69 KB
Breadcrumbs
TCSystemCS
/
MetaData
/
Orientation.cs
Copy path
File metadata and controls
205 lines (173 loc) · 7.69 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// *******************************************************************************
//
// ******* *** *** *
// * * * *
// * * * *****
// * * *** * * ** * ** ***
// * * * * * * * **** * * *
// * * * * * * * * * * *
// * *** *** * ** ** ** * *
// *
// *******************************************************************************
// see https://github.com/tgoessler/TCSystemCS for details.
// Copyright (C) 2003 - 2026 Thomas Goessler. All Rights Reserved.
// *******************************************************************************
//
// TCSystem is the legal property of its developers.
// Please refer to the COPYRIGHT file distributed with this source distribution.
//
// *******************************************************************************
#region Usings
using
System
;
#endregion
namespace
TCSystem
.
MetaData
;
/// <summary>Describes the EXIF orientation transform applied to an image.</summary>
public
enum
OrientationMode
{
/// <summary>The orientation is unknown.</summary>
Undefined
=
0
,
/// <summary>No transform is required.</summary>
Normal
=
1
,
/// <summary>Mirror horizontally.</summary>
MirrorHorizontal
=
2
,
/// <summary>Rotate by 180 degrees.</summary>
Rotate180
=
3
,
/// <summary>Mirror vertically.</summary>
MirrorVertical
=
4
,
/// <summary>Mirror horizontally and rotate clockwise by 270 degrees.</summary>
MirrorHorizontalRotateCw270
=
5
,
/// <summary>Rotate clockwise by 90 degrees.</summary>
RotateCw90
=
6
,
/// <summary>Mirror vertically and rotate clockwise by 90 degrees.</summary>
MirrorVerticalRotateCw90
=
7
,
/// <summary>Rotate clockwise by 270 degrees.</summary>
RotateCw270
=
8
}
/// <summary>Transforms normalized rectangles and faces according to image orientation.</summary>
public
static
class
Orientation
{
#region Public
/// <summary>Gets the rotation angle represented by an orientation mode.</summary>
/// <returns>The rotation in degrees.</returns>
public
static
double
Orientation2Degree
(
OrientationMode
mode
)
{
switch
(
mode
)
{
case
OrientationMode
.
Undefined
:
case
OrientationMode
.
Normal
:
case
OrientationMode
.
MirrorHorizontal
:
return
0.0
;
case
OrientationMode
.
Rotate180
:
case
OrientationMode
.
MirrorVertical
:
return
180
;
case
OrientationMode
.
MirrorHorizontalRotateCw270
:
case
OrientationMode
.
RotateCw270
:
case
OrientationMode
.
MirrorVerticalRotateCw90
:
return
90
;
case
OrientationMode
.
RotateCw90
:
return
270
;
default
:
throw
new
ArgumentOutOfRangeException
(
nameof
(
mode
)
,
mode
,
null
)
;
}
}
/// <summary>Transforms a normalized rectangle into the displayed orientation.</summary>
public
static
Rectangle
Orientate
(
Rectangle
rectangle
,
OrientationMode
mode
)
{
switch
(
mode
)
{
case
OrientationMode
.
Undefined
:
case
OrientationMode
.
Normal
:
return
rectangle
;
case
OrientationMode
.
MirrorHorizontal
:
return
FlipHorizontal
(
rectangle
)
;
case
OrientationMode
.
Rotate180
:
return
Rotate180
(
rectangle
)
;
case
OrientationMode
.
MirrorVertical
:
return
FlipVertical
(
rectangle
)
;
case
OrientationMode
.
MirrorHorizontalRotateCw270
:
return
RotateCw270
(
FlipHorizontal
(
rectangle
)
)
;
case
OrientationMode
.
RotateCw90
:
return
RotateCw90
(
rectangle
)
;
case
OrientationMode
.
MirrorVerticalRotateCw90
:
return
RotateCw90
(
FlipVertical
(
rectangle
)
)
;
case
OrientationMode
.
RotateCw270
:
return
RotateCw270
(
rectangle
)
;
default
:
throw
new
ArgumentOutOfRangeException
(
nameof
(
mode
)
,
mode
,
null
)
;
}
}
/// <summary>Returns a face whose rectangle is transformed into the displayed orientation.</summary>
public
static
Face
Orientate
(
Face
face
,
OrientationMode
mode
)
{
return
new
(
face
.
Id
,
Orientate
(
face
.
Rectangle
,
mode
)
,
face
.
FaceMode
,
face
.
FaceQuality
,
face
.
Visible
,
face
.
FaceDescriptor
)
;
}
/// <summary>Transforms a normalized rectangle from the displayed orientation back to stored coordinates.</summary>
public
static
Rectangle
OrientateBack
(
Rectangle
rectangle
,
OrientationMode
mode
)
{
switch
(
mode
)
{
case
OrientationMode
.
Undefined
:
case
OrientationMode
.
Normal
:
return
rectangle
;
case
OrientationMode
.
MirrorHorizontal
:
return
FlipHorizontal
(
rectangle
)
;
case
OrientationMode
.
Rotate180
:
return
Rotate180
(
rectangle
)
;
case
OrientationMode
.
MirrorVertical
:
return
FlipVertical
(
rectangle
)
;
case
OrientationMode
.
MirrorHorizontalRotateCw270
:
return
FlipHorizontal
(
RotateCw90
(
rectangle
)
)
;
case
OrientationMode
.
RotateCw90
:
return
RotateCw270
(
rectangle
)
;
case
OrientationMode
.
MirrorVerticalRotateCw90
:
return
FlipVertical
(
RotateCw270
(
rectangle
)
)
;
case
OrientationMode
.
RotateCw270
:
return
RotateCw90
(
rectangle
)
;
default
:
throw
new
ArgumentOutOfRangeException
(
nameof
(
mode
)
,
mode
,
null
)
;
}
}
/// <summary>Returns a face whose rectangle is transformed back to stored coordinates.</summary>
public
static
Face
OrientateBack
(
Face
face
,
OrientationMode
mode
)
{
return
new
(
face
.
Id
,
OrientateBack
(
face
.
Rectangle
,
mode
)
,
face
.
FaceMode
,
face
.
FaceQuality
,
face
.
Visible
,
face
.
FaceDescriptor
)
;
}
#endregion
#region Private
private
static
Rectangle
FlipVertical
(
Rectangle
rectangle
)
{
(
float
Value
,
float
)
min
=
(
rectangle
.
Left
.
Value
,
1.0f
-
rectangle
.
Bottom
.
Value
)
;
(
float
Value
,
float
)
max
=
(
rectangle
.
Right
.
Value
,
1.0f
-
rectangle
.
Top
.
Value
)
;
return
Rectangle
.
FromFloat
(
min
.
Item1
,
min
.
Item2
,
max
.
Item1
-
min
.
Item1
,
max
.
Item2
-
min
.
Item2
)
;
}
private
static
Rectangle
FlipHorizontal
(
Rectangle
rectangle
)
{
(
float
,
float
Value
)
min
=
(
1.0f
-
rectangle
.
Right
.
Value
,
rectangle
.
Top
.
Value
)
;
(
float
,
float
Value
)
max
=
(
1.0f
-
rectangle
.
Left
.
Value
,
rectangle
.
Bottom
.
Value
)
;
return
Rectangle
.
FromFloat
(
min
.
Item1
,
min
.
Item2
,
max
.
Item1
-
min
.
Item1
,
max
.
Item2
-
min
.
Item2
)
;
}
private
static
Rectangle
Rotate180
(
Rectangle
rectangle
)
{
(
float
,
float
)
min
=
(
1.0f
-
rectangle
.
Right
.
Value
,
1.0f
-
rectangle
.
Bottom
.
Value
)
;
(
float
,
float
)
max
=
(
1.0f
-
rectangle
.
Left
.
Value
,
1.0f
-
rectangle
.
Top
.
Value
)
;
return
Rectangle
.
FromFloat
(
min
.
Item1
,
min
.
Item2
,
max
.
Item1
-
min
.
Item1
,
max
.
Item2
-
min
.
Item2
)
;
}
private
static
Rectangle
RotateCw90
(
Rectangle
rectangle
)
{
(
float
Value
,
float
)
min
=
(
rectangle
.
Top
.
Value
,
1.0f
-
rectangle
.
Right
.
Value
)
;
(
float
Value
,
float
)
max
=
(
rectangle
.
Bottom
.
Value
,
1.0f
-
rectangle
.
Left
.
Value
)
;
return
Rectangle
.
FromFloat
(
min
.
Item1
,
min
.
Item2
,
max
.
Item1
-
min
.
Item1
,
max
.
Item2
-
min
.
Item2
)
;
}
private
static
Rectangle
RotateCw270
(
Rectangle
rectangle
)
{
(
float
,
float
Value
)
min
=
(
1.0f
-
rectangle
.
Bottom
.
Value
,
rectangle
.
Left
.
Value
)
;
(
float
,
float
Value
)
max
=
(
1.0f
-
rectangle
.
Top
.
Value
,
rectangle
.
Right
.
Value
)
;
return
Rectangle
.
FromFloat
(
min
.
Item1
,
min
.
Item2
,
max
.
Item1
-
min
.
Item1
,
max
.
Item2
-
min
.
Item2
)
;
}
#endregion
}
Back
|
FazBrowse Home
|
New Git URL