批处理制作二维码生成器
程序员文章站
2022-06-17 13:45:04
这个程序不能直接支持 unicode, 同样不能直接支持任何双字节或多字节字符(包括汉字), 但可以用十六进制转码的方式生成包含 unicode (或其他任何编码)字符的二...
这个程序不能直接支持 unicode, 同样不能直接支持任何双字节或多字节字符(包括汉字), 但可以用十六进制转码的方式生成包含 unicode (或其他任何编码)字符的二维码图形.
如果数据含有utf-8 unicode 字符时, 在数据头部加上 bom (\xef\xbb\xbf) 即可.
例如:
\xef\xbb\xbf\xe6\xb1\x89\xe5\xad\x97
上面的代码表示中文字符 "汉字"
任何 ascii 字符(\x00 到 \xff)都可以用十六进制转码方式输入, 也可以用明文输入(如果可以的话), 十六进制转码用 "\x" 开头, 后跟两位十六进制.
例如: \x20 表示空格
纠错等级有4级可选: l,m,q,h
掩码图形有 8 种可选: 0 到 7 的整数.
已更正的问题: 版本20141113, 当数据中含有双引号时, 有可能导致程序退出.
测试于 win7 64 位 及 xp 32 位
rem if you want to rewrite the registry to automatically set the console font size to 8x8 pixels, please un-remark the next line. rem %1 @goto :initcon @echo off & chcp 437 & mode 200, 200 echo; echo; qrcode.cmd echo; echo; author neorobin -- rewritten in cmd batch @ nov. 12, 2014 echo; echo; author davidshimjs -- qrcode for javascript library echo; see http://www.d-project.com/ echo; see http://jeromeetienne.github.com/jquery-qrcode/ echo; echo; --------------------------------------------------------------------- echo; qrcode for javascript echo; echo; copyright (c) 2009 kazuhiko arase echo; echo; url: http://www.d-project.com/ echo; echo; licensed under the mit license: echo; http://www.opensource.org/licenses/mit-license.php echo; echo; the word "qr code" is registered trademark of echo; denso wave incorporated echo; http://www.denso-wave.com/qrcode/faqpatent-e.html echo; echo; --------------------------------------------------------------------- echo; rem ************************************************************ rem * rem * main program rem * rem ************************************************************ rem if you want to clear some environment variables to speed up running, you can un-remark the next line. call :clearvars setlocal enabledelayedexpansion call :initglobalvars call :quickshow :main.loop rem if the data contains unicode utf-8 characters, you must add the bom data header (\xef\xbb\xbf). rem set "bom=\xef\xbb\xbf" echo; set /p "data=input data:" if "!data!"=="" goto :main.loop set "errorcorrectlevel=" set /p "t=choose a error correct level (l/m/q/h):" for %%a in (l:1 m:0 q:3 h:2) do for /f "tokens=1,2 delims=:" %%v in ("%%a") do if /i "%t%"=="%%v" set "errorcorrectlevel=%%w" if "%errorcorrectlevel%"=="" set "errorcorrectlevel=1" rem a - auto, [0..7] - spec, else random set /p "mp=choose a mask pattern between 0 and 7 :" if /i "!mp!"=="a" ( set "maskpattern=" ) else if "!mp!" geq "0" ( if "!mp!" leq "7" ( set /a "maskpattern = !mp:~0,1!" ) else ( set "mp=r" ) ) else ( set "mp=r" ) if "!mp!"=="r" ( set /a "maskpattern = !random! & 7" ) call :qrcode.makecode data errorcorrectlevel maskpattern goto :main.loop exit rem ************************************************************ rem * rem * functions rem * rem ************************************************************ :qrcode.makecode data errorcorrectlevel maskpattern setlocal enabledelayedexpansion echo; & echo;qrcode.makecode & echo; set "data=!%~1!" set /a "errorcorrectlevel = %~2" set "maskpattern=!%~3!" set data set errorcorrectlevel set maskpattern set "oqrcodemodel.datalist=" call :_gettypenumber typenumber data errorcorrectlevel rem if the initial size of the console is too small to display a large size qr code image, rem you can un-remark the next line to auto resize the console window. rem call :autoresizescr typenumber 20 set typenumber call :qrcodemodel.adddata oqrcodemodel.datalist oqrcodemodel.datacache data set oqrcodemodel.datalist call :qrcodemodel.make oqrcodemodel typenumber errorcorrectlevel maskpattern call :paint oqrcodemodel.modules oqrcodemodel.modulecount endlocal exit /b rem end of :qrcode.makecode rem *** :qrcodemodel.make oqrcodemodel typenumber errorcorrectlevel specifiedmaskpattern setlocal enabledelayedexpansion set "oqrcodemodel.datalist=!%~1.datalist!" set "oqrcodemodel.datacache=!%~1.datacache!" set /a "typenumber = %~2, errorcorrectlevel = %~3" set "bestmaskpattern=!%~4!" if "!bestmaskpattern!"=="" ( call :qrcodemodel.getbestmaskpattern oqrcodemodel typenumber errorcorrectlevel bestmaskpattern ) title qrcode.cmd typenumber: %typenumber%, errorcorrectlevel: %errorcorrectlevel%, bestmaskpattern: %bestmaskpattern% call :qrcodemodel.makeimpl oqrcodemodel typenumber 0 bestmaskpattern errorcorrectlevel ( endlocal set "%~1.modules=%oqrcodemodel.modules%" set "%~1.modules.defined=%oqrcodemodel.modules.defined%" set "%~1.modulecount=%oqrcodemodel.modulecount%" exit /b ) rem end of :qrcodemodel.make rem *** :qrcodemodel.makeimpl oqrcodemodel typenumber test maskpattern errorcorrectlevel setlocal enabledelayedexpansion set /a "typenumber = %~2, test = %~3, maskpattern = %~4, errorcorrectlevel = %~5" set "datalist=!%~1.datalist!" set "datacache=!%~1.datacache!" set /a "modulecount = typenumber * 4 + 17" set "modules=" set /a "imax= modulecount * modulecount, ibytemax = (imax >> 3) + ^!^!(imax & 7), iquadmax = ibytemax << 1" for /l %%i in (1 1 %ibytemax%) do set "modules=00!modules!" set "modules.defined=!modules!" echo;qrcodemodel.setuppositionprobepattern call :qrcodemodel.setuppositionprobepattern modules 0 0 modulecount call :qrcodemodel.setuppositionprobepattern modules "(modulecount - 7)" 0 modulecount call :qrcodemodel.setuppositionprobepattern modules 0 "(modulecount - 7)" modulecount echo;qrcodemodel.setuppositionadjustpattern call :qrcodemodel.setuppositionadjustpattern modules typenumber modulecount echo;qrcodemodel.setuptimingpattern call :qrcodemodel.setuptimingpattern modules modulecount echo;qrcodemodel.setuptypeinfo call :qrcodemodel.setuptypeinfo modules test maskpattern errorcorrectlevel modulecount if !typenumber! geq 7 ( echo;qrcodemodel.setuptypenumber call :qrcodemodel.setuptypenumber modules test typenumber modulecount ) if "%datacache%"=="" ( call :qrcodemodel.createdata datacache typenumber errorcorrectlevel datalist ) call :qrcodemodel.mapdata modules modulecount datacache maskpattern ( endlocal set "%~1.modules=%modules%" set "%~1.modules.defined=%modules.defined%" set "%~1.modulecount=%modulecount%" exit /b ) rem end of :qrcodemodel.makeimpl rem *** :qrcodemodel.getbestmaskpattern oqrcodemodel typenumber errorcorrectlevel bestmaskpattern echo; & echo;qrcodemodel.getbestmaskpattern & echo; setlocal enabledelayedexpansion set "oqrcodemodel.datalist=!%~1.datalist!" set "oqrcodemodel.datacache=!%~1.datacache!" set /a "typenumber = %~2, errorcorrectlevel = %~3" set /a "minlostpoint = 1 << imsb ^ -1, pattern = 0" for /l %%i in (0 1 7) do ( call :qrcodemodel.makeimpl oqrcodemodel typenumber 1 %%i errorcorrectlevel call :qrutil.getlostpoint oqrcodemodel lostpoint echo;pattern: %%i, lostpoint: !lostpoint! if !minlostpoint! gtr !lostpoint! ( set /a "minlostpoint = lostpoint, pattern = %%i" ) ) ( endlocal set "%~4=%pattern%" exit /b ) rem end of :qrcodemodel.getbestmaskpattern rem *** :qrutil.getlostpoint oqrcodemodel.qrcode lostpoint echo; & echo;qrcodemodel.getlostpoint & echo; setlocal enabledelayedexpansion set "modules=!%~1.modules!" set /a "modulecount = %~1.modulecount, lostpoint = 0, rm = modulecount - 1, cm = rm, m_2 = rm - 1" set "leq=-1-" set modulecount for /l %%r in (0 1 %rm%) do for /l %%c in (0 1 %cm%) do ( set /a "samecount = 0, ibs = %%c + %%r * modulecount, iqs = ibs >> 2" for %%a in (!iqs!) do ( set /a "dark = 0x!modules:~%%a,1! >> (3 ^^ (ibs & 3)) & 1" ) for %%l in (-1 0 1) do ( set /a "t = %%r + %%l, t |= modulecount %leq% t" if !t! geq 0 ( for %%f in (-1 0 1) do ( set /a "t = %%c + %%f, t |= modulecount %leq% t" if !t! geq 0 if "%%l%%f" neq "00" ( set /a "ibs1 = ibs + %%f + %%l * modulecount, iqs1 = ibs1 >> 2" for %%a in (!iqs1!) do ( set /a "samecount += ^!(dark ^^ (0x!modules:~%%a,1! >> (3 ^^ (ibs1 & 3)) & 1))" ) ) ) ) ) set /a "lostpoint += (5 - samecount >> imsb) & (samecount - 2)" ) for /l %%r in (0 1 %m_2%) do for /l %%c in (0 1 %m_2%) do ( set "t=0" set /a "ibs = %%c + %%r * modulecount, iqs = ibs >> 2" for %%a in (!iqs!) do ( set /a "t |= 0x!modules:~%%a,1! >> (3 ^^ (ibs & 3)) & 1" ) set /a "ibs += 1, iqs = ibs >> 2" for %%a in (!iqs!) do ( set /a "t |= (0x!modules:~%%a,1! >> (3 ^^ (ibs & 3)) & 1) << 1" ) set /a "ibs += modulecount, iqs = ibs >> 2" for %%a in (!iqs!) do ( set /a "t |= (0x!modules:~%%a,1! >> (3 ^^ (ibs & 3)) & 1) << 2" ) set /a "ibs -= 1, iqs = ibs >> 2" for %%a in (!iqs!) do ( set /a "t |= (0x!modules:~%%a,1! >> (3 ^^ (ibs & 3)) & 1) << 3" ) set /a "lostpoint += (^!t | ^!(t - 0xf)) << imsb >> imsb & 3" ) set /a "m_7 = modulecount - 7" for /l %%r in (0 1 %rm%) do for /l %%c in (0 1 %m_7%) do ( set /a "ibs = %%c + %%r * modulecount, iqs = ibs >> 2, ibs += 6, lenquad = (ibs >> 2) - iqs + 1" for /f "tokens=1-2" %%a in ("!iqs! !lenquad!") do ( set /a "lostpoint += ^!(0x!modules:~%%a,%%b! >> (3 ^^ (ibs & 3)) & 0x7f ^^ 0x5d) << imsb >> imsb & 40" ) ) set /a "m_7 = modulecount - 7" for /l %%c in (0 1 %cm%) do for /l %%r in (0 1 %m_7%) do ( set "t=0" set /a "ibs = %%c + %%r * modulecount, iqs = ibs >> 2" for %%a in (!iqs!) do ( set /a "t |= 0x!modules:~%%a,1! >> (3 ^^ (ibs & 3)) & 1" ) for /l %%d in (1 1 6) do ( set /a "ibs += modulecount, iqs = ibs >> 2" for %%a in (!iqs!) do ( set /a "t |= (0x!modules:~%%a,1! >> (3 ^^ (ibs & 3)) & 1) << %%d" ) ) set /a "lostpoint += ^!(t ^^ 0x5d) << imsb >> imsb & 40" ) set /a "t = modulecount * modulecount, iquadend = t / 4 + ^!^!(t %% 4) - 1" set /a "qstep = wordsize / 4, darkcount = 0" for /l %%i in (0 %qstep% %iquadend%) do ( set /a "t = 0x!modules:~%%i,%qstep%!" for /l %%j in (0 1 %imsb%) do set /a "darkcount += t >> %%j & 1" ) set /a "lostpoint += (x = 200 * darkcount / (modulecount * modulecount) - 100, t = x >> imsb, (t&-x|~t&x))" ( endlocal set "%~2=%lostpoint%" exit /b ) rem end of :qrutil.getlostpoint rem *** :_gettypenumber typenumber stext ncorrectlevel setlocal enabledelayedexpansion set "stext=!%~2!" set /a "ncorrectlevel = %~3, j = ncorrectlevel ^ 1" set "qrcodelimitlength=17_14_11_7 32_26_20_14 53_42_32_24 78_62_46_34 106_84_60_44 134_106_74_58 154_122_86_64 192_152_108_84 230_180_130_98 271_213_151_119 321_251_177_137 367_287_203_155 425_331_241_177 458_362_258_194 520_412_292_220 586_450_322_250 644_504_364_280 718_560_394_310 792_624_442_338 858_666_482_382 929_711_509_403 1003_779_565_439 1091_857_611_461 1171_911_661_511 1273_997_715_535 1367_1059_751_593 1465_1125_805_625 1528_1190_868_658 1628_1264_908_698 1732_1370_982_742 1840_1452_1030_790 1952_1538_1112_842 2068_1628_1168_898 2188_1722_1228_958 2303_1809_1283_983 2431_1911_1351_1051 2563_1989_1423_1093 2699_2099_1499_1139 2809_2213_1579_1219 2953_2331_1663_1273" call :datalist.getlength qrcodelimitlength qrcodelimitlength.length set /a "ntype = 1" call :strlen stext length set "i=0" :_gettypenumber.for_i if %i% geq %qrcodelimitlength.length% goto :_gettypenumber.for_i.break set "nlimit=0" call :{} qrcodelimitlength i qrcodelimitlength[i] call :[] qrcodelimitlength[i] j nlimit if %length% leq %nlimit% ( goto :_gettypenumber.for_i.break ) else ( set /a "ntype += 1" ) set /a "i += 1" goto :_gettypenumber.for_i :_gettypenumber.for_i.break if %ntype% gtr %qrcodelimitlength.length% ( call :throwerror "too long data" ) ( endlocal set "%~1=%ntype%" exit /b ) rem end of :_gettypenumber rem *** :qrrsblock.rs_block_table index arrrt setlocal enabledelayedexpansion set /a "i = %~1 / 31 + 1, j = %~1 %% 31 + 1" for /f "tokens=%i% delims=;" %%a in ("1_26_19 1_26_16 1_26_13 1_26_9 1_44_34 1_44_28 1_44_22 1_44_16 1_70_55 1_70_44 2_35_17 2_35_13 1_100_80 2_50_32 2_50_24 4_25_9 1_134_108 2_67_43 2_33_15_2_34_16 2_33_11_2_34_12 2_86_68 4_43_27 4_43_19 4_43_15 2_98_78 4_49_31 2_32_14_4_33_15 4_39_13_1_40_14 2_121_97 2_60_38_2_61_39 4_40_18_2_41_19;4_40_14_2_41_15 2_146_116 3_58_36_2_59_37 4_36_16_4_37_17 4_36_12_4_37_13 2_86_68_2_87_69 4_69_43_1_70_44 6_43_19_2_44_20 6_43_15_2_44_16 4_101_81 1_80_50_4_81_51 4_50_22_4_51_23 3_36_12_8_37_13 2_116_92_2_117_93 6_58_36_2_59_37 4_46_20_6_47_21 7_42_14_4_43_15 4_133_107 8_59_37_1_60_38 8_44_20_4_45_21 12_33_11_4_34_12 3_145_115_1_146_116 4_64_40_5_65_41 11_36_16_5_37_17 11_36_12_5_37_13 5_109_87_1_110_88 5_65_41_5_66_42 5_54_24_7_55_25 11_36_12 5_122_98_1_123_99 7_73_45_3_74_46;15_43_19_2_44_20 3_45_15_13_46_16 1_135_107_5_136_108 10_74_46_1_75_47 1_50_22_15_51_23 2_42_14_17_43_15 5_150_120_1_151_121 9_69_43_4_70_44 17_50_22_1_51_23 2_42_14_19_43_15 3_141_113_4_142_114 3_70_44_11_71_45 17_47_21_4_48_22 9_39_13_16_40_14 3_135_107_5_136_108 3_67_41_13_68_42 15_54_24_5_55_25 15_43_15_10_44_16 4_144_116_4_145_117 17_68_42 17_50_22_6_51_23 19_46_16_6_47_17 2_139_111_7_140_112 17_74_46 7_54_24_16_55_25 34_37_13 4_151_121_5_152_122 4_75_47_14_76_48 11_54_24_14_55_25 16_45_15_14_46_16 6_147_117_4_148_118;6_73_45_14_74_46 11_54_24_16_55_25 30_46_16_2_47_17 8_132_106_4_133_107 8_75_47_13_76_48 7_54_24_22_55_25 22_45_15_13_46_16 10_142_114_2_143_115 19_74_46_4_75_47 28_50_22_6_51_23 33_46_16_4_47_17 8_152_122_4_153_123 22_73_45_3_74_46 8_53_23_26_54_24 12_45_15_28_46_16 3_147_117_10_148_118 3_73_45_23_74_46 4_54_24_31_55_25 11_45_15_31_46_16 7_146_116_7_147_117 21_73_45_7_74_46 1_53_23_37_54_24 19_45_15_26_46_16 5_145_115_10_146_116 19_75_47_10_76_48 15_54_24_25_55_25 23_45_15_25_46_16 13_145_115_3_146_116 2_74_46_29_75_47 42_54_24_1_55_25 23_45_15_28_46_16;17_145_115 10_74_46_23_75_47 10_54_24_35_55_25 19_45_15_35_46_16 17_145_115_1_146_116 14_74_46_21_75_47 29_54_24_19_55_25 11_45_15_46_46_16 13_145_115_6_146_116 14_74_46_23_75_47 44_54_24_7_55_25 59_46_16_1_47_17 12_151_121_7_152_122 12_75_47_26_76_48 39_54_24_14_55_25 22_45_15_41_46_16 6_151_121_14_152_122 6_75_47_34_76_48 46_54_24_10_55_25 2_45_15_64_46_16 17_152_122_4_153_123 29_74_46_14_75_47 49_54_24_10_55_25 24_45_15_46_46_16 4_152_122_18_153_123 13_74_46_32_75_47 48_54_24_14_55_25 42_45_15_32_46_16 20_147_117_4_148_118 40_75_47_7_76_48 43_54_24_22_55_25;10_45_15_67_46_16 19_148_118_6_149_119 18_75_47_31_76_48 34_54_24_34_55_25 20_45_15_61_46_16") do ( for /f "tokens=%j%" %%b in ("%%a") do ( set "_=%%b" ) ) ( endlocal set "%~2=%_%" exit /b ) rem end of :qrrsblock.rs_block_table rem *** :qrrsblock.getrsblocks typenumber errorcorrectlevel listret setlocal enabledelayedexpansion set /a "typenumber = %~1, errorcorrectlevel = %~2" call :qrrsblock.getrsblocktable typenumber errorcorrectlevel rsblock if "%rsblock%"=="." ( call :throwerror "bad rs block @ typenumber: %typenumber% /errorcorrectlevel: %errorcorrectlevel%" ) call :length rsblock "_" len set /a "i_m = len / 3 - 1" set "list=" for /l %%i in (0 1 %i_m%) do ( call :[] rsblock "(%%i * 3)" count set /a "count_1 = count - 1" call :[] rsblock "(%%i * 3 + 1)" totalcount call :[] rsblock "(%%i * 3 + 2)" datacount for /l %%j in (0 1 !count_1!) do ( set "list=!list!!totalcount!_!datacount! " ) ) ( endlocal set "%~3=%list:~0,-1%" exit /b ) rem end of :qrrsblock.getrsblocks rem *** :qrrsblock.getrsblocktable typenumber errorcorrectlevel arrrt setlocal enabledelayedexpansion set /a "_t = %~2 & ~3" if %_t%==0 ( set /a "index = ((%~1 - 1) << 2) | (%~2 ^ 1)" call :qrrsblock.rs_block_table index ret ) else ( set "ret=." ) ( endlocal set "%~3=%ret%" exit /b ) rem end of :qrrsblock.getrsblocktable rem *** :qrcodemodel.createdata bytes typenumber errorcorrectlevel datalist setlocal enabledelayedexpansion set /a "pad0 = 0xec, pad1 = 0x11" set /a "typenumber = %~2" set "datalist=!%~4!" call :qrrsblock.getrsblocks typenumber errorcorrectlevel rsblocks set "buffer.buffer=" set "buffer.length=0" call :datalist.getlength datalist datalist.length set /a "im = datalist.length - 1" for /l %%i in (0 1 %im%) do ( call :{} datalist %%i data call :qrbitbuffer.put buffer.buffer buffer.length mode_8bit_byte 4 call :qrutil.getlengthinbits mode_8bit_byte typenumber len call :strlen data data.getlength set /a "data.getlength >>= 1" call :qrbitbuffer.put buffer.buffer buffer.length data.getlength len call :qr8bitbyte.write buffer.buffer buffer.length data ) set "totaldatacount=0" for %%a in (%rsblocks%) do ( set "t=%%a" set /a "totaldatacount += !t:_=&0|!" ) set /a "totaldatacount_m8 = totaldatacount << 3" if %buffer.length% gtr %totaldatacount_m8% ( call :throwerror "code length overflow. [%buffer.length% gtr %totaldatacount_m8%]" ) set /a "t = buffer.length + 4" if %t% leq %totaldatacount_m8% ( call :qrbitbuffer.put buffer.buffer buffer.length 0 4 ) set /a "im = buffer.length & 7 ^ 7" if %im% neq 7 ( for /l %%i in (0 1 %im%) do call :qrbitbuffer.putbit buffer.buffer buffer.length 0 ) :qrcodemodel.createdata.while_true if %buffer.length% geq %totaldatacount_m8% goto :qrcodemodel.createdata.break call :qrbitbuffer.put buffer.buffer buffer.length pad0 8 if %buffer.length% geq %totaldatacount_m8% goto :qrcodemodel.createdata.break call :qrbitbuffer.put buffer.buffer buffer.length pad1 8 goto :qrcodemodel.createdata.while_true :qrcodemodel.createdata.break call :qrcodemodel.createbytes bytes buffer.buffer rsblocks ( endlocal set "%~1=%bytes%" exit /b ) rem end of :qrcodemodel.createdata rem *** :qrcodemodel.mapdata modules modulecount datacache maskpattern setlocal enabledelayedexpansion set "m=!%~1!" set "m.def=!%~1.defined!" set "data=!%~3!" set /a "modulecount = %~2, modulecount_1 = modulecount - 1, "^ "inc = -1, row = modulecount_1, bitindex = 7, iquad = 0, maskpattern = %~4" set "leq=-1-" call :strlen data data.quadlen set "$0=~(row+rnk)&1" set "$1=~row&1" set "$2=^!(rnk %% 3)" set "$3=^!((row+rnk) %% 3)" set "$4=~((row>>1)+rnk/3)&1" set "$5=(t=row*rnk,^!(t&1)&^!(t %% 3))" set "$6=(t=row*rnk,~((t&1)+t %% 3)&1)" set "$7=~(row*rnk %% 3+((row+rnk)&1))&1" set /a "col = modulecount_1" :qrcodemodel.mapdata.for_col <nul set /p "=%bs%%bs%%bs%%bs%%bs%%bs%%bs%%bs%%bs%%bs%%bs%%bs%%bs%%bs%%bs%%bs%%bs%column: %col%/%modulecount_1% " if %col% leq 0 goto :qrcodemodel.mapdata.for_col.end set /a "t = ^!(col ^^ 6) << imsb >> imsb, col = t & 5 | ~t & col" :qrcodemodel.mapdata.while_true for %%c in (0 1) do ( set /a "rnk = col - %%c, ibs = rnk + row * modulecount, lenl = ibs >> 2, bit = 1 << (3 ^ (ibs & 3))" for %%a in (!lenl!) do ( set /a "quad.def = 0x!m.def:~%%a,1! & bit" ) if !quad.def!==0 ( set "dark=0" if !iquad! lss %data.quadlen% ( for %%i in (!iquad!) do ( set /a "dark = (0x!data:~%%i,2! >> bitindex) & 1" ) ) for %%i in (%maskpattern%) do set /a "mask = !$%%i!, dark ^^= mask" set /a "sbb = dark << imsb >> imsb, ind = lenl + 1, lenr = iquadmax - ind" for %%a in (!lenl!) do ( set /a "quad = 0x!m:~%%a,1!, quad = sbb & (bit | quad) | ~sbb & (~bit & quad), "^ "quad.def = 0x!m.def:~%%a,1! | bit" ) for /f "tokens=1-5" %%a in ("!lenl! !ind! !lenr! #!quad! #!quad.def!") do ( set "m=!m:~0,%%a!!%%d!!m:~%%b,%%c!" set "m.def=!m.def:~0,%%a!!%%e!!m.def:~%%b,%%c!" ) set /a "bitindex -= 1, t = bitindex >> imsb, bitindex = t & 7 | ~t & bitindex, iquad += t & 2" ) ) set /a "row += inc, t = row | modulecount %leq% row" if %t% lss 0 ( set /a "row -= inc, inc = -inc" goto :qrcodemodel.mapdata.while_true.break ) goto :qrcodemodel.mapdata.while_true :qrcodemodel.mapdata.while_true.break set /a "col -= 2" goto :qrcodemodel.mapdata.for_col :qrcodemodel.mapdata.for_col.end ( endlocal set "%~1=%m%" set "%~1.defined=%m.def%" exit /b ) rem end of :qrcodemodel.mapdata rem *** :datalist.getlength datalist datalist.length setlocal enabledelayedexpansion if "!%~1!"=="." ( set "length=0" ) else ( set "t=!%~1!" set "t1=!t: =!" call :strlen t len call :strlen t1 len1 set /a "length = len - len1 + 1" ) ( endlocal set "%~2=%length%" exit /b ) rem end of :datalist.getlength rem *** :qr8bitbyte.write qrbitbuffer.buffer qrbitbuffer.length qr8bitbyte.parseddata setlocal enabledelayedexpansion set "buf=!%~1!" set "buf.len=!%~2!" set "pd=!%~3!" call :strlen pd pd.len set /a "im = pd.len - 2" for /l %%i in (0 2 %im%) do ( set /a "num = 0x!pd:~%%i,2!" call :qrbitbuffer.put buf buf.len num 8 ) ( endlocal set "%~1=%buf%" set "%~2=%buf.len%" exit /b ) rem end of :qr8bitbyte.write rem *** :qrcodemodel.createbytes bytes qrbitbuffer.buffer rsblocks setlocal enabledelayedexpansion set /a "offset = 0, maxdccount = 0, maxeccount = 0" set "rsbs=!%~3!" call :datalist.getlength rsbs rmax set /a "rmax -= 1" set "dcdata=" set "ecdata=" for /l %%r in (0 1 %rmax%) do ( call :{} rsbs %%r rsbs[r] call :[] rsbs[r] 1 dccount call :[] rsbs[r] 0 rsbs[r].tc set /a "eccount = rsbs[r].tc - dccount, dcc_1 = dccount - 1,"^ "t = maxdccount - dccount >> imsb, maxdccount = t & dccount | ~t & maxdccount,"^ "t = maxeccount - eccount >> imsb, maxeccount = t & eccount | ~t & maxeccount" for /l %%i in (0 1 !dcc_1!) do ( set /a "_i = (%%i + offset) << 1" for %%a in (!_i!) do set "dcdata=!dcdata!!%~2:~%%a,2!" ) set "dcdata=!dcdata! " set /a "offset += dccount" call :qrutil.geterrorcorrectpolynomial eccount rspoly call :strlen rspoly rspoly.getlength set /a "shift = rspoly.getlength - 2 >> 1" call :{} dcdata %%r dcdata[r] call :qrpolynomial.qrpolynomial rawpoly dcdata[r] shift call :qrpolynomial.mod rawpoly rspoly modpoly call :strlen modpoly modpoly.getlength set /a "ecdata[r].length = rspoly.getlength - 2" set /a "j = modpoly.getlength - ecdata[r].length" set /a "is = j, im = ecdata[r].length - 2 + j" for /l %%i in (!is! 2 !im!) do ( if %%i geq 0 ( set "ecdata=!ecdata!!modpoly:~%%i,2!" ) else ( set "ecdata=!ecdata!00" ) ) set "ecdata=!ecdata! " ) set "ecdata=%ecdata:~0,-1%" set "dcdata=%dcdata:~0,-1%" set "totalcodecount=0" for %%a in (%rsbs%) do ( set "t=%%a" set /a "totalcodecount += !t:_=|0&!" ) set "data=" set /a "im = maxdccount - 1 << 1" for /l %%i in (0 2 %im%) do ( for /l %%r in (0 1 %rmax%) do ( call :{} dcdata %%r dcdata[r] call :strlen dcdata[r] dcdata[r].length if %%i lss !dcdata[r].length! ( set "data=!data!!dcdata[r]:~%%i,2!" ) ) ) set /a "im = maxeccount - 1 << 1" for /l %%i in (0 2 %im%) do ( for /l %%r in (0 1 %rmax%) do ( call :{} ecdata %%r ecdata[r] call :strlen ecdata[r] ecdata[r].length if %%i lss !ecdata[r].length! ( set "data=!data!!ecdata[r]:~%%i,2!" ) ) ) set /a "im = totalcodecount - 2" call :strlen data data.len for /l %%i in (%data.len% 2 %im%) do ( set "data=!data!00" ) ( endlocal set "%~1=%data%" exit /b ) rem end of :qrcodemodel.createbytes rem *** :qrutil.geterrorcorrectpolynomial errorcorrectlength arrret setlocal enabledelayedexpansion set "a=01" set /a "im = %~1 - 1 << 1" for /l %%i in (0 2 %im%) do ( set "num=01!exp_table:~%%i,2!" call :qrpolynomial.qrpolynomial poly num 0 call :qrpolynomial.multiply a poly a ) ( endlocal set "%~2=%a%" exit /b ) rem end of :qrutil.geterrorcorrectpolynomial rem *** :qrpolynomial.mod this e mod setlocal enabledelayedexpansion set "this=!%~1!" set "e=!%~2!" :qrpolynomial.mod.loop call :strlen this this.getlength call :strlen e e.getlength if %this.getlength% lss %e.getlength% ( goto :qrpolynomial.mod.end ) set /a "a = 0x!this:~0,2! << 1, b = 0x!e:~0,2! << 1" for /f "tokens=1-2" %%a in ("!a! !b!") do ( set /a "ratio = 0x!log_table:~%%a,2! - 0x!log_table:~%%b,2!" ) set "num=%this%" set /a "im = e.getlength - 2" for /l %%i in (0 2 %im%) do ( set /a "e[i] = 0x!e:~%%i,2! << 1" for %%a in (!e[i]!) do ( set /a "p = 0x!log_table:~%%a,2! + ratio, t=(p^^p-256)>>imsb, r=p %% 255, c = ^!r <<imsb>>imsb, p = (t & p | ~t & r + ((p>>imsb ^^ c) & 255)) << 1" ) set /a "ind = %%i + 2, lenr = this.getlength - ind" for %%a in (!p!) do ( set /a "n = 0x!num:~%%i,2! ^^ 0x!exp_table:~%%a,2!" ) set /a "h4 = n >> 4, l4 = n & 0xf" for /f "tokens=1-4" %%v in ("!ind! !lenr! #!h4! #!l4!") do set "num=!num:~0,%%i!!%%x!!%%y!!num:~%%v,%%w!" ) call :qrpolynomial.qrpolynomial this num 0 goto :qrpolynomial.mod.loop :qrpolynomial.mod.end ( endlocal set "%~3=%this%" exit /b ) rem end of :qrpolynomial.mod rem *** :qrpolynomial.multiply this e multi setlocal enabledelayedexpansion set "this=!%~1!" set "e=!%~2!" call :strlen this this.getlength call :strlen e e.getlength set /a "len = this.getlength + e.getlength - 2, im = this.getlength - 2, jm = e.getlength - 2" set "num=" for /l %%i in (1 1 %len%) do set "num=!num!0" for /l %%i in (0 2 %im%) do ( for /l %%j in (0 2 %jm%) do ( set /a "a = 0x!this:~%%i,2! << 1, b = 0x!e:~%%j,2! << 1" for /f "tokens=1-2" %%a in ("!a! !b!") do ( set /a "p = 0x!log_table:~%%a,2! + 0x!log_table:~%%b,2!" ) set /a "t=(p^^p-256)>>imsb, r=p %% 255, c = ^!r <<imsb>>imsb, p = (t & p | ~t & r + ((p>>imsb ^^ c) & 255)) << 1" set /a "lenl = %%i + %%j, ind = lenl + 2, lenr = len - ind" for /f "tokens=1-2" %%a in ("!lenl! !p!") do ( set /a "n = 0x!num:~%%a,2! ^^ 0x!exp_table:~%%b,2!" ) set /a "h4 = n >> 4, l4 = n & 0xf" for /f "tokens=1-5" %%u in ("!lenl! !ind! !lenr! #!h4! #!l4!") do set "num=!num:~0,%%u!!%%x!!%%y!!num:~%%v,%%w!" ) ) call :qrpolynomial.qrpolynomial t num 0 ( endlocal set "%~3=%t%" exit /b ) rem end of :qrpolynomial.multiply rem *** :qrpolynomial.qrpolynomial this.num num shift setlocal enabledelayedexpansion if "!%~2!"=="" ( call :throwerror "@qrpolynomial.qrpolynomial num:[%~2] / shift=[%~3]" ) set "num=!%~2!" set "offset=0" :qrpolynomial.qrpolynomial.l1 set /a "offs = offset << 1" for %%i in (%offs%) do set "num{offset}=!num:~%%i,2!" call :strlen num num.length set /a "num.length >>= 1" set /a "t = (offset - num.length) & (^! 0x%num{offset}% << imsb)" if %t% lss 0 ( set /a "offset += 1" goto :qrpolynomial.qrpolynomial.l1 ) set /a "im = num.length - offset - 1" for /l %%i in (0 1 %im%) do ( set /a "i_offset = %%i + offset << 1" for %%a in (!i_offset!) do set "this_num=!this_num!!num:~%%a,2!" ) set /a "shift = %~3" for /l %%i in (1 1 %shift%) do ( set "this_num=!this_num!00" ) ( endlocal set "%~1=%this_num%" exit /b ) rem end of :qrpolynomial.qrpolynomial rem *** :qrcodemodel.setuptypenumber modules test typenumber modulecount setlocal enabledelayedexpansion set "t=!%~1!" set "t.def=!%~1.defined!" set /a "typenumber = %~3" call :qrutil.getbchtypenumber bits typenumber for /l %%i in (0 1 17) do ( set /a "bit = ^!%~2 & ((bits >> %%i) & 1)" set /a "sbb = bit << imsb >> imsb, "^ "ibs = (%%i %% 3 + %~4 - 11) + (%%i / 3) * %~4, lenl = ibs >> 2, ind = lenl + 1, lenr = iquadmax - ind, bit = 1 << (3 ^ (ibs & 3))" for %%a in (!lenl!) do ( set /a "quad = 0x!t:~%%a,1!, quad = sbb & (bit | quad) | ~sbb & (~bit & quad), "^ "quad.def = 0x!t.def:~%%a,1! | bit" ) for /f "tokens=1-5" %%a in ("!lenl! !ind! !lenr! #!quad! #!quad.def!") do ( set "t=!t:~0,%%a!!%%d!!t:~%%b,%%c!" set "t.def=!t.def:~0,%%a!!%%e!!t.def:~%%b,%%c!" ) ) for /l %%i in (0 1 17) do ( set /a "bit = ^!%~2 & ((bits >> %%i) & 1)" set /a "sbb = bit << imsb >> imsb, "^ "ibs = (%%i / 3) + (%%i %% 3 + %~4 - 11) * %~4, lenl = ibs >> 2, ind = lenl + 1, lenr = iquadmax - ind, bit = 1 << (3 ^ (ibs & 3))" for %%a in (!lenl!) do ( set /a "quad = 0x!t:~%%a,1!, quad = sbb & (bit | quad) | ~sbb & (~bit & quad), "^ "quad.def = 0x!t.def:~%%a,1! | bit" ) for /f "tokens=1-5" %%a in ("!lenl! !ind! !lenr! #!quad! #!quad.def!") do ( set "t=!t:~0,%%a!!%%d!!t:~%%b,%%c!" set "t.def=!t.def:~0,%%a!!%%e!!t.def:~%%b,%%c!" ) ) ( endlocal set "%~1=%t%" set "%~1.defined=%t.def%" exit /b ) rem end of :qrcodemodel.setuptypenumber rem *** :qrcodemodel.setuptypeinfo modules test maskpattern errorcorrectlevel modulecount setlocal enabledelayedexpansion set "t=!%~1!" set "t.def=!%~1.defined!" set /a "data = %~4 << 3 | %~3" call :qrutil.getbchtypeinfo bits data for /l %%i in (0 1 14) do ( if %%i lss 6 ( set "r=%%i" ) else if %%i lss 8 ( set /a "r = %%i + 1" ) else ( set /a "r = %~5 - 15 + %%i" ) set /a "bit = ^!%~2 & ((bits >> %%i) & 1)" set /a "sbb = bit << imsb >> imsb, "^ "ibs = 8 + r * %~5, lenl = ibs >> 2, ind = lenl + 1, lenr = iquadmax - ind, bit = 1 << (3 ^ (ibs & 3))" for %%a in (!lenl!) do ( set /a "quad = 0x!t:~%%a,1!, quad = sbb & (bit | quad) | ~sbb & (~bit & quad), "^ "quad.def = 0x!t.def:~%%a,1! | bit" ) for /f "tokens=1-5" %%a in ("!lenl! !ind! !lenr! #!quad! #!quad.def!") do ( set "t=!t:~0,%%a!!%%d!!t:~%%b,%%c!" set "t.def=!t.def:~0,%%a!!%%e!!t.def:~%%b,%%c!" ) ) for /l %%i in (0 1 14) do ( if %%i lss 8 ( set /a "c = %~5 - %%i - 1" ) else if %%i lss 9 ( set /a "c = 15 - %%i" ) else ( set /a "c = 14 - %%i" ) set /a "bit = ^!%~2 & ((bits >> %%i) & 1), mod = bit" set /a "sbb = bit << imsb >> imsb, "^ "ibs = c + 8 * %~5, lenl = ibs >> 2, ind = lenl + 1, lenr = iquadmax - ind, bit = 1 << (3 ^ (ibs & 3))" for %%a in (!lenl!) do ( set /a "quad = 0x!t:~%%a,1!, quad = sbb & (bit | quad) | ~sbb & (~bit & quad), "^ "quad.def = 0x!t.def:~%%a,1! | bit" ) for /f "tokens=1-5" %%a in ("!lenl! !ind! !lenr! #!quad! #!quad.def!") do ( set "t=!t:~0,%%a!!%%d!!t:~%%b,%%c!" set "t.def=!t.def:~0,%%a!!%%e!!t.def:~%%b,%%c!" ) ) set /a "bit = mod" set /a "sbb = bit << imsb >> imsb, "^ "ibs = 8 + (%~5 - 8) * %~5, lenl = ibs >> 2, ind = lenl + 1, lenr = iquadmax - ind, bit = 1 << (3 ^ (ibs & 3))" for %%a in (!lenl!) do ( set /a "quad = 0x!t:~%%a,1!, quad = sbb & (bit | quad) | ~sbb & (~bit & quad), "^ "quad.def = 0x!t.def:~%%a,1! | bit" ) for /f "tokens=1-5" %%a in ("!lenl! !ind! !lenr! #!quad! #!quad.def!") do ( set "t=!t:~0,%%a!!%%d!!t:~%%b,%%c!" set "t.def=!t.def:~0,%%a!!%%e!!t.def:~%%b,%%c!" ) ( endlocal set "%~1=%t%" set "%~1.defined=%t.def%" exit /b ) rem end of :qrcodemodel.setuptypeinfo rem *** :qrutil.getbchtypeinfo bchtypeinfo data setlocal enabledelayedexpansion set /a "d = %~2 << 10" :qrutil.getbchtypeinfo.l1 call :qrutil.getbchdigit d.digit d set /a "_d = d.digit - g15.dgt" if !_d! geq 0 ( set /a "d ^= g15 << _d" goto :qrutil.getbchtypeinfo.l1 ) set /a "_ = (%~2 << 10 | d) ^ g15_mask" ( endlocal set "%~1=%_%" exit /b ) rem end of :qrutil.getbchtypeinfo rem *** :qrutil.getbchtypenumber bchtypenumber data setlocal enabledelayedexpansion set /a "d = %~2 << 12" :qrutil.getbchtypenumber.l1 call :qrutil.getbchdigit d.digit d set /a "_d = d.digit - g18.dgt" if !_d! geq 0 ( set /a "d ^= g18 << _d" goto :qrutil.getbchtypenumber.l1 ) set /a "_ = %~2 << 12 | d" ( endlocal set "%~1=%_%" exit /b ) rem end of :qrutil.getbchtypenumber rem *** :qrutil.getbchdigit digit data setlocal enabledelayedexpansion set /a "t = %~2" if %t% lss 0 ( set "_=%wordsize%" ) else ( set /a "t <<= 1" set "_=0" for %%i in (16 8 4 2 1) do ( set /a "_i = ~-^!(t >> %%i) & %%i, _ |= _i, t >>= _i" ) ) ( endlocal set "%~1=%_%" exit /b ) rem end of :qrutil.getbchdigit rem *** :qrcodemodel.setuppositionadjustpattern modules typenumber modulecount setlocal enabledelayedexpansion call :qrutil.pattern_position_table "(%~2 - 1)" pos call :length pos "_" pos.length set "t=!%~1!" set "t.def=!%~1.defined!" set /a "l_1 = pos.length - 1" for /l %%i in (0 1 %l_1%) do ( for /l %%j in (0 1 %l_1%) do ( call :[] pos %%i row call :[] pos %%j col set /a "ibs = col + row * %~3, iqs = ibs >> 2, bit = 1 << (3 ^ (ibs & 3))" for %%a in (!iqs!) do ( set /a "quad.def = 0x!t.def:~%%a,1! & bit" ) if !quad.def!==0 ( for /l %%r in (-2 1 2) do ( for /l %%c in (-2 1 2) do ( set /a "bit = ^!(%%r & 3 ^^ 2) | ^!(%%c & 3 ^^ 2) | ^!(%%r | %%c), sbb = bit << imsb >> imsb" set /a "ibs = col + %%c + (row + %%r) * %~3, lenl = ibs >> 2, ind = lenl + 1, lenr = iquadmax - ind, bit = 1 << (3 ^ (ibs & 3))" for %%a in (!lenl!) do ( set /a "quad = 0x!t:~%%a,1!, quad = sbb & (bit | quad) | ~sbb & (~bit & quad), "^ "quad.def = 0x!t.def:~%%a,1! | bit" ) for /f "tokens=1-5" %%a in ("!lenl! !ind! !lenr! #!quad! #!quad.def!") do ( set "t=!t:~0,%%a!!%%d!!t:~%%b,%%c!" set "t.def=!t.def:~0,%%a!!%%e!!t.def:~%%b,%%c!" ) ) ) ) ) ) ( endlocal set "%~1=%t%" set "%~1.defined=%t.def%" exit /b ) rem end of :qrcodemodel.setuppositionadjustpattern rem *** :{} list index vret setlocal enabledelayedexpansion set "t=!%~1!" set /a "i = %~2" if %i% leq 0 ( for /f %%a in ("%t%") do set "_=%%a" goto :{}.end ) set /a "i1 = i + 1" :{}.loop1 if %i1% gtr 31 ( for /f "tokens=31*" %%a in ("%t%") do set "t=%%b" set /a "i1 -= 31" goto :{}.loop1 ) for /f "tokens=%i1%" %%a in ("%t%") do set "_=%%a" :{}.end ( endlocal set "%~3=%_%" exit /b ) rem end of :{} rem *** :[] array index vrt setlocal enabledelayedexpansion set "_=" set /a "t=%~2 + 1" if "!%~1!" neq "." ( for /f "tokens=%t% delims=_" %%a in ("!%~1!") do set "_=%%a" ) ( endlocal set "%~3=%_%" exit /b ) rem end of :[] rem *** :length list delim len setlocal enabledelayedexpansion if "!%~1!"=="." ( set "_=0" ) else ( set /a "_=1+(!%~1:%~2=&0)+1+(0&!)" ) ( endlocal set "%~3=%_%" exit /b ) rem end of :length rem *** :qrutil.pattern_position_table index arrrt setlocal enabledelayedexpansion set /a "t=%~1, p=t-31" if %t% leq 0 ( set "_=." ) else if %p% leq 0 ( for /f "tokens=%t%" %%a in ("6_18 6_22 6_26 6_30 6_34 6_22_38 6_24_42 6_26_46 6_28_50 6_30_54 6_32_58 6_34_62 6_26_46_66 6_26_48_70 6_26_50_74 6_30_54_78 6_30_56_82 6_30_58_86 6_34_62_90 6_28_50_72_94 6_26_50_74_98 6_30_54_78_102 6_28_54_80_106 6_32_58_84_110 6_30_58_86_114 6_34_62_90_118 6_26_50_74_98_122 6_30_54_78_102_126 6_26_52_78_104_130 6_30_56_82_108_134 6_34_60_86_112_138") do ( set "_=%%a" ) ) else ( for /f "tokens=%p%" %%a in ("6_30_58_86_114_142 6_34_62_90_118_146 6_30_54_78_102_126_150 6_24_50_76_102_128_154 6_28_54_80_106_132_158 6_32_58_84_110_136_162 6_26_54_82_110_138_166 6_30_58_86_114_142_170") do ( set "_=%%a" ) ) ( endlocal set "%~2=%_%" exit /b ) rem end of :qrutil.pattern_position_table rem *** :qrutil.getlengthinbits mode type len setlocal enabledelayedexpansion set /a "_m = %~1, t = %~2, @11=10,@12=9,@14=8,@18=8, @21=12,@22=11,@24=16,@28=10, @31=14,@32=13,@34=16,@38=12,"^ "a=t-1,b=t-10,c=t-27,d=t-41, _t = (a^b)>>imsb&1 | (b^c)>>imsb&2 | (c^d)>>imsb&3" if %_t%==0 ( call :throwerror "error type: %t%" ) else ( set "_=!@%_t%%_m%!" ) ( endlocal set "%~3=%_%" exit /b ) rem end of :qrutil.getlengthinbits rem *** :throwerror errinfo color cf echo; & echo; & echo;error & echo; & echo; %~1 <nul set /p "=any key to exit..." >nul pause exit exit /b rem *** :qrcodemodel.setuptimingpattern modules modulecount setlocal enabledelayedexpansion set "t=!%~1!" set "t.def=!%~1.defined!" set /a "_m = %~2 - 9" for /l %%r in (8 1 %_m%) do ( set /a "ibs = 6 + %%r * %~2, iqs = ibs >> 2, bit = 1 << (3 ^ (ibs & 3))" for %%a in (!iqs!) do ( set /a "quad.def = 0x!t.def:~%%a,1! & bit" ) if !quad.def!==0 ( set /a "bit = ~%%r & 1" set /a "sbb = bit << imsb >> imsb, "^ "ibs = 6 + %%r * %~2, lenl = ibs >> 2, ind = lenl + 1, lenr = iquadmax - ind, bit = 1 << (3 ^ (ibs & 3))" for %%a in (!lenl!) do ( set /a "quad = 0x!t:~%%a,1!, quad = sbb & (bit | quad) | ~sbb & (~bit & quad), "^ "quad.def = 0x!t.def:~%%a,1! | bit" ) for /f "tokens=1-5" %%a in ("!lenl! !ind! !lenr! #!quad! #!quad.def!") do ( set "t=!t:~0,%%a!!%%d!!t:~%%b,%%c!" set "t.def=!t.def:~0,%%a!!%%e!!t.def:~%%b,%%c!" ) ) ) for /l %%c in (8 1 %_m%) do ( set /a "ibs = %%c + 6 * %~2, iqs = ibs >> 2, bit = 1 << (3 ^ (ibs & 3))" for %%a in (!iqs!) do ( set /a "quad.def = 0x!t.def:~%%a,1! & bit" ) if !quad.def!==0 ( set /a "bit = ~%%c & 1" set /a "sbb = bit << imsb >> imsb, "^ "ibs = %%c + 6 * %~2, lenl = ibs >> 2, ind = lenl + 1, lenr = iquadmax - ind, bit = 1 << (3 ^ (ibs & 3))" for %%a in (!lenl!) do ( set /a "quad = 0x!t:~%%a,1!, quad = sbb & (bit | quad) | ~sbb & (~bit & quad), "^ "quad.def = 0x!t.def:~%%a,1! | bit" ) for /f "tokens=1-5" %%a in ("!lenl! !ind! !lenr! #!quad! #!quad.def!") do ( set "t=!t:~0,%%a!!%%d!!t:~%%b,%%c!" set "t.def=!t.def:~0,%%a!!%%e!!t.def:~%%b,%%c!" ) ) ) ( endlocal set "%~1=%t%" set "%~1.defined=%t.def%" exit /b ) rem end of :qrcodemodel.setuptimingpattern rem *** :qrcodemodel.setuppositionprobepattern modules row col modulecount setlocal enabledelayedexpansion set "t=!%~1!" set "t.def=!%~1.defined!" set "lss=-" & set "leq=-1-" for /l %%r in (-1 1 7) do ( set /a "_r = %~2 + %%r, sbb = _r %leq% -1 | %~4 %leq% _r" if !sbb! geq 0 ( for /l %%c in (-1 1 7) do ( set /a "_c = %~3 + %%c, sbb = _c %leq% -1 | %~4 %leq% _c" if !sbb! geq 0 ( set /a "sbb = ( ( 0 %leq% %%r & %%r %leq% 6 & (^!%%c | ^!(%%c - 6)) << imsb ) | ( 0 %leq% %%c & %%c %leq% 6 & (^!%%r | ^!(%%r - 6)) << imsb ) | ( 2 %leq% %%r & %%r %leq% 4 & 2 %leq% %%c & %%c %leq% 4) ) >> imsb, "^ "ibs = _c + _r * %~4, lenl = ibs >> 2, ind = lenl + 1, lenr = iquadmax - ind, bit = 1 << (3 ^^ (ibs & 3))" for %%a in (!lenl!) do ( set /a "quad = 0x!t:~%%a,1!, quad = sbb & (bit | quad) | ~sbb & (~bit & quad), "^ "quad.def = 0x!t.def:~%%a,1! | bit" ) for /f "tokens=1-5" %%a in ("!lenl! !ind! !lenr! #!quad! #!quad.def!") do ( set "t=!t:~0,%%a!!%%d!!t:~%%b,%%c!" set "t.def=!t.def:~0,%%a!!%%e!!t.def:~%%b,%%c!" ) ) ) ) ) ( endlocal set "%~1=%t%" set "%~1.defined=%t.def%" exit /b ) rem end of :qrcodemodel.setuppositionprobepattern rem *** :paint modules modulecount test setlocal enabledelayedexpansion if "%~3" neq "" (set /a "test = %~3") else set "test=0" echo; color 0f & echo; set "black= " & set "white=%ascii219%" for %%i in (0 1 2 3 4 5 6 7 8 9 a b c d e f) do ( set "bits=" for /l %%j in (3 -1 0) do ( set /a "b = 0x%%i >> %%j & 1" set "bits=!bits!!b!" ) set "bits=!bits:0=%white%!" set "h2b=!h2b!"%%i=!bits:1=%black%!" " ) echo; set "w_quietzone=1" set /a "w = %~2 - 1, w1 = w_quietzone * 2 + %~2" set "quietzone=" & for /l %%i in (1 1 !w_quietzone!) do set "quietzone=!quietzone!%white%" for /l %%i in (1 1 !w_quietzone!) do (for /l %%j in (1 1 !w1!) do <nul set /p "=%white%") & echo; for /l %%i in (0 1 !w!) do ( set /a "ibs = %~2 * %%i, iqs = ibs >> 2, quadlen = ((ibs + %~2 - 1) >> 2) - iqs + 1, ibs &= 3" for /f "tokens=1-2" %%s in ("!iqs! !quadlen!") do ( set "_t=!%~1:~%%s,%%t!" if %test%==1 set "t.defined=!%~1.defined:~%%s,%%t!" ) for %%a in (%h2b%) do ( set "_t=!_t:%%~a!" if %test%==1 set "t.defined=!t.defined:%%~a!" ) if %test%==1 ( set /a "im = (quadlen << 2) - 1" set "t=" for /l %%i in (0 1 !im!) do ( if "!t.defined:~%%i,1!"=="%black%" ( set "t=!t!!_t:~%%i,1!" ) else ( set "t=!t!*" ) ) ) else ( set "t=!_t!" ) for /f "tokens=1-2" %%s in ("!ibs! !%~2!") do echo;!quietzone!!t:~%%s,%%t!!quietzone! ) for /l %%i in (1 1 !w_quietzone!) do (for /l %%j in (1 1 !w1!) do <nul set /p "=%white%") & echo; endlocal exit /b rem end of :paint rem *** :qrbitbuffer.put qrbitbuffer.buffer qrbitbuffer.length num length setlocal enabledelayedexpansion set "_b=!%~1!" set "_l=!%~2!" set /a "im = %~4 - 1" for /l %%i in (0 1 %im%) do ( call :qrbitbuffer.putbit _b _l "((%~3 >> (im - %%i)) & 1)" ) ( endlocal set "%~1=%_b%" set "%~2=%_l%" exit /b ) rem end of :qrbitbuffer.put rem *** :qrbitbuffer.putbit qrbitbuffer.buffer qrbitbuffer.length bit setlocal enabledelayedexpansion set "_b=!%~1!" call :strlen _b _buf_len set /a "_buf_len >>= 1" set /a "_l = %~2, bufindex = _l >> 3, bit = %~3" if %_buf_len% leq %bufindex% ( set "_b=%_b%00" ) if %bit%==1 ( set /a "lenl = bufindex << 1, ind = lenl + 2, lenr = (_buf_len << 1) - ind" for %%i in (!lenl!) do set /a "_byte = (0x!_b:~%%i,2!) | (0x80 >> (_l & 7))" set /a "h4 = _byte >> 4, l4 = _byte & 0xf" for /f "tokens=1-5" %%u in ("!lenl! !ind! !lenr! #!h4! #!l4!") do set "_b=!_b:~0,%%u!!%%x!!%%y!!_b:~%%v,%%w!" ) set /a "_l += 1" ( endlocal set "%~1=%_b%" set "%~2=%_l%" exit /b ) rem end of :qrbitbuffer.putbit rem *** :qrcodemodel.adddata qrcodemodel.datalist qrcodemodel.datacache data setlocal enabledelayedexpansion set "datalist=!%~1!" set "data=!%~3!" call :qr8bitbyte.parseddata data parseddata if "%datalist%"=="" ( set "datalist=!parseddata!" ) else ( set "datalist=%datalist% !parseddata!" ) ( endlocal set "%~1=%datalist%" set "%~2=" exit /b ) rem end of :qrcodemodel.adddata rem *** :qr8bitbyte.parseddata str parseddata ( setlocal enabledelayedexpansion set "ascii_20_7e=01234567890123456789012345678901 ^!"#$%%^&'(^)*+,-./0123456789:;^<=^>?@abcdefghijklmnopqrstuvwxyz[\]^^^^_`abcdefghijklmnopqrstuvwxyz{^|}~" for /l %%i in (0x20 1 0x7e) do ( set /a "h4 = %%i >> 4, l4 = %%i & 0xf" for /f "tokens=1-2" %%u in ("#!h4! #!l4!") do set "hex=!%%u!!%%v!" if "!ascii_20_7e:~%%i,1!"=="^" ( set "_^=5e" ) else if "!ascii_20_7e:~%%i,1!"=="*" ( rem set _*=!hex! ) else ( for %%a in ("!ascii_20_7e:~%%i,1!") do ( if "%%~a" lss "a" ( if "%%~a"=="!" ( set "_^!=21" ) else ( set _%%~a=!hex! ) ) else if "%%~a" leq "z" ( for /f "delims=abcdefghijklmnopqrstuvwxyz" %%b in ("%%~a") do set #%%~a=!hex! for /f "delims=abcdefghijklmnopqrstuvwxyz" %%b in ("%%~a") do set _%%~a=!hex! ) else ( set _%%~a=!hex! ) ) ) ) rem set "_*=42" & set "_?=63" & rem * and ? are wildcard, the above code does not generate rem the corresponding variables, but also unnecessary set "t=" call :strlen "%~1" iend set /a "iend -= 1, next = 0" for /l %%i in (0 1 !iend!) do ( if %%i geq !next! ( set "isescape=0" if /i "!%~1:~%%i,2!"=="\x" ( set /a "isescape = 1, a = %%i + 2, b = a + 1" for %%n in (!a! !b!) do ( if "!%~1:~%%n,1!"=="" ( set "isescape=0" ) else if "!%~1:~%%n,1!"==";" ( set "isescape=0" ) else ( for /f "delims=0123456789abcdefabcdef" %%b in ("!%~1:~%%n,1!") do ( set "isescape=0" ) ) ) if !isescape! equ 1 ( for %%n in (!a!) do ( set "t=!t!!%~1:~%%n,2!" set /a "next = %%i + 4" ) ) ) if !isescape! equ 0 ( for /f delims^=^ eol^= %%j in ("!%~1:~%%i,1!") do ( if "%%j"=="!" ( set "t=!t!21" ) else if "%%j"=="*" ( set "t=!t!2a" ) else if "%%j"=="?" ( set "t=!t!3f" ) else ( if "%%j"=="=" ( set "t=!t!3d" ) else if "%%j" lss "a" ( set "t=!t!!_%%j!" ) else if "%%j" leq "z" ( for /f "delims=abcdefghijklmnopqrstuvwxyz" %%b in ("%%j") do set "t=!t!!#%%j!" for /f "delims=abcdefghijklmnopqrstuvwxyz" %%b in ("%%j") do set "t=!t!!_%%j!" ) else ( set "t=!t!!_%%j!" ) ) ) ) ) ) ) ( endlocal set "%~2=%t%" exit /b ) rem end of :qr8bitbyte.parseddata rem *** :strlen str len ( setlocal enabledelayedexpansion set "len=0" & set "t=!%~1!#" for %%i in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do if "!t:~%%i!" neq "" set /a "len |= %%i" & set "t=!t:~%%i!" ) ( endlocal set "%~2=%len%" exit /b ) rem end of :strlen rem *** :qrmath.glog n vret setlocal enabledelayedexpansion set /a "n = %~1, i = n << 1" if %n% lss 1 ( call :throwerror "@qrmath.glog n:[%~1]" ) for %%i in (%i%) do set "ret=!log_table:~%%i,2!" ( endlocal set "%~2=%ret%" exit /b ) rem end of :qrmath.glog rem *** :qrmath.gexp n vret setlocal enabledelayedexpansion set /a "n=%~1, t = (n^^n-256)>>imsb, r=n %% 255, c = ^!r <<imsb>>imsb, i = (t & n | ~t & r + ((n>>imsb ^^ c) & 255)) << 1" for %%i in (%i%) do set "ret=!exp_table:~%%i,2!" ( endlocal set "%~2=%ret%" exit /b ) rem end of :qrmath.gexp rem *** :init.log_table log_table setlocal enabledelayedexpansion set "t=" for /l %%i in (0 1 255) do set "t=!t!.." call :strlen t log_table_len for /l %%i in (0 1 254) do ( set /a "_i = %%i << 1, h4 = %%i >> 4, l4 = %%i & 0xf" for %%a in (!_i!) do set /a "lenl = 0x!exp_table:~%%a,2! << 1" set /a "ind = lenl + 2, lenr = log_table_len - ind" for /f "tokens=1-5" %%u in ("!lenl! !ind! !lenr! #!h4! #!l4!") do set "t=!t:~0,%%u!!%%x!!%%y!!t:~%%v,%%w!" ) ( endlocal set "%~1=%t%" exit /b ) rem end of :init.log_table rem *** :init.exp_table exp_table setlocal enabledelayedexpansion set "et=" for /l %%i in (0 1 7) do ( set /a "t = 1 << %%i, h4 = t >> 4, l4 = t & 0xf" for /f "tokens=1-2" %%x in ("#!h4! #!l4!") do ( set "et=!et!!%%x!!%%y!" ) ) for /l %%i in (8 1 255) do ( set /a "i_4 = %%i - 4 << 1, i_5 = %%i - 5 << 1, i_6 = %%i - 6 << 1, i_8 = %%i - 8 << 1" for /f "tokens=1-4" %%a in ("!i_4! !i_5! !i_6! !i_8!") do ( set /a "t = 0x!et:~%%a,2! ^^ 0x!et:~%%b,2! ^^ 0x!et:~%%c,2! ^^ 0x!et:~%%d,2!" set /a "h4 = t >> 4, l4 = t & 0xf" for /f "tokens=1-2" %%x in ("#!h4! #!l4!") do set "et=!et!!%%x!!%%y!" ) ) ( endlocal set "%~1=%et%" exit /b ) rem end of :init.exp_table rem *** :autoresizescr typenumber margin setlocal for /f "tokens=1-2 delims=:" %%a in ('mode ^| find /i "s:" ^| find /i "n"') do set /a "%%a=%%b" set /a "modulecount = %~1 * 4 + 17" set /a "si* = modulecount + %~2" set /a "resize = lines - si* | columns - si*" set /a "lines = (t = lines - si* >> imsb, t & si* | ~t & lines)" set /a "columns = (t = columns - si* >> imsb, t & si* | ~t & columns)" if %resize% lss 0 mode %columns%, %lines% endlocal exit /b rem end of :autoresizescr rem *** :clearvars set "path=%systemroot%\system32" for /f "delims==" %%a in ('set') do ( if /i "%%a" neq "path" set "%%a=" ) exit /b rem end of :clearvars rem *** :getbackspaceandascii219 call :getascii219 >nul copy 219.chr /b + 13.chr /b 219_cr.chr /b <219_cr.chr set /p "ascii219=" for %%n in (13 219 219_cr) do del %%n.chr call :getbackspace bs exit /b rem end of :getbackspaceandascii219 rem *** :getascii219 setlocal set ^"genchr=(^ for %%n in (13 219) do if not exist %%n.chr (^ makecab /d compress=off /d reserveperdatablocksize=26 /d reserveperfoldersize=%%n 0.tmp %%n.chr ^>nul^&^ type %%n.chr ^| ((for /l %%n in (1 1 38) do pause)^>nul^&findstr "^^" ^>%%n.temp)^&^ ^>nul copy /y %%n.temp /a %%n.chr /b^&^ del %%n.temp^ )^ )^&^ del 0.tmp^" for %%n in (13 219) do (del /f /q /a %%n.chr >nul 2>&1) type nul >0.tmp cmd /q /v:on /c "%genchr%" endlocal exit /b rem end of :getascii219 rem *** :getbackspace vret for /f %%a in ('"prompt $h&for %%b in (1) do rem"')do set "%~1=%%a" exit /b rem end of :getbackspace rem *** :quickshow setlocal set "modules=fe44313afbea776cb43fc13e02ca360f524f2dd06e9322a555e5ce966fabb75a517e1715f2c11455dbaffcaff0ef0f878202ec13d33c414e1c672b2907faaaaaaaaaaaaaaaaafe0016cf14c94d13137500c7033fff6840f897070c4afad29f33b324c2cd720cf14bed1585f5a250d740b3511151b0347afe2e3766265b0a0db73511a388221747342f4714195737584599a05a25595d295c80a8a7b45218d6e66dbec36fb71f581718448e0c5a08a2dbeeb431751102e4886420dc5d2e6a4f2d2ba29acd92e974f2b616cf2c7ff587f11acc3296904aa42ce7be107dd8c6508ff4b56ddcb643b90f2cbb87341d09514f9900660fac6dfed9fcff398bf8a44010c74efac54d29c7fab2892a083fab1ddcabc91c11f15e4d7142da51f3f918ffd9d3bff6301f852752be76c760dc98c35549361a710c1260a0c0081be4edc20990f7237bbea7acbe31385162db8d84f413a667bffb315749b8b1f4ba8370f6a94a56815e2110cdff93db7e53992c6e54342d9fc0f9db1487e5a6565befb5960896f6bd10b0853b57d1bd280dca2cfecd5cd482ed67cf5e928d9b382490ce27b0c833e267247418c51826e8b17aa3ff7d640c69e73b3214917c84513ab7b0ce2561c173ee71289a42140369271b31f4c581d800ec0d6019dbc1cafd6c44e2b1b8e40055eb12eb967fdbaff8fadaf975a8fd1c7800c70af2c418a54602b5ad6a0b40ab3fd8aa571b0811b8afd1925ad1c3fede7fc6b20facb8afc826487c7a73a4009cd7b06dd9f6f63e732648a6566a918e4cc953435b73bdf325becf3c37bc9fef9820fc56db7737759618c611ad879402d1830db031051f423eb19d3c721b02f96fa65fca1eb7dfd15a25ac9a463c07c45d5048879ffa6a064f00d575082c195be3dc86d746b76ced6b748ce6086536cae8d9b6c076b3acf0a19cdcbbd6c8ddefdb3b787e72f4bb8f484c94a92df233a348facbfd16f121c452cc8d663269efbefb78000ee1c9084d2dfcd820bf49b48b3a5be10ad3c571387473d9cfffecbefbb54dfc805d01450672458131c53fa841aa4830abdb546b105b19d194659146f7f1cba2e0effbc3efb6fa8f8dd108a0d6016d1d454ab2e8f29a910a060263412f05ebaf920f143b12b124fee936636a62fcffa49100" set /a "modulecount = 17 + 4 * 16" call :paint modules modulecount endlocal exit /b rem end of :quickshow rem *** :delreg setlocal enabledelayedexpansion set "s=!time:~-4,1!" :delreg.loop set /a "elapse = (1!time:~-4,1! - s) %% 10" if %elapse% lss 2 goto :delreg.loop >nul reg delete hkcu\console\qrcode_cmd /f endlocal exit /b rem end of :delreg rem *** :initglobalvars for /l %%i in (7 8 127) do set /a "_=1<<%%i>>%%i>>1, imsb=_&%%i|~_&imsb" set /a "wordsize = imsb + 1" set /a "mode_number = 1 << 0, mode_alpha_num = 1 << 1, mode_8bit_byte = 1 << 2, mode_kanji = 1 << 3" set /a "g15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0)" set /a "g18 = (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0)" set /a "g15_mask = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1)" call :qrutil.getbchdigit g18.dgt g18 call :qrutil.getbchdigit g15.dgt g15 call :getbackspaceandascii219 for %%i in (0 1 2 3 4 5 6 7 8 9 a b c d e f) do ( set /a "i = 0x%%i" set "#!i!=%%i" ) call :init.exp_table exp_table call :init.log_table log_table exit /b rem end of :initglobalvars rem *** :initcon @echo off for %%a in ( fontsize:00080008 fontfamily:00000030 windowsize:00c800c8 screencolors:0000000f codepage:000001b5 screenbuffersize:00c800c8 ) do for /f "tokens=1,2 delims=:" %%b in ("%%a") do ( >nul reg add hkcu\console\qrcode_cmd /v %%b /t reg_dword /d 0x%%c /f ) start "qrcode_cmd" /max "%comspec%" /c "%~0" rem & (call :delreg) & exit rem end of :initcon