kazuhikoarase / qrcode-generator

QR Code Generator implementation in JavaScript, Java and more.
https://kazuhikoarase.github.io/qrcode-generator/js/demo/
MIT License
2.13k stars 683 forks source link

Brightscript port of QRCode Generator #110

Open ahwayakchih opened 2 years ago

ahwayakchih commented 2 years ago

Hi,

I created an initial port of JS version of qrcode-generator to BrightScript (used to write apps for Roku devices).

Would you be interested in merging this into main qrcode-generator repo? Or should it be a separate "fork" project?

I'll probably keep updating code with time (and use in my apps). I think i'll extract some parts to separate components or merge them into main QRCode component. ot sure yet :).

In any case, this works ok as is. To make a full test you'd have to have a Roku device at hand, but "core" functionality (generating QRCode data, plus turning it into ASCII-like render, same as with JS version) can be tested using brs. I included test and package.json that will use @hulu/roca test runner - all you need is to have a node.js installed (or running in container or VM :)).

npm install
npm test

brs (used by roca) implements only parts of BrightScript and SceneGraph APIs. Generating QRCode with it is A LOT slower than when running it on Roku device, so don't be scared if test runs over 6 seconds. On device it generates data in less than 600ms and turns it into PNG image in another ~350ms (or prints to console as ASCII in ~45ms).

Here's output from npm test command:

bash-5.1$ npm test

> test-brightscript-qrcode-generator@1.0.0 test
> roca

QRBitBuffer
  ✓ can be created
  ✓ has `getBuffer` method
  ✓ has `getLengthInBits` method
  ✓ has `pushBit` method
  ✓ has `put` method
QRCode
  QRCode
    ✓ should generate correct UTF8 text data

  QRPrinter
    ✓ should generate correct UTF8 string from exsiting QRCode
    ✓ should return correct UTF8 string from exsiting QRCode

QRMath
  ✓ glog is working
  ✓ gexp is working

  10 passing (5s)

Here's console output from Roku device running example channel:

06-08 16:11:00.943 [beacon.signal] |AppLaunchInitiate ---------> TimeBase(0 ms)
06-08 16:11:00.943 [beacon.signal] |AppCompileInitiate --------> TimeBase(0 ms)
06-08 16:11:00.945 [scrpt.cmpl] Compiling 'QRCode Generator', id 'dev'
06-08 16:11:00.951 [scrpt.load.mkup] Loading markup dev 'QRCode Generator'
06-08 16:11:00.957 [scrpt.unload.mkup] Unloading markup dev 'QRCode Generator'
06-08 16:11:00.966 [scrpt.parse.mkup.time] Parsed markup dev 'QRCode Generator' in 14 milliseconds

------ Compiling dev 'QRCode Generator' ------
06-08 16:11:01.021 [scrpt.ctx.cmpl.time] Compiled 'QRCode Generator', id 'dev' in 55 milliseconds (BCVer:0)
06-08 16:11:01.022 [scrpt.proc.mkup.time] Processed markup dev 'QRCode Generator' in 0 milliseconds
06-08 16:11:01.025 [beacon.signal] |AppCompileComplete --------> Duration(81 ms)
06-08 16:11:01.030 [ui.frm.plugin.running.enter] Entering PLUGIN_RUNNING for dev
06-08 16:11:01.030 [beacon.signal] |AppLaunchInitiate ---------> TimeBase(0 ms)
06-08 16:11:01.231 [beacon.signal] |AppSplashInitiate ---------> TimeBase(200 ms)
06-08 16:11:01.875 [beacon.signal] |AppSplashComplete ---------> Duration(644 ms)

06-08 16:11:01.969 [scrpt.ctx.run.enter] UI: Entering 'QRCode Generator', id 'dev'
------ Running dev 'QRCode Generator' runuserinterface ------
Init: TestScene
Creating QRCode took:           529ms
Creating PNG took:              361ms
QRCode image created as:        tmp:/a76a272ab306a3d6b1c0ddeed6a44e37.png
█▀▀▀▀▀▀▀█▀▀██▀██▀█▀▀▀██▀▀▀▀▀▀▀█
█ █▀▀▀█ █▄▀█▄▀██▄▄▀ ▀▀█ █▀▀▀█ █
█ █   █ █▄▄▀▄▀█ ▄▀▀█ ██ █   █ █
█ ▀▀▀▀▀ █▀█ ▄ █▀▄▀█ ▄ █ ▀▀▀▀▀ █
█▀█▀▀█▀▀▀▄ ▀██▄█▄ ██▄██▀██▀█▀▀█
███ ▄ █▀█▀▀▀▀▄▀  █▀ ▄▄█ ▄▄█▀▀▄█
█  █▄▀█▀▀  █▀▀█ ▀█▄▄███▄▄█ ▀█▄█
█ ▀▄█▀ ▀▄▄▀▄█ ▀ ▀▄▄▀ ██ █▀▀▀  █
█ ▄█  ▀▀  ▄ ▀ ▄  ▀▄█  ▀█ ▀██ ██
█▀█▀▄█▀▀▀▀█ ▄  ██▄▄▄█▀█▀▀█▀ ▄██
██▀▀██▀▀▀ █▄▀█▀▄█ █▀▀▀ ▀▀▀▀ ███
█▀▀▀▀▀▀▀█ ▄ ██ █ ▄▀ ▀ █▀█  ▄ ▄█
█ █▀▀▀█ █▄▀  ▀█▀▄ ▄ █ ▀▀▀ ▀▀  █
█ █   █ █ █▀▄█ ▄ █▀▄█  █▀▄▄ █ █
█ ▀▀▀▀▀ █▀▀█ █ ▄▄▄ ▀▀ ▄█▄█ █ ██
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Printing to console took:       45ms
06-08 16:11:08.863 [beacon.signal] |AppExitInitiate -----------> TimeBase(7832 ms)
06-08 16:11:08.864 [beacon.header] __________________________________________
06-08 16:11:08.864 [beacon.report] |AppLaunchInitiate ---------> TimeBase(0 ms)
06-08 16:11:08.864 [beacon.report] |AppSplashInitiate ---------> TimeBase(200 ms)
06-08 16:11:08.864 [beacon.report] |AppSplashComplete ---------> Duration(644 ms)
06-08 16:11:08.864 [beacon.report] |AppExitInitiate -----------> TimeBase(7832 ms)
06-08 16:11:08.865 [beacon.report] |AppExitComplete -----------> Duration(1 ms)
06-08 16:11:08.865 [beacon.footer] __________________________________________

Please not that the spacing between blocks depends on the font. In local Terminal i see no spacing, but in this PR's description i see some - depends on font config used on GitHub.

And here's a screenshot from the same run: screenshot