using Engine.Asset; using Engine.Renderer.Pixel; namespace Engine.Renderer.Texture; public interface IConstTexture where T : struct, IPixel { public int Width { get; } public int Height { get; } public void ReadPixels(int x, int y, int width, int height, T[,] pixels); } public static class ConstTextureExtensions { public static T[,] ReadPixels(this IConstTexture texture) where T : struct, IPixel => texture.ReadPixels(0, 0, texture.Width, texture.Height); public static T[,] ReadPixels(this IConstTexture texture, int x, int y, int width, int height) where T : struct, IPixel { var pixels = new T[width, height]; texture.ReadPixels(x, y, width, height, pixels); return pixels; } public static void ReadPixels(this IConstTexture texture, Image image) where T : struct, IPixel => texture.ReadPixels(0, 0, image); public static void ReadPixels(this IConstTexture texture, int x, int y, Image image) where T : struct, IPixel => texture.ReadPixels(x, y, image.Width, image.Height, image.Pixels); public static void ReadPixels(this IConstTexture texture, T[,] pixels) where T : struct, IPixel => texture.ReadPixels(0, 0, texture.Width, texture.Height, pixels); }