Skip to content

Commit

Permalink
Merge pull request #548 from Xian55/refactor/system-drawing-mostly-re…
Browse files Browse the repository at this point in the history
…placed-by-imagesharp

Refactor: Using only `DirectX` and `ImageSharp` based bitmap processing over `GDI`
  • Loading branch information
Xian55 authored Nov 5, 2023
2 parents a6678d9 + 5f26613 commit 73929a7
Show file tree
Hide file tree
Showing 64 changed files with 737 additions and 1,487 deletions.
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

0 comments on commit 73929a7

Please sign in to comment.