Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Using only DirectX and ImageSharp based bitmap processing over GDI #548

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BlazorServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void ConfigureServices(IServiceCollection services)
}
else
{
services.AddCoreConfiguration();
services.AddCoreConfiguration(log);
}

services.AddFrontend();
Expand Down
2 changes: 1 addition & 1 deletion BlazorServer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"Id": -1
},
"Reader": {
"Type": "GDI" // from Win7 'GDI' - from Win8 'DXGI' - from Win7 background 'GDIBlit'
"Type": "DXGI" // from Win7 'GDI' - from Win8 'DXGI' - from Win7 background 'GDIBlit'
},
"Diagnostics": {
"Enabled": false
Expand Down
103 changes: 0 additions & 103 deletions Core/AddonDataProvider/AddonDataProviderBitBlt.cs

This file was deleted.

13 changes: 0 additions & 13 deletions Core/AddonDataProvider/AddonDataProviderConfig.cs

This file was deleted.

74 changes: 0 additions & 74 deletions Core/AddonDataProvider/AddonDataProviderGDI.cs

This file was deleted.

97 changes: 0 additions & 97 deletions Core/AddonDataProvider/AddonDataProviderGDIConfig.cs

This file was deleted.

42 changes: 18 additions & 24 deletions Core/AddonDataProvider/IAddonDataProvider.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,36 @@
using System.Drawing.Imaging;
using System;
using System;

using static Core.AddonDataProviderConfig;
using System.Text;
using System.Runtime.CompilerServices;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp;

namespace Core;

public interface IAddonDataProvider : IDisposable
{
private static readonly Bgra32 firstColor = new(0, 0, 0, 255);
private static readonly Bgra32 lastlColor = new(30, 132, 129, 255);

void UpdateData();
void InitFrames(DataFrame[] frames) { }
void InitFrames(DataFrame[] frames);

int[] Data { get; }
StringBuilder TextBuilder { get; }

[SkipLocalsInit]
static unsafe void InternalUpdate(BitmapData bd,
static unsafe void InternalUpdate(Image<Bgra32> bd,
ReadOnlySpan<DataFrame> frames, Span<int> output)
{
int stride = bd.Stride;

ReadOnlySpan<byte> bitmapSpan =
new(bd.Scan0.ToPointer(), bd.Height * stride);
Bgra32 first = bd.DangerousGetPixelRowMemory(frames[0].Y)
.Span[frames[0].X];

ReadOnlySpan<byte> first =
bitmapSpan.Slice(frames[0].Y * stride + frames[0].X * BYTES_PER_PIXEL,
BYTES_PER_PIXEL);
Bgra32 last = bd.DangerousGetPixelRowMemory(frames[^1].Y)
.Span[frames[^1].X];

ReadOnlySpan<byte> last =
bitmapSpan.Slice(frames[^1].Y * stride + frames[^1].X * BYTES_PER_PIXEL,
BYTES_PER_PIXEL);

if (!first.SequenceEqual(fColor) ||
!last.SequenceEqual(lColor))
if (!first.Equals(firstColor) ||
!last.Equals(lastlColor))
{
return;
}
Expand All @@ -42,13 +39,10 @@ static unsafe void InternalUpdate(BitmapData bd,
{
DataFrame frame = frames[i];

int yOffset = frame.Y * stride;
int xOffset = frame.X * BYTES_PER_PIXEL;

ReadOnlySpan<byte> pixel =
bitmapSpan.Slice(yOffset + xOffset, BYTES_PER_PIXEL);
Span<Bgra32> row = bd.DangerousGetPixelRowMemory(frame.Y).Span;
ref Bgra32 pixel = ref row[frame.X];

output[frame.Index] = pixel[0] | (pixel[1] << 8) | (pixel[2] << 16);
output[frame.Index] = pixel.B | (pixel.G << 8) | (pixel.R << 16);
}
}

Expand Down
Loading