go-tinyqr

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

commit
dc11ecdae0a9889dc81a343585516404e8dc6ead
parent
bcdd5e378222dd9f20da94a99c0101d30ebf3a50
Author
tfh <tfh@skip.org>
Date
2019-01-10 00:05
Merge pull request #20 from warbaby/img_set_performance

Improve img bitmap fill performance

Diffstat

M qrcode.go 10 +++-------

1 files changed, 3 insertions, 7 deletions


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

@@ -293,12 +293,7 @@ func (q *QRCode) Image(size int) image.Image {
  293   293 	// Saves a few bytes to have them in this order
  294   294 	p := color.Palette([]color.Color{q.BackgroundColor, q.ForegroundColor})
  295   295 	img := image.NewPaletted(rect, p)
  296    -1 
  297    -1 	for i := 0; i < size; i++ {
  298    -1 		for j := 0; j < size; j++ {
  299    -1 			img.Set(i, j, q.BackgroundColor)
  300    -1 		}
  301    -1 	}
   -1   296 	fgClr := uint8(img.Palette.Index(q.ForegroundColor))
  302   297 
  303   298 	bitmap := q.symbol.bitmap()
  304   299 	for y, row := range bitmap {
@@ -308,7 +303,8 @@ func (q *QRCode) Image(size int) image.Image {
  308   303 				startY := y*pixelsPerModule + offset
  309   304 				for i := startX; i < startX+pixelsPerModule; i++ {
  310   305 					for j := startY; j < startY+pixelsPerModule; j++ {
  311    -1 						img.Set(i, j, q.ForegroundColor)
   -1   306 						pos := img.PixOffset(i, j)
   -1   307 						img.Pix[pos] = fgClr
  312   308 					}
  313   309 				}
  314   310 			}