Debian Codegraph @

qrcode/detector/detector.go

raw symbols SCIP
1 package detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/
2
3 import (
4 "mathscip-go gomod github.com/golang/go/src go1.17 math/"
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/commonscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/"
8 "github.com/makiuchi-d/gozxing/common/utilscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/"
9 "github.com/makiuchi-d/gozxing/qrcode/decoderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/decoder`/"
10 )
11
12 type Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector# struct {
13 imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image. *gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BitMatrixscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#
14 resultPointCallbackscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#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#
15 }
16
17 func NewDetectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/NewDetector().(image *gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BitMatrixscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#) *Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector# {
18 return &Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#{image, nil}
19 }
20
21 func (this *Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#) GetImagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#GetImage().() *gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BitMatrixscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix# {
22 return this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image.
23 }
24
25 func (this *Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#) GetResultPointCallbackscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#GetResultPointCallback().() 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# {
26 return this.resultPointCallbackscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#resultPointCallback.
27 }
28
29 func (this *Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#) DetectWithoutHintsscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#DetectWithoutHints().() (*commonscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/.DetectorResultscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/DetectorResult#, error) {
30 return this.Detectscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#Detect().(nil)
31 }
32
33 func (this *Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#) Detectscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#Detect().(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{}) (*commonscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/.DetectorResultscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/DetectorResult#, error) {
34 if hints != nil {
35 if cb, 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 {
36 this.resultPointCallbackscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#resultPointCallback., _ = cb.(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#)
37 }
38 }
39
40 finder := NewFinderPatternFinderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/NewFinderPatternFinder().(this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image., this.resultPointCallbackscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#resultPointCallback.)
41 info, e := finder.Findscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/FinderPatternFinder#Find().(hints)
42 if e != nil {
43 return nil, e
44 }
45
46 return this.ProcessFinderPatternInfoscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#ProcessFinderPatternInfo().(info)
47 }
48
49 func (this *Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#) ProcessFinderPatternInfoscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#ProcessFinderPatternInfo().(info *FinderPatternInfoscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/FinderPatternInfo#) (*commonscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/.DetectorResultscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/DetectorResult#, error) {
50 topLeft := info.GetTopLeftscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/FinderPatternInfo#GetTopLeft().()
51 topRight := info.GetTopRightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/FinderPatternInfo#GetTopRight().()
52 bottomLeft := info.GetBottomLeftscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/FinderPatternInfo#GetBottomLeft().()
53
54 moduleSize := this.calculateModuleSizescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#calculateModuleSize().(topLeft, topRight, bottomLeft)
55 if moduleSize < 1.0 {
56 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().("moduleSize = %v", moduleSize)
57 }
58 dimension, e := this.computeDimensionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#computeDimension().(topLeft, topRight, bottomLeft, moduleSize)
59 if e != nil {
60 return nil, e
61 }
62 provisionalVersion, e := decoderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/decoder`/.Version_GetProvisionalVersionForDimensionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/decoder`/Version_GetProvisionalVersionForDimension().(dimension)
63 if e != nil {
64 return nil, gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.WrapFormatExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/WrapFormatException().(e)
65 }
66 modulesBetweenFPCenters := provisionalVersion.GetDimensionForVersionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/decoder`/Version#GetDimensionForVersion().() - 7
67
68 var alignmentPattern *AlignmentPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/AlignmentPattern#
69 // Anything above version 1 has an alignment pattern
70 if len(provisionalVersion.GetAlignmentPatternCentersscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/decoder`/Version#GetAlignmentPatternCenters().()) > 0 {
71 // Guess where a "bottom right" finder pattern would have been
72 bottomRightX := topRight.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.() - topLeft.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.() + bottomLeft.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.()
73 bottomRightY := topRight.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.() - topLeft.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.() + bottomLeft.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.()
74
75 // Estimate that alignment pattern is closer by 3 modules
76 // from "bottom right" to known top left location
77 correctionToTopLeft := 1.0 - 3.0/float64(modulesBetweenFPCenters)
78 estAlignmentX := int(topLeft.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.() + correctionToTopLeft*(bottomRightX-topLeft.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.()))
79 estAlignmentY := int(topLeft.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.() + correctionToTopLeft*(bottomRightY-topLeft.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.()))
80
81 // Kind of arbitrary -- expand search radius before giving up
82 for i := 4; i <= 16; i <<= 1 {
83 alignmentPattern, e = this.findAlignmentInRegionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#findAlignmentInRegion().(moduleSize,
84 estAlignmentX,
85 estAlignmentY,
86 float64(i))
87 if e == nil {
88 break
89 } else if _, ok := e.(gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.NotFoundExceptionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/NotFoundException#); !ok {
90 return nil, e
91 }
92 }
93 // If we didn't find alignment pattern... well try anyway without it
94 }
95
96 transform := Detector_createTransformscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector_createTransform().(topLeft, topRight, bottomLeft, alignmentPattern, dimension)
97
98 bits, e := Detector_sampleGridscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector_sampleGrid().(this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image., transform, dimension)
99 if e != nil {
100 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)
101 }
102
103 var points []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#
104 if alignmentPattern == nil {
105 points = []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#{bottomLeft, topLeft, topRight}
106 } else {
107 points = []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#{bottomLeft, topLeft, topRight, alignmentPattern}
108 }
109 return commonscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/.NewDetectorResultscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/NewDetectorResult().(bits, points), nil
110 }
111
112 func Detector_createTransformscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector_createTransform().(topLeft, topRight, bottomLeft 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#, alignmentPattern *AlignmentPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/AlignmentPattern#, dimension int) *commonscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/.PerspectiveTransformscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/PerspectiveTransform# {
113 dimMinusThree := float64(dimension) - 3.5
114 var bottomRightX float64
115 var bottomRightY float64
116 var sourceBottomRightX float64
117 var sourceBottomRightY float64
118 if alignmentPattern != nil {
119 bottomRightX = alignmentPattern.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.()
120 bottomRightY = alignmentPattern.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.()
121 sourceBottomRightX = dimMinusThree - 3.0
122 sourceBottomRightY = sourceBottomRightX
123 } else {
124 // Don't have an alignment pattern, just make up the bottom-right point
125 bottomRightX = (topRight.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.() - topLeft.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.()) + bottomLeft.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.()
126 bottomRightY = (topRight.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.() - topLeft.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.()) + bottomLeft.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.()
127 sourceBottomRightX = dimMinusThree
128 sourceBottomRightY = dimMinusThree
129 }
130
131 return commonscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/.PerspectiveTransform_QuadrilateralToQuadrilateralscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/PerspectiveTransform_QuadrilateralToQuadrilateral().(
132 3.5,
133 3.5,
134 dimMinusThree,
135 3.5,
136 sourceBottomRightX,
137 sourceBottomRightY,
138 3.5,
139 dimMinusThree,
140 topLeft.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.(),
141 topLeft.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.(),
142 topRight.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.(),
143 topRight.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.(),
144 bottomRightX,
145 bottomRightY,
146 bottomLeft.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.(),
147 bottomLeft.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.())
148 }
149
150 func Detector_sampleGridscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector_sampleGrid().(image *gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BitMatrixscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#, transform *commonscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/.PerspectiveTransformscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/PerspectiveTransform#, dimension int) (*gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.BitMatrixscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#, error) {
151 sampler := commonscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/.GridSampler_GetInstancescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/GridSampler_GetInstance().()
152 return sampler.SampleGridWithTransformscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common`/GridSampler#SampleGridWithTransform.(image, dimension, dimension, transform)
153 }
154
155 func (this *Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#) computeDimensionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#computeDimension().(topLeft, topRight, bottomLeft 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#, moduleSize float64) (int, error) {
156 tltrCentersDimension := utilscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/.MathUtils_Roundscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/MathUtils_Round().(gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.ResultPoint_Distancescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint_Distance().(topLeft, topRight) / moduleSize)
157 tlblCentersDimension := utilscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/.MathUtils_Roundscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/MathUtils_Round().(gozxingscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/.ResultPoint_Distancescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint_Distance().(topLeft, bottomLeft) / moduleSize)
158 dimension := ((tltrCentersDimension + tlblCentersDimension) / 2) + 7
159 switch dimension % 4 {
160 default: // 1? do nothing
161 break
162 case 0:
163 dimension++
164 break
165 case 2:
166 dimension--
167 break
168 case 3:
169 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().("dimension = %v", dimension)
170 }
171 return dimension, nil
172 }
173
174 func (this *Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#) calculateModuleSizescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#calculateModuleSize().(topLeft, topRight, bottomLeft 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#) float64 {
175 // Take the average
176 return (this.calculateModuleSizeOneWayscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#calculateModuleSizeOneWay().(topLeft, topRight) +
177 this.calculateModuleSizeOneWayscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#calculateModuleSizeOneWay().(topLeft, bottomLeft)) / 2
178 }
179
180 func (this *Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#) calculateModuleSizeOneWayscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#calculateModuleSizeOneWay().(pattern, otherPattern 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#) float64 {
181 moduleSizeEst1 := this.sizeOfBlackWhiteBlackRunBothWaysscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#sizeOfBlackWhiteBlackRunBothWays().(int(pattern.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.()),
182 int(pattern.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.()),
183 int(otherPattern.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.()),
184 int(otherPattern.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.()))
185 moduleSizeEst2 := this.sizeOfBlackWhiteBlackRunBothWaysscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#sizeOfBlackWhiteBlackRunBothWays().(int(otherPattern.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.()),
186 int(otherPattern.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.()),
187 int(pattern.GetXscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetX.()),
188 int(pattern.GetYscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/ResultPoint#GetY.()))
189 if mathscip-go gomod github.com/golang/go/src go1.17 math/.IsNaNscip-go gomod github.com/golang/go/src go1.17 math/IsNaN().(moduleSizeEst1) {
190 return moduleSizeEst2 / 7.0
191 }
192 if mathscip-go gomod github.com/golang/go/src go1.17 math/.IsNaNscip-go gomod github.com/golang/go/src go1.17 math/IsNaN().(moduleSizeEst2) {
193 return moduleSizeEst1 / 7.0
194 }
195 // Average them, and divide by 7 since we've counted the width of 3 black modules,
196 // and 1 white and 1 black module on either side. Ergo, divide sum by 14.
197 return (moduleSizeEst1 + moduleSizeEst2) / 14.0
198 }
199
200 func (this *Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#) sizeOfBlackWhiteBlackRunBothWaysscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#sizeOfBlackWhiteBlackRunBothWays().(fromX, fromY, toX, toY int) float64 {
201
202 result := this.sizeOfBlackWhiteBlackRunscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#sizeOfBlackWhiteBlackRun().(fromX, fromY, toX, toY)
203
204 // Now count other way -- don't run off image though of course
205 scale := float64(1.0)
206 otherToX := fromX - (toX - fromX)
207 if otherToX < 0 {
208 scale = float64(fromX) / float64(fromX-otherToX)
209 otherToX = 0
210 } else if otherToX >= this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image..GetWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#GetWidth().() {
211 scale = float64(this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image..GetWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#GetWidth().()-1-fromX) / float64(otherToX-fromX)
212 otherToX = this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image..GetWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#GetWidth().() - 1
213 }
214 otherToY := int(float64(fromY) - float64(toY-fromY)*scale)
215
216 scale = 1.0
217 if otherToY < 0 {
218 scale = float64(fromY) / float64(fromY-otherToY)
219 otherToY = 0
220 } else if otherToY >= this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image..GetHeightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#GetHeight().() {
221 scale = float64(this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image..GetHeightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#GetHeight().()-1-fromY) / float64(otherToY-fromY)
222 otherToY = this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image..GetHeightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#GetHeight().() - 1
223 }
224 otherToX = int(float64(fromX) + float64(otherToX-fromX)*scale)
225
226 result += this.sizeOfBlackWhiteBlackRunscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#sizeOfBlackWhiteBlackRun().(fromX, fromY, otherToX, otherToY)
227
228 // Middle pixel is double-counted this way; subtract 1
229 return result - 1.0
230 }
231
232 func (this *Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#) sizeOfBlackWhiteBlackRunscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#sizeOfBlackWhiteBlackRun().(fromX, fromY, toX, toY int) float64 {
233 // Mild variant of Bresenham's algorithm;
234 // see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
235 steep := false
236 dx := toX - fromX
237 if dx < 0 {
238 dx = -dx
239 }
240 dy := toY - fromY
241 if dy < 0 {
242 dy = -dy
243 }
244 if dy > dx {
245 steep = true
246 fromX, fromY = fromY, fromX
247 toX, toY = toY, toX
248 dx, dy = dy, dx
249 }
250
251 error := -dx / 2
252 xstep := 1
253 if fromX >= toX {
254 xstep = -1
255 }
256 ystep := 1
257 if fromY >= toY {
258 ystep = -1
259 }
260
261 // In black pixels, looking for white, first or second time.
262 state := 0
263 // Loop up until x == toX, but not beyond
264 xLimit := toX + xstep
265 for x, y := fromX, fromY; x != xLimit; x += xstep {
266 realX := x
267 realY := y
268 if steep {
269 realX = y
270 realY = x
271 }
272
273 // Does current pixel mean we have moved white to black or vice versa?
274 // Scanning black in state 0,2 and white in state 1, so if we find the wrong
275 // color, advance to next state or end if we are in state 2 already
276 if (state == 1) == this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image..Getscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#Get().(realX, realY) {
277 if state == 2 {
278 return utilscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/.MathUtils_DistanceIntscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/MathUtils_DistanceInt().(x, y, fromX, fromY)
279 }
280 state++
281 }
282
283 error += dy
284 if error > 0 {
285 if y == toY {
286 break
287 }
288 y += ystep
289 error -= dx
290 }
291 }
292 // Found black-white-black; give the benefit of the doubt that the next pixel outside the image
293 // is "white" so this last point at (toX+xStep,toY) is the right ending. This is really a
294 // small approximation; (toX+xStep,toY+yStep) might be really correct. Ignore this.
295 if state == 2 {
296 return utilscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/.MathUtils_DistanceIntscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/common/util`/MathUtils_DistanceInt().(toX+xstep, toY, fromX, fromY)
297 }
298 // else we didn't find even black-white-black; no estimate is really possible
299 return mathscip-go gomod github.com/golang/go/src go1.17 math/.NaNscip-go gomod github.com/golang/go/src go1.17 math/NaN().()
300 }
301
302 func (this *Detectorscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#) findAlignmentInRegionscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#findAlignmentInRegion().(overallEstModuleSize float64, estAlignmentX, estAlignmentY int, allowanceFactor float64) (*AlignmentPatternscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/AlignmentPattern#, error) {
303 // Look for an alignment pattern (3 modules in size) around where it
304 // should be
305 allowance := int(allowanceFactor * overallEstModuleSize)
306 alignmentAreaLeftX := estAlignmentX - allowance
307 if alignmentAreaLeftX < 0 {
308 alignmentAreaLeftX = 0
309 }
310 alignmentAreaRightX := estAlignmentX + allowance
311 if a := this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image..GetWidthscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#GetWidth().() - 1; a < alignmentAreaRightX {
312 alignmentAreaRightX = a
313 }
314 if x := float64(alignmentAreaRightX - alignmentAreaLeftX); x < overallEstModuleSize*3 {
315 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().("x = %v, moduleSize = %v", x, overallEstModuleSize)
316 }
317
318 alignmentAreaTopY := estAlignmentY - allowance
319 if alignmentAreaTopY < 0 {
320 alignmentAreaTopY = 0
321 }
322 alignmentAreaBottomY := estAlignmentY + allowance
323 if a := this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image..GetHeightscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing`/BitMatrix#GetHeight().() - 1; a < alignmentAreaBottomY {
324 alignmentAreaBottomY = a
325 }
326
327 if y := float64(alignmentAreaBottomY - alignmentAreaTopY); y < overallEstModuleSize*3 {
328 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().("y = %v, moduleSize = %v", y, overallEstModuleSize)
329 }
330
331 alignmentFinder := NewAlignmentPatternFinderscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/NewAlignmentPatternFinder().(
332 this.imagescip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#image.,
333 alignmentAreaLeftX,
334 alignmentAreaTopY,
335 alignmentAreaRightX-alignmentAreaLeftX,
336 alignmentAreaBottomY-alignmentAreaTopY,
337 overallEstModuleSize,
338 this.resultPointCallbackscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/Detector#resultPointCallback.)
339 return alignmentFinder.Findscip-go gomod github.com/makiuchi-d/gozxing . `github.com/makiuchi-d/gozxing/qrcode/detector`/AlignmentPatternFinder#Find().()
340 }