News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

QR-Code

Started by Biterider, November 21, 2022, 07:52:12 AM

Previous topic - Next topic

jack

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

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.

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


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


Biterider

Hi
Long text UTF-8 test.  :biggrin:

Biterider

jj2007

Nice :thumbsup:

QuoteThe 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--

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".

Biterider

Hi
The original text is a learning text and comes from here.

Biterider

Biterider

Hi Hutch
Thanks for the tip about the CODETWO Desktop Reader. Works well here and saves me time on testing.  :thumbsup:

Biterider

jj2007

Hi Biterider,

What's your character limit?

Quote from: jj2007 on November 24, 2022, 01:03:06 PMThere are several sizes reported on the web:

QuoteModel 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
QuoteA 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

Hi JJ
It depends on what you are encoding:
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

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

Hi Biterider, yes, that makes sense, thanks :thumbsup:

TimoVJL

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

Quote from: TimoVJL on November 25, 2022, 03:40:08 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

https://www.nayuki.io/page/qr-code-generator-library

just static library code size.
May the source be with you