48 lines
1.4 KiB
C#
48 lines
1.4 KiB
C#
using Dashboard.Drawing;
|
|
using Dashboard.Pal;
|
|
using ReFuel.Stb;
|
|
|
|
namespace Dashboard.StbImage
|
|
{
|
|
public class StbImageLoader : IImageLoader
|
|
{
|
|
public string DriverName { get; } = "Dashboard Stb Image Loader";
|
|
public string DriverVendor { get; } = "Dashboard";
|
|
public Version DriverVersion { get; } = new Version(1, 0);
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
IContextBase IContextExtensionBase.Context => Context;
|
|
|
|
public void Require(Application context)
|
|
{
|
|
Context = context;
|
|
}
|
|
|
|
public ImageData LoadImageData(Stream stream)
|
|
{
|
|
using ReFuel.Stb.StbImage image = ReFuel.Stb.StbImage.Load(stream, StbiImageFormat.Rgba);
|
|
ReadOnlySpan<byte> data = image.AsSpan<byte>();
|
|
return new ImageData(TextureType.Texture2D, image.Format switch
|
|
{
|
|
StbiImageFormat.GreyAlpha => PixelFormat.Rg8I,
|
|
StbiImageFormat.Rgb => PixelFormat.Rgb8I,
|
|
StbiImageFormat.Rgba => PixelFormat.Rgba8I,
|
|
_ => PixelFormat.R8I,
|
|
},
|
|
image.Width,
|
|
image.Height,
|
|
data.ToArray());
|
|
}
|
|
|
|
public Application Context { get; private set; } = null!;
|
|
|
|
void IContextExtensionBase.Require(IContextBase context)
|
|
{
|
|
Require((Application)context);
|
|
}
|
|
}
|
|
}
|