forked from Nominom/BCnEncoder.NET
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDecodingAsyncTests.cs
More file actions
63 lines (52 loc) · 1.61 KB
/
Copy pathDecodingAsyncTests.cs
File metadata and controls
63 lines (52 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.IO;
using System.Threading.Tasks;
using BCnEncoder.Decoder;
using BCnEncoder.Encoder;
using BCnEncoder.Shared;
using BCnEncTests.Support;
using CommunityToolkit.HighPerformance;
using Xunit;
namespace BCnEncTests
{
public class DecodingAsyncTests
{
[Fact]
public async Task DecodeAsync()
{
var decoder = new BcDecoder();
var encoder = new BcEncoder();
var original = ImageLoader.TestGradient1;
var file = encoder.EncodeToKtx(original);
var image = await decoder.Decode2DAsync(file);
TestHelper.AssertImagesEqual(original, image, encoder.OutputOptions.Quality);
}
[Fact]
public async Task DecodeAllMipMapsAsync()
{
var decoder = new BcDecoder();
var encoder = new BcEncoder();
var original = ImageLoader.TestGradient1;
var file = encoder.EncodeToKtx(original);
var images = await decoder.DecodeAllMipMaps2DAsync(file);
TestHelper.AssertImagesEqual(original, images[0], encoder.OutputOptions.Quality);
}
[Fact]
public async Task DecodeRawAsync()
{
var decoder = new BcDecoder();
var encoder = new BcEncoder();
var original = ImageLoader.TestGradient1;
var file = encoder.EncodeToKtx(original);
var rawBytes = file.MipMaps[0].Faces[0].Data;
var mipWidth = (int)file.MipMaps[0].Width;
var mipHeight = (int)file.MipMaps[0].Height;
var decoded = await Task.Run(() =>
{
var pixels = decoder.DecodeRaw(rawBytes, mipWidth, mipHeight, CompressionFormat.Bc1);
return new Memory2D<ColorRgba32>(pixels, mipHeight, mipWidth);
});
TestHelper.AssertImagesEqual(original, decoded, encoder.OutputOptions.Quality);
}
}
}