News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

QR-Code

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

Previous topic - Next topic

jack

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

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

TimoVJL

#32
from static lib .text:
pFile Data Description Value
00000474 00002486 Size Of RawData 9350
from .obj
.textpFile Data Description Value
00000074 00001A1D Size Of RawData 6685
.datapFile Data Description Value
pFile Data Description Value
00000024 00000004 Size Of RawData 4
.rdatapFile 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.
May the source be with you

jj2007

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?

TimoVJL

#34
// 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);
}
May the source be with you

Biterider

Hi JJ
I posted the asm code above...
Here again, a bit refined

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

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

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

Quote from: Biterider on November 25, 2022, 05:44:25 PM
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:

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

HSE

Quote from: jj2007 on November 26, 2022, 12:53:14 AM
but even my third attempt to install ObjAsm32 failed

:thumbsup: Good try

Quote from: jj2007 on November 26, 2022, 12:53:14 AM
, so I am a bit lost...

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

jj2007

Quote from: HSE on November 26, 2022, 01:56:37 AMIt's not longer ObjAsm32, but ObjAsm-C.1

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

HSE

Quote from: jj2007 on November 26, 2022, 02:00:30 AM
Quote from: HSE on November 26, 2022, 01:56:37 AMIt'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

Quote from: HSE on November 26, 2022, 02:05:41 AMAnyway ObjAsm32 must work.

With CrtDLL.inc, Demo07:
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.

HSE

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

Quote from: TimoVJL on November 25, 2022, 06:19:31 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.

TimoVJL

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