-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
70 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
using CommunityToolkit.HighPerformance; | ||
using SightKeeper.Domain.Model; | ||
using SixLabors.ImageSharp.PixelFormats; | ||
|
||
namespace SightKeeper.Application; | ||
|
||
public interface ScreenCapture | ||
public interface ScreenCapture<TPixel> | ||
{ | ||
ReadOnlySpan2D<Bgra32> Capture(Vector2<ushort> resolution, Vector2<ushort> offset); | ||
ReadOnlySpan2D<TPixel> Capture(Vector2<ushort> resolution, Vector2<ushort> offset); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using CommunityToolkit.Diagnostics; | ||
using CommunityToolkit.HighPerformance; | ||
using HotKeys.ActionRunners; | ||
using HotKeys.Bindings; | ||
using SixLabors.ImageSharp; | ||
using SixLabors.ImageSharp.Advanced; | ||
using SixLabors.ImageSharp.PixelFormats; | ||
|
||
namespace SightKeeper.Application; | ||
|
||
public sealed class Screenshotter<TPixel> : Screenshotter | ||
where TPixel : unmanaged, IPixel<TPixel> | ||
{ | ||
public Screenshotter( | ||
ScreenCapture<TPixel> screenCapture, | ||
ScreenshotsDataAccess screenshotsDataAccess, | ||
ScreenBoundsProvider screenBoundsProvider, | ||
BindingsManager bindingsManager) | ||
: base(screenshotsDataAccess, screenBoundsProvider, bindingsManager) | ||
{ | ||
_screenCapture = screenCapture; | ||
} | ||
|
||
private readonly ScreenCapture<TPixel> _screenCapture; | ||
|
||
protected override void MakeScreenshots(ActionContext context) | ||
{ | ||
var contextEliminated = false; | ||
while (!contextEliminated && IsEnabled) | ||
{ | ||
Guard.IsNotNull(Library); | ||
var imageData = _screenCapture.Capture(Resolution, Offset); | ||
using var image = LoadImage(imageData); | ||
ScreenshotsDataAccess.CreateScreenshot(Library, image, DateTimeOffset.Now, Resolution); | ||
contextEliminated = context.WaitForElimination(Timeout); | ||
} | ||
} | ||
|
||
private static Image<TPixel> LoadImage(ReadOnlySpan2D<TPixel> imageData) | ||
{ | ||
if (imageData.TryGetSpan(out var span)) | ||
return Image.LoadPixelData(span, imageData.Width, imageData.Height); | ||
Image<TPixel> image = new(imageData.Width, imageData.Height); | ||
for (int i = 0; i < imageData.Height; i++) | ||
{ | ||
var source = imageData.GetRowSpan(i); | ||
var target = image.DangerousGetPixelRowMemory(i); | ||
source.CopyTo(target.Span); | ||
} | ||
return image; | ||
} | ||
} |