MCPcopy
hub / github.com/skip2/go-qrcode / encode

Method encode

qrcode.go:391–428  ·  view source on GitHub ↗

encode completes the steps required to encode the QR Code. These include adding the terminator bits and padding, splitting the data into blocks and applying the error correction, and selecting the best data mask.

()

Source from the content-addressed store, hash-verified

389// adding the terminator bits and padding, splitting the data into blocks and
390// applying the error correction, and selecting the best data mask.
391func (q *QRCode) encode() {
392 numTerminatorBits := q.version.numTerminatorBitsRequired(q.data.Len())
393
394 q.addTerminatorBits(numTerminatorBits)
395 q.addPadding()
396
397 encoded := q.encodeBlocks()
398
399 const numMasks int = 8
400 penalty := 0
401
402 for mask := 0; mask < numMasks; mask++ {
403 var s *symbol
404 var err error
405
406 s, err = buildRegularSymbol(q.version, mask, encoded, !q.DisableBorder)
407
408 if err != nil {
409 log.Panic(err.Error())
410 }
411
412 numEmptyModules := s.numEmptyModules()
413 if numEmptyModules != 0 {
414 log.Panicf("bug: numEmptyModules is %d (expected 0) (version=%d)",
415 numEmptyModules, q.VersionNumber)
416 }
417
418 p := s.penaltyScore()
419
420 //log.Printf("mask=%d p=%3d p1=%3d p2=%3d p3=%3d p4=%d\n", mask, p, s.penalty1(), s.penalty2(), s.penalty3(), s.penalty4())
421
422 if q.symbol == nil || p < penalty {
423 q.symbol = s
424 q.mask = mask
425 penalty = p
426 }
427 }
428}
429
430// addTerminatorBits adds final terminator bits to the encoded data.
431//

Callers 5

BitmapMethod · 0.95
ImageMethod · 0.95
TestClassifyDataModeFunction · 0.45
TestOptimiseEncodingFunction · 0.45

Calls 8

addTerminatorBitsMethod · 0.95
addPaddingMethod · 0.95
encodeBlocksMethod · 0.95
buildRegularSymbolFunction · 0.85
LenMethod · 0.80
numEmptyModulesMethod · 0.80
penaltyScoreMethod · 0.80

Tested by 3

TestClassifyDataModeFunction · 0.36
TestOptimiseEncodingFunction · 0.36