Author Topic: QR-Code  (Read 527 times)

jack

  • Member
  • **
  • Posts: 197
Re: QR-Code
« Reply #30 on: November 25, 2022, 06:58:30 AM »
hello TimoVJL  :smiley:
your C code compiles without complaints with the mingw toolchain, I built a dll and it's size before stripping was 92,324 bytes, after strip --strip-unneeded the size was 22,300 bytes
congratulations on the clean C code  :thumbsup:
-- edit -- the size of qrcodegen-demo.exe after stripping was 59K compiled with mingw

jj2007

  • Member
  • *****
  • Posts: 13274
  • Assembly is fun ;-)
    • MasmBasic
Re: QR-Code
« Reply #31 on: November 25, 2022, 08:54:51 AM »
That QR-Code-generator is quite small about 9 kB with Pelles C

It does look very interesting :thumbsup:
qrcodegen_na.exe is 21kBytes, though.
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.

TimoVJL

  • Member
  • *****
  • Posts: 1223
Re: QR-Code
« Reply #32 on: November 25, 2022, 09:11:15 AM »
from static lib .text:
Code: [Select]
pFile Data Description Value
00000474 00002486 Size Of RawData 9350
from .obj
.text
Code: [Select]
pFile Data Description Value
00000074 00001A1D Size Of RawData 6685
.data
Code: [Select]
pFile Data Description Value
pFile Data Description Value
00000024 00000004 Size Of RawData 4
.rdata
Code: [Select]
pFile Data Description Value
0000004C 000001F6 Size Of RawData 502

can't give easily same from msvc made .obj / .lib, as it have  COMDATs.
But if it so important, i might collect that data someway.
like 11936 bytes of code and data.

dll done with Pelles C and using msvcrt.
« Last Edit: November 25, 2022, 10:49:35 PM by TimoVJL »
May the source be with you

jj2007

  • Member
  • *****
  • Posts: 13274
  • Assembly is fun ;-)
    • MasmBasic
Re: QR-Code
« Reply #33 on: November 25, 2022, 11:23:15 AM »
Code: [Select]
includelib qrcodegen_na_msvcrt
qrcodegen_Mask_AUTO = -1
qrcodegen_encodeText PROTO C :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD
qrcodegen_Ecc_HIGH=3
qrcodegen_VERSION_MIN=1 ; The minimum version number supported in the QR Code Model 2 standard
qrcodegen_VERSION_MAX=40 ; The maximum version number supported in the QR Code Model 2 standard
qrcodegen_BUFFER_LEN_MAX=3917
...
.DATA?
qrcode db qrcodegen_BUFFER_LEN_MAX dup(?)
tempBuffer db qrcodegen_BUFFER_LEN_MAX dup(?)
.CODE
LoadQR:
  mov pData, offset qrcode
  invoke qrcodegen_encodeText, Chr$("https://www.nayuki.io/"), addr tempBuffer, addr qrcode,
     qrcodegen_Ecc_HIGH, qrcodegen_VERSION_MIN, qrcodegen_VERSION_MAX, qrcodegen_Mask_AUTO, TRUE

So far, so good: this does not throw an exception, and there is some stuff in the qrcode buffer. But how to get the width & height, and how is that "stuff" encoded?
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.

TimoVJL

  • Member
  • *****
  • Posts: 1223
Re: QR-Code
« Reply #34 on: November 25, 2022, 04:58:02 PM »
Code: [Select]
// Prints the given QR Code to the console.
static void printQr(const uint8_t qrcode[]) {
int size = qrcodegen_getSize(qrcode);
int border = 4;
for (int y = -border; y < size + border; y++) {
for (int x = -border; x < size + border; x++) {
fputs((qrcodegen_getModule(qrcode, x, y) ? "##" : "  "), stdout);
}
fputs("\n", stdout);
}
fputs("\n", stdout);
}
« Last Edit: November 25, 2022, 09:02:05 PM by TimoVJL »
May the source be with you

Biterider

  • Member
  • *****
  • Posts: 1043
  • ObjAsm Developer
    • ObjAsm
Re: QR-Code
« Reply #35 on: November 25, 2022, 05:44:25 PM »
Hi JJ
I posted the asm code above...
Here again, a bit refined

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

  mov esi, dSize
  invoke qrcodegen_getSize, pQrCode
  mov dQrSize, eax
  mov ecx, dBorder
  shl ecx, 1
  add eax, ecx
  xor edx, edx
  mul esi
  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, dBorder
        xor edx, edx
        mul esi
        add eax, sdX
        mov Rct.left, eax
        add eax, esi
        mov Rct.right, eax

        mov eax, edi
        add eax, dBorder
        xor edx, edx
        mul esi
        add eax, sdY
        mov Rct.top, eax
        add eax, esi
        mov Rct.bottom, eax
        lea xdx, Rct
        invoke FillRect, hDC, xdx, hBlackBrush
      .endif
      inc ebx
    .endw
    inc edi
  .endw
  ret
QrDraw endp

A regular call looks like

Code: [Select]
invoke QrDraw, hDC, addr QrCode, QR_OFFSET_X, QR_OFFSET_Y, QR_CELL_SIZE, QR_BORDER
with
  QR_BORDER = 4
  QR_OFFSET_X = 25
  QR_OFFSET_Y = 25
  QR_CELL_SIZE = 5

Biterider

jack

  • Member
  • **
  • Posts: 197
Re: QR-Code
« Reply #36 on: November 25, 2022, 11:38:32 PM »
I wonder if QR could be used to backup small programs on paper and then restored?
say that you split an exe for example into chunks and then create the QR's and print them on paper for backup, how many bytes per page could be saved ?
see https://stackoverflow.com/questions/11065415/how-much-data-information-can-we-save-store-in-a-qr-code

