Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 QR Code Generator (with working code), ECC solved!

views
     
TSmentalhealth.my
post Nov 11 2020, 10:04 PM, updated 6y ago

Getting Started
**
Validating
147 posts

Joined: Sep 2015
Has anyone done QR code generator before?

This is one of my KIV project, which I plan to implement in console window, making use of 80x25 or 80x50.

My project cannot cater for large QR code, but maybe Version 1 (21x21) to Version 4 (33x33) given this formula:

QUOTE
4 x version number + 17 dots on each side


The problem is QR codes use an error correction called Reed–Solomon. I fed up whenever I see an invention by Mat Salleh probably because of my inferiority complex. Hence, my project is being kept in view.

Doing a QR code generator is one thing, but doing a QR code reader is another.

I know I am reinventing the wheel, but I want to start from scratch, doing my simpler version of QR code generator (in console mode).

Maybe someone can help?

This post has been edited by mentalhealth.my: Nov 14 2020, 07:44 PM
WongGei
post Nov 11 2020, 11:22 PM

Regular
******
Senior Member
1,206 posts

Joined: Dec 2007
From: Kuala Lumpur
If you wish to learn something by doing a program that generate QR code, that's good. You have to do it yourself then you are able to learn.

This post has been edited by WongGei: Nov 11 2020, 11:22 PM
TSmentalhealth.my
post Nov 12 2020, 12:01 AM

Getting Started
**
Validating
147 posts

Joined: Sep 2015
QUOTE(WongGei @ Nov 11 2020, 11:22 PM)
If you wish to learn something by doing a program that generate QR code, that's good. You have to do it yourself then you are able to learn.
*
If more fellow coders could join, then this QR code generator will be a project by this community and for this community and beyond. biggrin.gif

Found a 2D and 1D barcodes generator written in C: https://sourceforge.net/projects/zint/

This post has been edited by mentalhealth.my: Nov 12 2020, 05:52 PM
WongGei
post Nov 13 2020, 11:02 AM

Regular
******
Senior Member
1,206 posts

Joined: Dec 2007
From: Kuala Lumpur
QUOTE(mentalhealth.my @ Nov 12 2020, 12:01 AM)
If more fellow coders could join, then this QR code generator will be a project by this community and for this community and beyond.  biggrin.gif

Found a 2D and 1D barcodes generator written in C: https://sourceforge.net/projects/zint/
*
I think you got it wrong. QR code standard must be established first, not the program.

https://www.qrcode.com/en/about/standards.html

It has been approved in 1997, means more than 23 years ago. And the draft is probably even older.

Without a standard, there no guideline to follow, more people just create more chaos.

If you wish to make a improved version of it, still, start from the current standard and improve it from there.

There are many library for the current standard, and you should start from there.

Make your standard/code open (open source or open standard) , then ask others to give comment or dive in.
TSmentalhealth.my
post Nov 13 2020, 12:42 PM

Getting Started
**
Validating
147 posts

Joined: Sep 2015
QUOTE(WongGei @ Nov 13 2020, 11:02 AM)
I think you got it wrong. QR code standard must be established first, not the program.

https://www.qrcode.com/en/about/standards.html
» Click to show Spoiler - click again to hide... «

*
Sure.

What I meant is I will use that simple Reed-Solomon encoder written by Cliff Hones in 2004 (included in the Zint API) and take care of the rest myself.

Thanks for the link but its spec is not free. I think Wikipedia has explained it quite well.

I will work on it and keep you all updated. (Most probably in Pascal language)

This post has been edited by mentalhealth.my: Nov 13 2020, 12:43 PM
teckyuan
post Nov 13 2020, 09:37 PM

Getting Started
**
Junior Member
137 posts

Joined: Mar 2008


Written a C# program in VS 2015.

This winform program will convert max input of 4k character to jpg.
Check this out.
https://github.com/teckyuan/qrcode

This post has been edited by teckyuan: Nov 13 2020, 09:38 PM
TSmentalhealth.my
post Nov 14 2020, 12:27 AM

Getting Started
**
Validating
147 posts

Joined: Sep 2015
QUOTE(teckyuan @ Nov 13 2020, 09:37 PM)
Written a C# program in VS 2015.

