Add .GIF image loading using ImageSharp
This commit is contained in:
parent
2c9958a64a
commit
66c324be53
|
@ -8,5 +8,6 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="rectpacksharp" Version="1.2.0" />
|
<PackageReference Include="rectpacksharp" Version="1.2.0" />
|
||||||
|
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -0,0 +1,29 @@
|
||||||
|
using Godot;
|
||||||
|
using SixLabors.ImageSharp.PixelFormats;
|
||||||
|
|
||||||
|
namespace KeepersCompound.TMV;
|
||||||
|
|
||||||
|
public partial class TextureLoader
|
||||||
|
{
|
||||||
|
// TODO: Replace this with my own implementation lol
|
||||||
|
// References:
|
||||||
|
// - https://www.w3.org/Graphics/GIF/spec-gif89a.txt
|
||||||
|
private static ImageTexture LoadGif(string path)
|
||||||
|
{
|
||||||
|
using var gifImage = SixLabors.ImageSharp.Image.Load<Rgba32>(path);
|
||||||
|
|
||||||
|
var width = gifImage.Width;
|
||||||
|
var height = gifImage.Height;
|
||||||
|
var image = Image.Create(width, height, false, Image.Format.Rgba8);
|
||||||
|
for (var y = 0; y < height; y++)
|
||||||
|
{
|
||||||
|
for (var x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
var pixel = gifImage[x, y].ToVector4();
|
||||||
|
image.SetPixel(x, y, new Color(pixel.X, pixel.Y, pixel.Z, pixel.W));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImageTexture.CreateFromImage(image);
|
||||||
|
}
|
||||||
|
}
|
|
@ -98,12 +98,13 @@ public partial class TextureLoader
|
||||||
return loaded;
|
return loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ImageTexture LoadTexture(string path)
|
public static ImageTexture LoadTexture(string path)
|
||||||
{
|
{
|
||||||
var ext = path.GetExtension().ToLower();
|
var ext = path.GetExtension().ToLower();
|
||||||
var texture = ext switch
|
var texture = ext switch
|
||||||
{
|
{
|
||||||
"pcx" => LoadPcx(path),
|
"pcx" => LoadPcx(path),
|
||||||
|
"gif" => LoadGif(path),
|
||||||
_ => ImageTexture.CreateFromImage(Image.LoadFromFile(path)),
|
_ => ImageTexture.CreateFromImage(Image.LoadFromFile(path)),
|
||||||
};
|
};
|
||||||
return texture;
|
return texture;
|
||||||
|
|
Loading…
Reference in New Issue