From 38a360793aeea4a52c558b1ee574b1f9539766b2 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Fri, 30 Aug 2024 18:22:40 +0100 Subject: [PATCH] Faster GIF loading --- project/code/TMV/TextureLoader.Gif.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/project/code/TMV/TextureLoader.Gif.cs b/project/code/TMV/TextureLoader.Gif.cs index 46ddc29..85deeb8 100644 --- a/project/code/TMV/TextureLoader.Gif.cs +++ b/project/code/TMV/TextureLoader.Gif.cs @@ -14,16 +14,9 @@ public partial class TextureLoader var width = gifImage.Width; var height = gifImage.Height; - var image = Image.CreateEmpty(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)); - } - } - + var bytes = new byte[width * height * 4]; + gifImage.CopyPixelDataTo(bytes); + var image = Image.CreateFromData(width, height, false, Image.Format.Rgba8, bytes); return ImageTexture.CreateFromImage(image); } } \ No newline at end of file