Skip to content

Commit

Permalink
⬆️ Upgrade to ImageSharp 3 (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomrijnbeek authored Mar 12, 2024
1 parent 3ff71f9 commit 881a614
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
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

0 comments on commit 881a614

Please sign in to comment.