示例#1
0
    public void LoadAsRgba32_FromFile(Device device, Type textureType, Type inputType)
    {
        string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "Imaging", "city.jpg");

        using Texture2D <Rgba32> texture = device.Get().LoadTexture2D <Rgba32, float4>(textureType, inputType, path);

        using Image <ImageSharpRgba32> loaded   = texture.ToImage <Rgba32, ImageSharpRgba32>();
        using Image <ImageSharpRgba32> original = Image.Load <ImageSharpRgba32>(path);

        TolerantImageComparer.AssertEqual(original, loaded, 0.0000032f);
    }
示例#2
0
    public void LoadAsBgra32_FromFile_WithSameFormat(Device device, Type textureType, Type inputType)
    {
        string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "Assets", "CityAfter1024x1024Sampling.png");

        using Texture2D <Bgra32> texture = device.Get().LoadTexture2D <Bgra32, float4>(textureType, inputType, path);

        using Image <ImageSharpBgra32> loaded   = texture.ToImage <Bgra32, ImageSharpBgra32>();
        using Image <ImageSharpBgra32> original = Image.Load <ImageSharpBgra32>(path);

        TolerantImageComparer.AssertEqual(original, loaded, 0.00000132f);
    }
示例#3
0
    public void SaveBgra32AsJpeg_ToFile(Device device, Type textureType, Type inputType)
    {
        string path         = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "Imaging");
        string expectedPath = Path.Combine(path, "city.jpg");
        string actualPath   = Path.Combine(path, "city_bgra32_saved.jpg");

        using Texture2D <Bgra32> texture = device.Get().LoadTexture2D <Bgra32, float4>(textureType, inputType, expectedPath);

        texture.Save(inputType, actualPath);

        TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.00001023f);
    }
示例#4
0
    public void LoadAsR8_FromFile(Device device, Type textureType)
    {
        string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "Imaging", "city.jpg");

        using Stream stream = File.OpenRead(path);

        using Texture2D <R8> texture = device.Get().LoadTexture2D <R8, float>(textureType, stream);

        using Image <ImageSharpL8> loaded   = texture.ToImage <R8, ImageSharpL8>();
        using Image <ImageSharpL8> original = Image.Load <ImageSharpL8>(path);

        TolerantImageComparer.AssertEqual(original, loaded, 0.000039f);
    }
示例#5
0
    public void SaveRgba32AsJpeg_ToFile_WithReadBackTexture(Device device, Type textureType, Type inputType)
    {
        string path         = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "Imaging");
        string expectedPath = Path.Combine(path, "city.jpg");
        string actualPath   = Path.Combine(path, "city_rgba32_saved.jpg");

        using Texture2D <Rgba32> texture          = device.Get().LoadTexture2D <Rgba32, float4>(textureType, inputType, expectedPath);
        using ReadBackTexture2D <Rgba32> readback = device.Get().AllocateReadBackTexture2D <Rgba32>(texture.Width, texture.Height);

        texture.CopyTo(readback);

        readback.Save(inputType, actualPath);

        TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.00001023f);
    }
示例#6
0
    public void SaveRgba32AsJpeg_ToStream(Device device, Type textureType)
    {
        string path         = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "Imaging");
        string expectedPath = Path.Combine(path, "city.jpg");
        string actualPath   = Path.Combine(path, "city_rgba32_saved.jpg");

        using Texture2D <Rgba32> texture = device.Get().LoadTexture2D <Rgba32, float4>(textureType, typeof(string), expectedPath);

        using (Stream stream = File.OpenWrite(actualPath))
        {
            texture.Save(stream, ImageFormat.Jpeg);
        }

        TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.00001023f);
    }
示例#7
0
    public void LoadAsRgba32_FromFile_WithUploadTexture(Device device, Type textureType, Type inputType)
    {
        string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "Imaging", "city.jpg");

        IImageInfo imageInfo = Image.Identify(path);

        using Texture2D <Rgba32> texture      = device.Get().AllocateTexture2D <Rgba32>(textureType, imageInfo.Width, imageInfo.Height);
        using UploadTexture2D <Rgba32> upload = device.Get().AllocateUploadTexture2D <Rgba32>(imageInfo.Width, imageInfo.Height);

        upload.Load(inputType, path);
        upload.CopyTo(texture);

        using Image <ImageSharpRgba32> loaded   = texture.ToImage <Rgba32, ImageSharpRgba32>();
        using Image <ImageSharpRgba32> original = Image.Load <ImageSharpRgba32>(path);

        TolerantImageComparer.AssertEqual(original, loaded, 0.0000032f);
    }
示例#8
0
    public void SaveR8AsJpeg_ToFile(Device device, Type textureType, Type inputType)
    {
        string path         = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "Imaging");
        string sourcePath   = Path.Combine(path, "city.jpg");
        string expectedPath = Path.Combine(path, "city_r8_reference.jpg");
        string actualPath   = Path.Combine(path, "city_r8_saved.jpg");

        using Texture2D <R8> texture = device.Get().LoadTexture2D <R8, float>(textureType, inputType, sourcePath);

        texture.Save(inputType, actualPath);

        using Image <ImageSharpL8> original = Image.Load <ImageSharpL8>(sourcePath);

        original.Save(expectedPath);

        TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.00004037f);
    }
示例#9
0
    public void SaveRgba32AsJpeg_ToBufferWriter(Device device, Type textureType)
    {
        string path         = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "Imaging");
        string expectedPath = Path.Combine(path, "city.jpg");
        string actualPath   = Path.Combine(path, "city_rgba32_saved.jpg");

        using Texture2D <Rgba32> texture = device.Get().LoadTexture2D <Rgba32, float4>(textureType, typeof(string), expectedPath);

        using (ArrayPoolBufferWriter <byte> writer = new())
        {
            texture.Save(writer, ImageFormat.Jpeg);

            File.WriteAllBytes(actualPath, writer.WrittenSpan.ToArray());
        }

        TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.00001023f);
    }
示例#10
0
        public void GaussianBlur(Device device)
        {
            _ = device.Get();

            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "Imaging");

            using var original = Image.Load <ImageSharpRgba32>(Path.Combine(path, "city.jpg"));
            using var cpu      = original.Clone(c => c.GaussianBlur(30f));
            using var gpu      = original.Clone(c => c.ApplyProcessor(new HlslGaussianBlurProcessor(device.Get(), 90)));

            string
                expectedPath = Path.Combine(path, "city_gaussian_cpu.jpg"),
                actualPath   = Path.Combine(path, "city_gaussian_gpu.jpg");

            cpu.Save(expectedPath);
            gpu.Save(actualPath);

            TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.000003f);
        }
示例#11
0
        public void BokehBlur(Device device)
        {
            // Early test to ensure the device is available. This saves time when running the
            // unit test if the target device is not available, as we skip the preprocessing.
            _ = device.Get();

            string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) !, "Imaging");

            using var original = Image.Load <ImageSharpRgba32>(Path.Combine(path, "city.jpg"));
            using var cpu      = original.Clone(c => c.BokehBlur(80, 2, 3));
            using var gpu      = original.Clone(c => c.ApplyProcessor(new HlslBokehBlurProcessor(device.Get(), 80, 2)));

            string
                expectedPath = Path.Combine(path, "city_bokeh_cpu.jpg"),
                actualPath   = Path.Combine(path, "city_bokeh_gpu.jpg");

            cpu.Save(expectedPath);
            gpu.Save(actualPath);

            TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.000009f);
        }