fukuchi / libqrencode

A fast and compact QR Code encoding library
https://fukuchi.org/works/qrencode/
GNU Lesser General Public License v2.1
2.57k stars 599 forks source link

Optimal text segmentation #206

Open RCasatta opened 1 year ago

RCasatta commented 1 year ago

According to https://www.nayuki.io/page/optimal-text-segmentation-for-qr-codes the optimal text segmentation of the string bitcoin:BC1PF4CHVJTQGVWNQ2VURZUJX623JVWUDEYC2MNQUFLXZD0K4FQ870QS40G5XT?amount=0.00000111&label=Prova%20QR&message=Hello results in 821 encoded bits, while it seems a QR encoded from qrencode achieve 832 bits with the following segments:

[Segment { mode: Byte, begin: 0, end: 7 }, Segment { mode: Alphanumeric, begin: 7, end: 70 }, Segment { mode: Byte, begin: 70, end: 119 }]

The optimal segmentation includes a Numeric segment that is not included by qrencode

image

nayuki commented 1 year ago

Note that the optimal text segmentation depends on the version number used. My segmentation is optimal for versions 1 to 26 (though the text requires at least version 5 at low ECC). Fukuchi's segmentation is optimal for version 27 to 40. You can see this when you play with my web page and override the minimum version to at least 27.

Though, after glancing at split.c and qrinput.c, I don't see any obvious explanation for the code's behavior.