Forum > Packages and Libraries
[Solved] Looking for QRCODE matrix generator
Fibonacci:
It must just make 2D array with 0 and 1. It must have no dependencies (0 units in uses section, maybe just SysUtils allowed).
It doesnt need to have all features implemented. Just standard text to QR code, one version, one error correction level.
Is there something like that?
If not I will port PHP code, it looks simple
https://github.com/psyon/php-qrcode/blob/master/qrcode.php#L532
Another simple one-file code, in C
https://github.com/nayuki/QR-Code-generator/blob/master/c/qrcodegen.c
Compiled binary just 38 kB and works well, I think I will use it as static linked library in my Pascal app.
My phone recognized valid QR code printed in console :D
Mongkey:
This would help you a lot, you could do it vice versa with pascal app -> bringing all zxing capabilities:
https://forum.lazarus.freepascal.org/index.php/topic,64616.0.html
Fibonacci:
--- Quote from: Mongkey on September 17, 2023, 05:35:44 am ---This would help you a lot:
https://forum.lazarus.freepascal.org/index.php/topic,64616.0.html
--- End quote ---
How? Its Pascal code calling Java bridge which imports many modules including QR generator. I need pure Pascal code that does all the job. No libraries, no imports. Exception would be statically linked library very small in size and without any other dependencies.
To be even more clear: cant use classes, nothing in uses section except for SysUtils.
--- Quote from: Mongkey on September 17, 2023, 05:35:44 am ---« Last Edit: Today at 05:41:26 am by Mongkey »
bringing all zxing capabilities
--- End quote ---
Thats a problem. No libraries.
Mongkey:
Seems you are a hero programmer :D, i live on a real world that needs fast and effective solutions.
Today got many cheap hardwares. Just like my friends said why are banking sector use jvm for its core? We had no any problem with hardware, even it needs 10 times pascal programming cost. But i apreciate your idealisms. And those need real work and many efforts.
Thank you
wp:
--- Quote from: Fibonacci on September 17, 2023, 05:21:36 am ---0 units in uses section, maybe just SysUtils allowed
--- End quote ---
Joking?
OK, let me take up the challenge...
The first thing which comes to my mind is LazBarcodes, available via Online-Package-Manager in Lazarus. It can generate QRCodes in pure Pascal code: https://wiki.lazarus.freepascal.org/LazBarcodes. Although based on the zint library it does not require any external libraries. It is built around Lazarus LCL though, and thus far away from "0 units in uses section".
But there is also a more puristic qrcode generator in the fpc sources: packages/fcl-image; a sample project is in packages/fcl-image/examples. Here is another sample project:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project1; uses fpqrcodegen, fpimgqrcode, fpWritePng; const TEXT_STRING = 'This is a qrcode generated by fpc.'; FILE_NAME = 'qrcode.png';var qrcode: TImageQRCodeGenerator;begin qrcode := TImageQRCodeGenerator.Create; try qrcode.PixelSize := 4; qrcode.Border := 8; qrcode.ErrorCorrectionLevel := EccHigh; qrcode.Generate(TEXT_STRING); qrcode.SaveToFile(FILE_NAME); finally qrcode.Free; end;end.
Or, even more puristic, just 0 and 1, the same code, but skipping the generation of the image. Like this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project2; uses fpqrcodegen; const TEXT_STRING = 'This is a qrcode generated by fpc.';var qrcode: TQRCodeGenerator; x,y: Integer;begin qrcode := TQRCodeGenerator.Create; try qrcode.ErrorCorrectionLevel := EccHigh; qrcode.Generate(TEXT_STRING); for y := 0 to qrcode.Size-1 do begin for x := 0 to qrcode.Size-1 do if qrcode.Bits[x,y] then Write('x') else Write(' '); WriteLn; end; finally qrcode.Free; end; ReadLn;end.
The used unit fpqrcodegen depends only on SysUtils.
--- Quote from: Fibonacci on September 17, 2023, 05:49:26 am ---cant use classes, nothing in uses section except for SysUtils.
--- End quote ---
Looking at fpqrcodegen in more detail I see that the class TQCodeGenerator is just a container to have everything at its own place. You could remove the class from the unit and use the other public functions to do the work. This leads to
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program project3; uses simpleqrcodegen; const TEXT_STRING = 'This is a qrcode generated by fpc.';var x,y: Integer; qrbuffer: TQRBuffer = nil; tmpbuffer: TQRBuffer = nil; size: Integer;begin SetLength(qrBuffer, QRBUFFER_LEN_MAX); SetLength(tmpBuffer, QRBUFFER_LEN_MAX); if QREncodeText(TEXT_STRING, tmpBuffer, qrBuffer, EccHIGH, QRVERSIONMIN, QRVERSIONMAX, mp0, false) then begin size := QRGetSize(qrBuffer); WriteLn('success'); WriteLn('Size: ', size); for y := 0 to size-1 do begin for x := 0 to size-1 do if QRGetModule(qrBuffer, x, y) then Write('x') else Write(' '); WriteLn; end; end; ReadLn;end. Unit "simpleqrcodegen" is the stripped-down version of fpqrcodegen which you can find in the attachment.
Navigation
[0] Message Index
[#] Next page