switch to gozxing for visual similarity with SIX reference impl

The SIX reference implementation in Java that can be found at
https://www.paymentstandards.ch/dam/downloads/qrcodegenerator.java
uses the zxing library to generate their QR codes.

zxing is also available as a Go version, which we now use.
This means the QR codes can be compared visually to the reference.
This commit is contained in:
Michael Stapelberg
2020-11-07 13:11:34 +01:00
parent 6bc1ad3197
commit 11ded9c5ab
3 changed files with 22 additions and 8 deletions

View File

@@ -19,8 +19,10 @@ import (
"image"
"image/draw"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"
"github.com/makiuchi-d/gozxing"
"github.com/makiuchi-d/gozxing/common"
"github.com/makiuchi-d/gozxing/qrcode"
"github.com/makiuchi-d/gozxing/qrcode/decoder"
)
// This is a port of the Java 1.7 reference example from paymentstandards.ch:
@@ -52,15 +54,17 @@ func generateSwissQrCode(payload string) (image.Image, error) {
}
func generateQrCodeImage(payload string) (image.Image, error) {
code, err := qr.Encode(payload, qr.M, qr.Unicode)
w := qrcode.NewQRCodeWriter()
hints := map[gozxing.EncodeHintType]interface{}{
gozxing.EncodeHintType_ERROR_CORRECTION: decoder.ErrorCorrectionLevel_M,
gozxing.EncodeHintType_CHARACTER_SET: common.CharacterSetECI_UTF8,
}
matrix, err := w.Encode(payload, gozxing.BarcodeFormat_QR_CODE, qrCodeEdgeSidePx, qrCodeEdgeSidePx, hints)
if err != nil {
return nil, err
}
qrcode, err := barcode.Scale(code, qrCodeEdgeSidePx, qrCodeEdgeSidePx)
if err != nil {
return nil, err
}
return qrcode, nil
return matrix, nil
}
func overlayWithSwissCross(qrCodeImage image.Image) (image.Image, error) {