Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBeekman committed May 13, 2023
2 parents 2a58837 + faa2143 commit 5a36bc3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 35 deletions.
6 changes: 3 additions & 3 deletions src/Artemis.Core/Artemis.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
<PackageReference Include="LiteDB" Version="5.0.16" />
<PackageReference Include="McMaster.NETCore.Plugins" Version="1.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="RGB.NET.Core" Version="2.0.0-prerelease.45" />
<PackageReference Include="RGB.NET.Layout" Version="2.0.0-prerelease.45" />
<PackageReference Include="RGB.NET.Presets" Version="2.0.0-prerelease.45" />
<PackageReference Include="RGB.NET.Core" Version="2.0.0-prerelease.53" />
<PackageReference Include="RGB.NET.Layout" Version="2.0.0-prerelease.53" />
<PackageReference Include="RGB.NET.Presets" Version="2.0.0-prerelease.53" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="2.0.0" />
Expand Down
36 changes: 7 additions & 29 deletions src/Artemis.Core/RGB.NET/SKTexture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Artemis.Core.SkiaSharp;
using RGB.NET.Core;
Expand Down Expand Up @@ -56,31 +56,12 @@ internal Color GetColorAtRenderTarget(in RenderTarget renderTarget)
if (skRectI.Width <= 0 || skRectI.Height <= 0)
return Color.Transparent;

int bufferSize = skRectI.Width * skRectI.Height * DATA_PER_PIXEL;
if (bufferSize <= STACK_ALLOC_LIMIT)
{
Span<byte> buffer = stackalloc byte[bufferSize];
GetRegionData(skRectI.Left, skRectI.Top, skRectI.Width, skRectI.Height, buffer);

Span<byte> pixelData = stackalloc byte[DATA_PER_PIXEL];
Sampler.Sample(new SamplerInfo<byte>(skRectI.Width, skRectI.Height, buffer), pixelData);

return GetColor(pixelData);
}
else
{
byte[] rent = ArrayPool<byte>.Shared.Rent(bufferSize);
SamplerInfo<byte> samplerInfo = new(skRectI.Left, skRectI.Top, skRectI.Width, skRectI.Height, Stride, DataPerPixel, Data);

Span<byte> buffer = new Span<byte>(rent).Slice(0, bufferSize);
GetRegionData(skRectI.Left, skRectI.Top, skRectI.Width, skRectI.Height, buffer);
Span<byte> pixelData = stackalloc byte[DATA_PER_PIXEL];
Sampler.Sample(samplerInfo, pixelData);

Span<byte> pixelData = stackalloc byte[DATA_PER_PIXEL];
Sampler.Sample(new SamplerInfo<byte>(skRectI.Width, skRectI.Height, buffer), pixelData);

ArrayPool<byte>.Shared.Return(rent);

return GetColor(pixelData);
}
return GetColor(pixelData);
}

private void ReleaseUnmanagedResources()
Expand All @@ -106,7 +87,6 @@ public void Dispose()

#region Constants

private const int STACK_ALLOC_LIMIT = 1024;
private const int DATA_PER_PIXEL = 4;

#endregion
Expand All @@ -128,10 +108,8 @@ internal void CopyPixelData()
}

/// <inheritdoc />
protected override Color GetColor(in ReadOnlySpan<byte> pixel)
{
return new Color(pixel[2], pixel[1], pixel[0]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override Color GetColor(in ReadOnlySpan<byte> pixel) => new(pixel[2], pixel[1], pixel[0]);

/// <inheritdoc />
public override Color this[in Rectangle rectangle] => Color.Transparent;
Expand Down
2 changes: 1 addition & 1 deletion src/Artemis.UI.Shared/Artemis.UI.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="Material.Icons.Avalonia" Version="2.0.0-preview3" />
<PackageReference Include="ReactiveUI" Version="18.4.26" />
<PackageReference Include="ReactiveUI.Validation" Version="3.1.7" />
<PackageReference Include="RGB.NET.Core" Version="2.0.0-prerelease.45" />
<PackageReference Include="RGB.NET.Core" Version="2.0.0-prerelease.53" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Artemis.UI/Artemis.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<PackageReference Include="Octopus.Octodiff" Version="2.0.261" />
<PackageReference Include="ReactiveUI" Version="18.4.26" />
<PackageReference Include="ReactiveUI.Validation" Version="3.1.7" />
<PackageReference Include="RGB.NET.Core" Version="2.0.0-prerelease.45" />
<PackageReference Include="RGB.NET.Layout" Version="2.0.0-prerelease.45" />
<PackageReference Include="RGB.NET.Core" Version="2.0.0-prerelease.53" />
<PackageReference Include="RGB.NET.Layout" Version="2.0.0-prerelease.53" />
<PackageReference Include="SkiaSharp" Version="2.88.3" />
<PackageReference Include="Splat.DryIoc" Version="14.6.8" />
</ItemGroup>
Expand Down

0 comments on commit 5a36bc3

Please sign in to comment.