Debian Codegraph @

oned/rss/rss14_reader.go

raw symbols SCIP
1 package rssscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/
2
3 import (
4 "strconvscip-go gomod github.com/golang/go/src go1.17 strconv/"
5
6 "github.com/makiuchi-d/gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/"
7 "github.com/makiuchi-d/gozxing/common/utilscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/"
8 "github.com/makiuchi-d/gozxing/onedscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/"
9 )
10
11 // Decodes RSS-14, including truncated and stacked variants. See ISO/IEC 24724:2006.
12
13 var (
14 rss14_OUTSIDE_EVEN_TOTAL_SUBSETscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_OUTSIDE_EVEN_TOTAL_SUBSET. = []int{1, 10, 34, 70, 126}
15 rss14_INSIDE_ODD_TOTAL_SUBSETscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_INSIDE_ODD_TOTAL_SUBSET. = []int{4, 20, 48, 81}
16 rss14_OUTSIDE_GSUMscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_OUTSIDE_GSUM. = []int{0, 161, 961, 2015, 2715}
17 rss14_INSIDE_GSUMscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_INSIDE_GSUM. = []int{0, 336, 1036, 1516}
18 rss14_OUTSIDE_ODD_WIDESTscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_OUTSIDE_ODD_WIDEST. = []int{8, 6, 4, 3, 1}
19 rss14_INSIDE_ODD_WIDESTscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_INSIDE_ODD_WIDEST. = []int{2, 4, 6, 8}
20
21 rss14_FINDER_PATTERNSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_FINDER_PATTERNS. = [][]int{
22 {3, 8, 2, 1},
23 {3, 5, 5, 1},
24 {3, 3, 7, 1},
25 {3, 1, 9, 1},
26 {2, 7, 4, 1},
27 {2, 5, 6, 1},
28 {2, 3, 8, 1},
29 {1, 5, 7, 1},
30 {1, 3, 9, 1},
31 }
32 )
33
34 type rss14Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader# struct {
35 *onedscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/.OneDReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#OneDReader.
36 *AbstractRSSReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#AbstractRSSReader.
37 possibleLeftPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleLeftPairs. []*Pairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#
38 possibleRightPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleRightPairs. []*Pairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#
39 }
40
41 func NewRSS14Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/NewRSS14Reader().() gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/Reader# {
42 reader := &rss14Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#{
43 AbstractRSSReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#AbstractRSSReader.: NewAbstractRSSReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/NewAbstractRSSReader().(),
44 possibleLeftPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleLeftPairs.: make([]*Pairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#, 0),
45 possibleRightPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleRightPairs.: make([]*Pairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#, 0),
46 }
47 reader.OneDReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#OneDReader. = onedscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/.NewOneDReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/NewOneDReader().(reader)
48 return reader
49 }
50
51 func (this *rss14Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#) DecodeRowscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#DecodeRow().(rowNumber int, row *gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BitArrayscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#, hints map[gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.DecodeHintTypescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/DecodeHintType#]interface{}) (*gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.Resultscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/Result#, error) {
52 leftPair := this.decodePairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#decodePair().(row, false, rowNumber, hints)
53 this.possibleLeftPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleLeftPairs. = this.addOrTallyscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#addOrTally().(this.possibleLeftPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleLeftPairs., leftPair)
54 row.Reversescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#Reverse().()
55 rightPair := this.decodePairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#decodePair().(row, true, rowNumber, hints)
56 this.possibleRightPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleRightPairs. = this.addOrTallyscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#addOrTally().(this.possibleRightPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleRightPairs., rightPair)
57 row.Reversescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#Reverse().()
58 for _, left := range this.possibleLeftPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleLeftPairs. {
59 if left.GetCountscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#GetCount().() > 1 {
60 for _, right := range this.possibleRightPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleRightPairs. {
61 if right.GetCountscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#GetCount().() > 1 && checkChecksumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/checkChecksum().(left, right) {
62 return constructResultscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/constructResult().(left, right), nil
63 }
64 }
65 }
66 }
67 return nil, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("no possible left/right pairs")
68 }
69
70 func (this *rss14Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#) addOrTallyscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#addOrTally().(possiblePairs []*Pairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#, pair *Pairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#) []*Pairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair# {
71 if pair == nil {
72 return possiblePairs
73 }
74 found := false
75 for _, other := range possiblePairs {
76 if other.GetValuescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/DataCharacter#GetValue().() == pair.GetValuescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/DataCharacter#GetValue().() {
77 other.IncrementCountscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#IncrementCount().()
78 found = true
79 break
80 }
81 }
82 if !found {
83 possiblePairs = append(possiblePairs, pair)
84 }
85 return possiblePairs
86 }
87
88 func (this *rss14Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#) Resetscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#Reset().() {
89 this.possibleLeftPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleLeftPairs. = this.possibleLeftPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleLeftPairs.[:0]
90 this.possibleRightPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleRightPairs. = this.possibleRightPairsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#possibleRightPairs.[:0]
91 }
92
93 func constructResultscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/constructResult().(leftPair, rightPair *Pairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#) *gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.Resultscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/Result# {
94 symbolValue := 4537077*leftPair.GetValuescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/DataCharacter#GetValue().() + rightPair.GetValuescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/DataCharacter#GetValue().()
95 text := strconvscip-go gomod github.com/golang/go/src go1.17 strconv/.Itoascip-go gomod github.com/golang/go/src go1.17 strconv/Itoa().(symbolValue)
96
97 buffer := make([]byte, 0, 14)
98 for i := 13 - len(text); i > 0; i-- {
99 buffer = append(buffer, '0')
100 }
101 buffer = append(buffer, []byte(text)...)
102
103 checkDigit := byte(0)
104 for i := 0; i < 13; i++ {
105 digit := buffer[i] - '0'
106 if (i & 0x01) == 0 {
107 checkDigit += 3 * digit
108 } else {
109 checkDigit += digit
110 }
111 }
112 checkDigit = 10 - (checkDigit % 10)
113 if checkDigit == 10 {
114 checkDigit = 0
115 }
116 buffer = append(buffer, checkDigit+'0')
117
118 leftPoints := leftPair.GetFinderPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#GetFinderPattern().().GetResultPointsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/FinderPattern#GetResultPoints().()
119 rightPoints := rightPair.GetFinderPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#GetFinderPattern().().GetResultPointsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/FinderPattern#GetResultPoints().()
120 result := gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewResultscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewResult().(
121 string(buffer),
122 nil,
123 []gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.ResultPointscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#{leftPoints[0], leftPoints[1], rightPoints[0], rightPoints[1]},
124 gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BarcodeFormat_RSS_14scip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BarcodeFormat_RSS_14.)
125 result.PutMetadatascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/Result#PutMetadata().(gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.ResultMetadataType_SYMBOLOGY_IDENTIFIERscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultMetadataType_SYMBOLOGY_IDENTIFIER., "]e0")
126 return result
127 }
128
129 func checkChecksumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/checkChecksum().(leftPair, rightPair *Pairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#) bool {
130 checkValue := (leftPair.GetChecksumPortionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/DataCharacter#GetChecksumPortion().() + 16*rightPair.GetChecksumPortionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/DataCharacter#GetChecksumPortion().()) % 79
131 targetCheckValue :=
132 9*leftPair.GetFinderPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#GetFinderPattern().().GetValuescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/FinderPattern#GetValue().() + rightPair.GetFinderPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair#GetFinderPattern().().GetValuescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/FinderPattern#GetValue().()
133 if targetCheckValue > 72 {
134 targetCheckValue--
135 }
136 if targetCheckValue > 8 {
137 targetCheckValue--
138 }
139 return checkValue == targetCheckValue
140 }
141
142 func (this *rss14Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#) decodePairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#decodePair().(row *gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BitArrayscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#, right bool, rowNumber int, hints map[gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.DecodeHintTypescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/DecodeHintType#]interface{}) *Pairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/Pair# {
143
144 startEnd, e := this.findFinderPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#findFinderPattern().(row, right)
145 if e != nil {
146 return nil // ignore NotFoundException
147 }
148
149 pattern, e := this.parseFoundFinderPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#parseFoundFinderPattern().(row, rowNumber, right, startEnd)
150 if e != nil {
151 return nil // ignore NotFoundException
152 }
153
154 if resultPointCallback, ok := hints[gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.DecodeHintType_NEED_RESULT_POINT_CALLBACKscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/DecodeHintType_NEED_RESULT_POINT_CALLBACK.].(gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.ResultPointCallbackscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPointCallback#); ok {
155 startEnd = pattern.GetStartEndscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/FinderPattern#GetStartEnd().()
156 center := float64(startEnd[0]+startEnd[1]-1) / 2.0
157 if right {
158 // row is actually reversed
159 center = float64(row.GetSizescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#GetSize().()) - 1 - center
160 }
161 resultPointCallback(gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewResultPointscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewResultPoint().(center, float64(rowNumber)))
162 }
163
164 outside, e := this.decodeDataCharacterscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#decodeDataCharacter().(row, pattern, true)
165 if e != nil {
166 return nil // ignore NotFoundException
167 }
168
169 inside, e := this.decodeDataCharacterscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#decodeDataCharacter().(row, pattern, false)
170 if e != nil {
171 return nil // ignore NotFoundException
172 }
173
174 return NewPairscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/NewPair().(1597*outside.GetValuescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/DataCharacter#GetValue().()+inside.GetValuescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/DataCharacter#GetValue().(),
175 outside.GetChecksumPortionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/DataCharacter#GetChecksumPortion().()+4*inside.GetChecksumPortionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/DataCharacter#GetChecksumPortion().(),
176 pattern)
177 }
178
179 func (this *rss14Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#) decodeDataCharacterscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#decodeDataCharacter().(row *gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BitArrayscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#, pattern *FinderPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/FinderPattern#, outsideChar bool) (*DataCharacterscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/DataCharacter#, error) {
180
181 counters := this.GetDataCharacterCountersscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetDataCharacterCounters().()
182 for x := 0; x < len(counters); x++ {
183 counters[x] = 0
184 }
185
186 if outsideChar {
187 onedscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/.RecordPatternInReversescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/RecordPatternInReverse().(row, pattern.GetStartEndscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/FinderPattern#GetStartEnd().()[0], counters)
188 } else {
189 onedscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/.RecordPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/RecordPattern().(row, pattern.GetStartEndscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/FinderPattern#GetStartEnd().()[1], counters)
190 // reverse it
191 for i, j := 0, len(counters)-1; i < j; i, j = i+1, j-1 {
192 counters[i], counters[j] = counters[j], counters[i]
193 }
194 }
195
196 numModules := 15
197 if outsideChar {
198 numModules = 16
199 }
200 elementWidth := float64(utilscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/.MathUtils_Sumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/MathUtils_Sum().(counters)) / float64(numModules)
201
202 oddCounts := this.GetOddCountsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetOddCounts().()
203 evenCounts := this.GetEvenCountsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetEvenCounts().()
204 oddRoundingErrors := this.GetOddRoundingErrorsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetOddRoundingErrors().()
205 evenRoundingErrors := this.GetEvenRoundingErrorsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetEvenRoundingErrors().()
206
207 for i := 0; i < len(counters); i++ {
208 value := float64(counters[i]) / elementWidth
209 count := int(value + 0.5) // Round
210 if count < 1 {
211 count = 1
212 } else if count > 8 {
213 count = 8
214 }
215 offset := i / 2
216 if (i & 0x01) == 0 {
217 oddCounts[offset] = count
218 oddRoundingErrors[offset] = value - float64(count)
219 } else {
220 evenCounts[offset] = count
221 evenRoundingErrors[offset] = value - float64(count)
222 }
223 }
224
225 e := this.adjustOddEvenCountsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#adjustOddEvenCounts().(outsideChar, numModules)
226 if e != nil {
227 return nil, e
228 }
229
230 oddSum := 0
231 oddChecksumPortion := 0
232 for i := len(oddCounts) - 1; i >= 0; i-- {
233 oddChecksumPortion *= 9
234 oddChecksumPortion += oddCounts[i]
235 oddSum += oddCounts[i]
236 }
237 evenChecksumPortion := 0
238 evenSum := 0
239 for i := len(evenCounts) - 1; i >= 0; i-- {
240 evenChecksumPortion *= 9
241 evenChecksumPortion += evenCounts[i]
242 evenSum += evenCounts[i]
243 }
244 checksumPortion := oddChecksumPortion + 3*evenChecksumPortion
245
246 if outsideChar {
247 if (oddSum&0x01) != 0 || oddSum > 12 || oddSum < 4 {
248 return nil, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("oddSum = %v", oddSum)
249 }
250 group := (12 - oddSum) / 2
251 oddWidest := rss14_OUTSIDE_ODD_WIDESTscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_OUTSIDE_ODD_WIDEST.[group]
252 evenWidest := 9 - oddWidest
253 vOdd := RSSUtils_getRSSvaluescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/RSSUtils_getRSSvalue().(oddCounts, oddWidest, false)
254 vEven := RSSUtils_getRSSvaluescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/RSSUtils_getRSSvalue().(evenCounts, evenWidest, true)
255 tEven := rss14_OUTSIDE_EVEN_TOTAL_SUBSETscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_OUTSIDE_EVEN_TOTAL_SUBSET.[group]
256 gSum := rss14_OUTSIDE_GSUMscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_OUTSIDE_GSUM.[group]
257 return NewDataCharacterscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/NewDataCharacter().(vOdd*tEven+vEven+gSum, checksumPortion), nil
258 } else {
259 if (evenSum&0x01) != 0 || evenSum > 10 || evenSum < 4 {
260 return nil, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("evenSum = %v", oddSum)
261 }
262 group := (10 - evenSum) / 2
263 oddWidest := rss14_INSIDE_ODD_WIDESTscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_INSIDE_ODD_WIDEST.[group]
264 evenWidest := 9 - oddWidest
265 vOdd := RSSUtils_getRSSvaluescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/RSSUtils_getRSSvalue().(oddCounts, oddWidest, true)
266 vEven := RSSUtils_getRSSvaluescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/RSSUtils_getRSSvalue().(evenCounts, evenWidest, false)
267 tOdd := rss14_INSIDE_ODD_TOTAL_SUBSETscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_INSIDE_ODD_TOTAL_SUBSET.[group]
268 gSum := rss14_INSIDE_GSUMscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_INSIDE_GSUM.[group]
269 return NewDataCharacterscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/NewDataCharacter().(vEven*tOdd+vOdd+gSum, checksumPortion), nil
270 }
271 }
272
273 func (this *rss14Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#) findFinderPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#findFinderPattern().(row *gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BitArrayscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#, rightFinderPattern bool) ([]int, error) {
274
275 counters := this.GetDecodeFinderCountersscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetDecodeFinderCounters().()
276 counters[0] = 0
277 counters[1] = 0
278 counters[2] = 0
279 counters[3] = 0
280
281 width := row.GetSizescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#GetSize().()
282 isWhite := false
283 rowOffset := 0
284 for rowOffset < width {
285 isWhite = !row.Getscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#Get().(rowOffset)
286 if rightFinderPattern == isWhite {
287 // Will encounter white first when searching for right finder pattern
288 break
289 }
290 rowOffset++
291 }
292
293 counterPosition := 0
294 patternStart := rowOffset
295 for x := rowOffset; x < width; x++ {
296 if row.Getscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#Get().(x) != isWhite {
297 counters[counterPosition]++
298 } else {
299 if counterPosition == 3 {
300 if RSSReader_isFinderPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/RSSReader_isFinderPattern().(counters) {
301 return []int{patternStart, x}, nil
302 }
303 patternStart += counters[0] + counters[1]
304 counters[0] = counters[2]
305 counters[1] = counters[3]
306 counters[2] = 0
307 counters[3] = 0
308 counterPosition--
309 } else {
310 counterPosition++
311 }
312 counters[counterPosition] = 1
313 isWhite = !isWhite
314 }
315 }
316 return nil, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("finder pattern not found")
317 }
318
319 func (this *rss14Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#) parseFoundFinderPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#parseFoundFinderPattern().(row *gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BitArrayscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#, rowNumber int, right bool, startEnd []int) (*FinderPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/FinderPattern#, error) {
320 // Actually we found elements 2-5
321 firstIsBlack := row.Getscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#Get().(startEnd[0])
322 firstElementStart := startEnd[0] - 1
323 // Locate element 1
324 for firstElementStart >= 0 && firstIsBlack != row.Getscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#Get().(firstElementStart) {
325 firstElementStart--
326 }
327 firstElementStart++
328 firstCounter := startEnd[0] - firstElementStart
329 // Make 'counters' hold 1-4
330 counters := this.GetDecodeFinderCountersscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetDecodeFinderCounters().()
331 copy(counters[1:], counters[:len(counters)-1])
332 counters[0] = firstCounter
333 value, e := RSSReader_parseFinderValuescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/RSSReader_parseFinderValue().(counters, rss14_FINDER_PATTERNSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14_FINDER_PATTERNS.)
334 if e != nil {
335 return nil, e
336 }
337 start := firstElementStart
338 end := startEnd[1]
339 if right {
340 // row is actually reversed
341 start = row.GetSizescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#GetSize().() - 1 - start
342 end = row.GetSizescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#GetSize().() - 1 - end
343 }
344 return NewFinderPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/NewFinderPattern().(value, []int{firstElementStart, startEnd[1]}, start, end, rowNumber), nil
345 }
346
347 func (this *rss14Readerscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#) adjustOddEvenCountsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/rss14Reader#adjustOddEvenCounts().(outsideChar bool, numModules int) error {
348
349 oddSum := utilscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/.MathUtils_Sumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/MathUtils_Sum().(this.GetOddCountsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetOddCounts().())
350 evenSum := utilscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/.MathUtils_Sumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/MathUtils_Sum().(this.GetEvenCountsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetEvenCounts().())
351
352 incrementOdd := false
353 decrementOdd := false
354 incrementEven := false
355 decrementEven := false
356
357 if outsideChar {
358 if oddSum > 12 {
359 decrementOdd = true
360 } else if oddSum < 4 {
361 incrementOdd = true
362 }
363 if evenSum > 12 {
364 decrementEven = true
365 } else if evenSum < 4 {
366 incrementEven = true
367 }
368 } else {
369 if oddSum > 11 {
370 decrementOdd = true
371 } else if oddSum < 5 {
372 incrementOdd = true
373 }
374 if evenSum > 10 {
375 decrementEven = true
376 } else if evenSum < 4 {
377 incrementEven = true
378 }
379 }
380
381 mismatch := oddSum + evenSum - numModules
382 oddParityBad := (oddSum & 0x01) == 0
383 if outsideChar {
384 oddParityBad = (oddSum & 0x01) == 1
385 }
386 evenParityBad := (evenSum & 0x01) == 1
387 /*if (mismatch == 2) {
388 if (!(oddParityBad && evenParityBad)) {
389 throw ReaderException.getInstance();
390 }
391 decrementOdd = true;
392 decrementEven = true;
393 } else if (mismatch == -2) {
394 if (!(oddParityBad && evenParityBad)) {
395 throw ReaderException.getInstance();
396 }
397 incrementOdd = true;
398 incrementEven = true;
399 } else */
400 switch mismatch {
401 case 1:
402 if oddParityBad {
403 if evenParityBad {
404 return gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("adjustOddEvenCounts mismatch=1")
405 }
406 decrementOdd = true
407 } else {
408 if !evenParityBad {
409 return gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("adjustOddEvenCounts mismatch=1")
410 }
411 decrementEven = true
412 }
413 break
414 case -1:
415 if oddParityBad {
416 if evenParityBad {
417 return gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("adjustOddEvenCounts mismatch=-1")
418 }
419 incrementOdd = true
420 } else {
421 if !evenParityBad {
422 return gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("adjustOddEvenCounts mismatch=-1")
423 }
424 incrementEven = true
425 }
426 break
427 case 0:
428 if oddParityBad {
429 if !evenParityBad {
430 return gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("adjustOddEvenCounts mismatch=0")
431 }
432 // Both bad
433 if oddSum < evenSum {
434 incrementOdd = true
435 decrementEven = true
436 } else {
437 decrementOdd = true
438 incrementEven = true
439 }
440 } else {
441 if evenParityBad {
442 return gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("adjustOddEvenCounts mismatch=0")
443 }
444 // Nothing to do!
445 }
446 break
447 default:
448 return gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("adjustOddEvenCounts mismatch=%v", mismatch)
449 }
450
451 if incrementOdd {
452 if decrementOdd {
453 return gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("adjustOddEvenCounts incrementOdd & decrementOdd")
454 }
455 RSSReader_incrementscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/RSSReader_increment().(this.GetOddCountsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetOddCounts().(), this.GetOddRoundingErrorsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetOddRoundingErrors().())
456 }
457 if decrementOdd {
458 RSSReader_decrementscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/RSSReader_decrement().(this.GetOddCountsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetOddCounts().(), this.GetOddRoundingErrorsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetOddRoundingErrors().())
459 }
460 if incrementEven {
461 if decrementEven {
462 return gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewNotFoundException().("adjustOddEvenCounts incrementEven & decrementEven")
463 }
464 RSSReader_incrementscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/RSSReader_increment().(this.GetEvenCountsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetEvenCounts().(), this.GetEvenRoundingErrorsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetEvenRoundingErrors().())
465 }
466 if decrementEven {
467 RSSReader_decrementscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/RSSReader_decrement().(this.GetEvenCountsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetEvenCounts().(), this.GetEvenRoundingErrorsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned/rss`/AbstractRSSReader#GetEvenRoundingErrors().())
468 }
469 return nil
470 }