addPadding pads the encoded data upto the full length required.
()
| 523 | |
| 524 | // addPadding pads the encoded data upto the full length required. |
| 525 | func (q *QRCode) addPadding() { |
| 526 | numDataBits := q.version.numDataBits() |
| 527 | |
| 528 | if q.data.Len() == numDataBits { |
| 529 | return |
| 530 | } |
| 531 | |
| 532 | // Pad to the nearest codeword boundary. |
| 533 | q.data.AppendNumBools(q.version.numBitsToPadToCodeword(q.data.Len()), false) |
| 534 | |
| 535 | // Pad codewords 0b11101100 and 0b00010001. |
| 536 | padding := [2]*bitset.Bitset{ |
| 537 | bitset.New(true, true, true, false, true, true, false, false), |
| 538 | bitset.New(false, false, false, true, false, false, false, true), |
| 539 | } |
| 540 | |
| 541 | // Insert pad codewords alternately. |
| 542 | i := 0 |
| 543 | for numDataBits-q.data.Len() >= 8 { |
| 544 | q.data.Append(padding[i]) |
| 545 | |
| 546 | i = 1 - i // Alternate between 0 and 1. |
| 547 | } |
| 548 | |
| 549 | if q.data.Len() != numDataBits { |
| 550 | log.Panicf("BUG: got len %d, expected %d", q.data.Len(), numDataBits) |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | // ToString produces a multi-line string that forms a QR-code image. |
| 555 | func (q *QRCode) ToString(inverseColor bool) string { |
no test coverage detected