Author Topic: QR-Code  (Read 749 times)

jack

  • Member
  • **
  • Posts: 198
Re: QR-Code
« Reply #15 on: November 23, 2022, 02:06:31 AM »
Biterider, did you also build qrencode.exe the command-line front-end ?
did you use Visual studio ?
I tried building zint with visual C but failed due to the library dependencies of libpng and zlib, even though I had built said libraries, but no matter what I tried I could not get it to work

Biterider

  • Member
  • *****
  • Posts: 1041
  • ObjAsm Developer
    • ObjAsm
Re: QR-Code
« Reply #16 on: November 23, 2022, 04:37:00 AM »
Hi jack
I just built the static libraries and compiled the .h file.
As mentioned, I had to remove all CRT dependencies and replace C functions with ObjMem procedures.
To render the QR-Code first run qrcodegen_encodeText and then draw it using standard GDI APIs.

Code: [Select]
Method Application.OnPaint, uses xsi, wParam:WPARAM, lParam:LPARAM
  local PS:PAINTSTRUCT, hDC:HDC, Rct:RECT
  local qrcode[qrcodegen_BUFFER_LEN_MAX]:BYTE, tempBuffer[qrcodegen_BUFFER_LEN_MAX]:BYTE

  QR_BORDER = 4
  QR_OFFSET_X = 25
  QR_OFFSET_Y = 25
  QR_CELL_SIZE = 5

  SetObject xsi
  mov hDC, $invoke(BeginPaint, [xsi].hWnd, addr PS)

  invoke GetClientRect, [xsi].hWnd, addr Rct
  invoke DrawEdge, hDC, addr Rct, EDGE_SUNKEN, BF_RECT

  invoke qrcodegen_encodeText, $OfsCStrA("Hello ObjAsm World", 21h), addr tempBuffer, addr qrcode, \
                               qrcodegen_Ecc_LOW, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, \
                               qrcodegen_Mask_AUTO, TRUE
  .if eax != FALSE
    invoke QrDraw, hDC, addr qrcode, QR_OFFSET_X, QR_OFFSET_Y, QR_CELL_SIZE, QR_BORDER
  .endif
  invoke EndPaint, [xsi].hWnd, addr PS
  xor eax, eax
MethodEnd

Code: [Select]
QrDraw proc uses xbx xdi xsi hDC:HDC, pQrCode:POINTER, sdX:SDWORD, sdY:SDWORD, dSize:DWORD, dBorder:DWORD
  local Rct:RECT, dQrSize:DWORD, hBlackBrush:HBRUSH
  local qrcode[qrcodegen_BUFFER_LEN_MAX]:BYTE, tempBuffer[qrcodegen_BUFFER_LEN_MAX]:BYTE

  mov eax, sizeof(qrcode)
  invoke qrcodegen_getSize, pQrCode
  mov dQrSize, eax
  mov ecx, dBorder
  shl ecx, 1
  add eax, ecx
  mov ecx, dSize
  xor edx, edx
  mul ecx
  mrm Rct.left, sdX, edx
  add edx, eax
  mov Rct.right, edx
  mrm Rct.top, sdY, edx
  add edx, eax
  mov Rct.bottom, edx
  invoke GetStockObject, WHITE_BRUSH
  lea xdx, Rct
  invoke FillRect, hDC, xdx, xax

  invoke GetStockObject, BLACK_BRUSH
  mov hBlackBrush, xax
  xor edi, edi
  .while edi < dQrSize
    xor ebx, ebx
    .while ebx < dQrSize
      invoke qrcodegen_getModule, pQrCode, ebx, edi
      .if eax != 0
        mov eax, ebx
        add eax, QR_BORDER
        mov ecx, QR_CELL_SIZE
        xor edx, edx
        mul ecx
        add eax, QR_OFFSET_X
        mov Rct.left, eax
        add eax, QR_CELL_SIZE
        mov Rct.right, eax

        mov eax, edi
        add eax, QR_BORDER
        mov ecx, QR_CELL_SIZE
        xor edx, edx
        mul ecx
        add eax, QR_OFFSET_Y
        mov Rct.top, eax
        add eax, QR_CELL_SIZE
        mov Rct.bottom, eax
        lea xdx, Rct
        invoke FillRect, hDC, xdx, hBlackBrush
      .endif
      inc ebx
    .endw
    inc edi
  .endw
  ret
QrDraw endp

Attached the .inc file and the 2 libraries. ObjMem.lib is required!  :biggrin:

Biterider

jj2007

  • Member
  • *****
  • Posts: 13302
  • Assembly is fun ;-)
    • MasmBasic
Re: QR-Code
« Reply #17 on: November 23, 2022, 09:52:46 AM »

Biterider

  • Member
  • *****
  • Posts: 1041
  • ObjAsm Developer
    • ObjAsm
