forked from Nominom/BCnEncoder.NET
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEncodeByteOrderTests.cs
More file actions
75 lines (60 loc) · 1.73 KB
/
Copy pathEncodeByteOrderTests.cs
File metadata and controls
75 lines (60 loc) · 1.73 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
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using BCnEncoder.Decoder;
using BCnEncoder.Encoder;
using BCnEncoder.ImageSharp;
using BCnEncoder.Shared;
using BCnEncTests.Support;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
namespace BCnEncTests
{
public class EncodeByteOrderTests
{
private void EncodeByteOrderTest<T>(PixelFormat pixelFormat) where T : unmanaged, IPixel<T>
{
using var imageOrig = ImageLoader.LoadTestImageSharp("../../../testImages/test_alpha_1_512.png");
var testImage = imageOrig.CloneAs<T>();
var pixels = testImage.GetPixelMemoryGroup()[0];
var bytes = MemoryMarshal.AsBytes(pixels.Span);
var encoder = new BcEncoder(CompressionFormat.Bc3);
var decoder = new BcDecoder();
using var ms = new MemoryStream();
encoder.EncodeToStream(bytes, testImage.Width, testImage.Height, pixelFormat, ms);
ms.Position = 0;
var decoded = decoder.DecodeToImageRgba32(ms);
var hasNoAlpha = pixelFormat == PixelFormat.Rgb24 || pixelFormat == PixelFormat.Bgr24;
TestHelper.AssertImagesEqual(imageOrig, decoded, encoder.OutputOptions.Quality,
!hasNoAlpha);
}
[Fact]
public void EncodeByteOrderBgra()
{
EncodeByteOrderTest<Bgra32>(PixelFormat.Bgra32);
}
[Fact]
public void EncodeByteOrderBgr()
{
EncodeByteOrderTest<Bgr24>(PixelFormat.Bgr24);
}
[Fact]
public void EncodeByteOrderArgb()
{
EncodeByteOrderTest<Argb32>(PixelFormat.Argb32);
}
[Fact]
public void EncodeByteOrderRgba()
{
EncodeByteOrderTest<Rgba32>(PixelFormat.Rgba32);
}
[Fact]
public void EncodeByteOrderRgb24()
{
EncodeByteOrderTest<Rgb24>(PixelFormat.Rgb24);
}
}
}