Recent

Author Topic: [Solved] QR Code generator in Pascal?  (Read 5629 times)

anyone

  • Guest
[Solved] QR Code generator in Pascal?
« on: November 12, 2020, 08:01:16 am »
I mean Free Pascal, console app can cater for smaller version of QR code in 80x25, or 80x50 console window.
Maybe version 1 (21x21) to version 4 (33x33)?

According to this formula:
Quote
4 x version number + 17 dots on each side

Is there any built-in library in Free Pascal to generate and/or read QR code?

I wanted to learn by doing it from scratch. But I am hesitant because of the Reed–Solomon error correction used in QR codes. I cannot seem to understand.

Can someone point me in the right direction? Has someone done QR code generator before (e.g. in console window)?
« Last Edit: November 14, 2020, 01:06:55 pm by anyone »

jwdietrich

  • Hero Member
  • *****
  • Posts: 1274
    • formatio reticularis
Re: QR Code generator in Pascal?
« Reply #1 on: November 12, 2020, 09:08:51 am »
The only Pascal implementation of Reed–Solomon error correction I am aware of has been published in a thesis that was accepted by a university in Berlin in 1986. If you don't have problems reading a German text, you can access it (along with code) from https://doi.org/10.14279/depositonce-1815. The code is in a PDF file linked from there.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 4.2.0 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: QR Code generator in Pascal?
« Reply #2 on: November 12, 2020, 09:19:38 am »
Is there any built-in library in Free Pascal to generate and/or read QR code?
https://wiki.lazarus.freepascal.org/LazBarcodes

anyone

  • Guest
Re: QR Code generator in Pascal?
« Reply #3 on: November 12, 2020, 10:37:04 am »
The only Pascal implementation of Reed–Solomon error correction I am aware of has been published in a thesis that was accepted by a university in Berlin in 1986. If you don't have problems reading a German text, you can access it (along with code) from https://doi.org/10.14279/depositonce-1815. The code is in a PDF file linked from there.

I found the Pascal code in Appendix. It is universal language when comes to programming dialect, although I can barely understand it. The discoverer of EC and whoever study the EC deserve credits and due respect.

Anyway, I found the LCC Repo has ported the simple Reed-Solomon encoder written by Cliff Hones in 2004 from C to Pascal.

Thanks jwdietrich!

anyone

  • Guest
Re: QR Code generator in Pascal?
« Reply #4 on: November 12, 2020, 10:41:14 am »
Is there any built-in library in Free Pascal to generate and/or read QR code?
https://wiki.lazarus.freepascal.org/LazBarcodes

Thank you, it uses Zint Barcode Generator as the backend and support all 2D barcodes (no 1D barcodes).

The author Jose Mejuto took great effort to port the original C code mainly written by Robin Stuart to Pascal.

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: QR Code generator in Pascal?
« Reply #5 on: November 12, 2020, 11:19:48 am »
Thank you, it uses Zint Barcode Generator as the backend and support all 2D barcodes (no 1D barcodes).

Quote
LazBarcodes is a set of controls to create 1D and 2D barcodes.
...
Status: In development
The 1D is probably the part that's 'still in development' ::)

At least you can use that code (including lbc_reedsolomon.pas) to see how it's done exactly for a QR code.

anyone

  • Guest
Re: QR Code generator in Pascal?
« Reply #6 on: November 14, 2020, 04:21:16 am »
Thank you, it uses Zint Barcode Generator as the backend and support all 2D barcodes (no 1D barcodes).

Quote
LazBarcodes is a set of controls to create 1D and 2D barcodes.
...
Status: In development
The 1D is probably the part that's 'still in development' ::)

At least you can use that code (including lbc_reedsolomon.pas) to see how it's done exactly for a QR code.

Thanks, the lbc_reedsolomon.pas is the only file I am using in my project.

https://github.com/win32app/qrcli

But it is not working....the QR code in the attached picture is unable to be read....Maybe problem with ECC?

Supposed my v1 (21x21) QR code generator use EC level=Low.

And I limit it to 14 binary data. EC low = 7 bytes. Is this how I call the Reed-Solomon procedure and pass the parameters?
Code: Pascal  [Select][+][-]
  1. rs_init_gf(285);
  2.  rs_init_code(7,0);
  3.  rs_encode(14,@data[0],@ecc[0]);
  4.  rs_free;

If the data is "Codemaster LYN", the code will generate ECC=196 176 115 55 211 250 0. Is this correct?

anyone

  • Guest
Re: QR Code generator in Pascal?
« Reply #7 on: November 14, 2020, 12:51:45 pm »
Hey, finally it is working.

The problem was I forgot to include mode indicator (4-bit) and length of message as part of the data...and my ECC was starts at 1 not 0...finally the ECC should be put in reversed order (6,5,4,3,2,1,0).

Solved!

anyone

  • Guest
Re: QR Code generator in Pascal?
« Reply #8 on: November 14, 2020, 12:54:01 pm »
I made the code open-source, you can download as attachment or go to GitHub repo (might be removed in the future).

Currently only v1 (21x21) QR code is supported. The max length is 17 but my program only allow 14 chars max.
« Last Edit: November 14, 2020, 01:45:05 pm by anyone »

rvk

  • Hero Member
  • *****
  • Posts: 6953
Re: [Solved] QR Code generator in Pascal?
« Reply #9 on: November 14, 2020, 01:31:06 pm »
👍

 

TinyPortal © 2005-2018