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
|
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="AnamorphicFactory.cs" company="HandBrake Project (http://handbrake.fr)">
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
// The Anamorphic factory.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrake.ApplicationServices.Interop.Factories
{
using System.Collections.Generic;
using HandBrake.ApplicationServices.Interop.Json.Anamorphic;
using HandBrake.ApplicationServices.Interop.Json.Shared;
using HandBrake.ApplicationServices.Interop.Model;
using HandBrake.ApplicationServices.Interop.Model.Encoding;
using HandBrake.ApplicationServices.Interop.Model.Preview;
using HandBrake.ApplicationServices.Services.Encode.Model;
/// <summary>
/// The anamorphic factory.
/// </summary>
public class AnamorphicFactory
{
/// <summary>
/// The keep setting.
/// </summary>
public enum KeepSetting
{
HB_KEEP_WIDTH = 0x01,
HB_KEEP_HEIGHT = 0x02,
HB_KEEP_DISPLAY_ASPECT = 0x04
}
/// <summary>
/// The create geometry.
/// </summary>
/// <param name="job">
/// The job.
/// </param>
/// <param name="title">
/// The current title.
/// </param>
/// <param name="keepWidthOrHeight">
/// Keep Width or Height. (Not Display Aspect)
/// </param>
/// <returns>
/// The <see cref="Geometry"/>.
/// </returns>
public static Geometry CreateGeometry(EncodeTask job, SourceVideoInfo title, KeepSetting keepWidthOrHeight) // Todo remove the need for these objects. Should use simpler objects.
{
int settingMode = (int)keepWidthOrHeight + (job.KeepDisplayAspect ? 0x04 : 0);
// Sanitize the Geometry First.
AnamorphicGeometry anamorphicGeometry = new AnamorphicGeometry
{
SourceGeometry = new Geometry
{
Width = title.Resolution.Width,
Height = title.Resolution.Height,
PAR = new PAR { Num = title.ParVal.Width, Den = title.ParVal.Height }
},
DestSettings = new DestSettings
{
AnamorphicMode = (int)job.Anamorphic,
Geometry =
{
Width = job.Width ?? 0,
Height = job.Height ?? 0,
PAR = new PAR
{
Num = job.Anamorphic != Anamorphic.Custom ? title.ParVal.Width : job.PixelAspectX,
Den = job.Anamorphic != Anamorphic.Custom ? title.ParVal.Height : job.PixelAspectY,
}
},
Keep = settingMode,
Crop = new List<int> { job.Cropping.Top, job.Cropping.Bottom, job.Cropping.Left, job.Cropping.Right },
Modulus = job.Modulus ?? 16,
MaxWidth = job.MaxWidth ?? 0,
MaxHeight = job.MaxHeight ?? 0,
ItuPAR = false
}
};
if (job.Anamorphic == Anamorphic.Custom)
{
anamorphicGeometry.DestSettings.Geometry.PAR = new PAR { Num = job.PixelAspectX, Den = job.PixelAspectY };
}
else
{
anamorphicGeometry.DestSettings.Geometry.PAR = new PAR { Num = title.ParVal.Width, Den = title.ParVal.Height };
}
return HandBrakeUtils.GetAnamorphicSize(anamorphicGeometry);
}
/// <summary>
/// Finds output geometry for the given preview settings and title.
/// </summary>
/// <param name="settings">The preview settings.</param>
/// <param name="title">Information on the title to consider.</param>
/// <returns>Geometry Information</returns>
public static Geometry CreateGeometry(PreviewSettings settings, SourceVideoInfo title)
{
int settingMode = settings.KeepDisplayAspect ? 0x04 : 0;
// Sanitize the Geometry First.
AnamorphicGeometry anamorphicGeometry = new AnamorphicGeometry
{
SourceGeometry = new Geometry
{
Width = title.Resolution.Width,
Height = title.Resolution.Height,
PAR = new PAR { Num = title.ParVal.Width, Den = title.ParVal.Height }
},
DestSettings = new DestSettings
{
AnamorphicMode = (int)settings.Anamorphic,
Geometry =
{
Width = settings.Width,
Height = settings.Height,
PAR = new PAR
{
Num = settings.Anamorphic != Anamorphic.Custom ? title.ParVal.Width : settings.PixelAspectX,
Den = settings.Anamorphic != Anamorphic.Custom ? title.ParVal.Height : settings.PixelAspectY,
}
},
Keep = settingMode,
Crop = new List<int> { settings.Cropping.Top, settings.Cropping.Bottom, settings.Cropping.Left, settings.Cropping.Right },
Modulus = settings.Modulus ?? 16,
MaxWidth = settings.MaxWidth,
MaxHeight = settings.MaxHeight,
ItuPAR = false
}
};
if (settings.Anamorphic == Anamorphic.Custom)
{
anamorphicGeometry.DestSettings.Geometry.PAR = new PAR { Num = settings.PixelAspectX, Den = settings.PixelAspectY };
}
else
{
anamorphicGeometry.DestSettings.Geometry.PAR = new PAR { Num = title.ParVal.Width, Den = title.ParVal.Height };
}
return HandBrakeUtils.GetAnamorphicSize(anamorphicGeometry);
}
}
}
|