| 1 | package onedscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/ |
| 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 | ) |
| 8 | |
| 9 | const ( |
| 10 | // These two values are critical for determining how permissive the decoding will be. |
| 11 | // We've arrived at these values through a lot of trial and error. Setting them any higher |
| 12 | // lets false positives creep in quickly. |
| 13 | UPCEANReader_MAX_AVG_VARIANCEscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_MAX_AVG_VARIANCE. = 0.48 |
| 14 | UPCEANReader_MAX_INDIVIDUAL_VARIANCEscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_MAX_INDIVIDUAL_VARIANCE. = 0.7 |
| 15 | ) |
| 16 | |
| 17 | var ( |
| 18 | // Start/end guard pattern. |
| 19 | UPCEANReader_START_END_PATTERNscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_START_END_PATTERN. = []int{1, 1, 1} |
| 20 | |
| 21 | // Pattern marking the middle of a UPC/EAN pattern, separating the two halves. |
| 22 | UPCEANReader_MIDDLE_PATTERNscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_MIDDLE_PATTERN. = []int{1, 1, 1, 1, 1} |
| 23 | |
| 24 | // end guard pattern. |
| 25 | UPCEANReader_END_PATTERNscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_END_PATTERN. = []int{1, 1, 1, 1, 1, 1} |
| 26 | |
| 27 | // "Odd", or "L" patterns used to encode UPC/EAN digits. |
| 28 | UPCEANReader_L_PATTERNSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_L_PATTERNS. = [][]int{ |
| 29 | {3, 2, 1, 1}, // 0 |
| 30 | {2, 2, 2, 1}, // 1 |
| 31 | {2, 1, 2, 2}, // 2 |
| 32 | {1, 4, 1, 1}, // 3 |
| 33 | {1, 1, 3, 2}, // 4 |
| 34 | {1, 2, 3, 1}, // 5 |
| 35 | {1, 1, 1, 4}, // 6 |
| 36 | {1, 3, 1, 2}, // 7 |
| 37 | {1, 2, 1, 3}, // 8 |
| 38 | {3, 1, 1, 2}, // 9 |
| 39 | } |
| 40 | |
| 41 | // As above but also including the "even", or "G" patterns used to encode UPC/EAN digits. |
| 42 | UPCEANReader_L_AND_G_PATTERNSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_L_AND_G_PATTERNS. [][]int |
| 43 | ) |
| 44 | |
| 45 | func initscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/init().() { |
| 46 | UPCEANReader_L_AND_G_PATTERNSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_L_AND_G_PATTERNS. = make([][]int, 20) |
| 47 | copy(UPCEANReader_L_AND_G_PATTERNSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_L_AND_G_PATTERNS., UPCEANReader_L_PATTERNSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_L_PATTERNS.) |
| 48 | for i := 10; i < 20; i++ { |
| 49 | widths := UPCEANReader_L_PATTERNSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_L_PATTERNS.[i-10] |
| 50 | reversedWidths := make([]int, len(widths)) |
| 51 | for j := 0; j < len(widths); j++ { |
| 52 | reversedWidths[j] = widths[len(widths)-j-1] |
| 53 | } |
| 54 | UPCEANReader_L_AND_G_PATTERNSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_L_AND_G_PATTERNS.[i] = reversedWidths |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | type upceanRowDecoderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanRowDecoder# interface { |
| 59 | RowDecoderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/RowDecoder# |
| 60 | |
| 61 | // getBarcodeFormat Get the format of this decoder. |
| 62 | // @return The 1D format. |
| 63 | getBarcodeFormatscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanRowDecoder#getBarcodeFormat.() gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BarcodeFormatscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BarcodeFormat# |
| 64 | |
| 65 | // decodeMiddle Subclasses override this to decode the portion of a barcode between the start |
| 66 | // and end guard patterns. |
| 67 | // |
| 68 | // @param row row of black/white values to search |
| 69 | // @param startRange start/end offset of start guard pattern |
| 70 | // @param resultString {@link StringBuilder} to append decoded chars to |
| 71 | // @return horizontal offset of first pixel after the "middle" that was decoded |
| 72 | // @throws NotFoundException if decoding could not complete successfully |
| 73 | decodeMiddlescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanRowDecoder#decodeMiddle.(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#, startRange []int, result []byte) (int, []byte, error) |
| 74 | |
| 75 | decodeEndscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanRowDecoder#decodeEnd.(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#, endStart int) ([]int, error) |
| 76 | |
| 77 | // checkChecksum Check checksum |
| 78 | // @param s string of digits to check |
| 79 | // @return {@link #checkStandardUPCEANChecksum(CharSequence)} |
| 80 | // @throws FormatException if the string does not contain only digits |
| 81 | checkChecksumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanRowDecoder#checkChecksum.(s string) (bool, error) |
| 82 | } |
| 83 | |
| 84 | type upceanReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader# struct { |
| 85 | upceanRowDecoderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#upceanRowDecoder. |
| 86 | *OneDReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#OneDReader. |
| 87 | decodeRowStringBufferscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#decodeRowStringBuffer. []byte |
| 88 | extensionReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#extensionReader. *UPCEANExtensionSupportscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANExtensionSupport# |
| 89 | } |
| 90 | |
| 91 | func newUPCEANReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/newUPCEANReader().(rowDecoder upceanRowDecoderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanRowDecoder#) *upceanReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader# { |
| 92 | this := &upceanReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#{ |
| 93 | upceanRowDecoderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#upceanRowDecoder.: rowDecoder, |
| 94 | decodeRowStringBufferscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#decodeRowStringBuffer.: make([]byte, 13), |
| 95 | extensionReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#extensionReader.: NewUPCEANExtensionSupportscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/NewUPCEANExtensionSupport().(), |
| 96 | } |
| 97 | this.OneDReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#OneDReader. = NewOneDReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/NewOneDReader().(rowDecoder) |
| 98 | return this |
| 99 | } |
| 100 | |
| 101 | func upceanReader_findStartGuardPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_findStartGuardPattern().(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#) ([]int, error) { |
| 102 | foundStart := false |
| 103 | var startRange []int |
| 104 | nextStart := 0 |
| 105 | counters := make([]int, len(UPCEANReader_START_END_PATTERNscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_START_END_PATTERN.)) |
| 106 | for !foundStart { |
| 107 | for i := range counters { |
| 108 | counters[i] = 0 |
| 109 | } |
| 110 | var e error |
| 111 | startRange, e = upceanReader_findGuardPatternWithCountersscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_findGuardPatternWithCounters().( |
| 112 | row, nextStart, false, UPCEANReader_START_END_PATTERNscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_START_END_PATTERN., counters) |
| 113 | if e != nil { |
| 114 | return nil, e |
| 115 | } |
| 116 | start := startRange[0] |
| 117 | nextStart = startRange[1] |
| 118 | // Make sure there is a quiet zone at least as big as the start pattern before the barcode. |
| 119 | // If this check would run off the left edge of the image, do not accept this barcode, |
| 120 | // as it is very likely to be a false positive. |
| 121 | quietStart := start - (nextStart - start) |
| 122 | if quietStart >= 0 { |
| 123 | foundStart, _ = row.IsRangescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#IsRange().(quietStart, start, false) |
| 124 | } |
| 125 | } |
| 126 | return startRange, nil |
| 127 | } |
| 128 | |
| 129 | func (this *upceanReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#) DecodeRowscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#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) { |
| 130 | start, e := upceanReader_findStartGuardPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_findStartGuardPattern().(row) |
| 131 | if e != nil { |
| 132 | return nil, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.WrapNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/WrapNotFoundException().(e) |
| 133 | } |
| 134 | return this.decodeRowWithStartRangescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#decodeRowWithStartRange().(rowNumber, row, start, hints) |
| 135 | } |
| 136 | |
| 137 | // decodeRowWithStartRange Like {@link #decodeRow(int, BitArray, Map)}, but |
| 138 | // allows caller to inform method about where the UPC/EAN start pattern is |
| 139 | // found. This allows this to be computed once and reused across many implementations.</p> |
| 140 | // |
| 141 | // @param rowNumber row index into the image |
| 142 | // @param row encoding of the row of the barcode image |
| 143 | // @param startGuardRange start/end column where the opening start pattern was found |
| 144 | // @param hints optional hints that influence decoding |
| 145 | // @return {@link Result} encapsulating the result of decoding a barcode in the row |
| 146 | // @throws NotFoundException if no potential barcode is found |
| 147 | // @throws ChecksumException if a potential barcode is found but does not pass its checksum |
| 148 | // @throws FormatException if a potential barcode is found but format is invalid |
| 149 | func (this *upceanReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#) decodeRowWithStartRangescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#decodeRowWithStartRange().( |
| 150 | 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#, startGuardRange []int, |
| 151 | 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) { |
| 152 | |
| 153 | var resultPointCallback 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# |
| 154 | if hint, 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.]; ok { |
| 155 | resultPointCallback = hint.(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#) |
| 156 | } |
| 157 | symbologyIdentifier := 0 |
| 158 | |
| 159 | if resultPointCallback != nil { |
| 160 | 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().( |
| 161 | float64(startGuardRange[0]+startGuardRange[1])/2.0, float64(rowNumber))) |
| 162 | } |
| 163 | |
| 164 | result := this.decodeRowStringBufferscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#decodeRowStringBuffer.[:0] |
| 165 | endStart, result, e := this.decodeMiddlescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanRowDecoder#decodeMiddle.(row, startGuardRange, result) |
| 166 | if e != nil { |
| 167 | return nil, e |
| 168 | } |
| 169 | |
| 170 | rowNumberf := float64(rowNumber) |
| 171 | if resultPointCallback != nil { |
| 172 | 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().(float64(endStart), rowNumberf)) |
| 173 | } |
| 174 | |
| 175 | endRange, e := this.decodeEndscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanRowDecoder#decodeEnd.(row, endStart) |
| 176 | if e != nil { |
| 177 | return nil, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.WrapNotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/WrapNotFoundException().(e) |
| 178 | } |
| 179 | |
| 180 | if resultPointCallback != nil { |
| 181 | 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().( |
| 182 | float64(endRange[0]+endRange[1])/2.0, rowNumberf)) |
| 183 | } |
| 184 | |
| 185 | // Make sure there is a quiet zone at least as big as the end pattern after the barcode. The |
| 186 | // spec might want more whitespace, but in practice this is the maximum we can count on. |
| 187 | end := endRange[1] |
| 188 | quietEnd := end + (end - endRange[0]) |
| 189 | if quietEnd >= row.GetSizescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#GetSize().() { |
| 190 | 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().("quietEnd=%v, row size=%v", quietEnd, row.GetSizescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#GetSize().()) |
| 191 | } |
| 192 | rowIsRange, _ := row.IsRangescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#IsRange().(end, quietEnd, false) |
| 193 | if !rowIsRange { |
| 194 | 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().("raw is not range") |
| 195 | } |
| 196 | |
| 197 | this.decodeRowStringBufferscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#decodeRowStringBuffer. = result |
| 198 | |
| 199 | resultString := string(result) |
| 200 | // UPC/EAN should never be less than 8 chars anyway |
| 201 | if len(resultString) < 8 { |
| 202 | return nil, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewFormatExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewFormatException().("len(resultString) = %v", len(resultString)) |
| 203 | } |
| 204 | ok, e := this.checkChecksumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanRowDecoder#checkChecksum.(resultString) |
| 205 | if e != nil { |
| 206 | return nil, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.WrapChecksumExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/WrapChecksumException().(e) |
| 207 | } |
| 208 | if !ok { |
| 209 | return nil, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewChecksumExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewChecksumException().() |
| 210 | } |
| 211 | |
| 212 | left := float64(startGuardRange[1]+startGuardRange[0]) / 2.0 |
| 213 | right := float64(endRange[1]+endRange[0]) / 2.0 |
| 214 | format := this.getBarcodeFormatscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanRowDecoder#getBarcodeFormat.() |
| 215 | decodeResult := 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().( |
| 216 | resultString, |
| 217 | nil, // no natural byte representation for these barcodes |
| 218 | []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#{ |
| 219 | 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().(left, float64(rowNumber)), |
| 220 | 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().(right, float64(rowNumber)), |
| 221 | }, |
| 222 | format) |
| 223 | |
| 224 | extensionLength := 0 |
| 225 | |
| 226 | extensionResult, e := this.extensionReaderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader#extensionReader..decodeRowscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANExtensionSupport#decodeRow().(rowNumber, row, endRange[1]) |
| 227 | if e == nil { |
| 228 | decodeResult.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_UPC_EAN_EXTENSIONscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultMetadataType_UPC_EAN_EXTENSION., extensionResult.GetTextscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/Result#GetText().()) |
| 229 | decodeResult.PutAllMetadatascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/Result#PutAllMetadata().(extensionResult.GetResultMetadatascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/Result#GetResultMetadata().()) |
| 230 | decodeResult.AddResultPointsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/Result#AddResultPoints().(extensionResult.GetResultPointsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/Result#GetResultPoints().()) |
| 231 | extensionLength = len(extensionResult.GetTextscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/Result#GetText().()) |
| 232 | } else { |
| 233 | // ignore ReaderException |
| 234 | if _, ok := e.(gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.ReaderExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ReaderException#); !ok { |
| 235 | return nil, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.WrapReaderExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/WrapReaderException().(e) |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | if hint, ok := hints[gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.DecodeHintType_ALLOWED_EAN_EXTENSIONSscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/DecodeHintType_ALLOWED_EAN_EXTENSIONS.]; ok { |
| 240 | allowedExtensions, ok := hint.([]int) |
| 241 | if ok { |
| 242 | valid := false |
| 243 | for _, length := range allowedExtensions { |
| 244 | if extensionLength == length { |
| 245 | valid = true |
| 246 | break |
| 247 | } |
| 248 | } |
| 249 | if !valid { |
| 250 | 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().() |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | if format == gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BarcodeFormat_EAN_13scip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BarcodeFormat_EAN_13. || format == gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BarcodeFormat_UPC_Ascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BarcodeFormat_UPC_A. { |
| 256 | countryID := eanManufacturerOrgSupportLookupCountryIdentifierscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/eanManufacturerOrgSupportLookupCountryIdentifier().(resultString) |
| 257 | if countryID != "" { |
| 258 | decodeResult.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_POSSIBLE_COUNTRYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultMetadataType_POSSIBLE_COUNTRY., countryID) |
| 259 | } |
| 260 | } |
| 261 | if format == gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BarcodeFormat_EAN_8scip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BarcodeFormat_EAN_8. { |
| 262 | symbologyIdentifier = 4 |
| 263 | } |
| 264 | |
| 265 | decodeResult.PutMetadatascip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/Result#PutMetadata().( |
| 266 | 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., "]E"+strconvscip-go gomod github.com/golang/go/src go1.17 strconv/.Itoascip-go gomod github.com/golang/go/src go1.17 strconv/Itoa().(symbologyIdentifier)) |
| 267 | |
| 268 | return decodeResult, nil |
| 269 | } |
| 270 | |
| 271 | // checkChecksum Check checksum |
| 272 | // @param s string of digits to check |
| 273 | // @return {@link #checkStandardUPCEANChecksum(CharSequence)} |
| 274 | // @throws FormatException if the string does not contain only digits |
| 275 | func upceanReader_checkChecksumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_checkChecksum().(s string) (bool, error) { |
| 276 | return upceanReader_checkStandardUPCEANChecksumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_checkStandardUPCEANChecksum().(s) |
| 277 | } |
| 278 | |
| 279 | // checkStandardUPCEANChecksum Computes the UPC/EAN checksum on a string of digits, |
| 280 | // and reports whether the checksum is correct or not. |
| 281 | // |
| 282 | // @param s string of digits to check |
| 283 | /// @return true iff string of digits passes the UPC/EAN checksum algorithm |
| 284 | // @throws FormatException if the string does not contain only digits |
| 285 | func upceanReader_checkStandardUPCEANChecksumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_checkStandardUPCEANChecksum().(s string) (bool, error) { |
| 286 | length := len(s) |
| 287 | if length == 0 { |
| 288 | return false, nil |
| 289 | } |
| 290 | check := int(s[length-1] - '0') |
| 291 | sum, e := upceanReader_getStandardUPCEANChecksumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_getStandardUPCEANChecksum().(s[:length-1]) |
| 292 | if e != nil { |
| 293 | return false, e |
| 294 | } |
| 295 | return sum == check, nil |
| 296 | } |
| 297 | |
| 298 | func upceanReader_getStandardUPCEANChecksumscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_getStandardUPCEANChecksum().(s string) (int, error) { |
| 299 | length := len(s) |
| 300 | sum := 0 |
| 301 | for i := length - 1; i >= 0; i -= 2 { |
| 302 | digit := int(s[i] - '0') |
| 303 | if digit < 0 || digit > 9 { |
| 304 | return 0, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewFormatExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewFormatException().("0x%02x is not digit", s[i]) |
| 305 | } |
| 306 | sum += digit |
| 307 | } |
| 308 | sum *= 3 |
| 309 | for i := length - 2; i >= 0; i -= 2 { |
| 310 | digit := int(s[i] - '0') |
| 311 | if digit < 0 || digit > 9 { |
| 312 | return 0, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NewFormatExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NewFormatException().("0x%02x is not digit", s[i]) |
| 313 | } |
| 314 | sum += digit |
| 315 | } |
| 316 | return (1000 - sum) % 10, nil |
| 317 | } |
| 318 | |
| 319 | func upceanReader_decodeEndscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_decodeEnd().(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#, endStart int) ([]int, error) { |
| 320 | return upceanReader_findGuardPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_findGuardPattern().(row, endStart, false, UPCEANReader_START_END_PATTERNscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_START_END_PATTERN.) |
| 321 | } |
| 322 | |
| 323 | func upceanReader_findGuardPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_findGuardPattern().(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#, rowOffset int, whiteFirst bool, pattern []int) ([]int, error) { |
| 324 | counters := make([]int, len(pattern)) |
| 325 | return upceanReader_findGuardPatternWithCountersscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_findGuardPatternWithCounters().(row, rowOffset, whiteFirst, pattern, counters) |
| 326 | } |
| 327 | |
| 328 | // UPCEANReader_findGuardPatternWithCounters Find guard pattern |
| 329 | // @param row row of black/white values to search |
| 330 | // @param rowOffset position to start search |
| 331 | // @param whiteFirst if true, indicates that the pattern specifies white/black/white/... |
| 332 | // pixel counts, otherwise, it is interpreted as black/white/black/... |
| 333 | // @param pattern pattern of counts of number of black and white pixels that are being |
| 334 | // searched for as a pattern |
| 335 | // @param counters array of counters, as long as pattern, to re-use |
| 336 | // @return start/end horizontal offset of guard pattern, as an array of two ints |
| 337 | // @throws NotFoundException if pattern is not found |
| 338 | func upceanReader_findGuardPatternWithCountersscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_findGuardPatternWithCounters().( |
| 339 | 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#, rowOffset int, whiteFirst bool, pattern, counters []int) ([]int, error) { |
| 340 | |
| 341 | width := row.GetSizescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#GetSize().() |
| 342 | if whiteFirst { |
| 343 | rowOffset = row.GetNextUnsetscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#GetNextUnset().(rowOffset) |
| 344 | } else { |
| 345 | rowOffset = row.GetNextSetscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#GetNextSet().(rowOffset) |
| 346 | } |
| 347 | counterPosition := 0 |
| 348 | patternStart := rowOffset |
| 349 | patternLength := len(pattern) |
| 350 | isWhite := whiteFirst |
| 351 | for x := rowOffset; x < width; x++ { |
| 352 | if row.Getscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitArray#Get().(x) != isWhite { |
| 353 | counters[counterPosition]++ |
| 354 | } else { |
| 355 | if counterPosition == patternLength-1 { |
| 356 | if PatternMatchVariancescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/PatternMatchVariance().(counters, pattern, UPCEANReader_MAX_INDIVIDUAL_VARIANCEscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_MAX_INDIVIDUAL_VARIANCE.) < UPCEANReader_MAX_AVG_VARIANCEscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_MAX_AVG_VARIANCE. { |
| 357 | return []int{patternStart, x}, nil |
| 358 | } |
| 359 | patternStart += counters[0] + counters[1] |
| 360 | copy(counters[:counterPosition-1], counters[2:counterPosition+1]) |
| 361 | counters[counterPosition-1] = 0 |
| 362 | counters[counterPosition] = 0 |
| 363 | counterPosition-- |
| 364 | } else { |
| 365 | counterPosition++ |
| 366 | } |
| 367 | counters[counterPosition] = 1 |
| 368 | isWhite = !isWhite |
| 369 | } |
| 370 | } |
| 371 | 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().() |
| 372 | } |
| 373 | |
| 374 | // UPCEANReader_decodeDigit Attempts to decode a single UPC/EAN-encoded digit. |
| 375 | // |
| 376 | // @param row row of black/white values to decode |
| 377 | // @param counters the counts of runs of observed black/white/black/... values |
| 378 | // @param rowOffset horizontal offset to start decoding from |
| 379 | // @param patterns the set of patterns to use to decode -- sometimes different encodings |
| 380 | // for the digits 0-9 are used, and this indicates the encodings for 0 to 9 that should |
| 381 | // be used |
| 382 | // @return horizontal offset of first pixel beyond the decoded digit |
| 383 | // @throws NotFoundException if digit cannot be decoded |
| 384 | func upceanReader_decodeDigitscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/upceanReader_decodeDigit().(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#, counters []int, rowOffset int, patterns [][]int) (int, error) { |
| 385 | e := RecordPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/RecordPattern().(row, rowOffset, counters) |
| 386 | if e != nil { |
| 387 | return 0, e |
| 388 | } |
| 389 | bestVariance := UPCEANReader_MAX_AVG_VARIANCEscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_MAX_AVG_VARIANCE. // worst variance we'll accept |
| 390 | bestMatch := -1 |
| 391 | max := len(patterns) |
| 392 | for i := 0; i < max; i++ { |
| 393 | pattern := patterns[i] |
| 394 | variance := PatternMatchVariancescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/PatternMatchVariance().(counters, pattern, UPCEANReader_MAX_INDIVIDUAL_VARIANCEscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/oned`/UPCEANReader_MAX_INDIVIDUAL_VARIANCE.) |
| 395 | if variance < bestVariance { |
| 396 | bestVariance = variance |
| 397 | bestMatch = i |
| 398 | } |
| 399 | } |
| 400 | if bestMatch < 0 { |
| 401 | return 0, 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().() |
| 402 | } |
| 403 | return bestMatch, nil |
| 404 | } |