Add [Upload]Texture2D<T>.Save overload for Stream
このコミットが含まれているのは:
1 親
989ac8aeef
コミット
5d5dc541bc
6ファイル変更
+322
-67
検索条件に一致するファイルはありません
@@ -27,7 +27,7 @@ public class ImagingTests
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(typeof(string))]
|
||||
[Data(typeof(ReadOnlySpan<char>))]
|
||||
public void LoadAsRgba32FromFile(Device device, Type textureType, Type inputType)
|
||||
public void LoadAsRgba32_FromFile(Device device, Type textureType, Type inputType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
|
||||
@@ -43,61 +43,7 @@ public class ImagingTests
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(typeof(string))]
|
||||
[Data(typeof(ReadOnlySpan<char>))]
|
||||
public void LoadAsBgra32FromFile(Device device, Type textureType, Type inputType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(typeof(string))]
|
||||
[Data(typeof(ReadOnlySpan<char>))]
|
||||
public void LoadAsBgra32FromFileWithSameFormat(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);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(typeof(string))]
|
||||
[Data(typeof(ReadOnlySpan<char>))]
|
||||
public void LoadAsR8FromFile(Device device, Type textureType, Type inputType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
|
||||
using Texture2D<R8> texture = device.Get().LoadTexture2D<R8, float>(textureType, inputType, path);
|
||||
|
||||
using Image<ImageSharpL8> loaded = texture.ToImage<R8, ImageSharpL8>();
|
||||
using Image<ImageSharpL8> original = Image.Load<ImageSharpL8>(path);
|
||||
|
||||
TolerantImageComparer.AssertEqual(original, loaded, 0.000039f);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
public void LoadAsRgba32FromBuffer(Device device, Type textureType)
|
||||
public void LoadAsRgba32_FromBuffer(Device device, Type textureType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
|
||||
@@ -115,7 +61,7 @@ public class ImagingTests
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
public void LoadAsRgba32FromStream(Device device, Type textureType)
|
||||
public void LoadAsRgba32_FromStream(Device device, Type textureType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
|
||||
@@ -129,6 +75,114 @@ public class ImagingTests
|
||||
TolerantImageComparer.AssertEqual(original, loaded, 0.0000032f);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(typeof(string))]
|
||||
[Data(typeof(ReadOnlySpan<char>))]
|
||||
public void LoadAsBgra32_FromFile(Device device, Type textureType, Type inputType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
public void LoadAsBgra32_FromStream(Device device, Type textureType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
|
||||
using Stream stream = File.OpenRead(path);
|
||||
|
||||
using Texture2D<Bgra32> texture = device.Get().LoadTexture2D<Bgra32, float4>(textureType, stream);
|
||||
|
||||
using Image<ImageSharpBgra32> loaded = texture.ToImage<Bgra32, ImageSharpBgra32>();
|
||||
using Image<ImageSharpBgra32> original = Image.Load<ImageSharpBgra32>(path);
|
||||
|
||||
TolerantImageComparer.AssertEqual(original, loaded, 0.00000132f);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(typeof(string))]
|
||||
[Data(typeof(ReadOnlySpan<char>))]
|
||||
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);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
public void LoadAsBgra32_FromStream_WithSameFormat(Device device, Type textureType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Assets", "CityAfter1024x1024Sampling.png");
|
||||
|
||||
using Stream stream = File.OpenRead(path);
|
||||
|
||||
using Texture2D<Bgra32> texture = device.Get().LoadTexture2D<Bgra32, float4>(textureType, stream);
|
||||
|
||||
using Image<ImageSharpBgra32> loaded = texture.ToImage<Bgra32, ImageSharpBgra32>();
|
||||
using Image<ImageSharpBgra32> original = Image.Load<ImageSharpBgra32>(path);
|
||||
|
||||
TolerantImageComparer.AssertEqual(original, loaded, 0.00000132f);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(typeof(string))]
|
||||
[Data(typeof(ReadOnlySpan<char>))]
|
||||
public void LoadAsR8_FromFile(Device device, Type textureType, Type inputType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
|
||||
using Texture2D<R8> texture = device.Get().LoadTexture2D<R8, float>(textureType, inputType, path);
|
||||
|
||||
using Image<ImageSharpL8> loaded = texture.ToImage<R8, ImageSharpL8>();
|
||||
using Image<ImageSharpL8> original = Image.Load<ImageSharpL8>(path);
|
||||
|
||||
TolerantImageComparer.AssertEqual(original, loaded, 0.000039f);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
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);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[Device(Device.Warp)]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
@@ -155,7 +209,7 @@ public class ImagingTests
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(typeof(string))]
|
||||
[Data(typeof(ReadOnlySpan<char>))]
|
||||
public void SaveRgba32AsJpeg(Device device, Type textureType, Type inputType)
|
||||
public void SaveRgba32AsJpeg_ToFile(Device device, Type textureType, Type inputType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
|
||||
string expectedPath = Path.Combine(path, "city.jpg");
|
||||
@@ -168,13 +222,33 @@ public class ImagingTests
|
||||
TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.00001023f);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
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);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(typeof(string))]
|
||||
[Data(typeof(ReadOnlySpan<char>))]
|
||||
public void SaveRgba32AsJpeg_WithReadBackTexture(Device device, Type textureType, Type inputType)
|
||||
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");
|
||||
@@ -190,12 +264,35 @@ public class ImagingTests
|
||||
TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.00001023f);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
public void SaveRgba32AsJpeg_ToStream_WithReadBackTexture(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 ReadBackTexture2D<Rgba32> readback = device.Get().AllocateReadBackTexture2D<Rgba32>(texture.Width, texture.Height);
|
||||
|
||||
texture.CopyTo(readback);
|
||||
|
||||
using (Stream stream = File.OpenWrite(actualPath))
|
||||
{
|
||||
readback.Save(stream, ImageFormat.Jpeg);
|
||||
}
|
||||
|
||||
TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.00001023f);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[Device(Device.Warp)]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void SaveRgba32AsJpeg_WithReadBackTexture_WithNullPath(Device device, Type textureType)
|
||||
public void SaveRgba32AsJpeg_ToFile_WithReadBackTexture_WithNullPath(Device device, Type textureType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
|
||||
@@ -207,13 +304,30 @@ public class ImagingTests
|
||||
readback.Save(typeof(string), null!);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[Device(Device.Warp)]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void SaveRgba32AsJpeg_ToStream_WithReadBackTexture_WithNullStream(Device device, Type textureType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
|
||||
using Texture2D<Rgba32> texture = device.Get().LoadTexture2D<Rgba32, float4>(textureType, typeof(string), path);
|
||||
using ReadBackTexture2D<Rgba32> readback = device.Get().AllocateReadBackTexture2D<Rgba32>(texture.Width, texture.Height);
|
||||
|
||||
texture.CopyTo(readback);
|
||||
|
||||
readback.Save(null!, ImageFormat.Jpeg);
|
||||
}
|
||||
|
||||
[CombinatorialTestMethod]
|
||||
[AllDevices]
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(typeof(string))]
|
||||
[Data(typeof(ReadOnlySpan<char>))]
|
||||
public void SaveBgra32AsJpeg(Device device, Type textureType, Type inputType)
|
||||
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");
|
||||
@@ -232,7 +346,7 @@ public class ImagingTests
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[Data(typeof(string))]
|
||||
[Data(typeof(ReadOnlySpan<char>))]
|
||||
public void SaveR8AsJpeg(Device device, Type textureType, Type inputType)
|
||||
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");
|
||||
@@ -255,7 +369,7 @@ public class ImagingTests
|
||||
[Resource(typeof(ReadOnlyTexture2D<,>))]
|
||||
[Resource(typeof(ReadWriteTexture2D<,>))]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void SaveRgba32AsJpeg_WithNullPath(Device device, Type textureType)
|
||||
public void SaveRgba32AsJpeg_ToFile_WithNullPath(Device device, Type textureType)
|
||||
{
|
||||
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg");
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする