-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
inverted_luminance_source.go
64 lines (55 loc) · 1.66 KB
/
inverted_luminance_source.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
package gozxing
type InvertedLuminanceSource struct {
LuminanceSource
}
func NewInvertedLuminanceSource(delegate LuminanceSource) LuminanceSource {
return &InvertedLuminanceSource{delegate}
}
func (this *InvertedLuminanceSource) GetRow(y int, row []byte) ([]byte, error) {
var e error
row, e = this.LuminanceSource.GetRow(y, row)
if e != nil {
return row, e
}
width := this.GetWidth()
for i := 0; i < width; i++ {
row[i] = 255 - (row[i] & 0xff)
}
return row, nil
}
func (this *InvertedLuminanceSource) GetMatrix() []byte {
matrix := this.LuminanceSource.GetMatrix()
length := this.GetWidth() * this.GetHeight()
invertedMatrix := make([]byte, length)
for i := 0; i < length; i++ {
invertedMatrix[i] = 255 - (matrix[i] & 0xff)
}
return invertedMatrix
}
func (this *InvertedLuminanceSource) Crop(left, top, width, height int) (LuminanceSource, error) {
cropped, e := this.LuminanceSource.Crop(left, top, width, height)
if e != nil {
return nil, e
}
return NewInvertedLuminanceSource(cropped), nil
}
func (this *InvertedLuminanceSource) Invert() LuminanceSource {
return this.LuminanceSource
}
func (this *InvertedLuminanceSource) RotateCounterClockwise() (LuminanceSource, error) {
rotated, e := this.LuminanceSource.RotateCounterClockwise()
if e != nil {
return nil, e
}
return NewInvertedLuminanceSource(rotated), nil
}
func (this *InvertedLuminanceSource) RotateCounterClockwise45() (LuminanceSource, error) {
rotated, e := this.LuminanceSource.RotateCounterClockwise45()
if e != nil {
return nil, e
}
return NewInvertedLuminanceSource(rotated), nil
}
func (this *InvertedLuminanceSource) String() string {
return LuminanceSourceString(this)
}