forked from makiuchi-d/gozxing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary_bitmap.go
88 lines (75 loc) · 2.4 KB
/
binary_bitmap.go
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
package gozxing
import (
errors "golang.org/x/xerrors"
)
type BinaryBitmap struct {
binarizer Binarizer
matrix *BitMatrix
}
func NewBinaryBitmap(binarizer Binarizer) (*BinaryBitmap, error) {
if binarizer == nil {
return nil, errors.New("IllegalArgumentException: Binarizer must be non-null")
}
return &BinaryBitmap{binarizer, nil}, nil
}
func (this *BinaryBitmap) GetWidth() int {
return this.binarizer.GetWidth()
}
func (this *BinaryBitmap) GetHeight() int {
return this.binarizer.GetHeight()
}
func (this *BinaryBitmap) GetBlackRow(y int, row *BitArray) (*BitArray, error) {
return this.binarizer.GetBlackRow(y, row)
}
func (this *BinaryBitmap) GetBlackMatrix() (*BitMatrix, error) {
// The matrix is created on demand the first time it is requested, then cached. There are two
// reasons for this:
// 1. This work will never be done if the caller only installs 1D Reader objects, or if a
// 1D Reader finds a barcode before the 2D Readers run.
// 2. This work will only be done once even if the caller installs multiple 2D Readers.
if this.matrix == nil {
var e error
this.matrix, e = this.binarizer.GetBlackMatrix()
if e != nil {
return nil, e
}
}
return this.matrix, nil
}
func (this *BinaryBitmap) IsCropSupported() bool {
return this.binarizer.GetLuminanceSource().IsCropSupported()
}
func (this *BinaryBitmap) Crop(left, top, width, height int) (*BinaryBitmap, error) {
newSource, e := this.binarizer.GetLuminanceSource().Crop(left, top, width, height)
if e != nil {
return nil, e
}
return NewBinaryBitmap(this.binarizer.CreateBinarizer(newSource))
}
func (this *BinaryBitmap) IsRotateSupported() bool {
return this.binarizer.GetLuminanceSource().IsRotateSupported()
}
func (this *BinaryBitmap) RotateCounterClockwise() (*BinaryBitmap, error) {
newSource, e := this.binarizer.GetLuminanceSource().RotateCounterClockwise()
if e != nil {
return nil, e
}
return NewBinaryBitmap(this.binarizer.CreateBinarizer(newSource))
}
func (this *BinaryBitmap) RotateCounterClockwise45() (*BinaryBitmap, error) {
newSource, e := this.binarizer.GetLuminanceSource().RotateCounterClockwise45()
if e != nil {
return nil, e
}
return NewBinaryBitmap(this.binarizer.CreateBinarizer(newSource))
}
func (this *BinaryBitmap) String() string {
matrix, e := this.GetBlackMatrix()
if e != nil {
if _, ok := e.(NotFoundException); ok {
return ""
}
return e.Error()
}
return matrix.String()
}