@slidevideo/cli 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/IMPRESSUM.md +13 -0
- package/LICENSE-TERMS.md +58 -0
- package/README.md +25 -0
- package/addons/slidevideo/geometry.ts +127 -0
- package/addons/slidevideo/global-top.vue +232 -0
- package/addons/slidevideo/package.json +1 -0
- package/addons/slidevideo/playback-entries.ts +14 -0
- package/addons/slidevideo/preview.ts +157 -0
- package/dist/adapters/browser-runtime.d.ts +37 -0
- package/dist/adapters/browser-runtime.js +1 -0
- package/dist/adapters/edge.d.ts +7 -0
- package/dist/adapters/edge.js +46 -0
- package/dist/adapters/elevenlabs.d.ts +7 -0
- package/dist/adapters/elevenlabs.js +58 -0
- package/dist/adapters/powerpoint-preview.d.ts +2 -0
- package/dist/adapters/powerpoint-preview.js +18 -0
- package/dist/adapters/powerpoint.d.ts +21 -0
- package/dist/adapters/powerpoint.js +434 -0
- package/dist/adapters/registry.d.ts +4 -0
- package/dist/adapters/registry.js +13 -0
- package/dist/adapters/slidev-inputs.d.ts +1 -0
- package/dist/adapters/slidev-inputs.js +86 -0
- package/dist/adapters/slidev-inspection.d.ts +3 -0
- package/dist/adapters/slidev-inspection.js +79 -0
- package/dist/adapters/slidev-server.d.ts +1 -0
- package/dist/adapters/slidev-server.js +48 -0
- package/dist/adapters/slidev.d.ts +30 -0
- package/dist/adapters/slidev.js +251 -0
- package/dist/annotation-paint.d.ts +19 -0
- package/dist/annotation-paint.js +13 -0
- package/dist/annotations.d.ts +27 -0
- package/dist/annotations.js +115 -0
- package/dist/assembly.d.ts +48 -0
- package/dist/assembly.js +138 -0
- package/dist/calibration.d.ts +24 -0
- package/dist/calibration.js +346 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +180 -0
- package/dist/compositor.d.ts +18 -0
- package/dist/compositor.js +155 -0
- package/dist/contracts.d.ts +358 -0
- package/dist/contracts.js +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.js +15 -0
- package/dist/executables.d.ts +23 -0
- package/dist/executables.js +165 -0
- package/dist/installation.d.ts +6 -0
- package/dist/installation.js +32 -0
- package/dist/license-key.d.ts +12 -0
- package/dist/license-key.js +55 -0
- package/dist/license-status.d.ts +16 -0
- package/dist/license-status.js +12 -0
- package/dist/media.d.ts +12 -0
- package/dist/media.js +57 -0
- package/dist/overlay-assets.d.ts +2 -0
- package/dist/overlay-assets.js +58 -0
- package/dist/pipeline.d.ts +50 -0
- package/dist/pipeline.js +257 -0
- package/dist/preview/contracts.d.ts +34 -0
- package/dist/preview/contracts.js +1 -0
- package/dist/preview/player.d.ts +1 -0
- package/dist/preview/player.js +129 -0
- package/dist/preview/server.d.ts +1 -0
- package/dist/preview/server.js +112 -0
- package/dist/preview/view.d.ts +1 -0
- package/dist/preview/view.js +36 -0
- package/dist/revoked-keys.json +1 -0
- package/dist/run.d.ts +12 -0
- package/dist/run.js +109 -0
- package/dist/setup-install.d.ts +7 -0
- package/dist/setup-install.js +98 -0
- package/dist/setup-license.d.ts +2 -0
- package/dist/setup-license.js +63 -0
- package/dist/setup.d.ts +34 -0
- package/dist/setup.js +218 -0
- package/dist/speech.d.ts +6 -0
- package/dist/speech.js +125 -0
- package/dist/storyboard.d.ts +6 -0
- package/dist/storyboard.js +86 -0
- package/dist/timing.d.ts +6 -0
- package/dist/timing.js +162 -0
- package/package.json +134 -0
- package/schemas/annotation-geometry.v1.json +130 -0
- package/schemas/revoked-keys.schema.json +11 -0
- package/schemas/run-manifest.v1.json +96 -0
- package/schemas/schedule.v1.json +108 -0
- package/schemas/schedule.v2.json +496 -0
- package/schemas/speech.v1.json +173 -0
- package/schemas/storyboard.v1.json +461 -0
- package/schemas/storyboard.v2.json +802 -0
- package/schemas/timing-evidence.v1.json +129 -0
- package/skills/slidevideo/SKILL.md +56 -0
- package/skills/slidevideo/references/production.md +76 -0
- package/skills/slidevideo/references/storyboard.md +272 -0
- package/tools/edge-tts/edge-tts.py +19 -0
- package/tools/edge-tts/requirements.lock +34 -0
- package/tools/powerpoint/Native.cs +277 -0
- package/tools/powerpoint/powerpoint.ps1 +714 -0
- package/tools/powerpoint/preview.ps1 +100 -0
- package/tools/powerpoint/requirements.json +11 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Diagnostics;
|
|
4
|
+
using System.Drawing;
|
|
5
|
+
using System.Drawing.Drawing2D;
|
|
6
|
+
using System.Drawing.Imaging;
|
|
7
|
+
using System.Runtime.InteropServices;
|
|
8
|
+
using System.Security.Cryptography;
|
|
9
|
+
using System.Text;
|
|
10
|
+
using System.Threading;
|
|
11
|
+
|
|
12
|
+
namespace SlideVideo {
|
|
13
|
+
public static class PreviewInput {
|
|
14
|
+
private static readonly Queue<string> commands = new Queue<string>();
|
|
15
|
+
public static void Start() {
|
|
16
|
+
var reader = new Thread(delegate() {
|
|
17
|
+
string line;
|
|
18
|
+
while ((line = Console.ReadLine()) != null) { lock (commands) commands.Enqueue(line); }
|
|
19
|
+
});
|
|
20
|
+
reader.IsBackground = true;
|
|
21
|
+
reader.Start();
|
|
22
|
+
}
|
|
23
|
+
public static string Next() { lock (commands) return commands.Count == 0 ? null : commands.Dequeue(); }
|
|
24
|
+
}
|
|
25
|
+
public sealed class AudienceRect {
|
|
26
|
+
public int left, top, width, height, client_width, client_height;
|
|
27
|
+
public uint dpi;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public sealed class ContentRect {
|
|
31
|
+
public int x, y, width, height;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public static class Native {
|
|
35
|
+
private delegate bool EnumProc(IntPtr window, IntPtr parameter);
|
|
36
|
+
[StructLayout(LayoutKind.Sequential)] private struct Rect { public int Left, Top, Right, Bottom; }
|
|
37
|
+
[StructLayout(LayoutKind.Sequential)] private struct Point { public int X, Y; }
|
|
38
|
+
[DllImport("user32.dll")] private static extern bool ClientToScreen(IntPtr window, ref Point point);
|
|
39
|
+
[DllImport("user32.dll")] private static extern bool EnumWindows(EnumProc callback, IntPtr parameter);
|
|
40
|
+
[DllImport("user32.dll")] private static extern bool EnumChildWindows(IntPtr window, EnumProc callback, IntPtr parameter);
|
|
41
|
+
[DllImport("user32.dll")] private static extern bool PrintWindow(IntPtr window, IntPtr dc, uint flags);
|
|
42
|
+
[DllImport("user32.dll")] private static extern bool IsWindowVisible(IntPtr window);
|
|
43
|
+
[DllImport("user32.dll")] private static extern bool GetClientRect(IntPtr window, out Rect rectangle);
|
|
44
|
+
[DllImport("user32.dll", CharSet = CharSet.Unicode)] private static extern int GetWindowText(IntPtr window, StringBuilder text, int length);
|
|
45
|
+
[DllImport("user32.dll", CharSet = CharSet.Unicode)] private static extern int GetClassName(IntPtr window, StringBuilder text, int length);
|
|
46
|
+
[DllImport("user32.dll")] private static extern uint GetWindowThreadProcessId(IntPtr window, out uint process);
|
|
47
|
+
[DllImport("user32.dll")] private static extern bool SetWindowPos(IntPtr window, IntPtr after, int x, int y, int width, int height, uint flags);
|
|
48
|
+
[DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr window);
|
|
49
|
+
[DllImport("user32.dll")] private static extern IntPtr GetDC(IntPtr window);
|
|
50
|
+
[DllImport("user32.dll")] private static extern int ReleaseDC(IntPtr window, IntPtr dc);
|
|
51
|
+
[DllImport("user32.dll")] public static extern bool SetProcessDPIAware();
|
|
52
|
+
[DllImport("user32.dll")] private static extern uint GetDpiForWindow(IntPtr window);
|
|
53
|
+
[DllImport("user32.dll")] private static extern IntPtr OpenInputDesktop(uint flags, bool inherit, uint access);
|
|
54
|
+
[DllImport("user32.dll")] private static extern bool CloseDesktop(IntPtr desktop);
|
|
55
|
+
[DllImport("user32.dll", CharSet = CharSet.Unicode)] private static extern bool GetUserObjectInformation(IntPtr handle, int index, StringBuilder name, int length, out int needed);
|
|
56
|
+
[DllImport("gdi32.dll")] private static extern bool BitBlt(IntPtr destination, int x, int y, int width, int height, IntPtr source, int sourceX, int sourceY, uint operation);
|
|
57
|
+
[DllImport("dwmapi.dll")] private static extern int DwmFlush();
|
|
58
|
+
|
|
59
|
+
public static bool HasInteractiveDesktop() {
|
|
60
|
+
if (!Environment.UserInteractive || Process.GetCurrentProcess().SessionId == 0) return false;
|
|
61
|
+
var desktop = OpenInputDesktop(0, false, 1);
|
|
62
|
+
if (desktop == IntPtr.Zero) return false;
|
|
63
|
+
try {
|
|
64
|
+
var name = new StringBuilder(256);
|
|
65
|
+
int needed;
|
|
66
|
+
return GetUserObjectInformation(desktop, 2, name, name.Capacity * sizeof(char), out needed) &&
|
|
67
|
+
name.ToString().Equals("Default", StringComparison.OrdinalIgnoreCase);
|
|
68
|
+
} finally { CloseDesktop(desktop); }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public static int WindowProcess(long handle) {
|
|
72
|
+
uint process;
|
|
73
|
+
if (GetWindowThreadProcessId(new IntPtr(handle), out process) == 0) throw new InvalidOperationException("Cannot identify the native PowerPoint process.");
|
|
74
|
+
return checked((int)process);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public static long FindShow(int process, string name, long editor) {
|
|
78
|
+
var found = new List<long>();
|
|
79
|
+
EnumWindows(delegate(IntPtr window, IntPtr parameter) {
|
|
80
|
+
uint owner;
|
|
81
|
+
GetWindowThreadProcessId(window, out owner);
|
|
82
|
+
if (owner != process || !IsWindowVisible(window) || window.ToInt64() == editor) return true;
|
|
83
|
+
var title = new StringBuilder(2048);
|
|
84
|
+
var type = new StringBuilder(256);
|
|
85
|
+
GetWindowText(window, title, title.Capacity);
|
|
86
|
+
GetClassName(window, type, type.Capacity);
|
|
87
|
+
if (type.ToString() == "PPTFrameClass" && title.ToString().IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0) found.Add(window.ToInt64());
|
|
88
|
+
return true;
|
|
89
|
+
}, IntPtr.Zero);
|
|
90
|
+
if (found.Count > 1) throw new InvalidOperationException("More than one audience window matches the private presentation.");
|
|
91
|
+
return found.Count == 1 ? found[0] : 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public static string Describe(long handle) {
|
|
95
|
+
var title = new StringBuilder(2048);
|
|
96
|
+
var type = new StringBuilder(256);
|
|
97
|
+
GetWindowText(new IntPtr(handle), title, title.Capacity);
|
|
98
|
+
GetClassName(new IntPtr(handle), type, type.Capacity);
|
|
99
|
+
return type.ToString() + " | " + title.ToString();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public static void Place(long handle, int width, int height) {
|
|
103
|
+
var window = new IntPtr(handle);
|
|
104
|
+
if (!SetWindowPos(window, new IntPtr(-1), 0, 0, width, height, 0x40)) throw new InvalidOperationException("Cannot position the audience window.");
|
|
105
|
+
SetForegroundWindow(window);
|
|
106
|
+
DwmFlush();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public static void PlacePreview(long handle, int width, int height) {
|
|
110
|
+
if (!SetWindowPos(new IntPtr(handle), new IntPtr(-2), 0, 0, width, height, 0x50)) throw new InvalidOperationException("Cannot position the native preview window.");
|
|
111
|
+
DwmFlush();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public static AudienceRect PreviewContent(long handle, double aspect) {
|
|
115
|
+
AudienceRect content = null;
|
|
116
|
+
var parent = new IntPtr(handle);
|
|
117
|
+
Rect client;
|
|
118
|
+
if (!GetClientRect(parent, out client)) throw new InvalidOperationException("Cannot measure the native preview window.");
|
|
119
|
+
var parentOrigin = new Point();
|
|
120
|
+
if (!ClientToScreen(parent, ref parentOrigin)) throw new InvalidOperationException("Cannot locate the native preview window.");
|
|
121
|
+
EnumChildWindows(parent, delegate(IntPtr child, IntPtr unused) {
|
|
122
|
+
var type = new StringBuilder(256);
|
|
123
|
+
GetClassName(child, type, type.Capacity);
|
|
124
|
+
Rect rect;
|
|
125
|
+
if (!IsWindowVisible(child) || !type.ToString().Equals("screenClass", StringComparison.OrdinalIgnoreCase) || !GetClientRect(child, out rect) || rect.Right < 320 || rect.Bottom < 180 || Math.Abs((double)rect.Right / rect.Bottom - aspect) > 2.0 / rect.Bottom) return true;
|
|
126
|
+
var origin = new Point();
|
|
127
|
+
if (!ClientToScreen(child, ref origin)) return true;
|
|
128
|
+
int left = origin.X - parentOrigin.X, top = origin.Y - parentOrigin.Y;
|
|
129
|
+
if (left < 0 || top < 0 || left + rect.Right > client.Right || top + rect.Bottom > client.Bottom) return true;
|
|
130
|
+
if (content == null || rect.Right * rect.Bottom > content.width * content.height) content = new AudienceRect { left = left, top = top, width = rect.Right, height = rect.Bottom, client_width = client.Right, client_height = client.Bottom, dpi = GetDpiForWindow(parent) };
|
|
131
|
+
return true;
|
|
132
|
+
}, IntPtr.Zero);
|
|
133
|
+
if (content == null) throw new InvalidOperationException("Cannot identify the native slideshow content without calibration. This PowerPoint window layout is unsupported for preview.");
|
|
134
|
+
return content;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
public static string PreviewJpeg(long handle, AudienceRect rectangle, int width, int height) {
|
|
138
|
+
EnsureGeometry(handle, rectangle);
|
|
139
|
+
using (var image = new Bitmap(rectangle.client_width, rectangle.client_height, PixelFormat.Format24bppRgb)) {
|
|
140
|
+
using (var graphics = Graphics.FromImage(image)) {
|
|
141
|
+
var dc = graphics.GetHdc();
|
|
142
|
+
try {
|
|
143
|
+
if (!PrintWindow(new IntPtr(handle), dc, 3)) throw new InvalidOperationException("PowerPoint did not render the live preview window.");
|
|
144
|
+
} finally { graphics.ReleaseHdc(dc); }
|
|
145
|
+
}
|
|
146
|
+
using (var output = new Bitmap(width, height)) {
|
|
147
|
+
using (var graphics = Graphics.FromImage(output)) {
|
|
148
|
+
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
149
|
+
graphics.DrawImage(image, new Rectangle(0, 0, width, height), new Rectangle(rectangle.left, rectangle.top, rectangle.width, rectangle.height), GraphicsUnit.Pixel);
|
|
150
|
+
}
|
|
151
|
+
using (var stream = new System.IO.MemoryStream()) {
|
|
152
|
+
output.Save(stream, ImageFormat.Jpeg);
|
|
153
|
+
return "data:image/jpeg;base64," + Convert.ToBase64String(stream.ToArray());
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private static Bitmap Capture(long handle, bool desktop = false) {
|
|
160
|
+
var window = new IntPtr(handle);
|
|
161
|
+
Rect rect;
|
|
162
|
+
if (!GetClientRect(window, out rect) || rect.Right <= 0 || rect.Bottom <= 0) throw new InvalidOperationException("The audience window has no visible client pixels.");
|
|
163
|
+
var image = new Bitmap(rect.Right, rect.Bottom, PixelFormat.Format24bppRgb);
|
|
164
|
+
var position = new Point();
|
|
165
|
+
if (desktop && !ClientToScreen(window, ref position)) throw new InvalidOperationException("Cannot locate the audience client on the desktop.");
|
|
166
|
+
var sourceWindow = desktop ? IntPtr.Zero : window;
|
|
167
|
+
var source = GetDC(sourceWindow);
|
|
168
|
+
try {
|
|
169
|
+
using (var graphics = Graphics.FromImage(image)) {
|
|
170
|
+
var destination = graphics.GetHdc();
|
|
171
|
+
try {
|
|
172
|
+
if (!BitBlt(destination, 0, 0, image.Width, image.Height, source, position.X, position.Y, 0x40CC0020)) throw new InvalidOperationException("Cannot capture audience pixels.");
|
|
173
|
+
} finally { graphics.ReleaseHdc(destination); }
|
|
174
|
+
}
|
|
175
|
+
return image;
|
|
176
|
+
} catch { image.Dispose(); throw; }
|
|
177
|
+
finally { ReleaseDC(sourceWindow, source); }
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private static bool Matches(Color pixel, Color color) {
|
|
181
|
+
return Math.Abs(pixel.R - color.R) < 8 && Math.Abs(pixel.G - color.G) < 8 && Math.Abs(pixel.B - color.B) < 8;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
public static AudienceRect Measure(long handle, string hex, double aspect) {
|
|
185
|
+
using (var image = Capture(handle)) {
|
|
186
|
+
var color = ColorTranslator.FromHtml(hex);
|
|
187
|
+
int middleX = image.Width / 2, middleY = image.Height / 2;
|
|
188
|
+
if (!Matches(image.GetPixel(middleX, middleY), color)) throw new InvalidOperationException("The marker has not painted in the audience window.");
|
|
189
|
+
int left = middleX, right = middleX, top = middleY, bottom = middleY;
|
|
190
|
+
while (left > 0 && Matches(image.GetPixel(left - 1, middleY), color)) left--;
|
|
191
|
+
while (right + 1 < image.Width && Matches(image.GetPixel(right + 1, middleY), color)) right++;
|
|
192
|
+
while (top > 0 && Matches(image.GetPixel(middleX, top - 1), color)) top--;
|
|
193
|
+
while (bottom + 1 < image.Height && Matches(image.GetPixel(middleX, bottom + 1), color)) bottom++;
|
|
194
|
+
int width = right - left + 1, height = bottom - top + 1;
|
|
195
|
+
if (width < 320 || height < 180 || Math.Abs((double)width / height - aspect) > 2.0 / height) throw new InvalidOperationException("The measured audience rectangle does not preserve the deck aspect ratio.");
|
|
196
|
+
for (int y = top + 2; y < bottom; y += Math.Max(1, height / 12))
|
|
197
|
+
for (int x = left + 2; x < right; x += Math.Max(1, width / 12))
|
|
198
|
+
if (!Matches(image.GetPixel(x, y), color)) throw new InvalidOperationException("The audience marker is obscured or is not rectangular.");
|
|
199
|
+
return new AudienceRect { left = left, top = top, width = width, height = height, client_width = image.Width, client_height = image.Height, dpi = GetDpiForWindow(new IntPtr(handle)) };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
public static void EnsureGeometry(long handle, AudienceRect rectangle) {
|
|
204
|
+
Rect current;
|
|
205
|
+
var window = new IntPtr(handle);
|
|
206
|
+
if (!IsWindowVisible(window) || !GetClientRect(window, out current) || current.Right != rectangle.client_width || current.Bottom != rectangle.client_height || GetDpiForWindow(window) != rectangle.dpi) throw new InvalidOperationException("The native audience window geometry changed during playback.");
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public static ContentRect OutputContent(AudienceRect rectangle, int width, int height) {
|
|
210
|
+
if (width <= 0 || height <= 0 || rectangle.width <= 0 || rectangle.height <= 0) throw new InvalidOperationException("The native output content rectangle is degenerate.");
|
|
211
|
+
double scale = Math.Min((double)width / rectangle.width, (double)height / rectangle.height);
|
|
212
|
+
int scaledWidth = Math.Min(width, (int)Math.Round(rectangle.width * scale, MidpointRounding.AwayFromZero));
|
|
213
|
+
int scaledHeight = Math.Min(height, (int)Math.Round(rectangle.height * scale, MidpointRounding.AwayFromZero));
|
|
214
|
+
return new ContentRect { x = (width - scaledWidth) / 2, y = (height - scaledHeight) / 2, width = scaledWidth, height = scaledHeight };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public static bool ColorPresent(long handle, AudienceRect rectangle, string hex) {
|
|
218
|
+
EnsureGeometry(handle, rectangle);
|
|
219
|
+
var color = ColorTranslator.FromHtml(hex);
|
|
220
|
+
using (var image = Capture(handle)) {
|
|
221
|
+
foreach (double y in new double[] { 0.02, 0.5, 0.98 }) {
|
|
222
|
+
foreach (double x in new double[] { 0.02, 0.5, 0.98 }) {
|
|
223
|
+
if (!Matches(image.GetPixel(rectangle.left + (int)(rectangle.width * x), rectangle.top + (int)(rectangle.height * y)), color)) return false;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
public static void Save(long handle, AudienceRect rectangle, string file, int width, int height) {
|
|
231
|
+
EnsureGeometry(handle, rectangle);
|
|
232
|
+
using (var image = Capture(handle))
|
|
233
|
+
using (var crop = image.Clone(new Rectangle(rectangle.left, rectangle.top, rectangle.width, rectangle.height), PixelFormat.Format24bppRgb))
|
|
234
|
+
using (var output = new Bitmap(width, height)) {
|
|
235
|
+
using (var graphics = Graphics.FromImage(output)) {
|
|
236
|
+
graphics.Clear(Color.Black);
|
|
237
|
+
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
238
|
+
double scale = Math.Min((double)width / crop.Width, (double)height / crop.Height);
|
|
239
|
+
int scaledWidth = (int)Math.Round(crop.Width * scale), scaledHeight = (int)Math.Round(crop.Height * scale);
|
|
240
|
+
graphics.DrawImage(crop, new Rectangle((width - scaledWidth) / 2, (height - scaledHeight) / 2, scaledWidth, scaledHeight));
|
|
241
|
+
}
|
|
242
|
+
output.Save(file, ImageFormat.Png);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
public static void SaveWindow(long handle, string file) {
|
|
247
|
+
using (var image = Capture(handle)) image.Save(file, ImageFormat.Png);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
public static void SaveDesktopWindow(long handle, string file) {
|
|
251
|
+
using (var image = Capture(handle, true)) image.Save(file, ImageFormat.Png);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
public static string Readback(long handle, AudienceRect rectangle) {
|
|
255
|
+
EnsureGeometry(handle, rectangle);
|
|
256
|
+
DwmFlush();
|
|
257
|
+
using (var image = Capture(handle)) {
|
|
258
|
+
var data = image.LockBits(new Rectangle(rectangle.left, rectangle.top, rectangle.width, rectangle.height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
|
|
259
|
+
try {
|
|
260
|
+
var pixels = new byte[rectangle.width * rectangle.height * 3];
|
|
261
|
+
for (int row = 0; row < rectangle.height; row++) Marshal.Copy(IntPtr.Add(data.Scan0, row * data.Stride), pixels, row * rectangle.width * 3, rectangle.width * 3);
|
|
262
|
+
using (var sha = SHA256.Create()) return BitConverter.ToString(sha.ComputeHash(pixels)).Replace("-", "").ToLowerInvariant();
|
|
263
|
+
} finally { image.UnlockBits(data); }
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
public static void StopRecorder(int process, long startTicks, string processName) {
|
|
268
|
+
try {
|
|
269
|
+
using (var recorder = Process.GetProcessById(process)) {
|
|
270
|
+
if (recorder.StartTime.ToUniversalTime().Ticks != startTicks || !recorder.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase)) throw new InvalidOperationException("Recorder identity changed. The process was preserved.");
|
|
271
|
+
recorder.Kill();
|
|
272
|
+
recorder.WaitForExit(5000);
|
|
273
|
+
}
|
|
274
|
+
} catch (ArgumentException) { }
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|