This repository was archived by the owner on Nov 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 560
Expand file tree
/
Copy pathBitmapTest.kt
More file actions
91 lines (79 loc) · 2.66 KB
/
BitmapTest.kt
File metadata and controls
91 lines (79 loc) · 2.66 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
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.graphics
import android.graphics.Bitmap
import android.graphics.ColorSpace
import android.support.test.filters.SdkSuppress
import org.junit.Assert.assertEquals
import org.junit.Test
class BitmapTest {
@Test fun create() {
val bitmap = createBitmap(7, 9)
assertEquals(7, bitmap.width)
assertEquals(9, bitmap.height)
assertEquals(Bitmap.Config.ARGB_8888, bitmap.config)
}
@Test fun createWithConfig() {
val bitmap = createBitmap(7, 9, config = Bitmap.Config.RGB_565)
assertEquals(Bitmap.Config.RGB_565, bitmap.config)
}
@SdkSuppress(minSdkVersion = 26)
@Test fun createWithColorSpace() {
val colorSpace = ColorSpace.get(ColorSpace.Named.ADOBE_RGB)
val bitmap = createBitmap(7, 9, colorSpace = colorSpace)
assertEquals(colorSpace, bitmap.colorSpace)
}
@Test fun scale() {
val b = createBitmap(7, 9).scale(3, 5)
assertEquals(3, b.width)
assertEquals(5, b.height)
}
@Test fun applyCanvas() {
val p = createBitmap(2, 2).applyCanvas {
drawColor(0x40302010)
}.getPixel(1, 1)
assertEquals(0x40302010, p)
}
@Test fun getPixel() {
val b = createBitmap(2, 2).applyCanvas {
drawColor(0x40302010)
}
assertEquals(0x40302010, b[1, 1])
}
@Test fun setPixel() {
val b = createBitmap(2, 2)
b[1, 1] = 0x40302010
assertEquals(0x40302010, b[1, 1])
}
@Test fun crop() {
val src = createBitmap(10, 10)
src[3, 5] = 0x40302010
val res = src.crop(3, 5, 2, 2)
assertEquals(2, res.width)
assertEquals(2, res.height)
assertEquals(0x40302010, res[0, 0])
}
@Test fun rotate() {
val src = createBitmap(10, 10)
src[3, 5] = 0x40302010
src[0, 0] = 0x10203010
val res = src.rotate(90f, 0f, 0f)
assertEquals(10, res.width)
assertEquals(10, res.height)
assertEquals(0x10203010, res[9, 0])
assertEquals(0x40302010, res[4, 3])
}
}