go-tinyqr

An experimental minimal QR Code generator  http://go-qrcode.appspot.com
git clone https://git.ce9e.org/go-tinyqr.git

commit
4d19c4c4112d82871ce6cf1cba02a3cdc5860658
parent
fe00d3979fbb456bbcfde6fb5ca6b3bda548652e
Author
Tom Harwood <tfh@skip.org>
Date
2014-04-23 19:08
Fix symbols consisting of a single block not having their remainder bits applied.

Diffstat

M qrcode.go 11 ++++++-----
M qrcode_decode_test.go 5 +++--
M symbol.go 17 +++++++++++++++++

3 files changed, 26 insertions, 7 deletions


diff --git a/qrcode.go b/qrcode.go

@@ -316,6 +316,12 @@ func (q *QRCode) encode(numTerminatorBits int) {
  316   316 			log.Panic(err.Error())
  317   317 		}
  318   318 
   -1   319 		numEmptyModules := s.numEmptyModules()
   -1   320 		if numEmptyModules != 0 {
   -1   321 			log.Panicf("bug: numEmptyModules is %d (expected 0) (version=%d)",
   -1   322 				numEmptyModules, q.VersionNumber)
   -1   323 		}
   -1   324 
  319   325 		p := s.penaltyScore()
  320   326 
  321   327 		//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())
@@ -372,11 +378,6 @@ func (q *QRCode) encodeBlocks() *bitset.Bitset {
  372   378 
  373   379 	// Interleave the blocks.
  374   380 
  375    -1 	// A single block doesn't need interleaving.
  376    -1 	if len(block) == 1 {
  377    -1 		return block[0].data
  378    -1 	}
  379    -1 
  380   381 	result := bitset.New()
  381   382 
  382   383 	// Combine data blocks.

diff --git a/qrcode_decode_test.go b/qrcode_decode_test.go

@@ -152,8 +152,9 @@ func TestDecodeFuzz(t *testing.T) {
  152   152 
  153   153 		var content string
  154   154 		for j := 0; j < len; j++ {
  155    -1 			// zbarimg has trouble with null bytes, hence start from ASCII 1.
  156    -1 			content += string(1+r.Intn(254))
   -1   155 			// zbarimg seems to have trouble with special characters, test printable
   -1   156 			// characters only for now.
   -1   157 			content += string(32+r.Intn(94))
  157   158 		}
  158   159 
  159   160 		for _, level := range []RecoveryLevel{Low, Medium, High, Highest} {

diff --git a/symbol.go b/symbol.go

@@ -73,6 +73,23 @@ func (m *symbol) empty(x int, y int) bool {
   73    73 	return !m.isUsed[y+m.quietZoneSize][x+m.quietZoneSize]
   74    74 }
   75    75 
   -1    76 // numEmptyModules returns the number of empty modules.
   -1    77 //
   -1    78 // Initially numEmptyModules is symbolSize * symbolSize. After every module has
   -1    79 // been set (to either true or false), the number of empty modules is zero.
   -1    80 func (m *symbol) numEmptyModules() int {
   -1    81 	var count int
   -1    82 	for y := 0; y < m.symbolSize; y++ {
   -1    83 		for x := 0; x < m.symbolSize; x++ {
   -1    84 			if !m.isUsed[y + m.quietZoneSize][x + m.quietZoneSize] {
   -1    85 				count++
   -1    86 			}
   -1    87 		}
   -1    88 	}
   -1    89 
   -1    90 	return count
   -1    91 }
   -1    92 
   76    93 // set sets the module at (x, y) to v.
   77    94 func (m *symbol) set(x int, y int, v bool) {
   78    95 	m.module[y+m.quietZoneSize][x+m.quietZoneSize] = v