mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-07-06 20:36:26 +02:00
Use SkiaSharp for Avalonia in place of ImageSharp (#6269)
* Rebased Transformation all at once Use SkiaSharp instead of ImageSharp * Apply suggestions from code review Co-authored-by: Ac_K <Acoustik666@gmail.com> * Change back unintentionally changed comment --------- Co-authored-by: Ac_K <Acoustik666@gmail.com> Co-authored-by: Emmanuel Hansen <emmausssss@gmail.com>
This commit is contained in:
parent
07435ad844
commit
595e514f18
7 changed files with 104 additions and 71 deletions
|
@ -40,20 +40,17 @@ using Ryujinx.UI.Common;
|
|||
using Ryujinx.UI.Common.Configuration;
|
||||
using Ryujinx.UI.Common.Helper;
|
||||
using Silk.NET.Vulkan;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Formats.Png;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using SkiaSharp;
|
||||
using SPB.Graphics.Vulkan;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using static Ryujinx.Ava.UI.Helpers.Win32NativeInterop;
|
||||
using AntiAliasing = Ryujinx.Common.Configuration.AntiAliasing;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
using InputManager = Ryujinx.Input.HLE.InputManager;
|
||||
using IRenderer = Ryujinx.Graphics.GAL.IRenderer;
|
||||
using Key = Ryujinx.Input.Key;
|
||||
|
@ -366,25 +363,33 @@ namespace Ryujinx.Ava
|
|||
return;
|
||||
}
|
||||
|
||||
Image image = e.IsBgra ? Image.LoadPixelData<Bgra32>(e.Data, e.Width, e.Height)
|
||||
: Image.LoadPixelData<Rgba32>(e.Data, e.Width, e.Height);
|
||||
var colorType = e.IsBgra ? SKColorType.Bgra8888 : SKColorType.Rgba8888;
|
||||
using var bitmap = new SKBitmap(new SKImageInfo(e.Width, e.Height, colorType, SKAlphaType.Premul));
|
||||
|
||||
if (e.FlipX)
|
||||
Marshal.Copy(e.Data, 0, bitmap.GetPixels(), e.Data.Length);
|
||||
|
||||
SKBitmap bitmapToSave = null;
|
||||
|
||||
if (e.FlipX || e.FlipY)
|
||||
{
|
||||
image.Mutate(x => x.Flip(FlipMode.Horizontal));
|
||||
bitmapToSave = new SKBitmap(bitmap.Width, bitmap.Height);
|
||||
|
||||
using var canvas = new SKCanvas(bitmapToSave);
|
||||
|
||||
canvas.Clear(SKColors.Transparent);
|
||||
|
||||
float scaleX = e.FlipX ? -1 : 1;
|
||||
float scaleY = e.FlipY ? -1 : 1;
|
||||
|
||||
var matrix = SKMatrix.CreateScale(scaleX, scaleY, bitmap.Width / 2f, bitmap.Height / 2f);
|
||||
|
||||
canvas.SetMatrix(matrix);
|
||||
|
||||
canvas.DrawBitmap(bitmap, new SKPoint(e.FlipX ? -bitmap.Width : 0, e.FlipY ? -bitmap.Height : 0));
|
||||
}
|
||||
|
||||
if (e.FlipY)
|
||||
{
|
||||
image.Mutate(x => x.Flip(FlipMode.Vertical));
|
||||
}
|
||||
|
||||
image.SaveAsPng(path, new PngEncoder
|
||||
{
|
||||
ColorType = PngColorType.Rgb,
|
||||
});
|
||||
|
||||
image.Dispose();
|
||||
SaveBitmapAsPng(bitmapToSave ?? bitmap, path);
|
||||
bitmapToSave?.Dispose();
|
||||
|
||||
Logger.Notice.Print(LogClass.Application, $"Screenshot saved to {path}", "Screenshot");
|
||||
}
|
||||
|
@ -396,6 +401,14 @@ namespace Ryujinx.Ava
|
|||
}
|
||||
}
|
||||
|
||||
private void SaveBitmapAsPng(SKBitmap bitmap, string path)
|
||||
{
|
||||
using var data = bitmap.Encode(SKEncodedImageFormat.Png, 100);
|
||||
using var stream = File.OpenWrite(path);
|
||||
|
||||
data.SaveTo(stream);
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (OperatingSystem.IsWindows())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue