using SkiaSharp;

namespace NodePipeline.Application;

public static class ImageLoader
{
    public static ImageBuffer Load(string path)
    {
        using var bitmap = SKBitmap.Decode(path);
        var buffer = new ImageBuffer(bitmap.Width, bitmap.Height);
        var span = buffer.GetPixelSpan();
        var idx = 0;

        for (var y = 0; y < bitmap.Height; y++)
        for (var x = 0; x < bitmap.Width; x++)
        {
            var c = bitmap.GetPixel(x, y);
            span[idx++] = c.Red;
            span[idx++] = c.Green;
            span[idx++] = c.Blue;
            span[idx++] = c.Alpha;
        }

        return buffer;
    }
}