46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using Engine.Asset;
|
|
using Engine.Graphics.Pixel;
|
|
|
|
namespace Engine.Graphics.Texture;
|
|
|
|
public interface IConstTexture
|
|
{
|
|
public int Width { get; }
|
|
public int Height { get; }
|
|
|
|
public void ReadPixels<T>(int parX, int parY, int parWidth, int parHeight, T[,] parPixels)
|
|
where T : struct, IPixel;
|
|
}
|
|
|
|
public static class ConstTextureExtensions
|
|
{
|
|
public static T[,] ReadPixels<T>(this IConstTexture parTexture) where T : struct, IPixel
|
|
{
|
|
return parTexture.ReadPixels<T>(0, 0, parTexture.Width, parTexture.Height);
|
|
}
|
|
|
|
public static T[,] ReadPixels<T>(this IConstTexture parTexture, int parX, int parY, int parWidth, int parHeight)
|
|
where T : struct, IPixel
|
|
{
|
|
var pixels = new T[parWidth, parHeight];
|
|
parTexture.ReadPixels(parX, parY, parWidth, parHeight, pixels);
|
|
|
|
return pixels;
|
|
}
|
|
|
|
public static void ReadPixels<T>(this IConstTexture parTexture, Image<T> parImage) where T : struct, IPixel
|
|
{
|
|
parTexture.ReadPixels(0, 0, parImage);
|
|
}
|
|
|
|
public static void ReadPixels<T>(this IConstTexture parTexture, int parX, int parY, Image<T> parImage)
|
|
where T : struct, IPixel
|
|
{
|
|
parTexture.ReadPixels(parX, parY, parImage.Width, parImage.Height, parImage.Pixels);
|
|
}
|
|
|
|
public static void ReadPixels<T>(this IConstTexture parTexture, T[,] parPixels) where T : struct, IPixel
|
|
{
|
|
parTexture.ReadPixels(0, 0, parTexture.Width, parTexture.Height, parPixels);
|
|
}
|
|
} |