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
212
213
|
// --------------------------------------------------------------------------------------------------------------------
// <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;
using System.Runtime.InteropServices;
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 hb_set_anamorphic_size_native.
/// </summary>
/// <param name="job">
/// The job.
/// </param>
/// <param name="title">
/// The title.
/// </param>
/// <returns>
/// The <see cref="AnamorphicResult"/> object.
/// </returns>
public static AnamorphicResult hb_set_anamorphic_size(PictureSettingsJob job, PictureSettingsTitle title)
{
int outputHeight = 0;
int outputParHeight = 0;
int outputParWidth = 0;
int outputWidth = 0;
hb_job_s nativeJob = new hb_job_s
{
modulus = job.Modulus.HasValue ? job.Modulus.Value : 16,
anamorphic =
new hb_anamorphic_substruct
{
par_width = job.ParW,
par_height = job.ParH,
itu_par = 0,
mode = (int)job.AnamorphicMode,
dar_width = 0,
dar_height = 0,
keep_display_aspect = job.KeepDisplayAspect ? 1 : 0
},
maxWidth = title.Width,
maxHeight = title.Height,
keep_ratio = job.KeepDisplayAspect ? 1 : 0,
width = job.Width,
height = job.Height,
crop = new[] { job.Crop.Top, job.Crop.Bottom, job.Crop.Left, job.Crop.Right }
};
hb_title_s title_s = new hb_title_s
{
crop = new[] { job.Crop.Top, job.Crop.Bottom, job.Crop.Left, job.Crop.Right },
width = title.Width,
height = title.Height,
pixel_aspect_width = title.ParW,
pixel_aspect_height = title.ParH,
aspect = 0
};
IntPtr pointer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(hb_title_s)));
Marshal.StructureToPtr(title_s, pointer, false);
nativeJob.title = pointer;
HBFunctions.hb_set_anamorphic_size(
ref nativeJob, ref outputWidth, ref outputHeight, ref outputParWidth, ref outputParHeight);
return new AnamorphicResult { OutputWidth = outputWidth, OutputHeight = outputHeight, OutputParWidth = outputParWidth, OutputParHeight = outputParHeight };
}
}
}
|