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

⬆️ Upgrade to ImageSharp 3 #75

Merged
merged 1 commit into from
Mar 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.3" />
</ItemGroup>

<ItemGroup>
Expand Down
20 changes: 13 additions & 7 deletions Bearded.Graphics.ImageSharp/ImageTextureData.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
using Bearded.Graphics.Textures;
using OpenTK.Graphics.OpenGL;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.PixelFormats;

namespace Bearded.Graphics.ImageSharp;

public sealed class ImageTextureData : ITextureData
{
private static readonly Configuration configuration;
private static readonly DecoderOptions decoderOptions;

static ImageTextureData()
{
configuration = Configuration.Default.Clone();
var configuration = Configuration.Default.Clone();
configuration.PreferContiguousImageBuffers = true;
decoderOptions = new DecoderOptions
{
Configuration = configuration
};
}

private readonly Image<Bgra32> image;
Expand All @@ -21,21 +26,22 @@ static ImageTextureData()

public int Height { get; }

public static ITextureData From(string path) => new ImageTextureData(Image.Load<Bgra32>(configuration, path));
public static ITextureData From(string path) => new ImageTextureData(Image.Load<Bgra32>(decoderOptions, path));

public static ITextureData From(Stream stream) => new ImageTextureData(Image.Load<Bgra32>(configuration, stream));
public static ITextureData From(Stream stream) => new ImageTextureData(Image.Load<Bgra32>(decoderOptions, stream));

public static ITextureData From(Image bitmap) => new ImageTextureData(bitmap.CloneAs<Bgra32>(configuration));
public static ITextureData From(Image bitmap) => new ImageTextureData(bitmap.CloneAs<Bgra32>(
decoderOptions.Configuration));

public static ITextureData From(string path, IEnumerable<ITextureTransformation> transformations)
{
using var image = Image.Load<Bgra32>(configuration, path);
using var image = Image.Load<Bgra32>(decoderOptions, path);
return From(image, transformations);
}

public static ITextureData From(Stream stream, IEnumerable<ITextureTransformation> transformations)
{
using var image = Image.Load<Bgra32>(configuration, stream);
using var image = Image.Load<Bgra32>(decoderOptions, stream);
return From(image, transformations);
}

Expand Down
Loading