- commit
- 622db714a433d12b4f7ee689a9af37697d6940c2
- parent
- bcdd5e378222dd9f20da94a99c0101d30ebf3a50
- Author
- wangbei <wangbei@qiyi.com>
- Date
- 2019-01-05 12:39
perf: improve img bitmap fill performance
Diffstat
| M | qrcode.go | 11 | ++++++----- |
1 files changed, 6 insertions, 5 deletions
diff --git a/qrcode.go b/qrcode.go
@@ -293,11 +293,11 @@ 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)
-1 296 bgClr := uint8(img.Palette.Index(q.BackgroundColor))
-1 297 fgClr := uint8(img.Palette.Index(q.ForegroundColor))
296 298
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 }
-1 299 for i := range img.Pix {
-1 300 img.Pix[i] = bgClr
301 301 }
302 302
303 303 bitmap := q.symbol.bitmap()
@@ -308,7 +308,8 @@ func (q *QRCode) Image(size int) image.Image {
308 308 startY := y*pixelsPerModule + offset
309 309 for i := startX; i < startX+pixelsPerModule; i++ {
310 310 for j := startY; j < startY+pixelsPerModule; j++ {
311 -1 img.Set(i, j, q.ForegroundColor)
-1 311 pos := img.PixOffset(i, j)
-1 312 img.Pix[pos] = fgClr
312 313 }
313 314 }
314 315 }