This winform program will convert max input of 4k character to jpg.
Check this out.
https://github.com/teckyuan/qrcode
*
Your Form1.cs has 52 lines of code and I see it uses ZXing (https://github.com/zxing).

Great work! rclxms.gif
TSmentalhealth.my
post Nov 14 2020, 11:10 AM

Getting Started
**
Validating
147 posts

Joined: Sep 2015
QUOTE(WongGei @ Nov 13 2020, 11:02 AM)
» Click to show Spoiler - click again to hide... «


Make your standard/code open (open source or open standard) , then ask others to give comment or dive in.
*
Hi WongGei and everyone else.

I have created the repo on GitHub: https://github.com/win32app/qrcli

Original output directly from console window which supposed to be scanned and read as "Codemaster LYN", but no, it is not working.
user posted image

I edited the white background to make it high intensity: (also not working)
user posted image


Maybe this time someone can help with error correction codes? I cannot find what is example ECC for EC Level = Low (7 bytes) in v1 QR code.

Is this correct?

CODE
 rs_init_gf(285);
 rs_init_code(7,0);
 rs_encode(14,@data[0],@ecc[0]);
 rs_free;


QUOTE
The QR code specification says to use byte-wise modulo 100011101 arithmetic (where 100011101 is a binary number that is equivalent to 285 in decimal).


rs_init_code accept paramaters:
CODE
procedure rs_init_code(nsym: Integer; index: Integer);


So I just set the nsym to 7 chars?

And PByte is pointer to byte array:
CODE
procedure rs_encode(len: Integer; data: PBYTE; res: PBYTE);


Is it okay to set the len to length of string to be encoded, or must include the final 7 bytes of error correction codes as well? i.e. 14 + 7, or just 14 (maximum length accepted by my program)

v1 (21x21) accepts 17 binary chars (regardless of uppercase + lowercase letter , alphanumeric, all symbols)
And EC low is 7 bytes. Masking pattern is every two row (i.e. black = 0, white = 1, then following row black = 1, white = 0, and repeats)

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

Any input is most welcomed!

This post has been edited by mentalhealth.my: Nov 14 2020, 11:23 AM
angch
post Nov 14 2020, 03:00 PM

On my way
****
Junior Member
636 posts

Joined: Jul 2006
Awesome! Good start. I took a quick glance through, looks alright.
TSmentalhealth.my
post Nov 14 2020, 07:43 PM

Getting Started
**
Validating
147 posts

Joined: Sep 2015
QUOTE(angch @ Nov 14 2020, 03:00 PM)
Awesome! Good start. I took a quick glance through, looks alright.
*
Hey, finally I solved it! This is a decodable QR code. Try to scan.... biggrin.gif
user posted image

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!
TSmentalhealth.my
post Nov 14 2020, 07:49 PM

Getting Started
**
Validating
147 posts

Joined: Sep 2015
One more..... tongue.gif

user posted image

Download Windows 32-bit Executable (no dependency on 3rd party libs) and Pascal source code.
Attached File  qrcli_lyn.zip ( 76.39k ) Number of downloads: 71


To use it, just type

CODE
QRCLI HelloWorld


I don't know if spaces is allowed, because it reads the first command-line parameter only.

This post has been edited by mentalhealth.my: Nov 14 2020, 08:43 PM
TSmentalhealth.my
post Nov 16 2020, 03:01 PM

Getting Started
**
Validating
147 posts

Joined: Sep 2015
I plan to port it to C#, does anyone support this idea?
TSmentalhealth.my
post Dec 1 2020, 06:49 PM

Getting Started
**
Validating
147 posts

Joined: Sep 2015
My QR code generator Explained:


Courtesy of https://en.wikipedia.org/wiki/QR_code
user posted image
QUOTE
The format information records two things: the error correction level and the mask pattern used for the symbol.

My note: It has two pairs of stripes along the 3 x Position square, each pair has 2 stripes containing the format info, with one pair being the duplicate.

Version 1 QR code does not need to have version info, does not have Alignment square, but has timing dots and quiet zone (the white border around the entire matrix)


My QR code generator (both in console app and web app ) are using the following standard:

1. Byte encoding (Mode Indicator), up to 17 characters max.
2. Error correction level = Low (7 bytes)
3. Version 1 (21 x 21, excluding quiet zone)
4. Mask pattern = 1 (dark is 0 on even rows, 1 on odd rows)

Encoding modes
CODE

Indicator  Meaning
0001 Numeric (10 bits per 3 digits)
0010 Alphanumeric (11 bits per 2 characters)
0100 Byte encoding (8 bits per character)
...
...
0000 End of message (Terminator)



Number of bits in a length field
CODE
Encoding Ver. 1–9 10–26 27–40
Numeric  10  12 14
Alphanumeric 9  11 13
Byte  8  16 16
Kanji  8  10 12



Error correction level:

CODE
Level L (Low) 7% of data bytes can be restored.
Level M (Medium) 15% of data bytes can be restored.
Level Q (Quartile) 25% of data bytes can be restored.
Level H (High) 30% of data bytes can be restored.


Please note that in the picture shown on top of this post, E1 ... E7 should contains 7-byte ECC (error correction codes) in reversed order, that is, E1 = ECC[6], E2= ECC[5]....E7=ECC[0].

This post has been edited by mentalhealth.my: Dec 4 2020, 08:15 PM
FlierMate
post Dec 27 2021, 11:09 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
................

This post has been edited by FlierMate: Dec 31 2021, 05:33 PM
FlierMate11
post Nov 8 2022, 08:41 PM

New Member
*
Validating
17 posts

Joined: Oct 2022
Now I have another idea, of creating barcode generator in text mode window.

Is this feasible?

Anyone want to join? I can use C# / Pascal for Windows, or QBasic for DOS.

Example lines created with Alt+ 219 and Alt+ 221 symbol.
user posted image

 

Change to:
| Lo-Fi Version
0.0245sec    1.00    6 queries    GZIP Disabled
Time is now: 24th December 2025 - 09:02 PM