@@ -20,39 +20,51 @@ import android.graphics.Bitmap
20
20
import android.graphics.ImageFormat
21
21
import android.graphics.Point
22
22
import android.graphics.Rect
23
+ import android.os.Build
23
24
import androidx.camera.core.ImageProxy
24
25
import java.lang.RuntimeException
25
26
import java.nio.ByteBuffer
26
27
27
- class BarcodeReader {
28
+ public class BarcodeReader {
29
+ private val supportedYUVFormats: List <Int > =
30
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
31
+ listOf (ImageFormat .YUV_420_888 , ImageFormat .YUV_422_888 , ImageFormat .YUV_444_888 )
32
+ } else {
33
+ listOf (ImageFormat .YUV_420_888 )
34
+ }
35
+
36
+ init {
37
+ System .loadLibrary(" zxing_android" )
38
+ }
28
39
29
40
// Enumerates barcode formats known to this package.
30
41
// Note that this has to be kept synchronized with native (C++/JNI) side.
31
- enum class Format {
42
+ public enum class Format {
32
43
NONE , AZTEC , CODABAR , CODE_39 , CODE_93 , CODE_128 , DATA_BAR , DATA_BAR_EXPANDED ,
33
44
DATA_MATRIX , EAN_8 , EAN_13 , ITF , MAXICODE , PDF_417 , QR_CODE , MICRO_QR_CODE , UPC_A , UPC_E
34
45
}
35
- enum class ContentType {
46
+
47
+ public enum class ContentType {
36
48
TEXT , BINARY , MIXED , GS1 , ISO15434 , UNKNOWN_ECI
37
49
}
38
50
39
- data class Options (
51
+ public data class Options (
40
52
val formats : Set <Format > = setOf(),
41
53
val tryHarder : Boolean = false ,
42
54
val tryRotate : Boolean = false ,
43
55
val tryInvert : Boolean = false ,
44
56
val tryDownscale : Boolean = false
45
57
)
46
58
47
- data class Position (
59
+ public data class Position (
48
60
val topLeft : Point ,
49
61
val topRight : Point ,
50
62
val bottomLeft : Point ,
51
63
val bottomRight : Point ,
52
64
val orientation : Double
53
65
)
54
66
55
- data class Result (
67
+ public data class Result (
56
68
val format : Format = Format .NONE ,
57
69
val bytes : ByteArray? = null ,
58
70
val text : String? = null ,
@@ -64,12 +76,11 @@ class BarcodeReader {
64
76
val symbologyIdentifier : String? = null
65
77
)
66
78
67
- var options : Options = Options ()
79
+ public var options : Options = Options ()
68
80
69
- fun read (image : ImageProxy ): Result ? {
70
- val supportedYUVFormats = arrayOf(ImageFormat .YUV_420_888 , ImageFormat .YUV_422_888 , ImageFormat .YUV_444_888 )
71
- if (image.format !in supportedYUVFormats) {
72
- error(" invalid image format" )
81
+ public fun read (image : ImageProxy ): Result ? {
82
+ check(image.format in supportedYUVFormats) {
83
+ " Invalid image format: ${image.format} . Must be one of: $supportedYUVFormats "
73
84
}
74
85
75
86
var result = Result ()
@@ -97,11 +108,11 @@ class BarcodeReader {
97
108
}
98
109
}
99
110
100
- fun read (bitmap : Bitmap , cropRect : Rect = Rect (), rotation : Int = 0): Result ? {
111
+ public fun read (bitmap : Bitmap , cropRect : Rect = Rect (), rotation : Int = 0): Result ? {
101
112
return read(bitmap, options, cropRect, rotation)
102
113
}
103
114
104
- fun read (bitmap : Bitmap , options : Options , cropRect : Rect = Rect (), rotation : Int = 0): Result ? {
115
+ public fun read (bitmap : Bitmap , options : Options , cropRect : Rect = Rect (), rotation : Int = 0): Result ? {
105
116
var result = Result ()
106
117
val status = with (options) {
107
118
readBitmap(
@@ -128,8 +139,4 @@ class BarcodeReader {
128
139
formats : String , tryHarder : Boolean , tryRotate : Boolean , tryInvert : Boolean , tryDownscale : Boolean ,
129
140
result : Result ,
130
141
): String?
131
-
132
- init {
133
- System .loadLibrary(" zxing_android" )
134
- }
135
142
}
0 commit comments