jj2007

  • Member
  • *****
  • Posts: 13274
  • Assembly is fun ;-)
    • MasmBasic
Re: QR-Code
« Reply #37 on: November 26, 2022, 12:53:14 AM »
Hi JJ
I posted the asm code above...
Here again, a bit refined

Hi Biterider,

I am awfully sorry, but even my third attempt to install ObjAsm32 failed, so I am a bit lost...

I've tried hard some years ago, then again some months ago, and now today. There are always cryptic error messages :sad:

Code: [Select]
C:\Masm32\ObjAsm32\Examples\Demo02>make.bat
Project: Demo02
Compiling resources...
Building resource object...
Assembling project...
Linking object modules...

***************************
********** ERROR **********
***************************
C:\Masm32\ObjAsm32\Examples\Demo02>

P.S.:
\Masm32\ObjAsm32\Examples\Demo04\Demo04.asm assembled with make.bat, but the exe complains about htmlhelp.dll missing

Demo05.obj : error LNK2001: unresolved external symbol _HtmlHelpA@16
Demo06: lots of errors, e.g. error A2175:invalid qualified type : TBBUTTONINFO
Demo07, 8, 9: cannot open file : C:\Masm32\Include\CrtDll.inc
Demo11 & 16: \Masm32\Include\Windows.inc(21860) : error A2191:cannot include structure in self DEBUG MODE : ACTIVE -> WND
Demo14 assembles fine but I have no idea what the 2560 byte exe is supposed to do.

\Masm32\ObjAsm32\Projects\XTreeView\Make.bat: error LNK2001: unresolved external symbol _HtmlHelpA@16
...
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.

HSE

  • Member
  • *****
  • Posts: 2253
  • AMD 7-32 / i3 10-64
Re: QR-Code
« Reply #38 on: November 26, 2022, 01:56:37 AM »
but even my third attempt to install ObjAsm32 failed

 :thumbsup: Good try

, so I am a bit lost...

Yes. It's not longer ObjAsm32, but ObjAsm-C.1
Equations in Assembly: SmplMath

jj2007

  • Member
  • *****
  • Posts: 13274
  • Assembly is fun ;-)
    • MasmBasic
Re: QR-Code
« Reply #39 on: November 26, 2022, 02:00:30 AM »
It's not longer ObjAsm32, but ObjAsm-C.1

Ok, thanks. However, I can't see an installer in the 127MB I just downloaded :sad:
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.

HSE

  • Member
  • *****
  • Posts: 2253
  • AMD 7-32 / i3 10-64
Re: QR-Code
« Reply #40 on: November 26, 2022, 02:05:41 AM »
It's not longer ObjAsm32, but ObjAsm-C.1

Ok, thanks. However, I can't see an installer in the 127MB I just downloaded :sad:

Anyway ObjAsm32 must work.

Code: (CrtDll.inc) [Select]
; Thanx to Vortex for his work
;
; To expand the lib definition file:
; link /DLL /def:crtdll.def /NOENTRY /subsystem:windows crtdll.obj

printf      PROTO C :DWORD, :VARARG
sprintf     PROTO C :DWORD,:DWORD, :VARARG
sscanf      PROTO C :DWORD,:DWORD, :VARARG
Equations in Assembly: SmplMath

jj2007

  • Member
  • *****
  • Posts: 13274
  • Assembly is fun ;-)
    • MasmBasic
Re: QR-Code
« Reply #41 on: November 26, 2022, 02:09:53 AM »
Anyway ObjAsm32 must work.

With CrtDLL.inc, Demo07:
Code: [Select]
C:\Masm32\ObjAsm32\Code\Objects\DialogPassword.inc(68) : error A2109:only white space or comment can follow backslash
 StringW(32): Macro Called From
  $OfsCStrW(5): Macro Called From
   $OfsCStr(2): Macro Called From
    C:\Masm32\ObjAsm32\Code\Objects\DialogPassword.inc(68): Include File

And many other errors...

Demo08: \Masm32\ObjAsm32\Code\Objects\Rebar.inc(107) : error A2175:invalid qualified type : TBBUTTONINFO plus 26 other errors.
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.

HSE

  • Member
  • *****
  • Posts: 2253
  • AMD 7-32 / i3 10-64
Re: QR-Code
« Reply #42 on: November 26, 2022, 03:15:28 AM »
Mmm. My installation was a little "tuned" several times. and a lot during lockdown for an specific project. 

No single example is building now, only the big project. Project have 1.7MB of code, perhaps 30000 loc  :biggrin: :biggrin: :biggrin:
Equations in Assembly: SmplMath

jj2007

  • Member
  • *****
  • Posts: 13274
  • Assembly is fun ;-)
    • MasmBasic
Re: QR-Code
« Reply #43 on: November 26, 2022, 07:04:08 AM »
https://www.nayuki.io/page/qr-code-generator-library

just static library code size.

This is good stuff, Timo, but it's an import library that depends on the presence of qrcodegen_na_msvcrt.dll. The only functions used there are memmove and strstr - if you could eliminate them, the DLL would no longer be needed.
Masm32 Tips, Tricks and Traps

Some members can't live without insulting others. It tells us a lot about them.

TimoVJL

  • Member
  • *****
  • Posts: 1223
Re: QR-Code
« Reply #44 on: November 26, 2022, 08:40:05 AM »
Actually dlls was just for examples, so everyone can try them.
Static libraries are usually difficult cases for too many programmers, as they often have linking time problems.
May the source be with you