This repository has been archived by the owner on Jul 8, 2022. It is now read-only.
/
RGBATest.kt
103 lines (86 loc) · 4.2 KB
/
RGBATest.kt
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
package com.soywiz.korim.color
import org.junit.Test
import kotlin.test.assertEquals
class RGBATest {
@Test
fun premultiply() {
assertEquals("#7f7f7f7f", RGBA.toHexString(RGBA.premultiply(RGBA.packFast(0xFF, 0xFF, 0xFF, 0x7F))))
assertEquals("#7f7f7f7f", RGBA.toHexString(RGBA.premultiplyFast(RGBA.packFast(0xFF, 0xFF, 0xFF, 0x7F))))
assertEquals("#ffffffff", RGBA.toHexString(RGBA.premultiplyFast(RGBA.packFast(0xFF, 0xFF, 0xFF, 0xFF))))
assertEquals("#0000007f", RGBA.toHexString(RGBA.premultiplyFast(RGBA.packFast(0x00, 0x00, 0x00, 0x7F))))
assertEquals("#3f3f3f7f", RGBA.toHexString(RGBA.premultiplyFast(RGBA.packFast(0x7F, 0x7F, 0x7F, 0x7F))))
assertEquals("#001f3f7f", RGBA.toHexString(RGBA.premultiplyFast(RGBA.packFast(0x00, 0x3F, 0x7F, 0x7F))))
}
@Test
fun depremultiply() {
assertEquals("#007fffff", RGBA.toHexString(RGBA.depremultiplyAccurate(Colors["#007fffff"])))
assertEquals("#007fffff", RGBA.toHexString(RGBA.depremultiplyFast(Colors["#007fffff"])))
assertEquals("#007fffff", RGBA.toHexString(RGBA.depremultiplyFaster(Colors["#007fffff"])))
assertEquals("#007fffff", RGBA.toHexString(RGBA.depremultiplyFastest(Colors["#007fffff"])))
assertEquals("#2666ff7f", RGBA.toHexString(RGBA.depremultiplyAccurate(Colors["#13337f7f"])))
assertEquals("#2666ff7f", RGBA.toHexString(RGBA.depremultiplyFast(Colors["#13337f7f"])))
assertEquals("#2666fe7f", RGBA.toHexString(RGBA.depremultiplyFaster(Colors["#13337f7f"])))
assertEquals("#2066fe7f", RGBA.toHexString(RGBA.depremultiplyFastest(Colors["#13337f7f"])))
assertEquals("#00ffff7f", RGBA.toHexString(RGBA.depremultiplyAccurate(Colors["#007fff7f"])))
assertEquals("#00ffff7f", RGBA.toHexString(RGBA.depremultiplyFast(Colors["#007fff7f"])))
assertEquals("#00fefe7f", RGBA.toHexString(RGBA.depremultiplyFaster(Colors["#007fff7f"])))
assertEquals("#00fefe7f", RGBA.toHexString(RGBA.depremultiplyFastest(Colors["#007fff7f"])))
assertEquals("#00ffff3f", RGBA.toHexString(RGBA.depremultiplyAccurate(Colors["#007fff3f"])))
assertEquals("#00ffff3f", RGBA.toHexString(RGBA.depremultiplyFast(Colors["#007fff3f"])))
assertEquals("#00fcfc3f", RGBA.toHexString(RGBA.depremultiplyFaster(Colors["#007fff3f"])))
assertEquals("#00fcfc3f", RGBA.toHexString(RGBA.depremultiplyFastest(Colors["#007fff3f"])))
assertEquals("#00000000", RGBA.toHexString(RGBA.depremultiplyAccurate(Colors["#007fff00"])))
assertEquals("#00000000", RGBA.toHexString(RGBA.depremultiplyFast(Colors["#007fff00"])))
assertEquals("#00000000", RGBA.toHexString(RGBA.depremultiplyFaster(Colors["#007fff00"])))
assertEquals("#00000000", RGBA.toHexString(RGBA.depremultiplyFastest(Colors["#007fff00"])))
}
@Test
fun name2() {
assertEquals("#123456ff", RGBA.toHexString(Colors["#123456"]))
assertEquals("#12345678", RGBA.toHexString(Colors["#12345678"]))
assertEquals("#000000ff", RGBA.toHexString(Colors["#000"]))
assertEquals("#777777ff", RGBA.toHexString(Colors["#777"]))
assertEquals("#ffffffff", RGBA.toHexString(Colors["#FFF"]))
assertEquals("#00000000", RGBA.toHexString(Colors["#0000"]))
assertEquals("#77777700", RGBA.toHexString(Colors["#7770"]))
assertEquals("#ffffff00", RGBA.toHexString(Colors["#FFF0"]))
}
val colors = intArrayOf(RGBA.pack(0xFF, 0xFF, 0xFF, 0x7F), RGBA.pack(0x7F, 0x6F, 0x33, 0x90))
//@Test
////@Ignore
//fun benchmarkPremultiplyAccurate() {
// var m = 0
// for (n in 0 until 8192 * 8192) m += RGBA.premultiplyAccurate(colors[n and 1])
//}
//@Test
////@Ignore
//fun benchmarkPremultiplyFast() {
// var m = 0
// for (n in 0 until 8192 * 8192) m += RGBA.premultiplyFast(colors[n and 1])
//}
//@Test
////@Ignore
//fun benchmarkDepremultiplyAccurate() {
// var m = 0
// for (n in 0 until 8192 * 8192) m += RGBA.depremultiplyAccurate(colors[n and 1])
//}
//@Test
////@Ignore
//fun benchmarkDepremultiplyFast() {
// var m = 0
// for (n in 0 until 8192 * 8192) m += RGBA.depremultiplyFast(colors[n and 1])
//}
//@Test
////@Ignore
//fun benchmarkDepremultiplyFastest() {
// var m = 0
// for (n in 0 until 8192 * 8192) m += RGBA.depremultiplyFastest(colors[n and 1])
//}
//@Test
////@Ignore
//fun benchmark3() {
// var m = 0
// val c = RGBA.pack(0xFF, 0xFF, 0xFF, 0x7F)
// for (n in 0 until 10000000000) m += RGBA.premultiplyFast2(c)
//}
}