-
Notifications
You must be signed in to change notification settings - Fork 205
Expand file tree
/
Copy pathBitmapWithAlphaTests.cs
More file actions
117 lines (103 loc) · 3.75 KB
/
BitmapWithAlphaTests.cs
File metadata and controls
117 lines (103 loc) · 3.75 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Drawing.Imaging;
using System.Resources;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NumSharp.UnitTest.Utilities;
namespace NumSharp.UnitTest
{
[TestClass]
public class BitmapWithAlphaTests : TestClass
{
[ClassInitialize]
public static void RequireWindows(TestContext _)
{
if (!OperatingSystem.IsWindows())
Assert.Inconclusive("System.Drawing.Common requires Windows (GDI+).");
}
[TestMethod]
public void ToNDArray_Case1()
{
var bitmap = EmbeddedBitmap("captcha-a");
var nd = bitmap.ToNDArray(discardAlpha: true, copy: true);
nd.Should().BeShaped(1, 165, 400, 3);
}
[TestMethod]
public void ToNDArray_Case2()
{
var bitmap = EmbeddedBitmap("captcha-a");
var nd = bitmap.ToNDArray(discardAlpha: true, copy: false);
nd.Should().BeShaped(1, 165, 400, 3);
}
[TestMethod]
public void ToNDArray_Case3()
{
var bitmap = EmbeddedBitmap("captcha-a");
var nd = bitmap.ToNDArray(discardAlpha: false, copy: true);
nd.Should().BeShaped(1, 165, 400, 4);
}
[TestMethod]
public void ToNDArray_Case4()
{
var bitmap = EmbeddedBitmap("captcha-a");
var nd = bitmap.ToNDArray(discardAlpha: false, copy: false);
nd.Should().BeShaped(1, 165, 400, 4);
}
[TestMethod]
public void ToNDArray_Odd_Width()
{
var bitmap = EmbeddedBitmap("odd-width");
var nd = bitmap.ToNDArray(discardAlpha: false, copy: false);
nd.Should().BeShaped(1, 554, 475, 3);
}
[TestMethod]
public void ToBitmap_Odd_Width()
{
var bitmap = EmbeddedBitmap("odd-width");
var nd = bitmap.ToNDArray(discardAlpha: false, copy: false);
var bitmap2 = nd.ToBitmap();
bitmap2.Width.Should().Be(bitmap.Width);
bitmap2.Height.Should().Be(bitmap.Height);
}
[TestMethod]
public void ToNDArray_Case5_flat()
{
var bitmap = EmbeddedBitmap("captcha-a");
var nd = bitmap.ToNDArray(discardAlpha: true, copy: true, flat: true);
nd.Should().BeShaped(1 * 165 * 400 * 3);
}
[TestMethod]
public void ToNDArray_Case6_flat()
{
var bitmap = EmbeddedBitmap("captcha-a");
var nd = bitmap.ToNDArray(discardAlpha: true, copy: false, flat: true);
nd.Should().BeShaped(1 * 165 * 400 * 3);
}
[TestMethod]
public void ToNDArray_Case7_flat()
{
var bitmap = EmbeddedBitmap("captcha-a");
var nd = bitmap.ToNDArray(discardAlpha: false, copy: true, flat: true);
nd.Should().BeShaped(1 * 165 * 400 * 4);
}
[TestMethod]
public void ToNDArray_Case8_flat()
{
var bitmap = EmbeddedBitmap("captcha-a");
var nd = bitmap.ToNDArray(discardAlpha: false, copy: false, flat: true);
nd.Should().BeShaped(1 * 165 * 400 * 4);
}
[TestMethod]
public void ToBitmap_PixelFormat_DontCare_Case1()
{
var bm = np.arange(0, 3 * 3 * 3).reshape(1, 3, 3, 3).astype(NPTypeCode.Byte).ToBitmap();
bm.PixelFormat.Should().Be(PixelFormat.Format24bppRgb);
}
[TestMethod]
public void ToBitmap_PixelFormat_DontCare_Case2()
{
var bm = np.arange(0, 3 * 3 * 4).reshape(1, 3, 3, 4).astype(NPTypeCode.Byte).ToBitmap();
bm.PixelFormat.Should().Be(PixelFormat.Format32bppArgb);
}
}
}