Re: QR-Code
« Reply #18 on: November 24, 2022, 12:14:41 AM »
Hi
Long text UTF-8 test.  :biggrin:

Biterider

jj2007

  • Member
  • *****
  • Posts: 13302
  • Assembly is fun ;-)
    • MasmBasic
Re: QR-Code
« Reply #19 on: November 24, 2022, 12:42:15 AM »
Nice :thumbsup:

Quote
The coldest place in the world is the Russian village of Oymyakon. This village is located in the East. About 500 (five hundred) people live there. In the winter the usual temperature is minus fifty (50) degrees Celsius. Once it was minus 71 degrees in the village! But the inhabitants of the village were used to the cold. Everyone knows each other here. Everyone helps each other out.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10005
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: QR-Code
« Reply #20 on: November 24, 2022, 12:44:40 AM »
Just did the same. Looks like Russian.

The coldest place in the world is the Russian village of Oymyakon. This village is located in the East. About 500 (five hundred) people live there. In winter, the usual temperature is minus 50 (fifty) degrees. Once in this village it was minus 71 (seventy one) degrees! But the villagers got used to the cold. Here everyone knows each other. Everyone helps each other.

Used a tool called "CODETWO".
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Biterider

  • Member
  • *****
  • Posts: 1041
  • ObjAsm Developer
    • ObjAsm
Re: QR-Code
« Reply #21 on: November 24, 2022, 12:58:51 AM »
Hi
The original text is a learning text and comes from here.

Biterider

Biterider

  • Member
  • *****
  • Posts: 1041
  • ObjAsm Developer
    • ObjAsm
Re: QR-Code
« Reply #22 on: November 24, 2022, 03:58:47 AM »
Hi Hutch
Thanks for the tip about the CODETWO Desktop Reader. Works well here and saves me time on testing.  :thumbsup:

Biterider

jj2007

  • Member
  • *****
  • Posts: 13302
  • Assembly is fun ;-)
    • MasmBasic
Re: QR-Code
« Reply #23 on: November 24, 2022, 01:31:12 PM »
Hi Biterider,

What's your character limit?

There are several sizes reported on the web:

Quote
Model 1:
The original QR Code, a code capable of coding 1,167 numerals with its maximum version being 14 (73 x 73 modules)

Model 2
This code can encode up to 7,089 numerals with its maximum version being 40 (177 x 177 modules).

https://blinq.me/blog/what-size-should-a-qr-code-be
Quote
A QR code can store up to 4,296 alphanumeric characters of arbitrary text. The text can be anything from contact information, a URL, or even a telephone number.

Biterider

  • Member
  • *****
  • Posts: 1041
  • ObjAsm Developer
    • ObjAsm
Re: QR-Code
« Reply #24 on: November 24, 2022, 06:22:05 PM »
Hi JJ
It depends on what you are encoding:
Code: [Select]
getNumRawDataModules: (from Source code)
 Returns the number of data bits that can be stored in a QR Code of the given version number, after
 all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
 The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.

That means if you encode ASCII chars in the range "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:" that are stored as indices (shorter than 8 bits) you have a huge capacity. It decreases rapidly if you choose other encodings.

Biterider


Biterider

  • Member
  • *****
  • Posts: 1041
  • ObjAsm Developer
    • ObjAsm
Re: QR-Code
« Reply #25 on: November 24, 2022, 08:44:38 PM »
Hi JJ
Further reading in the qrcodegen.h file:

Quote
* In the most optimistic case, a QR Code at version 40 with low ECC
 * can hold any UTF-8 string up to 2953 bytes, or any alphanumeric string
 * up to 4296 characters, or any digit string up to 7089 characters.
 * These numbers represent the hard upper limit of the QR Code standard.

Biterider

jj2007

  • Member
  • *****
  • Posts: 13302
  • Assembly is fun ;-)
    • MasmBasic
Re: QR-Code
« Reply #26 on: November 24, 2022, 10:17:10 PM »
Hi Biterider, yes, that makes sense, thanks :thumbsup:

TimoVJL

  • Member
  • *****
  • Posts: 1231
Re: QR-Code
« Reply #27 on: November 25, 2022, 03:40:08 AM »
That QR-Code-generator is quite small about 9 kB with Pelles C
Later i might give msvc info
May the source be with you

jj2007

  • Member
  • *****
  • Posts: 13302
  • Assembly is fun ;-)
    • MasmBasic
Re: QR-Code
« Reply #28 on: November 25, 2022, 06:11:38 AM »
That QR-Code-generator is quite small about 9 kB with Pelles C

9kB for the call to GetProcAddress, or for a call to the import library?

TimoVJL

  • Member
  • *****
  • Posts: 1231
Re: QR-Code
« Reply #29 on: November 25, 2022, 06:19:31 AM »
May the source be with you