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
206
207
208
209
210
211
|
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PictureSize.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>
// Defines the PictureSize type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrakeWPF.Helpers
{
using System.Diagnostics;
using HandBrake.Interop.HbLib;
using HandBrake.Interop.Model;
using HandBrake.Interop.Model.Encoding;
/// <summary>
/// The picture size Helpers
/// </summary>
public class PictureSize
{
/// <summary>
/// The picture settings job.
/// </summary>
public class PictureSettingsJob
{
/// <summary>
/// Gets or sets the crop.
/// </summary>
public Cropping Crop { get; set; }
/// <summary>
/// Gets or sets the modulus.
/// </summary>
public int? Modulus { get; set; }
/// <summary>
/// Gets or sets the par w.
/// </summary>
public int ParW { get; set; }
/// <summary>
/// Gets or sets the par h.
/// </summary>
public int ParH { get; set; }
/// <summary>
/// Gets or sets a value indicating whether itu par.
/// </summary>
public bool ItuPar { get; set; }
/// <summary>
/// Gets or sets the width.
/// </summary>
public int Width { get; set; }
/// <summary>
/// Gets or sets the height.
/// </summary>
public int Height { get; set; }
/// <summary>
/// Gets or sets the anamorphic mode.
/// </summary>
public Anamorphic AnamorphicMode { get; set; }
/// <summary>
/// Gets or sets the max width.
/// </summary>
public int MaxWidth { get; set; }
/// <summary>
/// Gets or sets the max height.
/// </summary>
public int MaxHeight { get; set; }
/// <summary>
/// Gets or sets a value indicating whether keep display aspect.
/// </summary>
public bool KeepDisplayAspect { get; set; }
/// <summary>
/// Gets or sets the dar width.
/// </summary>
public int DarWidth { get; set; }
/// <summary>
/// Gets or sets the dar height.
/// </summary>
public int DarHeight { get; set; }
}
/// <summary>
/// The picture settings title.
/// </summary>
public class PictureSettingsTitle
{
/// <summary>
/// Gets or sets the width.
/// </summary>
public int Width { get; set; }
/// <summary>
/// Gets or sets the height.
/// </summary>
public int Height { get; set; }
/// <summary>
/// Gets or sets the par w.
/// </summary>
public int ParW { get; set; }
/// <summary>
/// Gets or sets the par h.
/// </summary>
public int ParH { get; set; }
/// <summary>
/// Gets or sets the aspect.
/// </summary>
public double Aspect { get; set; }
}
/// <summary>
/// The anamorphic result.
/// </summary>
public class AnamorphicResult
{
/// <summary>
/// Gets or sets the output width.
/// </summary>
public int OutputWidth { get; set; }
/// <summary>
/// Gets or sets the output height.
/// </summary>
public int OutputHeight { get; set; }
/// <summary>
/// Gets or sets the output par width.
/// </summary>
public double OutputParWidth { get; set; }
/// <summary>
/// Gets or sets the output par height.
/// </summary>
public double OutputParHeight { get; set; }
}
/// <summary>
/// The keep setting.
/// </summary>
public enum KeepSetting
{
HB_KEEP_WIDTH = 0x01,
HB_KEEP_HEIGHT = 0x02,
HB_KEEP_DISPLAY_ASPECT = 0x04
}
/// <summary>
/// The hb_set_anamorphic_size 2.
/// </summary>
/// <param name="job">
/// The job.
/// </param>
/// <param name="title">
/// The title.
/// </param>
/// <param name="setting">
/// The setting.
/// </param>
/// <returns>
/// The <see cref="AnamorphicResult"/>.
/// </returns>
public static AnamorphicResult hb_set_anamorphic_size2(PictureSettingsJob job, PictureSettingsTitle title, KeepSetting setting)
{
int settingMode = (int)setting + (job.KeepDisplayAspect ? 0x04 : 0);
hb_geometry_settings_s uiGeometry = new hb_geometry_settings_s
{
crop = new[] { job.Crop.Top, job.Crop.Bottom, job.Crop.Left, job.Crop.Right },
itu_par = 0,
keep = settingMode,
maxWidth = job.MaxWidth,
maxHeight = job.MaxHeight,
mode = (int)(hb_anamorphic_mode_t)job.AnamorphicMode,
modulus = job.Modulus.HasValue ? job.Modulus.Value : 16,
geometry = new hb_geometry_s { height = job.Height, width = job.Width, par = job.AnamorphicMode != Anamorphic.Custom ? new hb_rational_t { den = title.ParH, num = title.ParW } : new hb_rational_t { den = job.ParH, num = job.ParW }}
};
hb_geometry_s sourceGeometry = new hb_geometry_s
{
width = title.Width,
height = title.Height,
par = new hb_rational_t { den = title.ParH, num = title.ParW }
};
hb_geometry_s result = new hb_geometry_s();
HBFunctions.hb_set_anamorphic_size2(ref sourceGeometry, ref uiGeometry, ref result);
int outputWidth = result.width;
int outputHeight = result.height;
int outputParWidth = result.par.num;
int outputParHeight = result.par.den;
Debug.WriteLine("hb_set_anamorphic_size2: {0}x{1}", outputWidth, outputHeight);
return new AnamorphicResult { OutputWidth = outputWidth, OutputHeight = outputHeight, OutputParWidth = outputParWidth, OutputParHeight = outputParHeight };
}
}
}
|