fast_qr-0.13.1/.cargo_vcs_info.json0000644000000001360000000000100125550ustar { "git": { "sha1": "7bc495e7b3991db6f4f7fc5dc88fc101409c73b0" }, "path_in_vcs": "" }fast_qr-0.13.1/Cargo.lock0000644000000675750000000000100105540ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "adler2" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "aho-corasick" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] name = "anes" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstyle" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" [[package]] name = "arrayref" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" [[package]] name = "arrayvec" version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "base64" version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" [[package]] name = "bumpalo" version = "3.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "793db76d6187cd04dff33004d8e6c9cc4e05cd330500379d2394209271b4aeee" [[package]] name = "bytemuck" version = "1.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422" [[package]] name = "byteorder-lite" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" [[package]] name = "cast" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cfg-if" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" [[package]] name = "ciborium" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" dependencies = [ "ciborium-io", "ciborium-ll", "serde", ] [[package]] name = "ciborium-io" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" [[package]] name = "ciborium-ll" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" dependencies = [ "ciborium-io", "half", ] [[package]] name = "clap" version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" version = "4.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" dependencies = [ "anstyle", "clap_lex", ] [[package]] name = "clap_lex" version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "color_quant" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "core_maths" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77745e017f5edba1a9c1d854f6f3a52dac8a12dd5af5d2f54aecf61e43d80d30" dependencies = [ "libm", ] [[package]] name = "crc32fast" version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ "cfg-if", ] [[package]] name = "criterion" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bf7af66b0989381bd0be551bd7cc91912a655a58c6918420c9527b1fd8b4679" dependencies = [ "anes", "cast", "ciborium", "clap", "criterion-plot", "itertools 0.13.0", "num-traits", "oorandom", "plotters", "rayon", "regex", "serde", "serde_json", "tinytemplate", "walkdir", ] [[package]] name = "criterion-plot" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" dependencies = [ "cast", "itertools 0.10.5", ] [[package]] name = "crossbeam-deque" version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" dependencies = [ "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crunchy" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929" [[package]] name = "data-url" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a" [[package]] name = "either" version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "fast_qr" version = "0.13.1" dependencies = [ "base64", "criterion", "qrcode", "resvg", "wasm-bindgen", ] [[package]] name = "fdeflate" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" dependencies = [ "simd-adler32", ] [[package]] name = "flate2" version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d" dependencies = [ "crc32fast", "miniz_oxide", ] [[package]] name = "float-cmp" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" [[package]] name = "fontconfig-parser" version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbc773e24e02d4ddd8395fd30dc147524273a83e54e0f312d986ea30de5f5646" dependencies = [ "roxmltree", ] [[package]] name = "fontdb" version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "457e789b3d1202543297a350643cf459f836cade38934e7a4cf6a39e7cde2905" dependencies = [ "fontconfig-parser", "log", "memmap2", "slotmap", "tinyvec", "ttf-parser", ] [[package]] name = "gif" version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2" dependencies = [ "color_quant", "weezl", ] [[package]] name = "half" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9" dependencies = [ "cfg-if", "crunchy", ] [[package]] name = "image" version = "0.25.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db35664ce6b9810857a38a906215e75a9c879f0696556a39f59c62829710251a" dependencies = [ "bytemuck", "byteorder-lite", "num-traits", ] [[package]] name = "image-webp" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14d75c7014ddab93c232bc6bb9f64790d3dfd1d605199acd4b40b6d69e691e9f" dependencies = [ "byteorder-lite", "quick-error", ] [[package]] name = "imagesize" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edcd27d72f2f071c64249075f42e205ff93c9a4c5f6c6da53e79ed9f9832c285" [[package]] name = "itertools" version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ "either", ] [[package]] name = "itertools" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" dependencies = [ "either", ] [[package]] name = "itoa" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "js-sys" version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" dependencies = [ "once_cell", "wasm-bindgen", ] [[package]] name = "kurbo" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1077d333efea6170d9ccb96d3c3026f300ca0773da4938cc4c811daa6df68b0c" dependencies = [ "arrayvec", "smallvec", ] [[package]] name = "libc" version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "libm" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] name = "log" version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "memmap2" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f" dependencies = [ "libc", ] [[package]] name = "miniz_oxide" version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" dependencies = [ "adler2", "simd-adler32", ] [[package]] name = "num-traits" version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "once_cell" version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "oorandom" version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" [[package]] name = "pico-args" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" [[package]] name = "plotters" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" dependencies = [ "num-traits", "plotters-backend", "plotters-svg", "wasm-bindgen", "web-sys", ] [[package]] name = "plotters-backend" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" [[package]] name = "plotters-svg" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" dependencies = [ "plotters-backend", ] [[package]] name = "png" version = "0.17.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526" dependencies = [ "bitflags 1.3.2", "crc32fast", "fdeflate", "flate2", "miniz_oxide", ] [[package]] name = "proc-macro2" version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] [[package]] name = "qrcode" version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d68782463e408eb1e668cf6152704bd856c78c5b6417adaee3203d8f4c1fc9ec" dependencies = [ "image", ] [[package]] name = "quick-error" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quote" version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] [[package]] name = "rayon" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", ] [[package]] name = "rayon-core" version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ "crossbeam-deque", "crossbeam-utils", ] [[package]] name = "regex" version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", "regex-automata", "regex-syntax", ] [[package]] name = "regex-automata" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "resvg" version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8928798c0a55e03c9ca6c4c6846f76377427d2c1e1f7e6de3c06ae57942df43" dependencies = [ "gif", "image-webp", "log", "pico-args", "rgb", "svgtypes", "tiny-skia", "usvg", "zune-jpeg", ] [[package]] name = "rgb" version = "0.8.50" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a" dependencies = [ "bytemuck", ] [[package]] name = "roxmltree" version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97" [[package]] name = "rustversion" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" [[package]] name = "rustybuzz" version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd3c7c96f8a08ee34eff8857b11b49b07d71d1c3f4e88f8a88d4c9e9f90b1702" dependencies = [ "bitflags 2.9.1", "bytemuck", "core_maths", "log", "smallvec", "ttf-parser", "unicode-bidi-mirroring", "unicode-ccc", "unicode-properties", "unicode-script", ] [[package]] name = "ryu" version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "same-file" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" dependencies = [ "winapi-util", ] [[package]] name = "serde" version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "serde_json" version = "1.0.140" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" dependencies = [ "itoa", "memchr", "ryu", "serde", ] [[package]] name = "simd-adler32" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" [[package]] name = "simplecss" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a9c6883ca9c3c7c90e888de77b7a5c849c779d25d74a1269b0218b14e8b136c" dependencies = [ "log", ] [[package]] name = "siphasher" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" [[package]] name = "slotmap" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbff4acf519f630b3a3ddcfaea6c06b42174d9a44bc70c620e9ed1649d58b82a" dependencies = [ "version_check", ] [[package]] name = "smallvec" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "strict-num" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" dependencies = [ "float-cmp", ] [[package]] name = "svgtypes" version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68c7541fff44b35860c1a7a47a7cadf3e4a304c457b58f9870d9706ece028afc" dependencies = [ "kurbo", "siphasher", ] [[package]] name = "syn" version = "2.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6397daf94fa90f058bd0fd88429dd9e5738999cca8d701813c80723add80462" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "tiny-skia" version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab" dependencies = [ "arrayref", "arrayvec", "bytemuck", "cfg-if", "log", "png", "tiny-skia-path", ] [[package]] name = "tiny-skia-path" version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c9e7fc0c2e86a30b117d0462aa261b72b7a99b7ebd7deb3a14ceda95c5bdc93" dependencies = [ "arrayref", "bytemuck", "strict-num", ] [[package]] name = "tinytemplate" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" dependencies = [ "serde", "serde_json", ] [[package]] name = "tinyvec" version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09b3661f17e86524eccd4371ab0429194e0d7c008abb45f7a7495b1719463c71" dependencies = [ "tinyvec_macros", ] [[package]] name = "tinyvec_macros" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "ttf-parser" version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31" dependencies = [ "core_maths", ] [[package]] name = "unicode-bidi" version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" [[package]] name = "unicode-bidi-mirroring" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfa6e8c60bb66d49db113e0125ee8711b7647b5579dc7f5f19c42357ed039fe" [[package]] name = "unicode-ccc" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce61d488bcdc9bc8b5d1772c404828b17fc481c0a582b5581e95fb233aef503e" [[package]] name = "unicode-ident" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "unicode-properties" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" [[package]] name = "unicode-script" version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fb421b350c9aff471779e262955939f565ec18b86c15364e6bdf0d662ca7c1f" [[package]] name = "unicode-vo" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1d386ff53b415b7fe27b50bb44679e2cc4660272694b7b6f3326d8480823a94" [[package]] name = "usvg" version = "0.45.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80be9b06fbae3b8b303400ab20778c80bbaf338f563afe567cf3c9eea17b47ef" dependencies = [ "base64", "data-url", "flate2", "fontdb", "imagesize", "kurbo", "log", "pico-args", "roxmltree", "rustybuzz", "simplecss", "siphasher", "strict-num", "svgtypes", "tiny-skia-path", "unicode-bidi", "unicode-script", "unicode-vo", "xmlwriter", ] [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "walkdir" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ "same-file", "winapi-util", ] [[package]] name = "wasm-bindgen" version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", "once_cell", "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", "proc-macro2", "quote", "syn", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" dependencies = [ "unicode-ident", ] [[package]] name = "web-sys" version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" dependencies = [ "js-sys", "wasm-bindgen", ] [[package]] name = "weezl" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a751b3277700db47d3e574514de2eced5e54dc8a5436a3bf7a0b248b2cee16f3" [[package]] name = "winapi-util" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ "windows-sys", ] [[package]] name = "windows-sys" version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "xmlwriter" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9" [[package]] name = "zune-core" version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a" [[package]] name = "zune-jpeg" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f6fe2e33d02a98ee64423802e16df3de99c43e5cf5ff983767e1128b394c8ac" dependencies = [ "zune-core", ] fast_qr-0.13.1/Cargo.toml0000644000000043130000000000100105540ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.59" name = "fast_qr" version = "0.13.1" authors = ["erwan.vivien "] build = false include = [ "src", "Cargo.toml", "./README.md", "./LICENSE", "benches", ] autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "Generates optimized QRCode" homepage = "https://fast-qr.com/" documentation = "https://docs.rs/fast_qr/latest/fast_qr/" readme = "README.md" keywords = [ "qr", "qrcode", "qr-generator", "qrcode-generator", "qr-gen", ] categories = [ "multimedia", "multimedia::encoding", "multimedia::images", ] license = "MIT" repository = "https://github.com/erwanvivien/fast_qr/" [package.metadata.docs.rs] features = [ "image", "svg", ] rustdoc-args = [ "--cfg", "docsrs", ] [package.metadata.wasm-pack.profile.release] wasm-opt = ["-Oz"] [features] image = [ "svg", "dep:resvg", ] svg = [] wasm-bindgen = ["dep:wasm-bindgen"] [lib] name = "fast_qr" crate-type = [ "cdylib", "rlib", ] path = "src/lib.rs" [[bench]] name = "qr" path = "benches/qr.rs" harness = false [dependencies.resvg] version = "0.45.1" optional = true [dev-dependencies.base64] version = "0.22.1" [dev-dependencies.qrcode] version = "0.14.1" [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.criterion] version = "0.6" [target.'cfg(target_arch = "wasm32")'.dependencies.wasm-bindgen] version = "0.2" optional = true [target.'cfg(target_arch = "wasm32")'.dev-dependencies.criterion] version = "0.6" features = [ "cargo_bench_support", "plotters", ] default-features = false [profile.release] opt-level = "s" lto = true codegen-units = 1 debug = 0 panic = "abort" strip = "debuginfo" fast_qr-0.13.1/Cargo.toml.orig000064400000000000000000000036741046102023000142460ustar 00000000000000[package] name = "fast_qr" version = "0.13.1" authors = ["erwan.vivien "] edition = "2021" description = "Generates optimized QRCode" documentation = "https://docs.rs/fast_qr/latest/fast_qr/" homepage = "https://fast-qr.com/" readme = "README.md" repository = "https://github.com/erwanvivien/fast_qr/" keywords = ["qr", "qrcode", "qr-generator", "qrcode-generator", "qr-gen"] categories = ["multimedia", "multimedia::encoding", "multimedia::images"] include = ["src", "Cargo.toml", "./README.md", "./LICENSE", "benches"] rust-version = "1.59" license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] crate-type = ["cdylib", "rlib"] [dependencies] resvg = { version = "0.45.1", optional = true } [features] svg = [] image = ["svg", "dep:resvg"] wasm-bindgen = ["dep:wasm-bindgen"] [target.'cfg(target_arch = "wasm32")'.dependencies] wasm-bindgen = { version = "0.2", optional = true } [profile.release] debug = false lto = true codegen-units = 1 opt-level = 's' # Optimize for size panic = 'abort' # About unwinding code strip = "debuginfo" [package.metadata.wasm-pack.profile.release] wasm-opt = ["-Oz"] [dev-dependencies] base64 = "0.22.1" qrcode = "0.14.1" [target.'cfg(target_arch = "wasm32")'.dev-dependencies] criterion = { version = "0.6", default-features = false, features = [ "cargo_bench_support", "plotters", ] } [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] criterion = "0.6" [[bench]] name = "qr" harness = false [package.metadata.docs.rs] features = ["image", "svg"] rustdoc-args = ["--cfg", "docsrs"] [[example]] name = "custom" path = "examples/custom.rs" required-features = ["image"] [[example]] name = "embed" path = "examples/embed.rs" required-features = ["image"] [[example]] name = "image" path = "examples/image.rs" required-features = ["image"] [[example]] name = "svg" path = "examples/svg.rs" required-features = ["svg"] fast_qr-0.13.1/README.md000064400000000000000000000110321046102023000126210ustar 00000000000000
Example qr for website example.com
`fast_qr` is approximately 6-7 times faster than `qrcode`, see [benchmarks](#benchmarks) You can create a QR as - [x] Raw matrix, well suited for custom usage - [x] Vectorized image, well suited for web usage - [x] Image, well suited for mobile / print usage # Usage ## Rust ### Examples You can run the examples with: ```sh cargo run --example simple cargo run --example svg -F svg cargo run --example image -F image ``` They are all explained in detail below. ### Converts `QRCode` to Unicode ```rust use fast_qr::convert::ConvertError; use fast_qr::qr::QRBuilder; fn main() -> Result<(), ConvertError> { // QRBuilder::new can fail if content is too big for version, // please check before unwrapping. let qrcode = QRBuilder::new("https://example.com/") .build() .unwrap(); let str = qrcode.to_str(); // .print() exists println!("{}", str); Ok(()) } ``` ### Converts `QRCode` to SVG [docs.rs](https://docs.rs/fast_qr/latest/fast_qr/convert/svg/index.html) _Note: It requires the `svg` feature_ ```rust use fast_qr::convert::ConvertError; use fast_qr::convert::{svg::SvgBuilder, Builder, Shape}; use fast_qr::qr::QRBuilder; fn main() -> Result<(), ConvertError> { // QRBuilder::new can fail if content is too big for version, // please check before unwrapping. let qrcode = QRBuilder::new("https://example.com/") .build() .unwrap(); let _svg = SvgBuilder::default() .shape(Shape::RoundedSquare) .to_file(&qrcode, "out.svg"); Ok(()) } ``` ### Converts `QRCode` to an image [docs.rs](https://docs.rs/fast_qr/latest/fast_qr/convert/image/index.html) _Note: It requires the `image` feature_ ```rust use fast_qr::convert::ConvertError; use fast_qr::convert::{image::ImageBuilder, Builder, Shape}; use fast_qr::qr::QRBuilder; fn main() -> Result<(), ConvertError> { // QRBuilder::new can fail if content is too big for version, // please check before unwrapping. let qrcode = QRBuilder::new("https://example.com/") .build() .unwrap(); let _img = ImageBuilder::default() .shape(Shape::RoundedSquare) .background_color([255, 255, 255, 0]) // Handles transparency .fit_width(600) .to_file(&qrcode, "out.png"); Ok(()) } ``` ## JavaScript / Typescript ### Installation ```bash npm install --save fast_qr # Or yarn add fast_qr ``` ### Create an svg ```js /// Once `init` is called, `qr_svg` can be called any number of times import init, { qr_svg, SvgOptions, Shape } from '/pkg/fast_qr.js' const options = new SvgOptions() .margin(4) .shape(Shape.Square) .image("") // Can be a URL or a base64 encoded image .background_color("#b8a4e5") .module_color("#ffffff"); // Using then / catch: init() .then(() => { for (let i = 0; i < 10; i++) { const svg = qr_svg("https://fast-qr.com", options); console.log(svg); } }) .catch(console.error); // Or using modern async await: await init(); for (let i = 0; i < 10; i++) { const svg = qr_svg("https://fast-qr.com", options); console.log(svg); } ``` # Build WASM ### WASM module also exists in NPM registry Package is named `fast_qr` and can be installed like so : ``` npm install --save fast_qr ``` ### WASM module might be bundled Find a bundled version in the latest [release](https://github.com/erwanvivien/fast_qr/releases). ### WASM module can be built from source ```bash ./wasm-pack.sh # Runs build in release mode and wasm-opt twice again wasm-pack pack pkg # Creates an archive of said package # wasm-pack publish pkg # Creates an archive & publish it to npm ``` ## Benchmarks According to the following benchmarks, `fast_qr` is approximately 6-7x faster than `qrcode`. | Benchmark | Lower | Estimate | Upper | | | :----------- | :-------: | :-------: | :-------: | ----------------------- | | V03H/qrcode | 524.30 us | 535.02 us | 547.13 us | | | V03H/fast_qr | 82.079 us | 82.189 us | 82.318 us | fast_qr is 6.51x faster | | V10H/qrcode | 2.1105 ms | 2.1145 ms | 2.1186 ms | | | V10H/fast_qr | 268.70 us | 269.28 us | 269.85 us | fast_qr is 7.85x faster | | V40H/qrcode | 18.000 ms | 18.037 ms | 18.074 ms | | | V40H/fast_qr | 2.4313 ms | 2.4362 ms | 2.4411 ms | fast_qr is 7.40x faster | More benchmarks can be found in [/benches folder](https://github.com/erwanvivien/fast_qr/tree/master/benches). fast_qr-0.13.1/benches/README.md000064400000000000000000000100121046102023000142250ustar 00000000000000# Benchmarking `fast_qr` & `qrcode` ## Benchmark Windows Powershell | Benchmark | Lower | Estimate | Upper | Ratio | | :-- | :--: | :--: | :--: | -- | | V03H/qrcode | 1.1646 ms | 1.1717 ms | 1.1804 ms | | | V03H/fast_qr | 113.58 µs | 113.95 µs | 114.37 µs | fast_qr is 10.28x faster | | V10H/qrcode | 4.8396 ms | 4.8459 ms | 4.8524 ms | | | V10H/fast_qr | 368.77 µs | 369.98 µs | 371.86 µs | fast_qr is 13.10x faster | | V40H/qrcode | 46.726 ms | 46.769 ms | 46.815 ms | | | V40H/fast_qr | 3.2223 ms | 3.2327 ms | 3.2458 ms | fast_qr is 14.47x faster | - System: Windows - Machine: AMD64 - Processor: Intel64 Family 6 Model 158 Stepping 13, GenuineIntel ## Benchmark Windows Subsystem Linux | Benchmark | Lower | Estimate | Upper | Ratio | | :-- | :--: | :--: | :--: | -- | | V03H/qrcode | 623.48 µs | 624.84 µs | 626.68 µs | | | V03H/fast_qr | 103.42 µs | 104.06 µs | 104.75 µs | fast_qr is 6.00x faster | | V10H/qrcode | 2.5158 ms | 2.5174 ms | 2.5193 ms | | | V10H/fast_qr | 334.00 µs | 334.33 µs | 334.72 µs | fast_qr is 7.53x faster | | V40H/qrcode | 22.188 ms | 22.221 ms | 22.273 ms | | | V40H/fast_qr | 2.9143 ms | 2.9166 ms | 2.9190 ms | fast_qr is 7.62x faster | - System: Linux - Machine: x86_64 - Processor: x86_64 ## Benchmark Linux | Benchmark | Lower | Estimate | Upper | | | :----------- | :-------: | :-------: | :-------: | ----------------------- | | V03H/qrcode | 524.30 us | 535.02 us | 547.13 us | | | V03H/fast_qr | 82.079 us | 82.189 us | 82.318 us | fast_qr is 6.51x faster | | V10H/qrcode | 2.1105 ms | 2.1145 ms | 2.1186 ms | | | V10H/fast_qr | 268.70 us | 269.28 us | 269.85 us | fast_qr is 7.85x faster | | V40H/qrcode | 18.000 ms | 18.037 ms | 18.074 ms | | | V40H/fast_qr | 2.4313 ms | 2.4362 ms | 2.4411 ms | fast_qr is 7.40x faster | - System: Linux - Machine: x86_64 - Processor: - RAM: 8GB --- | Benchmark | Lower | Estimate | Upper | | | :----------- | :-------: | :-------: | :-------: | ----------------------- | | V03H/qrcode | 1.0524 ms | 1.0714 ms | 1.0915 ms | | | V03H/fast_qr | 184.70 us | 187.05 us | 189.85 us | fast_qr is 5.73x faster | | V10H/qrcode | 3.9165 ms | 3.9448 ms | 3.9761 ms | | | V10H/fast_qr | 579.63 us | 584.54 us | 589.93 us | fast_qr is 6.75x faster | | V40H/qrcode | 35.741 ms | 36.093 ms | 36.476 ms | | | V40H/fast_qr | 5.0615 ms | 5.1513 ms | 5.2476 ms | fast_qr is 7.01x faster | - System: Linux - Machine: x86_64 - Processor: - RAM: 5GB ## Benchmark Mac | Benchmark | Lower | Estimate | Upper | Ratio | | :-- | :--: | :--: | :--: | -- | | V03H/qrcode | 558.89 µs | 561.68 µs | 564.83 µs | | | V03H/fast_qr | 70.701 µs | 71.788 µs | 73.095 µs | fast_qr is 7.82x faster | | V10H/qrcode | 2.2440 ms | 2.2502 ms | 2.2565 ms | | | V10H/fast_qr | 210.11 µs | 210.50 µs | 210.92 µs | fast_qr is 10.69x faster | | V40H/qrcode | 19.469 ms | 19.519 ms | 19.587 ms | | | V40H/fast_qr | 1.8431 ms | 1.8459 ms | 1.8488 ms | fast_qr is 10.57x faster | - System: Darwin - Machine: arm64 - Processor: arm Benchmarking powered by [Criterion.rs](https://github.com/bheisler/criterion.rs). \ Feel free to run some benchmarking yourself! fast_qr-0.13.1/benches/bench.py000064400000000000000000000053301046102023000144060ustar 00000000000000import enum import numbers import os import subprocess import re cur_dir = os.getcwd() toml_path = os.path.join(cur_dir, "Cargo.toml") if not os.getcwd().endswith("fast_qr") or not os.path.exists(toml_path): toml_path = "../Cargo.toml" # Dry-run to see the compilation output try: cargo_bench = subprocess.run( ["cargo", "bench", "--manifest-path", toml_path, "--no-run"] ) except Exception as e: print("An error occurred while building cargo bench") print(e) exit(1) try: cargo_bench = subprocess.check_output( ["cargo", "bench", "--manifest-path", toml_path], stderr=subprocess.STDOUT ) except Exception as e: print("An error occurred while running cargo bench") print(e) exit(1) lines = list(map(lambda x: x.decode("utf-8"), cargo_bench.splitlines())) analyze_regex = re.compile(r"^Benchmarking (.*): Analyzing$", re.M | re.I) benchmark_names = analyze_regex.findall("\n".join(lines)) time_lines = [] for line in lines: for benchmark in benchmark_names: if line.startswith(benchmark): time_lines.append(line) break time_lines.sort() # print("\n".join(time_lines)) number = re.compile(r"(\d+(?:\.\d*)?\s*(?:ms|ns|µs|s))") def print_bench(benchmark_name: str, lower: str, estimate: str, upper: str, ratio=" " * len('fast_qr is 10.16x faster')): print( f"| {benchmark_name:<24} | {lower:<9} | {estimate:<9} | {upper:<9} | {ratio:<24} |" ) print_bench("Benchmark", "Lower", "Estimate", "Upper", "Ratio") print_bench(":--", ":--:", ":--:", ":--:", "--") def number_with_unit(s): if s.endswith("ns"): return float(s) * 1000000000 if s.endswith("ms"): return float(s[:-2]) * 1000000 elif s.endswith("µs"): return float(s[:-2]) * 1000 elif s.endswith("s"): return float(s[:-1]) else: raise "Not a valid number" for i in range(0, len(time_lines), 2): test1, time1 = time_lines[i + 0].split("time:") test2, time2 = time_lines[i + 1].split("time:") test1, test2 = test1.strip(), test2.strip() data1 = number.findall(time1) data2 = number.findall(time2) data1_number = list(map(number_with_unit, data1)) data2_number = list(map(number_with_unit, data2)) ratio = data2_number[1] / data1_number[1] print_bench(test2, data2[0], data2[1], data2[2], "") print_bench(test1, data1[0], data1[1], data1[2], f"fast_qr is {ratio:.2f}x faster") import platform print(f"- System: {platform.system()}") print(f"- Machine: {platform.machine()}") print(f"- Processor: {platform.processor()}") print() print( "Benchmarking powered by [Criterion.rs](https://github.com/bheisler/criterion.rs). \\\n" "Feel free to run some benchmarkings yourself!\n\n" ) fast_qr-0.13.1/benches/qr.rs000064400000000000000000000034241046102023000137470ustar 00000000000000use std::time::Duration; use criterion::*; use std::hint::black_box; use fast_qr::QRBuilder; fn bench_fastqr_qrcode(c: &mut Criterion) { let bytes: &[u8] = b"https://example.com/"; for (id, fast_qr_version, fast_qr_level, qrocde_version, qrcode_level) in &[ ( "V03H", fast_qr::Version::V03, fast_qr::ECL::H, qrcode::Version::Normal(3), qrcode::EcLevel::H, ), ( "V10H", fast_qr::Version::V10, fast_qr::ECL::H, qrcode::Version::Normal(10), qrcode::EcLevel::H, ), ( "V40H", fast_qr::Version::V40, fast_qr::ECL::H, qrcode::Version::Normal(40), qrcode::EcLevel::H, ), ] { let mut group = c.benchmark_group(*id); group.measurement_time(Duration::from_secs(10)); group.throughput(Throughput::Bytes(bytes.len() as u64)); group.sample_size(200); group.bench_function("qrcode", |b| { b.iter(|| { qrcode::QrCode::with_version( black_box(b"https://example.com/"), *qrocde_version, *qrcode_level, ) .unwrap() }) }); group.bench_function("fast_qr", |b| { b.iter(|| { QRBuilder::new(black_box("https://example.com/")) .ecl(*fast_qr_level) .version(*fast_qr_version) .build() .unwrap() }) }); group.finish(); } } criterion_group!(benches, bench_fastqr_qrcode); criterion_main!(benches); fast_qr-0.13.1/src/compact.rs000064400000000000000000000172061046102023000141360ustar 00000000000000//! Struct containing an u8-array of C size to store bitwise boolean values #![deny(unsafe_code)] #![warn(missing_docs)] use core::fmt::{Display, Formatter}; use crate::Version; /// Values to keep last X bits of a u8 /// `KEEP_LAST[i]` equates `(1 << i) - 1` /// /// # Example /// ```rust /// # pub const KEEP_LAST: [usize; 65] = [ /// # 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, /// # 32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, /// # 16777215, 33554431, 67108863, 134217727, 268435455, 536870911, 1073741823, /// # 2147483647, 4294967295, 8589934591, 17179869183, 34359738367, 68719476735, /// # 137438953471, 274877906943, 549755813887, 1099511627775, 2199023255551, /// # 4398046511103, 8796093022207, 17592186044415, 35184372088831, /// # 70368744177663, 140737488355327, 281474976710655, 562949953421311, /// # 1125899906842623, 2251799813685247, 4503599627370495, 9007199254740991, /// # 18014398509481983, 36028797018963967, 72057594037927935, /// # 144115188075855871, 288230376151711743, 576460752303423487, /// # 1152921504606846975, 2305843009213693951, 4611686018427387903, /// # 9223372036854775807, 18446744073709551615, /// # ]; /// let mut b = 0b1010_1010; /// assert_eq!(b & KEEP_LAST[3], 0b010) /// ``` #[rustfmt::skip] #[cfg(not(target_arch = "wasm32"))] pub const KEEP_LAST: [usize; 65] = [ 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131_071, 262_143, 524_287, 1_048_575, 2_097_151, 4_194_303, 8_388_607, 16_777_215, 33_554_431, 67_108_863, 134_217_727, 268_435_455, 536_870_911, 1_073_741_823, 2_147_483_647, 4_294_967_295, 8_589_934_591, 17_179_869_183, 34_359_738_367, 68_719_476_735, 137_438_953_471, 274_877_906_943, 549_755_813_887, 1_099_511_627_775, 2_199_023_255_551, 4_398_046_511_103, 8_796_093_022_207, 17_592_186_044_415, 35_184_372_088_831, 70_368_744_177_663, 140_737_488_355_327, 281_474_976_710_655, 562_949_953_421_311, 1_125_899_906_842_623, 2_251_799_813_685_247, 4_503_599_627_370_495, 9_007_199_254_740_991, 18_014_398_509_481_983, 36_028_797_018_963_967, 72_057_594_037_927_935, 144_115_188_075_855_871, 288_230_376_151_711_743, 576_460_752_303_423_487, 1_152_921_504_606_846_975, 2_305_843_009_213_693_951, 4_611_686_018_427_387_903, 9_223_372_036_854_775_807, 18_446_744_073_709_551_615, ]; /// Values to keep last X bits of a u8 /// `KEEP_LAST[i]` equates `(1 << i) - 1` #[rustfmt::skip] #[cfg(target_arch = "wasm32")] pub const KEEP_LAST: [usize; 33] = [ 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1_023, 2_047, 4_095, 8_191, 16_383, 32_767, 65_535, 131_071, 262_143, 524_287, 1_048_575, 2_097_151, 4_194_303, 8_388_607, 16_777_215, 33_554_431, 67_108_863, 134_217_727, 268_435_455, 536_870_911, 1_073_741_823, 2_147_483_647, 4_294_967_295, ]; /// `CompactQR` is a struct that contains a `Vec` to store boolean values as bits. pub struct CompactQR { pub len: usize, pub data: Vec, } /// Returns a string visualization of the `CompactQR`. \ /// `CompactQR { len: 4, data: [0b1111_1010] }.to_string()` => `"1010"` impl Display for CompactQR { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { let mut res = String::with_capacity(self.len); for i in 0..(self.data.capacity() / 8) { let nb = self.data[i]; for j in 0..8 { if i * 8 + j >= self.len { return f.write_str(&res); } let j = 7 - j; let c = if nb & (1 << j) == 0 { '0' } else { '1' }; res.push(c); } } f.write_str(&res) } } #[allow(clippy::cast_possible_truncation)] impl CompactQR { /// Instantiates a new `CompactQR`, should not be used, reduces performance. #[allow(dead_code)] pub const fn new() -> Self { CompactQR { len: 0, data: Vec::new(), } } pub fn from_version(version: Version) -> Self { let len = version.max_bytes(); let data = vec![0; len * 8]; CompactQR { len: 0, data } } /// Instantiates a new `CompactQR`, with a given length, expects the length to be a multiple of 8. #[allow(dead_code)] #[cfg(test)] pub fn with_len(data_length: usize) -> Self { let length = data_length / 8 + usize::from(data_length % 8 != 0); CompactQR { len: 0, data: vec![0; length], } } /// Increase the length of data to specified length. pub fn increase_len(&mut self, data_length: usize) { if data_length / 8 >= self.data.len() { self.data.resize(data_length / 8 + 1, 0); } } /// Instantiates a new `CompactQR` from an already created array pub fn from_array(data: &[u8], len: usize) -> Self { CompactQR { len, data: data.to_vec(), } } /// Returns `len`, length is the current number of bits / boolean values stored in the array. pub const fn len(&self) -> usize { self.len } /// Returns `data`, the array of bits. pub const fn get_data(&self) -> &Vec { &self.data } /// Pushes eight values in the `CompactQR`, if the array is not big enough, it will be resized. #[inline(always)] #[allow(dead_code)] pub fn push_u8(&mut self, bits: u8) { self.increase_len(self.len + 8); let right = self.len % 8; let first_idx = self.len / 8; if right == 0 { self.data[first_idx] = bits; } else { let left = 8 - right; self.data[first_idx] |= (bits >> right) & (KEEP_LAST[left] as u8); self.data[first_idx + 1] |= (bits & KEEP_LAST[right] as u8) << left; } self.len += 8; } /// Pushes the u8 array in the `CompactQR`, using the `push_u8` function. \ /// If the array is not big enough, it will be resized. #[inline(always)] pub fn push_u8_slice(&mut self, slice: &[u8]) { self.increase_len(self.len + 8 * slice.len()); for &u in slice { self.push_u8(u); } } /// Pushes `len` values to the `CompactQR`. \ /// If the array is not big enough, it will be resized. #[inline(always)] pub fn push_bits(&mut self, bits: usize, len: usize) { self.increase_len(self.len + len); // Caps to max usize bits let bits = bits & KEEP_LAST[len]; let rem_space = (8 - self.len % 8) % 8; let first = self.len / 8; if rem_space > len { self.data[first] |= (bits << (rem_space - len)) as u8; self.len += len; return; } if rem_space != 0 { self.data[first] |= ((bits >> (len - rem_space)) & KEEP_LAST[rem_space]) as u8; self.len += rem_space; } for i in (8..=len - rem_space).rev().step_by(8) { self.push_u8((bits >> (i - 8)) as u8); } let remaining = (len - rem_space) % 8; if remaining == 0 { return; } self.data[self.len / 8] += ((bits & KEEP_LAST[remaining]) as u8) << (8 - remaining); self.len += remaining; } /// Fills the `CompactQR`'s remaining space with `[236, 17]`. /// Expects the `CompactQR` `len` to be a multiple of 8. #[inline(always)] pub fn fill(&mut self) { const PAD_BYTES: [u8; 2] = [0b1110_1100, 0b0001_0001]; //[236, 17] #[cfg(debug_assertions)] assert_eq!(self.len % 8, 0); for (i, _) in (self.len..self.data.len()).step_by(8).enumerate() { let bits = PAD_BYTES[i % 2]; self.push_u8(bits); } } } fast_qr-0.13.1/src/convert/image.rs000064400000000000000000000137521046102023000152540ustar 00000000000000//! Converts [`QRCode`] to an image //! //! ```rust //! use fast_qr::convert::ConvertError; //! use fast_qr::convert::{image::ImageBuilder, Builder, Shape}; //! use fast_qr::qr::QRBuilder; //! //! # fn main() -> Result<(), ConvertError> { //! // QRBuilde::new can fail if content is too big for version, //! // please check before unwrapping. //! let qrcode = QRBuilder::new("https://example.com/") //! .build() //! .unwrap(); //! //! let _img = ImageBuilder::default() //! .shape(Shape::RoundedSquare) //! .fit_width(600) //! .to_file(&qrcode, "out.png"); //! //! # std::fs::remove_file("out.png"); //! # Ok(()) //! # } //! ``` use std::fmt::Formatter; use std::io; use crate::QRCode; use super::Color; use super::{svg::SvgBuilder, Builder, Shape}; use resvg::tiny_skia::{self, Pixmap}; use resvg::usvg::{self, Size, Transform}; /// [`ImageBuilder`] contains an [`SvgBuilder`] and adds some options \ /// - fit_height adds a max-height boundary /// - fit_width adds a max-width boundary pub struct ImageBuilder { fit_height: Option, fit_width: Option, svg_builder: SvgBuilder, } /// Error when converting to image #[derive(Debug)] pub enum ImageError { /// Error while writing to file IoError(io::Error), /// Error while creating image ImageError(String), /// Error while convert to bytes EncodingError(String), } impl std::error::Error for ImageError {} impl std::fmt::Display for ImageError { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { ImageError::IoError(io_err) => f.write_str(io_err.to_string().as_str()), ImageError::ImageError(error) => f.write_str(error.as_str()), ImageError::EncodingError(error) => f.write_str(error.as_str()), } } } /// Creates an ImageBuilder instance, which contains an [`SvgBuilder`] impl Default for ImageBuilder { fn default() -> Self { ImageBuilder { fit_height: None, fit_width: None, svg_builder: Default::default(), } } } impl Builder for ImageBuilder { fn margin(&mut self, margin: usize) -> &mut Self { self.svg_builder.margin(margin); self } fn module_color>(&mut self, module_color: C) -> &mut Self { self.svg_builder.module_color(module_color); self } fn background_color>(&mut self, background_color: C) -> &mut Self { self.svg_builder.background_color(background_color); self } fn shape(&mut self, shape: Shape) -> &mut Self { self.svg_builder.shape(shape); self } fn image(&mut self, image: String) -> &mut Self { self.svg_builder.image(image); self } fn image_background_color>(&mut self, image_background_color: C) -> &mut Self { self.svg_builder .image_background_color(image_background_color); self } fn image_background_shape( &mut self, image_background_shape: super::ImageBackgroundShape, ) -> &mut Self { self.svg_builder .image_background_shape(image_background_shape); self } fn image_size(&mut self, image_size: f64) -> &mut Self { self.svg_builder.image_size(image_size); self } fn image_gap(&mut self, gap: f64) -> &mut Self { self.svg_builder.image_gap(gap); self } fn image_position(&mut self, x: f64, y: f64) -> &mut Self { self.svg_builder.image_position(x, y); self } fn shape_color>(&mut self, shape: Shape, color: C) -> &mut Self { self.svg_builder.shape_color(shape, color); self } } impl ImageBuilder { /// Add a max-height boundary pub fn fit_height(&mut self, height: u32) -> &mut Self { self.fit_height = Some(height); self } /// Add a max-width boundary pub fn fit_width(&mut self, width: u32) -> &mut Self { self.fit_width = Some(width); self } // From https://github.com/RazrFalcon/resvg/blob/374a25f/crates/resvg/tests/integration/main.rs /// Return a pixmap containing the svg for a QRCode pub fn to_pixmap(&self, qr: &QRCode) -> Pixmap { let opt = usvg::Options::default(); let tree = { let svg_data = self.svg_builder.to_str(qr); let tree = usvg::Tree::from_str(&svg_data, &opt); tree.expect("Failed to parse SVG") }; let (width, height, transform) = self.fit(tree.size()); let mut pixmap = tiny_skia::Pixmap::new(width, height).expect("Failed to create pixmap"); resvg::render(&tree, transform, &mut pixmap.as_mut()); pixmap } /// Saves the image for a QRCode to a file pub fn to_file(&self, qr: &QRCode, file: &str) -> Result<(), ImageError> { use io::{Error, ErrorKind}; self.to_pixmap(qr) .save_png(file) .map_err(|err| ImageError::IoError(Error::new(ErrorKind::Other, err.to_string()))) } /// Saves the image for a QRCode in a byte buffer pub fn to_bytes(&self, qr: &QRCode) -> Result, ImageError> { let out = self.to_pixmap(qr); out.encode_png() .map_err(|err| ImageError::EncodingError(err.to_string())) } fn fit(&self, tree_size: Size) -> (u32, u32, Transform) { let factor = match (self.fit_width, self.fit_height) { // Get the scaling factor by checking which dimensions can be scaled up the least (Some(width), Some(height)) => { (width as f32 / tree_size.width()).min(height as f32 / tree_size.height()) } (Some(width), None) => width as f32 / tree_size.width(), (None, Some(height)) => height as f32 / tree_size.height(), (None, None) => 1f32, }; ( (tree_size.width() * factor) as u32, (tree_size.height() * factor) as u32, tiny_skia::Transform::from_scale(factor, factor), ) } } fast_qr-0.13.1/src/convert/mod.rs000064400000000000000000000370301046102023000147440ustar 00000000000000//! Converts a [`crate::QRCode`] to image or SVG you will need to activate associated feature flag #[cfg(feature = "svg")] #[cfg_attr(docsrs, doc(cfg(feature = "svg")))] pub mod svg; use core::ops::Deref; #[cfg(feature = "svg")] use svg::SvgError; #[cfg(feature = "image")] #[cfg_attr(docsrs, doc(cfg(feature = "image")))] pub mod image; #[cfg(feature = "image")] use image::ImageError; use crate::Module; /// Converts a position to a module svg /// # Example /// /// For the square shape, the svg is `M{x},{y}h1v1h-1` /// /// ```rust /// # use fast_qr::Module; /// fn square(y: usize, x: usize, _module: Module) -> String { /// format!("M{x},{y}h1v1h-1") /// } /// ``` pub type ModuleFunction = fn(usize, usize, Module) -> String; #[cfg(all(target_arch = "wasm32", feature = "wasm-bindgen"))] use wasm_bindgen::prelude::*; /// Different possible Shapes to represent modules in a [`crate::QRCode`] #[repr(C)] #[wasm_bindgen] #[cfg(feature = "wasm-bindgen")] #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd)] pub enum Shape { /// Square Shape Square, /// Circle Shape Circle, /// RoundedSquare Shape RoundedSquare, /// Vertical Shape Vertical, /// Horizontal Shape Horizontal, /// Diamond Shape Diamond, } /// Different possible Shapes to represent modules in a [`crate::QRCode`] #[cfg(not(feature = "wasm-bindgen"))] #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd)] pub enum Shape { /// Square Shape Square, /// Circle Shape Circle, /// RoundedSquare Shape RoundedSquare, /// Vertical Shape Vertical, /// Horizontal Shape Horizontal, /// Diamond Shape Diamond, /// Custom Shape with a function / closure /// # Example /// ```rust /// use fast_qr::convert::Shape; /// let command_function = |y, x, cell| { /// if x % 2 == 0 { /// // Works thanks to Deref /// Shape::Square(y, x, cell) /// } else { /// // Rectangle /// format!("M{x},{y}h1v.5h-1") /// } /// }; /// let command = Shape::Command(command_function); /// ``` /// /// /// /// /// Command(ModuleFunction), } impl From for usize { fn from(shape: Shape) -> Self { match shape { Shape::Square => 0, Shape::Circle => 1, Shape::RoundedSquare => 2, Shape::Vertical => 3, Shape::Horizontal => 4, Shape::Diamond => 5, #[cfg(not(feature = "wasm-bindgen"))] Shape::Command(_) => 6, } } } impl From for Shape { #[allow(clippy::match_same_arms)] fn from(shape: String) -> Self { match shape.to_lowercase().as_str() { "square" => Shape::Square, "circle" => Shape::Circle, "rounded_square" => Shape::RoundedSquare, "vertical" => Shape::Vertical, "horizontal" => Shape::Horizontal, "diamond" => Shape::Diamond, _ => Shape::Square, } } } impl From for &str { fn from(shape: Shape) -> Self { match shape { Shape::Square => "square", Shape::Circle => "circle", Shape::RoundedSquare => "rounded_square", Shape::Vertical => "vertical", Shape::Horizontal => "horizontal", Shape::Diamond => "diamond", #[cfg(not(feature = "wasm-bindgen"))] Shape::Command(_) => "command", } } } impl Shape { pub(crate) fn square(y: usize, x: usize, _: Module) -> String { format!("M{x},{y}h1v1h-1") } pub(crate) fn circle(y: usize, x: usize, _: Module) -> String { format!("M{},{y}.5a.5,.5 0 1,1 0,-.1", x + 1) } pub(crate) fn rounded_square(y: usize, x: usize, _: Module) -> String { format!("M{x}.2,{y}.2 {x}.8,{y}.2 {x}.8,{y}.8 {x}.2,{y}.8z") } pub(crate) fn horizontal(y: usize, x: usize, _: Module) -> String { format!("M{x},{y}.1h1v.8h-1") } pub(crate) fn vertical(y: usize, x: usize, _: Module) -> String { format!("M{x}.1,{y}h.8v1h-.8") } pub(crate) fn diamond(y: usize, x: usize, _: Module) -> String { format!("M{x}.5,{y}l.5,.5l-.5,.5l-.5,-.5z") } const FUNCTIONS: [ModuleFunction; 6] = [ Shape::square, Shape::circle, Shape::rounded_square, Shape::vertical, Shape::horizontal, Shape::diamond, ]; } impl Deref for Shape { type Target = ModuleFunction; fn deref(&self) -> &Self::Target { let index: usize = (*self).into(); match self { #[cfg(not(feature = "wasm-bindgen"))] Self::Command(func) => func, _ => &Self::FUNCTIONS[index], } } } /// Different possible image background shapes #[cfg_attr(feature = "wasm-bindgen", repr(C), wasm_bindgen)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd)] pub enum ImageBackgroundShape { /// Square shape Square, /// Circle shape Circle, /// Rounded square shape RoundedSquare, } /// Contains possible errors for a conversion #[derive(Debug)] pub enum ConvertError { /// Contains error message for a SVG conversion #[cfg(feature = "svg")] #[cfg_attr(docsrs, doc(cfg(feature = "svg")))] Svg(String), /// Contains error message for an Image conversion #[cfg(feature = "image")] #[cfg_attr(docsrs, doc(cfg(feature = "image")))] Image(String), /// Contains error message if a file write failed Io(std::io::Error), } #[cfg(feature = "svg")] #[cfg_attr(docsrs, doc(cfg(feature = "svg")))] impl From for ConvertError { fn from(err: SvgError) -> Self { match err { SvgError::SvgError(svg_err) => Self::Svg(svg_err), #[cfg(not(feature = "wasm-bindgen"))] SvgError::IoError(io_err) => Self::Io(io_err), } } } #[cfg(feature = "image")] #[cfg_attr(docsrs, doc(cfg(feature = "image")))] impl From for ConvertError { fn from(err: ImageError) -> Self { match err { ImageError::EncodingError(image_err) => Self::Image(image_err), ImageError::ImageError(image_err) => Self::Image(image_err), ImageError::IoError(io_err) => Self::Io(io_err), } } } /// Converts an array of pixel color to it's hexadecimal representation /// # Example /// ```rust /// # use fast_qr::convert::rgba2hex; /// let color = [0, 0, 0, 255]; /// assert_eq!(&rgba2hex(color), "#000000"); /// ``` #[must_use] pub fn rgba2hex(color: [u8; 4]) -> String { let mut hex = String::with_capacity(9); hex.push('#'); hex.push_str(&format!("{:02x}", color[0])); hex.push_str(&format!("{:02x}", color[1])); hex.push_str(&format!("{:02x}", color[2])); if color[3] != 255 { hex.push_str(&format!("{:02x}", color[3])); } hex } /// Allows to take String, string slices, arrays or slices of u8 (3 or 4) to create a [Color] pub struct Color(pub String); impl Color { /// Returns the contained color #[must_use] pub fn to_str(&self) -> &str { &self.0 } } impl From for Color { fn from(color: String) -> Self { Self(color) } } impl From<&str> for Color { fn from(color: &str) -> Self { Self(color.to_string()) } } impl From<[u8; 4]> for Color { fn from(color: [u8; 4]) -> Self { Self(rgba2hex(color)) } } impl From<[u8; 3]> for Color { fn from(color: [u8; 3]) -> Self { Self::from([color[0], color[1], color[2], 255]) } } impl From<&[u8]> for Color { fn from(color: &[u8]) -> Self { if color.len() == 3 { Self::from([color[0], color[1], color[2]]) } else if color.len() == 4 { Self::from([color[0], color[1], color[2], color[3]]) } else { panic!("Invalid color length"); } } } impl From> for Color { fn from(color: Vec) -> Self { Self::from(&color[..]) } } /// Trait for `SvgBuilder` and `ImageBuilder` pub trait Builder { /// Updates margin (default: 4) fn margin(&mut self, margin: usize) -> &mut Self; /// Updates module color (default: #000000) fn module_color>(&mut self, module_color: C) -> &mut Self; /// Updates background color (default: #FFFFFF) fn background_color>(&mut self, background_color: C) -> &mut Self; /// Adds a shape to the shapes list fn shape(&mut self, shape: Shape) -> &mut Self; /// Add a shape to the shapes list with a specific color fn shape_color>(&mut self, shape: Shape, color: C) -> &mut Self; // Manages the image part /// Provides the image path or an base64 encoded image fn image(&mut self, image: String) -> &mut Self; /// Updates the image background color (default: #FFFFFF) fn image_background_color>(&mut self, image_background_color: C) -> &mut Self; /// Updates the image background shape (default: Square) fn image_background_shape(&mut self, image_background_shape: ImageBackgroundShape) -> &mut Self; /// Updates the image size and the gap between the image and the [`crate::QRCode`] /// Default is around 30% of the [`crate::QRCode`] size fn image_size(&mut self, image_size: f64) -> &mut Self; /// Updates the gap between the image and the [`crate::QRCode`] fn image_gap(&mut self, gap: f64) -> &mut Self; /// Updates the image position, anchor is the center of the image. Default is the center of the [`crate::QRCode`] fn image_position(&mut self, x: f64, y: f64) -> &mut Self; } fast_qr-0.13.1/src/convert/svg.rs000064400000000000000000000256651046102023000147770ustar 00000000000000//! Converts [`QRCode`] to SVG //! //! ```rust //! use fast_qr::convert::ConvertError; //! use fast_qr::convert::{svg::SvgBuilder, Builder, Shape}; //! use fast_qr::qr::QRBuilder; //! //! # fn main() -> Result<(), ConvertError> { //! // QRBuilde::new can fail if content is too big for version, //! // please check before unwrapping. //! let qrcode = QRBuilder::new("https://example.com/") //! .build() //! .unwrap(); //! //! let _svg = SvgBuilder::default() //! .shape(Shape::RoundedSquare) //! .to_file(&qrcode, "out.svg"); //! //! # std::fs::remove_file("out.svg"); //! # Ok(()) //! # } //! ``` use crate::{QRCode, Version}; use super::{Builder, Color, ImageBackgroundShape, ModuleFunction, Shape}; /// Builder for svg, can set shape, margin, background_color, dot_color pub struct SvgBuilder { /// Command vector allows predefined or custom shapes /// The default is square, commands can be added using `.shape()` commands: Vec, /// Commands can also have a custom color /// The default is `dot_color`, commands with specific colors can be /// added using `.shape_color()` command_colors: Vec>, /// The margin for the svg, default is 4 margin: usize, /// The background color for the svg, default is #FFFFFF background_color: Color, /// The color for each module, default is #000000 dot_color: Color, // Image Embedding /// Image to embed in the svg, can be a path or a base64 string image: Option, /// Background color for the image, default is #FFFFFF image_background_color: Color, /// Background shape for the image, default is square image_background_shape: ImageBackgroundShape, /// Size of the image (in module size), default is ~1/3 of the svg image_size: Option, /// Gap between the image and the border (in module size), default is calculated image_gap: Option, /// Position of the image, default is center image_position: Option<(f64, f64)>, } #[derive(Debug)] /// Possible errors when converting to SVG pub enum SvgError { /// Error while writing file #[cfg(not(feature = "wasm-bindgen"))] IoError(std::io::Error), /// Error while creating svg SvgError(String), } /// Creates a Builder instance impl Default for SvgBuilder { fn default() -> Self { SvgBuilder { background_color: [255; 4].into(), dot_color: [0, 0, 0, 255].into(), margin: 4, commands: Vec::new(), command_colors: Vec::new(), // Image Embedding image: None, image_background_color: [255; 4].into(), image_background_shape: ImageBackgroundShape::Square, image_size: None, image_gap: None, image_position: None, } } } impl Builder for SvgBuilder { fn margin(&mut self, margin: usize) -> &mut Self { self.margin = margin; self } fn module_color>(&mut self, dot_color: C) -> &mut Self { self.dot_color = dot_color.into(); self } fn background_color>(&mut self, background_color: C) -> &mut Self { self.background_color = background_color.into(); self } fn shape(&mut self, shape: Shape) -> &mut Self { self.commands.push(*shape); self.command_colors.push(None); self } fn shape_color>(&mut self, shape: Shape, color: C) -> &mut Self { self.commands.push(*shape); self.command_colors.push(Some(color.into())); self } fn image(&mut self, image: String) -> &mut Self { self.image = Some(image); self } fn image_background_color>(&mut self, image_background_color: C) -> &mut Self { self.image_background_color = image_background_color.into(); self } fn image_background_shape( &mut self, image_background_shape: ImageBackgroundShape, ) -> &mut Self { self.image_background_shape = image_background_shape; self } fn image_size(&mut self, image_size: f64) -> &mut Self { self.image_size = Some(image_size); self } fn image_gap(&mut self, gap: f64) -> &mut Self { self.image_gap = Some(gap); self } fn image_position(&mut self, x: f64, y: f64) -> &mut Self { self.image_position = Some((x, y)); self } } impl SvgBuilder { fn image_placement(image_background_shape: ImageBackgroundShape, n: usize) -> (f64, f64) { use ImageBackgroundShape::{Circle, RoundedSquare, Square}; #[rustfmt::skip] const SQUARE: [f64; 40] = [ 5f64, 9f64, 9f64, 11f64, 13f64, 13f64, 15f64, 17f64, 17f64, 19f64, 21f64, 21f64, 23f64, 25f64, 25f64, 27f64, 29f64, 29f64, 31f64, 33f64, 33f64, 35f64, 37f64, 37f64, 39f64, 41f64, 41f64, 43f64, 45f64, 45f64, 47f64, 49f64, 49f64, 51f64, 53f64, 53f64, 55f64, 57f64, 57f64, 59f64, ]; const ROUNDED_SQUARE: [f64; 40] = SQUARE; const CIRCLE: [f64; 40] = SQUARE; // Using hardcoded values let version = Version::from_n(n) as usize; let border_size = match image_background_shape { Square => SQUARE[version], RoundedSquare => ROUNDED_SQUARE[version], Circle => CIRCLE[version], }; // Allows for a module gap between the image and the border let gap = match image_background_shape { Square | RoundedSquare => 2f64, Circle => 3f64, }; // Make the image border bigger for bigger versions let gap = gap * (version + 10) as f64 / 10f64; (border_size, (border_size - gap).round()) } fn image(&self, n: usize) -> String { if self.image.is_none() { return String::new(); } let image = self.image.as_ref().unwrap(); let mut out = String::with_capacity(image.len() + 100); let (mut border_size, mut image_size) = Self::image_placement(self.image_background_shape, n); if let Some(override_size) = self.image_size { let gap = -(image_size - border_size); border_size = override_size + gap; image_size = override_size; } if let Some(override_gap) = self.image_gap { border_size = image_size + override_gap * 2f64; } let mut placed_coord_x = (self.margin * 2 + n) as f64 - border_size; // Adjust for non-integer initial x coordinates so as not to partially cover bits by rounding down. if placed_coord_x % 2f64 != 0f64 { placed_coord_x += 1f64; border_size -= 1f64; } placed_coord_x /= 2f64; let mut placed_coord = (placed_coord_x, placed_coord_x); if let Some((x, y)) = self.image_position { placed_coord = (x - border_size / 2f64, y - border_size / 2f64); } let format = match self.image_background_shape { ImageBackgroundShape::Square => { r#""# } ImageBackgroundShape::Circle => { r#""# } ImageBackgroundShape::RoundedSquare => { r#""# } }; let format = format .replace("{0}", &placed_coord.0.to_string()) .replace("{1}", &placed_coord.1.to_string()) .replace("{2}", &border_size.to_string()) .replace("{3}", self.image_background_color.to_str()); out.push_str(&format); out.push_str(&format!( r#""#, placed_coord.0 + (border_size - image_size) / 2f64, placed_coord.1 + (border_size - image_size) / 2f64, image_size, image )); out } fn path(&self, qr: &QRCode) -> String { const DEFAULT_COMMAND: [ModuleFunction; 1] = [Shape::square]; const DEFAULT_COMMAND_COLOR: [Option; 1] = [None]; // TODO: cleanup this basic logic let command_colors: &[Option] = if !self.commands.is_empty() { &self.command_colors } else { &DEFAULT_COMMAND_COLOR }; let commands: &[ModuleFunction] = if !self.commands.is_empty() { &self.commands } else { &DEFAULT_COMMAND }; let mut paths = vec![String::with_capacity(10 * qr.size * qr.size); commands.len()]; for path in paths.iter_mut() { path.push_str(r#""#, command_color.to_str())); } paths.join("") } /// Return a string containing the svg for a qr code pub fn to_str(&self, qr: &QRCode) -> String { let n = qr.size; let mut out = String::with_capacity(11 * n * n / 2); out.push_str(&format!( r#""#, self.margin * 2 + n )); out.push_str(&format!( r#""#, self.margin * 2 + n, self.background_color.to_str() )); out.push_str(&self.path(qr)); out.push_str(&self.image(n)); out.push_str(""); out } /// Saves the svg for a qr code to a file #[cfg(not(feature = "wasm-bindgen"))] pub fn to_file(&self, qr: &QRCode, file: &str) -> Result<(), SvgError> { use std::fs::File; use std::io::Write; let out = self.to_str(qr); let mut f = File::create(file).map_err(SvgError::IoError)?; f.write_all(out.as_bytes()).map_err(SvgError::IoError)?; Ok(()) } } fast_qr-0.13.1/src/datamasking.rs000064400000000000000000000124011046102023000147630ustar 00000000000000//! Contains the HEIGHT functions that can alter `QRCode` #![deny(unsafe_code)] #![warn(missing_docs)] use crate::module::ModuleType; use crate::QRCode; /// The different mask patterns. The mask pattern should only be applied to /// the data and error correction portion of the QR code. #[derive(Debug, Copy, Clone)] pub enum Mask { /// QR code pattern n°0: `(x + y) % 2 == 0`. Checkerboard = 0, /// QR code pattern n°1: `y % 2 == 0`. HorizontalLines = 1, /// QR code pattern n°2: `x % 3 == 0`. VerticalLines = 2, /// QR code pattern n°3: `(x + y) % 3 == 0`. DiagonalLines = 3, /// QR code pattern n°4: `((x/3) + (y/2)) % 2 == 0`. LargeCheckerboard = 4, /// QR code pattern n°5: `(x*y)%2 + (x*y)%3 == 0`. Fields = 5, /// QR code pattern n°6: `((x*y)%2 + (x*y)%3) % 2 == 0`. Diamonds = 6, /// QR code pattern n°7: `((x+y)%2 + (x*y)%3) % 2 == 0`. Meadow = 7, } /// Mask function nb°**0**, `Mask::Checkerboard`. fn mask_checkerboard(qr: &mut QRCode) { for row in 0..qr.size { for column in (row & 1..qr.size).step_by(2) { let module = &mut qr[row][column]; if module.module_type() == ModuleType::Data { module.toggle(); } } } } /// Mask function nb°**1**, `Mask::HorizontalLines`. fn mask_horizontal(qr: &mut QRCode) { for row in (0..qr.size).step_by(2) { for column in 0..qr.size { let module = &mut qr[row][column]; if module.module_type() == ModuleType::Data { module.toggle(); } } } } /// Mask function nb°**2**, `Mask::VerticalLines`. fn mask_vertical(qr: &mut QRCode) { for row in 0..qr.size { for column in (0..qr.size).step_by(3) { let module = &mut qr[row][column]; if module.module_type() == ModuleType::Data { module.toggle(); } } } } /// Mask function nb°**3**, `Mask::DiagonalLines`. fn mask_diagonal(qr: &mut QRCode) { for row in 0..qr.size { let start = (3 - row % 3) % 3; for column in (start..qr.size).step_by(3) { let module = &mut qr[row][column]; if module.module_type() == ModuleType::Data { module.toggle(); } } } } /// Mask function nb°**4**, `Mask::LargeCheckerboard`. fn mask_large_checkerboard(qr: &mut QRCode) { for row in 0..qr.size { let start = ((row >> 1) & 1) * 3; // ((row / 2) % 2) * 3; for column in (start..qr.size).step_by(6) { for i in column..core::cmp::min(qr.size, column + 3) { let module = &mut qr[row][i]; if module.module_type() == ModuleType::Data { module.toggle(); } } } } } fn mask_5_6(qr: &mut QRCode, offset: &[(usize, usize)]) { for row in (0..qr.size).step_by(6) { for column in 0..qr.size { let module = &mut qr[row][column]; if module.module_type() == ModuleType::Data { module.toggle(); } let module = &mut qr[column][row]; if module.module_type() == ModuleType::Data && (row % 6 != 0 || column % 6 != 0) { module.toggle(); } } } for row in (0..qr.size).step_by(6) { for column in (0..qr.size).step_by(6) { for (y, x) in offset { if row + y >= qr.size || column + x >= qr.size { continue; } let module = &mut qr[row + y][column + x]; if module.module_type() == ModuleType::Data { module.toggle(); } } } } } /// Mask function nb°**5**, `Mask::Fields`. fn mask_field(qr: &mut QRCode) { const OFFSETS: [(usize, usize); 4] = [(2, 3), (3, 2), (3, 4), (4, 3)]; mask_5_6(qr, &OFFSETS); } /// Mask function nb°**6**, `Mask::Diamonds`. fn mask_diamond(qr: &mut QRCode) { #[rustfmt::skip] const OFFSETS: [(usize, usize); 12] = [ (1, 1), (1, 2), (2, 1), (2, 3), (2, 4), (3, 2), (3, 4), (4, 2), (4, 3), (4, 5), (5, 4), (5, 5) ]; mask_5_6(qr, &OFFSETS); } /// Mask function nb°**7**, `Mask::Meadow`. fn mask_meadow(qr: &mut QRCode) { for row in 0..qr.size { for column in row..qr.size { if (((row + column) % 2) + ((row * column) % 3)) % 2 != 0 { continue; } let module = &mut qr[row][column]; if module.module_type() == ModuleType::Data { module.toggle(); } let module = &mut qr[column][row]; if column != row && module.module_type() == ModuleType::Data { module.toggle(); } } } } /// Applies the function at `mask_nb` on `mat` pub fn mask(qr: &mut QRCode, mask: Mask) { match mask { Mask::Checkerboard => mask_checkerboard(qr), Mask::HorizontalLines => mask_horizontal(qr), Mask::VerticalLines => mask_vertical(qr), Mask::DiagonalLines => mask_diagonal(qr), Mask::LargeCheckerboard => mask_large_checkerboard(qr), Mask::Fields => mask_field(qr), Mask::Diamonds => mask_diamond(qr), Mask::Meadow => mask_meadow(qr), } } fast_qr-0.13.1/src/default.rs000064400000000000000000000175531046102023000141410ustar 00000000000000//! Creates the default empty `QRCode` (no data) #![deny(unsafe_code)] #![warn(missing_docs)] use crate::datamasking::Mask; use crate::module::Module; use crate::version::Version; use crate::{hardcode, QRCode, ECL}; /// Size of FIP (Finder Patterns) const POSITION_SIZE: usize = 7; pub fn transpose(qr: &QRCode) -> QRCode { let mut transpose = qr.clone(); for i in 0..qr.size { for j in i + 1..qr.size { transpose[i][j] = qr[j][i]; transpose[j][i] = qr[i][j]; } } transpose } pub fn create_matrix(version: Version) -> QRCode { let size = version.size(); let mut qr = QRCode::default(size); create_matrix_pattern(&mut qr); create_matrix_timing(&mut qr); create_matrix_dark_module(&mut qr); create_matrix_alignments(&mut qr, version); create_matrix_version_info(&mut qr, version); create_matrix_empty(&mut qr); let n: usize = qr.size; // Format information is not placed on the matrix yet // But we fill it anyway with garbage data to make it easier for placement { if (version as usize) < (Version::V01 as usize) { return qr; } for i in 0..=5 { // Top left qr[8][i] = Module::format(Module::LIGHT); qr[i][8] = Module::format(Module::LIGHT); // Top right qr[8][n - 1 - i] = Module::format(Module::LIGHT); // Bottom left qr[n - 1 - i][8] = Module::format(Module::LIGHT); } // Top left qr[8][7] = Module::format(Module::LIGHT); qr[8][8] = Module::format(Module::LIGHT); qr[7][8] = Module::format(Module::LIGHT); // Top right qr[8][n - 1 - 6] = Module::format(Module::LIGHT); qr[8][n - 1 - 7] = Module::format(Module::LIGHT); // Bottom left qr[n - 1 - 6][8] = Module::format(Module::LIGHT); } qr } /// Adds the 3 needed squares pub fn create_matrix_pattern(qr: &mut QRCode) { let length = qr.size; let offsets = [ (0, 0), (length - POSITION_SIZE, 0), (0, length - POSITION_SIZE), ]; // Required pattern (4.1 Positions) for (y, x) in offsets { // Border for j in 0..=6 { qr[y][j + x] = Module::finder_pattern(Module::DARK); qr[6 + y][j + x] = Module::finder_pattern(Module::DARK); qr[j + y][x] = Module::finder_pattern(Module::DARK); qr[j + y][6 + x] = Module::finder_pattern(Module::DARK); } for j in 1..=5 { qr[y + 1][j + x] = Module::finder_pattern(Module::LIGHT); qr[5 + y][j + x] = Module::finder_pattern(Module::LIGHT); qr[j + y][x + 1] = Module::finder_pattern(Module::LIGHT); qr[j + y][5 + x] = Module::finder_pattern(Module::LIGHT); } for j in 2..=4 { qr[j + y][2 + x] = Module::finder_pattern(Module::DARK); qr[j + y][3 + x] = Module::finder_pattern(Module::DARK); qr[j + y][4 + x] = Module::finder_pattern(Module::DARK); } } } /// Adds the two lines of Timing patterns pub fn create_matrix_timing(qr: &mut QRCode) { let length = qr.size; // Required pattern (4.3 Timing) for i in POSITION_SIZE + 1..length - POSITION_SIZE { let value = if (POSITION_SIZE + 1) % 2 == i % 2 { Module::DARK } else { Module::LIGHT }; qr[POSITION_SIZE - 1][i] = Module::timing(value); qr[i][POSITION_SIZE - 1] = Module::timing(value); } } /// Adds the forever present pixel pub fn create_matrix_dark_module(qr: &mut QRCode) { // Dark module let n: usize = qr.size; qr[n - 8][8] = Module::dark(Module::DARK); } /// Adds the smaller squares if needed pub fn create_matrix_alignments(qr: &mut QRCode, version: Version) { if let Version::V01 = version { return; } // Alignments (smaller cubes) let alignment_patterns = version.alignment_patterns_grid(); let max = alignment_patterns.len() - 1; for (i, &alignment_y) in alignment_patterns.iter().enumerate() { for (j, &alignment_x) in alignment_patterns.iter().enumerate() { if i == 0 && (j == max || j == 0) || (i == max && j == 0) { continue; } let y = alignment_y - 2; let x = alignment_x - 2; for offset in 0..=4 { qr[y][x + offset] = Module::alignment(Module::DARK); qr[y + 4][x + offset] = Module::alignment(Module::DARK); qr[y + offset][x] = Module::alignment(Module::DARK); qr[y + offset][x + 4] = Module::alignment(Module::DARK); } let y = alignment_y - 1; let x = alignment_x - 1; for offset in 0..=2 { qr[y][x + offset] = Module::alignment(Module::LIGHT); qr[y + 2][x + offset] = Module::alignment(Module::LIGHT); qr[y + offset][x] = Module::alignment(Module::LIGHT); qr[y + offset][x + 2] = Module::alignment(Module::LIGHT); } qr[alignment_y][alignment_x] = Module::alignment(Module::DARK); } } } /// Adds the version information if needed pub fn create_matrix_version_info(qr: &mut QRCode, version: Version) { if (version as usize) < (Version::V07 as usize) { return; } let version_info = version.information(); let n: usize = qr.size; for i in 0..=2 { for j in 0..=5 { let shift_i = 2 - i; let shift_j = 5 - j; let shift: u32 = 1 << ((5 - shift_j) * 3 + (2 - shift_i)); let value = (version_info & shift) != 0; qr[j][n - 11 + i] = Module::version(value); qr[n - 11 + i][j] = Module::version(value); } } } /// Adds the format information if needed pub fn create_matrix_format_info(qr: &mut QRCode, quality: ECL, mask: Mask) { let format_info = hardcode::ecm_to_format_information(quality, mask); let n: usize = qr.size; for i in (0..=5).rev() { let shift = 1 << (i + 9); let value = (format_info & shift) != 0; qr[8][5 - i] = Module::format(value); qr[n - 6 + i][8] = Module::format(value); } for i in 0..=5 { let shift = 1 << i; let value = (format_info & shift) != 0; qr[i][8] = Module::format(value); qr[8][n - i - 1] = Module::format(value); } { let shift = 1 << 8; let value = (format_info & shift) != 0; // Six on left qr[8][7] = Module::format(value); // Six on bottom qr[n - 7][8] = Module::format(value); } { let shift = 1 << 7; let value = (format_info & shift) != 0; // Seven on left qr[8][8] = Module::format(value); // Seven on right qr[8][n - 8] = Module::format(value); } { let shift = 1 << 6; let value = (format_info & shift) != 0; // Height on left qr[7][8] = Module::format(value); // Height on right qr[8][n - 7] = Module::format(value); } } /// Adds the space between finder patterns and data fn create_matrix_empty(qr: &mut QRCode) { let n: usize = qr.size; for i in 0..=7 { // Top left qr[i][7] = Module::empty(Module::LIGHT); qr[7][i] = Module::empty(Module::LIGHT); // Bottom left qr[n - 8 + i][7] = Module::empty(Module::LIGHT); qr[n - 8][i] = Module::empty(Module::LIGHT); // Top right qr[i][n - 8] = Module::empty(Module::LIGHT); qr[7][n - 8 + i] = Module::empty(Module::LIGHT); } } #[cfg(test)] pub fn create_mat_from_bool(bool_mat: &[[bool; N]; N]) -> QRCode { let mut mat = create_matrix(Version::from_n(N)); for (i, row) in bool_mat.iter().enumerate() { for (j, &value) in row.iter().enumerate() { mat[i][j].set(value); } } mat } fast_qr-0.13.1/src/ecl.rs000064400000000000000000000014071046102023000132470ustar 00000000000000//! Contains all different levels of quality. //! And allows to find easily max bits per version/quality pair #![deny(unsafe_code)] #![warn(missing_docs)] use std::fmt::Write; /// Error Correction Coding has 4 levels #[derive(Copy, Clone, Debug)] #[allow(dead_code)] #[cfg_attr(feature = "wasm-bindgen", wasm_bindgen::prelude::wasm_bindgen)] pub enum ECL { /// Low, 7% L, /// Medium, 15% M, /// Quartile, 25% Q, /// High, 30% H, } impl core::fmt::Display for ECL { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { match self { ECL::L => f.write_char('L'), ECL::M => f.write_char('M'), ECL::Q => f.write_char('Q'), ECL::H => f.write_char('H'), } } } fast_qr-0.13.1/src/encode.rs000064400000000000000000000133211046102023000137370ustar 00000000000000//! Contains all functions required to encode any string as a `QRCode` #![deny(unsafe_code)] #![warn(missing_docs)] use crate::compact::CompactQR; use crate::ecl::ECL; use crate::hardcode; use crate::version::Version; /// Enum for the 3 encoding mode #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum Mode { /// Numeric mode (0-9 only) Numeric, /// Alphanumeric mode (0-9, A-Z, $%*./:+-?.= [space]) Alphanumeric, /// Byte mode (any) Byte, } /// Encodes the string according the mode and version pub fn encode(input: &[u8], ecl: ECL, mode: Mode, version: Version) -> CompactQR { let cci_bits = hardcode::cci_bits(version, mode); let mut compact = CompactQR::from_version(version); match mode { Mode::Numeric => encode_numeric(&mut compact, input, cci_bits), Mode::Alphanumeric => encode_alphanumeric(&mut compact, input, cci_bits), Mode::Byte => encode_byte(&mut compact, input, cci_bits), }; let data_bits = hardcode::data_bits(version, ecl); add_terminator(&mut compact, data_bits); pad_to_8(&mut compact); compact.fill(); compact } /// Find the best encoding (Numeric -> Alnum -> Byte) pub fn best_encoding(input: &[u8]) -> Mode { fn try_encode_numeric(input: &[u8], i: usize) -> Mode { for &c in input.iter().skip(i) { if !c.is_ascii_digit() { return try_encode_alphanumeric(input, i); } } Mode::Numeric } fn try_encode_alphanumeric(input: &[u8], i: usize) -> Mode { for &c in input.iter().skip(i) { if !is_qr_alphanumeric(c) { return Mode::Byte; } } Mode::Alphanumeric } try_encode_numeric(input, 0) } /// Encodes numeric strings (i.e. "123456789"), referring to 8.4.2 of the spec. pub(crate) fn encode_numeric(compact: &mut CompactQR, input: &[u8], cci_bits: usize) { #[derive(Clone, Copy)] enum NumericEncoding { Single, Double, Triple, } fn encode_number(compact: &mut CompactQR, number: usize, encoding: NumericEncoding) { match encoding { NumericEncoding::Single => compact.push_bits(number, 4), NumericEncoding::Double => compact.push_bits(number, 7), NumericEncoding::Triple => compact.push_bits(number, 10), } } compact.push_bits(0b0001, 4); compact.push_bits(input.len(), cci_bits); let mut i = 0; let len = input.len() - input.len() % 3; while i < len { let number = ascii_to_digit(input[i]) * 100 + ascii_to_digit(input[i + 1]) * 10 + ascii_to_digit(input[i + 2]); encode_number(compact, number, NumericEncoding::Triple); i += 3; } // If the length is a multiple of 3, we are done if len == input.len() { return; } let mut number = 0; while i < input.len() { number *= 10; number += ascii_to_digit(input[i]); i += 1; } let encoding = match i % 3 { 1 => NumericEncoding::Single, 2 => NumericEncoding::Double, _ => unreachable!("i % 3 can only be 1 or 2"), }; encode_number(compact, number, encoding); } /// Encodes alphanumeric strings (i.e. "FAST-QR123"), referring to 8.4.3 of the spec. pub(crate) fn encode_alphanumeric(compact: &mut CompactQR, input: &[u8], cci_bits: usize) { compact.push_bits(0b0010, 4); compact.push_bits(input.len(), cci_bits); let even_size = input.len() - input.len() % 2; for chunk in input.chunks_exact(2) { let a = ascii_to_alphanumeric(chunk[0]); let b = ascii_to_alphanumeric(chunk[1]); compact.push_bits(a * 45 + b, 11); } if even_size != input.len() { compact.push_bits(ascii_to_alphanumeric(*input.last().unwrap()), 6); } } /// Encodes any string (i.e. ""), referring to 8.4.4 of the spec. pub(crate) fn encode_byte(compact: &mut CompactQR, input: &[u8], cci_bits: usize) { compact.push_bits(0b0100, 4); compact.push_bits(input.len(), cci_bits); compact.push_u8_slice(input); } /// Adds needed terminator padding, terminating the data `BitString`, referring to 8.4.8 of the spec. fn add_terminator(compact: &mut CompactQR, data_bits: usize) { let len = data_bits - compact.len(); let len = core::cmp::min(len, 4); compact.push_bits(0, len); } /// Adds the padding to make the length of the `BitString` a multiple of 8, referring to 8.4.9 of the spec. fn pad_to_8(compact: &mut CompactQR) { let len = (8 - compact.len() % 8) % 8; compact.push_bits(0, len); } /// Converts ascii number to it's value in usize \ /// "5" -> 5 fn ascii_to_digit(c: u8) -> usize { assert!( c.is_ascii_digit(), "Unexpected character '{}' in Numeric mode", c as char ); (c - b'0') as usize } /// Converts ascii alnum to it's numeric value, characters included in `AlphaNumeric` are: \ /// 0-9, A-Z, $%*./:+-?.= [space] \ /// referring to 7.1 of the spec. pub(crate) fn ascii_to_alphanumeric(c: u8) -> usize { match c { b'0'..=b'9' => (c - b'0') as usize, b'A'..=b'Z' => (c - b'A') as usize + 10, b' ' => 36, b'$' => 37, b'%' => 38, b'*' => 39, b'+' => 40, b'-' => 41, b'.' => 42, b'/' => 43, b':' => 44, _ => panic!("Unexpected character '{}' in Alphanumeric mode", c as char), } } /// Checks if character c is alphanumeric: 0-9, A-Z, $%*./:+-?.= [space] \ /// referring to 7.1 of the spec. const fn is_qr_alphanumeric(c: u8) -> bool { matches!(c, b'A'..=b'Z' | b'0'..=b'9' | b' ' | b'$' | b'%' | b'*' | b'+' | b'-' | b'.' | b'/' | b':') } fast_qr-0.13.1/src/hardcode.rs000064400000000000000000000405221046102023000142560ustar 00000000000000//! Contains all different levels of quality. //! And allows to find easily max bits per version/quality pair #![deny(unsafe_code)] #![warn(missing_docs)] use crate::datamasking::Mask; use crate::ecl::ECL; use crate::encode::Mode; use crate::version::Version; /// Fetches the right array to retrieve the information on **groups** #[allow(clippy::too_many_lines)] pub const fn ecc_to_groups(quality: ECL, version: Version) -> [(usize, usize); 2] { const L: [u32; 40] = [ (1 << 24) | (19 << 16), // (0 << 8) | 0 (1 << 24) | (34 << 16), // (0 << 8) | 0 (1 << 24) | (55 << 16), // (0 << 8) | 0 (1 << 24) | (80 << 16), // (0 << 8) | 0 (1 << 24) | (108 << 16), // (0 << 8) | 0 (2 << 24) | (68 << 16), // (0 << 8) | 0 (2 << 24) | (78 << 16), // (0 << 8) | 0 (2 << 24) | (97 << 16), // (0 << 8) | 0 (2 << 24) | (116 << 16), // (0 << 8) | 0 (2 << 24) | (68 << 16) | (2 << 8) | 69, (4 << 24) | (81 << 16), // (0 << 8) | 0 (2 << 24) | (92 << 16) | (2 << 8) | 93, (4 << 24) | (107 << 16), // (0 << 8) | 0 (3 << 24) | (115 << 16) | (1 << 8) | 116, (5 << 24) | (87 << 16) | (1 << 8) | 88, (5 << 24) | (98 << 16) | (1 << 8) | 99, (1 << 24) | (107 << 16) | (5 << 8) | 108, (5 << 24) | (120 << 16) | (1 << 8) | 121, (3 << 24) | (113 << 16) | (4 << 8) | 114, (3 << 24) | (107 << 16) | (5 << 8) | 108, (4 << 24) | (116 << 16) | (4 << 8) | 117, (2 << 24) | (111 << 16) | (7 << 8) | 112, (4 << 24) | (121 << 16) | (5 << 8) | 122, (6 << 24) | (117 << 16) | (4 << 8) | 118, (8 << 24) | (106 << 16) | (4 << 8) | 107, (10 << 24) | (114 << 16) | (2 << 8) | 115, (8 << 24) | (122 << 16) | (4 << 8) | 123, (3 << 24) | (117 << 16) | (10 << 8) | 118, (7 << 24) | (116 << 16) | (7 << 8) | 117, (5 << 24) | (115 << 16) | (10 << 8) | 116, (13 << 24) | (115 << 16) | (3 << 8) | 116, (17 << 24) | (115 << 16), // (0 << 8) | 0 (17 << 24) | (115 << 16) | (1 << 8) | 116, (13 << 24) | (115 << 16) | (6 << 8) | 116, (12 << 24) | (121 << 16) | (7 << 8) | 122, (6 << 24) | (121 << 16) | (14 << 8) | 122, (17 << 24) | (122 << 16) | (4 << 8) | 123, (4 << 24) | (122 << 16) | (18 << 8) | 123, (20 << 24) | (117 << 16) | (4 << 8) | 118, (19 << 24) | (118 << 16) | (6 << 8) | 119, ]; const M: [u32; 40] = [ (1 << 24) | (16 << 16), // (0 << 8) | 0 (1 << 24) | (28 << 16), // (0 << 8) | 0 (1 << 24) | (44 << 16), // (0 << 8) | 0 (2 << 24) | (32 << 16), // (0 << 8) | 0 (2 << 24) | (43 << 16), // (0 << 8) | 0 (4 << 24) | (27 << 16), // (0 << 8) | 0 (4 << 24) | (31 << 16), // (0 << 8) | 0 (2 << 24) | (38 << 16) | (2 << 8) | 39, (3 << 24) | (36 << 16) | (2 << 8) | 37, (4 << 24) | (43 << 16) | (1 << 8) | 44, (1 << 24) | (50 << 16) | (4 << 8) | 51, (6 << 24) | (36 << 16) | (2 << 8) | 37, (8 << 24) | (37 << 16) | (1 << 8) | 38, (4 << 24) | (40 << 16) | (5 << 8) | 41, (5 << 24) | (41 << 16) | (5 << 8) | 42, (7 << 24) | (45 << 16) | (3 << 8) | 46, (10 << 24) | (46 << 16) | (1 << 8) | 47, (9 << 24) | (43 << 16) | (4 << 8) | 44, (3 << 24) | (44 << 16) | (11 << 8) | 45, (3 << 24) | (41 << 16) | (13 << 8) | 42, (17 << 24) | (42 << 16), // (0 << 8) | 0 (17 << 24) | (46 << 16), // (0 << 8) | 0 (4 << 24) | (47 << 16) | (14 << 8) | 48, (6 << 24) | (45 << 16) | (14 << 8) | 46, (8 << 24) | (47 << 16) | (13 << 8) | 48, (19 << 24) | (46 << 16) | (4 << 8) | 47, (22 << 24) | (45 << 16) | (3 << 8) | 46, (3 << 24) | (45 << 16) | (23 << 8) | 46, (21 << 24) | (45 << 16) | (7 << 8) | 46, (19 << 24) | (47 << 16) | (10 << 8) | 48, (2 << 24) | (46 << 16) | (29 << 8) | 47, (10 << 24) | (46 << 16) | (23 << 8) | 47, (14 << 24) | (46 << 16) | (21 << 8) | 47, (14 << 24) | (46 << 16) | (23 << 8) | 47, (12 << 24) | (47 << 16) | (26 << 8) | 48, (6 << 24) | (47 << 16) | (34 << 8) | 48, (29 << 24) | (46 << 16) | (14 << 8) | 47, (13 << 24) | (46 << 16) | (32 << 8) | 47, (40 << 24) | (47 << 16) | (7 << 8) | 48, (18 << 24) | (47 << 16) | (31 << 8) | 48, ]; const Q: [u32; 40] = [ (1 << 24) | (13 << 16), // (0 << 8) | 0 (1 << 24) | (22 << 16), // (0 << 8) | 0 (2 << 24) | (17 << 16), // (0 << 8) | 0 (2 << 24) | (24 << 16), // (0 << 8) | 0 (2 << 24) | (15 << 16) | (2 << 8) | 16, (4 << 24) | (19 << 16), // (0 << 8) | 0 (2 << 24) | (14 << 16) | (4 << 8) | 15, (4 << 24) | (18 << 16) | (2 << 8) | 19, (4 << 24) | (16 << 16) | (4 << 8) | 17, (6 << 24) | (19 << 16) | (2 << 8) | 20, (4 << 24) | (22 << 16) | (4 << 8) | 23, (4 << 24) | (20 << 16) | (6 << 8) | 21, (8 << 24) | (20 << 16) | (4 << 8) | 21, (11 << 24) | (16 << 16) | (5 << 8) | 17, (5 << 24) | (24 << 16) | (7 << 8) | 25, (15 << 24) | (19 << 16) | (2 << 8) | 20, (1 << 24) | (22 << 16) | (15 << 8) | 23, (17 << 24) | (22 << 16) | (1 << 8) | 23, (17 << 24) | (21 << 16) | (4 << 8) | 22, (15 << 24) | (24 << 16) | (5 << 8) | 25, (17 << 24) | (22 << 16) | (6 << 8) | 23, (7 << 24) | (24 << 16) | (16 << 8) | 25, (11 << 24) | (24 << 16) | (14 << 8) | 25, (11 << 24) | (24 << 16) | (16 << 8) | 25, (7 << 24) | (24 << 16) | (22 << 8) | 25, (28 << 24) | (22 << 16) | (6 << 8) | 23, (8 << 24) | (23 << 16) | (26 << 8) | 24, (4 << 24) | (24 << 16) | (31 << 8) | 25, (1 << 24) | (23 << 16) | (37 << 8) | 24, (15 << 24) | (24 << 16) | (25 << 8) | 25, (42 << 24) | (24 << 16) | (1 << 8) | 25, (10 << 24) | (24 << 16) | (35 << 8) | 25, (29 << 24) | (24 << 16) | (19 << 8) | 25, (44 << 24) | (24 << 16) | (7 << 8) | 25, (39 << 24) | (24 << 16) | (14 << 8) | 25, (46 << 24) | (24 << 16) | (10 << 8) | 25, (49 << 24) | (24 << 16) | (10 << 8) | 25, (48 << 24) | (24 << 16) | (14 << 8) | 25, (43 << 24) | (24 << 16) | (22 << 8) | 25, (34 << 24) | (24 << 16) | (34 << 8) | 25, ]; const H: [u32; 40] = [ (1 << 24) | (9 << 16), // (0 << 8) | 0 (1 << 24) | (16 << 16), // (0 << 8) | 0 (2 << 24) | (13 << 16), // (0 << 8) | 0 (4 << 24) | (9 << 16), // (0 << 8) | 0 (2 << 24) | (11 << 16) | (2 << 8) | 12, (4 << 24) | (15 << 16), // (0 << 8) | 0 (4 << 24) | (13 << 16) | (1 << 8) | 14, (4 << 24) | (14 << 16) | (2 << 8) | 15, (4 << 24) | (12 << 16) | (4 << 8) | 13, (6 << 24) | (15 << 16) | (2 << 8) | 16, (3 << 24) | (12 << 16) | (8 << 8) | 13, (7 << 24) | (14 << 16) | (4 << 8) | 15, (12 << 24) | (11 << 16) | (4 << 8) | 12, (11 << 24) | (12 << 16) | (5 << 8) | 13, (11 << 24) | (12 << 16) | (7 << 8) | 13, (3 << 24) | (15 << 16) | (13 << 8) | 16, (2 << 24) | (14 << 16) | (17 << 8) | 15, (2 << 24) | (14 << 16) | (19 << 8) | 15, (9 << 24) | (13 << 16) | (16 << 8) | 14, (15 << 24) | (15 << 16) | (10 << 8) | 16, (19 << 24) | (16 << 16) | (6 << 8) | 17, (34 << 24) | (13 << 16), // (0 << 8) | 0 (16 << 24) | (15 << 16) | (14 << 8) | 16, (30 << 24) | (16 << 16) | (2 << 8) | 17, (22 << 24) | (15 << 16) | (13 << 8) | 16, (33 << 24) | (16 << 16) | (4 << 8) | 17, (12 << 24) | (15 << 16) | (28 << 8) | 16, (11 << 24) | (15 << 16) | (31 << 8) | 16, (19 << 24) | (15 << 16) | (26 << 8) | 16, (23 << 24) | (15 << 16) | (25 << 8) | 16, (23 << 24) | (15 << 16) | (28 << 8) | 16, (19 << 24) | (15 << 16) | (35 << 8) | 16, (11 << 24) | (15 << 16) | (46 << 8) | 16, (59 << 24) | (16 << 16) | (1 << 8) | 17, (22 << 24) | (15 << 16) | (41 << 8) | 16, (2 << 24) | (15 << 16) | (64 << 8) | 16, (24 << 24) | (15 << 16) | (46 << 8) | 16, (42 << 24) | (15 << 16) | (32 << 8) | 16, (10 << 24) | (15 << 16) | (67 << 8) | 16, (20 << 24) | (15 << 16) | (61 << 8) | 16, ]; let version = version as usize; let ecgroups = match quality { ECL::L => L[version], ECL::M => M[version], ECL::Q => Q[version], ECL::H => H[version], }; let (g1_count, g1_size, g2_count, g2_size) = ( (ecgroups >> 24) & 0xFF, (ecgroups >> 16) & 0xFF, (ecgroups >> 8) & 0xFF, ecgroups & 0xFF, ); [ (g1_count as usize, g1_size as usize), (g2_count as usize, g2_size as usize), ] } /// Fetches the right array to retrieve the **format information** pub const fn ecm_to_format_information(quality: ECL, mask: Mask) -> u16 { const L: [u16; 8] = [ 0b111_0111_1100_0100, 0b111_0010_1111_0011, 0b111_1101_1010_1010, 0b111_1000_1001_1101, 0b110_0110_0010_1111, 0b110_0011_0001_1000, 0b110_1100_0100_0001, 0b110_1001_0111_0110, ]; const M: [u16; 8] = [ 0b101_0100_0001_0010, 0b101_0001_0010_0101, 0b101_1110_0111_1100, 0b101_1011_0100_1011, 0b100_0101_1111_1001, 0b100_0000_1100_1110, 0b100_1111_1001_0111, 0b100_1010_1010_0000, ]; const Q: [u16; 8] = [ 0b011_0101_0101_1111, 0b011_0000_0110_1000, 0b011_1111_0011_0001, 0b011_1010_0000_0110, 0b010_0100_1011_0100, 0b010_0001_1000_0011, 0b010_1110_1101_1010, 0b010_1011_1110_1101, ]; const H: [u16; 8] = [ 0b001_0110_1000_1001, 0b001_0011_1011_1110, 0b001_1100_1110_0111, 0b001_1001_1101_0000, 0b000_0111_0110_0010, 0b000_0010_0101_0101, 0b000_1101_0000_1100, 0b000_1000_0011_1011, ]; match quality { ECL::L => L[mask as usize], ECL::M => M[mask as usize], ECL::Q => Q[mask as usize], ECL::H => H[mask as usize], } } /// Returns the number of **data codewords** according to `version` and `ecl` pub const fn data_codewords(version: Version, ecl: ECL) -> usize { const L: [u16; 40] = [ 19, 34, 55, 80, 108, 136, 156, 194, 232, 274, 324, 370, 428, 461, 523, 589, 647, 721, 795, 861, 932, 1006, 1094, 1174, 1276, 1370, 1468, 1531, 1631, 1735, 1843, 1955, 2071, 2191, 2306, 2434, 2566, 2702, 2812, 2956, ]; const M: [u16; 40] = [ 16, 28, 44, 64, 86, 108, 124, 154, 182, 216, 254, 290, 334, 365, 415, 453, 507, 563, 627, 669, 714, 782, 860, 914, 1000, 1062, 1128, 1193, 1267, 1373, 1455, 1541, 1631, 1725, 1812, 1914, 1992, 2102, 2216, 2334, ]; const Q: [u16; 40] = [ 13, 22, 34, 48, 62, 76, 88, 110, 132, 154, 180, 206, 244, 261, 295, 325, 367, 397, 445, 485, 512, 568, 614, 664, 718, 754, 808, 871, 911, 985, 1033, 1115, 1171, 1231, 1286, 1354, 1426, 1502, 1582, 1666, ]; const H: [u16; 40] = [ 9, 16, 26, 36, 46, 60, 66, 86, 100, 122, 140, 158, 180, 197, 223, 253, 283, 313, 341, 385, 406, 442, 464, 514, 538, 596, 628, 661, 701, 745, 793, 845, 901, 961, 986, 1054, 1096, 1142, 1222, 1276, ]; (match ecl { ECL::L => L[version as usize], ECL::M => M[version as usize], ECL::Q => Q[version as usize], ECL::H => H[version as usize], }) as usize } /// Returns the number **data bits** according to `version` and `ecl` pub const fn data_bits(version: Version, ecl: ECL) -> usize { data_codewords(version, ecl) * 8 } /// Returns the **number of bits** required to represent a number according to `version` and `mode` pub const fn cci_bits(version: Version, mode: Mode) -> usize { use Version::{V10, V27}; match mode { Mode::Numeric => match version { v if (v as usize) >= (V27 as usize) => 14, v if (v as usize) >= (V10 as usize) => 12, _ => 10, }, Mode::Alphanumeric => match version { v if (v as usize) >= (V27 as usize) => 13, v if (v as usize) >= (V10 as usize) => 11, _ => 9, }, Mode::Byte => match version { v if (v as usize) >= (V10 as usize) => 16, _ => 8, }, } } /// Returns required **dividing polynomial** according to `version` and `ecl` pub const fn get_polynomial(version: Version, ecl: ECL) -> &'static [u8] { use Version::{ V01, V02, V03, V04, V05, V06, V07, V08, V09, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34, V35, V36, V37, V38, V39, V40, }; use ECL::{H, L, M, Q}; match (version, ecl) { (V01, L) => &[0, 87, 229, 146, 149, 238, 102, 21], (V01, M) | (V02, L) => &[0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45], (V01, Q) => &[ 0, 74, 152, 176, 100, 86, 100, 106, 104, 130, 218, 206, 140, 78, ], (V03, L) => &[ 0, 8, 183, 61, 91, 202, 37, 51, 58, 58, 237, 140, 124, 5, 99, 105, ], (V02 | V06, M) | (V04, H) => &[ 0, 120, 104, 107, 109, 102, 161, 76, 3, 91, 191, 147, 169, 182, 194, 225, 120, ], (V01, H) => &[ 0, 43, 139, 206, 78, 43, 239, 123, 206, 214, 147, 24, 99, 150, 39, 243, 163, 136, ], (V03 | V05 | V07, Q) | (V04 | V07, M) | (V06 | V10, L) => &[ 0, 215, 234, 158, 94, 184, 97, 118, 170, 79, 187, 152, 148, 252, 179, 5, 98, 96, 153, ], (V04 | V07 | V11, L) | (V09 | V14, Q) => &[ 0, 17, 60, 79, 50, 61, 163, 26, 187, 202, 180, 221, 225, 83, 239, 156, 164, 212, 212, 188, 190, ], (V02 | V08, Q) | (V03 | V05 | V13, H) | (V08 | V09 | V12 | V13, M) | (V15, L) => &[ 0, 210, 171, 247, 242, 93, 230, 14, 109, 221, 53, 200, 74, 8, 172, 98, 80, 219, 134, 160, 105, 165, 231, ], (V05 | V14 | V15, M) | (V06 | V10 | V13 | V16, Q) | (V08 | V12 | V16, L) | (V09 | V11 | V14 | V15 | V22, H) => &[ 0, 229, 121, 135, 48, 211, 117, 251, 126, 159, 180, 169, 152, 192, 226, 228, 218, 111, 0, 117, 232, 87, 96, 227, 21, ], (V03 | V10 | V18 | V19 | V20 | V21, M) | (V04 | V12 | V19, Q) | (V05 | V13 | V25, L) | (V07 | V08 | V19, H) => &[ 0, 173, 125, 158, 2, 103, 182, 118, 17, 145, 201, 111, 28, 165, 53, 161, 21, 245, 142, 13, 102, 48, 227, 153, 145, 218, 70, ], (V02 | V06 | V10 | V12 | V17 | V18 | V20, H) | (V11 | V17 | V18 | V21 | V26, Q) | ( V16 | V17 | V22 | V23 | V24 | V25 | V26 | V27 | V28 | V29 | V30 | V31 | V32 | V33 | V34 | V35 | V36 | V37 | V38 | V39 | V40, M, ) | (V17 | V19 | V20 | V21 | V22 | V26, L) => &[ 0, 168, 223, 200, 104, 224, 234, 108, 180, 110, 190, 195, 147, 205, 27, 232, 201, 21, 43, 245, 87, 42, 195, 212, 119, 242, 37, 9, 123, ], ( V09 | V14 | V18 | V23 | V24 | V27 | V28 | V29 | V30 | V31 | V32 | V33 | V34 | V35 | V36 | V37 | V38 | V39 | V40, L, ) | (V11, M) | ( V15 | V20 | V22 | V23 | V24 | V25 | V27 | V28 | V29 | V30 | V31 | V32 | V33 | V34 | V35 | V36 | V37 | V38 | V39 | V40, Q, ) | ( V16 | V21 | V23 | V24 | V25 | V26 | V27 | V28 | V29 | V30 | V31 | V32 | V33 | V34 | V35 | V36 | V37 | V38 | V39 | V40, H, ) => &[ 0, 41, 173, 145, 152, 216, 31, 179, 182, 50, 48, 110, 86, 239, 96, 222, 125, 42, 173, 226, 193, 224, 130, 156, 37, 251, 216, 238, 40, 192, 180, ], } } /// Contains the score for **light/dark module ratio**, referring 8.8.2 (Table 24) of the spec. pub const PERCENT_SCORE: [u8; 100] = [ 90, 90, 90, 90, 90, 80, 80, 80, 80, 80, 70, 70, 70, 70, 70, 60, 60, 60, 60, 60, 50, 50, 50, 50, 50, 40, 40, 40, 40, 40, 30, 30, 30, 30, 30, 20, 20, 20, 20, 20, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 30, 30, 30, 30, 30, 40, 40, 40, 40, 40, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 90, 90, 90, 90, 90, ]; fast_qr-0.13.1/src/helpers.rs000064400000000000000000000037461046102023000141560ustar 00000000000000//! Matrix helpers functions #![deny(unsafe_code)] #![warn(missing_docs)] use crate::module::Module; use crate::QRCode; /// Used to print a ` ` (space) const EMPTY: char = ' '; /// Used to print a `█` const BLOCK: char = '█'; /// Used to print a `▀` const TOP: char = '▀'; /// Used to print a `▄` const BOTTOM: char = '▄'; /// Helper to print two lines at the same time fn print_line(line1: &[Module], line2: &[Module], size: usize) -> String { let mut line = String::with_capacity(size); for i in 0..size { match (line1[i].value(), line2[i].value()) { (true, true) => line.push(EMPTY), (true, false) => line.push(BOTTOM), (false, true) => line.push(TOP), (false, false) => line.push(BLOCK), } } line } /// Prints a matrix with margins pub fn print_matrix_with_margin(qr: &QRCode) -> String { let mut out = String::new(); let line = print_line( &[Module::empty(true); 177], &[Module::empty(false); 177], qr.size, ); out.push(BOTTOM); out.push_str(&line); out.push_str(&format!("{BOTTOM}\n")); // Black background for i in (0..qr.size - 1).step_by(2) { let line = print_line(&qr[i], &qr[i + 1], qr.size); out.push(BLOCK); out.push_str(&line); out.push_str(&format!("{BLOCK}\n")); } let line = print_line(&qr[qr.size - 1], &[Module::empty(false); 177], qr.size); out.push(BLOCK); out.push_str(&line); out.push(BLOCK); out } #[cfg(test)] use crate::{compact::CompactQR, Version}; /// Convert a vector of u8 to it's representation in bits /// /// If bits are required by the QR code (referring to 8.6 of the spec), they are added to the end of the vector. /// /// ## Example /// { 101 } => "01100101" #[cfg(test)] pub fn binary_to_binarystring_version(binary: [u8; 5430], version: Version) -> CompactQR { let max = version.max_bytes() * 8; CompactQR::from_array(&binary, max + version.missing_bits()) } fast_qr-0.13.1/src/lib.rs000064400000000000000000000051321046102023000132510ustar 00000000000000#![cfg_attr(docsrs, feature(doc_cfg))] #![warn(missing_docs)] //! # Easy to use fast QRCode generator //! //! More examples can be found on [GitHub](https://github.com/erwanvivien/fast_qr/tree/master/examples). //! //! ## Converts [`QRCode`] to Unicode //! //! ```rust //! # use fast_qr::convert::ConvertError; //! use fast_qr::qr::QRBuilder; //! //! # fn main() -> Result<(), ConvertError> { //! // QRBuilder::new can fail if content is too big for version, //! // please check before unwrapping. //! let qrcode = QRBuilder::new("https://example.com/") //! .build() //! .unwrap(); //! //! let str = qrcode.to_str(); // .print() exists //! println!("{}", str); //! //! # Ok(()) //! # } //! ``` //! //! ## Converts [`QRCode`] to SVG //! //! ```rust //! # use fast_qr::convert::ConvertError; //! use fast_qr::convert::{svg::SvgBuilder, Builder, Shape}; //! use fast_qr::qr::QRBuilder; //! //! # fn main() -> Result<(), ConvertError> { //! // QRBuilder::new can fail if content is too big for version, //! // please check before unwrapping. //! let qrcode = QRBuilder::new("https://example.com/") //! .build() //! .unwrap(); //! //! let _svg = SvgBuilder::default() //! .shape(Shape::RoundedSquare) //! .to_file(&qrcode, "out.svg"); //! # std::fs::remove_file("out.svg"); //! //! # Ok(()) //! # } //! ``` //! //! ## Converts [`QRCode`] to an image //! //! ```rust //! # use fast_qr::convert::ConvertError; //! use fast_qr::convert::{image::ImageBuilder, Builder, Shape}; //! use fast_qr::qr::QRBuilder; //! //! # fn main() -> Result<(), ConvertError> { //! // QRBuilder::new can fail if content is too big for version, //! // please check before unwrapping. //! let qrcode = QRBuilder::new("https://example.com/") //! .build() //! .unwrap(); //! //! let _img = ImageBuilder::default() //! .shape(Shape::RoundedSquare) //! .background_color([255, 255, 255, 0]) // transparency //! .fit_width(600) //! .to_file(&qrcode, "out.png"); //! # std::fs::remove_file("out.png"); //! //! # Ok(()) //! # } //! ``` pub use crate::datamasking::Mask; pub use crate::ecl::ECL; pub use crate::encode::Mode; pub use crate::module::{Module, ModuleType}; pub use crate::qr::{QRBuilder, QRCode}; pub use crate::version::Version; mod compact; #[doc(hidden)] pub mod datamasking; pub mod convert; mod default; mod ecl; mod encode; mod hardcode; #[cfg(not(feature = "wasm-bindgen"))] mod helpers; mod module; mod placement; mod polynomials; #[macro_use] pub mod qr; mod score; mod version; #[cfg(test)] mod tests; #[cfg(target_arch = "wasm32")] mod wasm; #[cfg(target_arch = "wasm32")] pub use wasm::*; fast_qr-0.13.1/src/module.rs000064400000000000000000000133551046102023000137760ustar 00000000000000/// Module is a single pixel in the QR code. #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(u8)] pub enum ModuleType { /// The module is part of the data (Encoded data) Data = 0 << 1, /// The module is part of the finder pattern (bigger cubes) FinderPattern = 1 << 1, /// The module is part of the alignment pattern (smaller cubes) Alignment = 2 << 1, /// The module is part of the timing pattern (Line between finder patterns) Timing = 3 << 1, /// The module is part of the format information Format = 4 << 1, /// The module is part of the version information Version = 5 << 1, /// Dark module DarkModule = 6 << 1, /// Space between finder patterns Empty = 7 << 1, } impl From for ModuleType { fn from(value: u8) -> Self { match value { 0 => ModuleType::Data, 1 => ModuleType::FinderPattern, 2 => ModuleType::Alignment, 3 => ModuleType::Timing, 4 => ModuleType::Format, 5 => ModuleType::Version, 6 => ModuleType::DarkModule, 7 => ModuleType::Empty, _ => unreachable!(), } } } /// Module is a single pixel in the QR code. /// Module uses u8 to store value and type. #[derive(Copy, Clone, Debug)] pub struct Module(pub u8); impl Module { /// Represents a dark module, which is a black pixel. pub const DARK: bool = true; /// Represents a light module, which is a white pixel. pub const LIGHT: bool = false; /// Creates a new module with the given type and value. #[must_use] pub const fn new(value: bool, module_type: ModuleType) -> Self { let value = value as u8; Module(value | (module_type as u8)) } /// Creates a new module with the given value with type data. #[must_use] pub const fn data(value: bool) -> Self { Module::new(value, ModuleType::Data) } /// Creates a new module with the given value with type finder pattern. #[must_use] pub const fn finder_pattern(value: bool) -> Self { Module::new(value, ModuleType::FinderPattern) } /// Creates a new module with the given value with type alignment. #[must_use] pub const fn alignment(value: bool) -> Self { Module::new(value, ModuleType::Alignment) } /// Creates a new module with the given value with type timing. #[must_use] pub const fn timing(value: bool) -> Self { Module::new(value, ModuleType::Timing) } /// Creates a new module with the given value with type format. #[must_use] pub const fn format(value: bool) -> Self { Module::new(value, ModuleType::Format) } /// Creates a new module with the given value with type version. #[must_use] pub const fn version(value: bool) -> Self { Module::new(value, ModuleType::Version) } /// Creates a new module with the given value with type dark module. #[must_use] pub const fn dark(value: bool) -> Self { Module::new(value, ModuleType::DarkModule) } /// Creates a new module with the given value with type empty. #[must_use] pub const fn empty(value: bool) -> Self { Module::new(value, ModuleType::Empty) } /// Returns the boolean value of the module. #[must_use] pub const fn value(self) -> bool { self.0 & 1 == 1 } /// Returns the type of the module. #[must_use] pub fn module_type(self) -> ModuleType { ModuleType::from(self.0 >> 1) } /// Sets the boolean value of the module. pub fn set(&mut self, value: bool) { self.0 = if value { self.0 | 1 } else { self.0 & !1 }; } /// Toggles the boolean value of the module. pub fn toggle(&mut self) { self.0 ^= 1; } } impl From for Module { fn from(value: bool) -> Self { Module::empty(value) } } impl PartialEq for Module { fn eq(&self, other: &bool) -> bool { self.value() == *other } } impl PartialEq for Module { fn eq(&self, other: &Self) -> bool { self.0 == other.0 } } impl Eq for Module {} #[cfg(test)] mod test { use super::*; #[test] fn byte_size() { assert_eq!(std::mem::size_of::(), 1); } #[test] fn data() { let module = Module::data(Module::LIGHT); assert_eq!(module.module_type(), ModuleType::Data); } #[test] fn finder_pattern() { let module = Module::finder_pattern(Module::LIGHT); assert_eq!(module.module_type(), ModuleType::FinderPattern); } #[test] fn alignment() { let module = Module::alignment(Module::LIGHT); assert_eq!(module.module_type(), ModuleType::Alignment); } #[test] fn timing() { let module = Module::timing(Module::LIGHT); assert_eq!(module.module_type(), ModuleType::Timing); } #[test] fn format() { let module = Module::format(Module::LIGHT); assert_eq!(module.module_type(), ModuleType::Format); } #[test] fn version() { let module = Module::version(Module::LIGHT); assert_eq!(module.module_type(), ModuleType::Version); } #[test] fn dark() { let module = Module::dark(Module::LIGHT); assert_eq!(module.module_type(), ModuleType::DarkModule); } #[test] fn value_light() { let module = Module::data(Module::LIGHT); assert_eq!(module.value(), Module::LIGHT); } #[test] fn value_dark() { let module = Module::data(Module::DARK); assert_eq!(module.value(), Module::DARK); } #[test] fn set() { let mut module = Module::data(Module::LIGHT); module.set(Module::DARK); assert_eq!(module.value(), Module::DARK); } } fast_qr-0.13.1/src/placement.rs000064400000000000000000000073731046102023000144640ustar 00000000000000//! Places data on a matrix #![deny(unsafe_code)] #![warn(missing_docs)] use crate::compact::CompactQR; use crate::datamasking::Mask; use crate::encode::Mode; use crate::module::ModuleType; use crate::{datamasking, default, encode, polynomials, score, QRCode}; use crate::{Version, ECL}; use core::iter::Rev; use core::ops::Range; pub enum BiRange { Forward(Range), Backwards(Rev>), } impl Iterator for BiRange { type Item = usize; fn next(&mut self) -> Option { match self { BiRange::Forward(range) => range.next(), BiRange::Backwards(range) => range.next(), } } } #[cfg(test)] pub fn test_place_on_matrix_data(qr: &mut QRCode, structure_as_binarystring: &CompactQR) { place_on_matrix_data(qr, structure_as_binarystring); } /// Places the data on the matrix pub fn place_on_matrix_data(qr: &mut QRCode, structure_as_binarystring: &CompactQR) { let structure_bytes_tmp = structure_as_binarystring.get_data(); let mut rev = true; let mut idx = 0; // 0, 2, 4, 7, 9, .., N (skipping 6) for x in (0..6).chain(7..qr.size).rev().step_by(2) { let y_range = if rev { BiRange::Backwards((0..qr.size).rev()) } else { BiRange::Forward(0..qr.size) }; for y in y_range { if qr[y][x].module_type() == ModuleType::Data { let c = structure_bytes_tmp[idx / 8] & (1 << (7 - idx % 8)); idx += 1; qr[y][x].set(c != 0); } if qr[y][x - 1].module_type() == ModuleType::Data { let c = structure_bytes_tmp[idx / 8] & (1 << (7 - idx % 8)); idx += 1; qr[y][x - 1].set(c != 0); } } rev = !rev; } #[cfg(debug_assertions)] { let version = Version::from_n(qr.size); assert_eq!(idx - version.missing_bits(), version.max_bytes() * 8); } } const MASKS: [Mask; 8] = [ Mask::Checkerboard, Mask::HorizontalLines, Mask::VerticalLines, Mask::DiagonalLines, Mask::LargeCheckerboard, Mask::Fields, Mask::Diamonds, Mask::Meadow, ]; /// Main function to place everything in the `QRCode`, returns a valid matrix pub fn place_on_matrix( structure_as_binarystring: &CompactQR, quality: ECL, version: Version, mask: &mut Option, ) -> QRCode { let mut best_score = u32::MAX; let mut best_mask = MASKS[0]; let mut qr = default::create_matrix(version); place_on_matrix_data(&mut qr, structure_as_binarystring); let transpose = default::transpose(&qr); for mask in MASKS { let mut copy = qr.clone(); let copy_transpose = transpose.clone(); datamasking::mask(&mut copy, mask); let matrix_score = score::score(©, ©_transpose); if matrix_score < best_score { best_score = matrix_score; best_mask = mask; } } best_mask = mask.unwrap_or(best_mask); *mask = Some(best_mask); default::create_matrix_format_info(&mut qr, quality, best_mask); datamasking::mask(&mut qr, best_mask); qr.mask = *mask; qr } /// Generate the whole matrix pub fn create_matrix( input: &[u8], ecl: ECL, mode: Mode, version: Version, mask: &mut Option, ) -> QRCode { let data_codewords = encode::encode(input, ecl, mode, version); let structure = polynomials::structure(data_codewords.get_data(), ecl, version); let max = version.max_bytes() * 8; let structure_binstring = CompactQR::from_array(&structure, max + version.missing_bits()); QRCode { mode: Some(mode), ecl: Some(ecl), version: Some(version), ..place_on_matrix(&structure_binstring, ecl, version, mask) } } fast_qr-0.13.1/src/polynomials.rs000064400000000000000000000147751046102023000150660ustar 00000000000000//! Is used to compute ECC (Error Correction Coding) #![deny(unsafe_code)] #![warn(missing_docs)] use crate::hardcode; use crate::polynomials; use crate::{Version, ECL}; /// Used in the ring, convert a^x using `LOG[x % 255]` to it's decimal Galois-Field value const LOG: [u8; 256] = [ 1, 2, 4, 8, 16, 32, 64, 128, 29, 58, 116, 232, 205, 135, 19, 38, 76, 152, 45, 90, 180, 117, 234, 201, 143, 3, 6, 12, 24, 48, 96, 192, 157, 39, 78, 156, 37, 74, 148, 53, 106, 212, 181, 119, 238, 193, 159, 35, 70, 140, 5, 10, 20, 40, 80, 160, 93, 186, 105, 210, 185, 111, 222, 161, 95, 190, 97, 194, 153, 47, 94, 188, 101, 202, 137, 15, 30, 60, 120, 240, 253, 231, 211, 187, 107, 214, 177, 127, 254, 225, 223, 163, 91, 182, 113, 226, 217, 175, 67, 134, 17, 34, 68, 136, 13, 26, 52, 104, 208, 189, 103, 206, 129, 31, 62, 124, 248, 237, 199, 147, 59, 118, 236, 197, 151, 51, 102, 204, 133, 23, 46, 92, 184, 109, 218, 169, 79, 158, 33, 66, 132, 21, 42, 84, 168, 77, 154, 41, 82, 164, 85, 170, 73, 146, 57, 114, 228, 213, 183, 115, 230, 209, 191, 99, 198, 145, 63, 126, 252, 229, 215, 179, 123, 246, 241, 255, 227, 219, 171, 75, 150, 49, 98, 196, 149, 55, 110, 220, 165, 87, 174, 65, 130, 25, 50, 100, 200, 141, 7, 14, 28, 56, 112, 224, 221, 167, 83, 166, 81, 162, 89, 178, 121, 242, 249, 239, 195, 155, 43, 86, 172, 69, 138, 9, 18, 36, 72, 144, 61, 122, 244, 245, 247, 243, 251, 235, 203, 139, 11, 22, 44, 88, 176, 125, 250, 233, 207, 131, 27, 54, 108, 216, 173, 71, 142, 1, ]; /// Reverses a ring value, converts decimal value x using `ANTILOG[x % 255]` to it's alpha power value const ANTILOG: [u8; 256] = [ 175, 0, 1, 25, 2, 50, 26, 198, 3, 223, 51, 238, 27, 104, 199, 75, 4, 100, 224, 14, 52, 141, 239, 129, 28, 193, 105, 248, 200, 8, 76, 113, 5, 138, 101, 47, 225, 36, 15, 33, 53, 147, 142, 218, 240, 18, 130, 69, 29, 181, 194, 125, 106, 39, 249, 185, 201, 154, 9, 120, 77, 228, 114, 166, 6, 191, 139, 98, 102, 221, 48, 253, 226, 152, 37, 179, 16, 145, 34, 136, 54, 208, 148, 206, 143, 150, 219, 189, 241, 210, 19, 92, 131, 56, 70, 64, 30, 66, 182, 163, 195, 72, 126, 110, 107, 58, 40, 84, 250, 133, 186, 61, 202, 94, 155, 159, 10, 21, 121, 43, 78, 212, 229, 172, 115, 243, 167, 87, 7, 112, 192, 247, 140, 128, 99, 13, 103, 74, 222, 237, 49, 197, 254, 24, 227, 165, 153, 119, 38, 184, 180, 124, 17, 68, 146, 217, 35, 32, 137, 46, 55, 63, 209, 91, 149, 188, 207, 205, 144, 135, 151, 178, 220, 252, 190, 97, 242, 86, 211, 171, 20, 42, 93, 158, 132, 60, 57, 83, 71, 109, 65, 162, 31, 45, 67, 216, 183, 123, 164, 118, 196, 23, 73, 236, 127, 12, 111, 246, 108, 161, 59, 82, 41, 157, 85, 170, 251, 96, 134, 177, 187, 204, 62, 90, 203, 89, 95, 176, 156, 169, 160, 81, 11, 245, 22, 235, 122, 117, 44, 215, 79, 174, 213, 233, 230, 231, 173, 232, 116, 214, 244, 234, 168, 80, 88, 175, ]; /// Return a string of human readable polynomial /// /// `[0, 75, 249, 78, 6]` => "α0x4 + α75x3 + α249x2 + α78x + α6" #[cfg(test)] pub fn generated_to_string(poly: &[u8]) -> String { let mut s = String::new(); let length = poly.len(); for (i, item) in poly.iter().enumerate() { s.push_str(&format!( "α{}{}", item, &match length - i - 1 { 0 => String::new(), 1 => String::from("x + "), n => format!("x{} + ", n), }, )); } s } /// Takes an array and divides it by the other in a Galois Field (256) /// ```txt /// from: [ 32, 91, 11, 120, 209, 114, 220, 77, 67, 64, 236, /// 17, 236, 17, 236, 17] (integer) /// by : [ 0, 251, 67, 46, 61, 118, /// 70, 64, 94, 32, 45] (alpha) /// ``` /// /// `from` should be of length `from.len() + by.len()`, so we pad zeroes, like so: /// ```txt /// from: [ 32, 91, 11, 120, 209, 114, 220, 77, 67, 64, 236, /// 17, 236, 17, 236, 17, 0, ..eight.., 0] (integer) /// ``` /// /// Then the actual division takes place /// We convert `from` from INTEGER to ALPHA pub fn division(from: &[u8], by: &[u8]) -> [u8; 255] { let mut from_mut = [0; 255]; let start = 256 - from.len() - by.len(); from_mut[start..(256 - by.len())].copy_from_slice(&from[..((256 - by.len()) - start)]); for i in start..start + from.len() { if from_mut[i] == 0 { continue; } let alpha = ANTILOG[from_mut[i] as usize]; for j in 0..by.len() { let tmp = by[j] as usize + alpha as usize; from_mut[i + j] ^= LOG[tmp % 255]; } } from_mut } /// Uses the data and error(generator polynomial) to compute the divisions /// for each block. pub fn structure(data: &[u8], quality: ECL, version: Version) -> [u8; 5430] { const MAX_ERROR: usize = 30; const MAX_GROUP_COUNT: usize = 81; const MAX_DATABITS: usize = 3000; // Need to find a more accurate way to do this. // let mut interleaved_data = vec![0; 0]; let error = hardcode::get_polynomial(version, quality); let [(g1_count, g1_size), (g2_count, g2_size)] = hardcode::ecc_to_groups(quality, version); let groups_count_total = g1_count + g2_count; let mut interleaved_data = [0; MAX_DATABITS + MAX_ERROR * MAX_GROUP_COUNT]; let start_error_idx = hardcode::data_codewords(version, quality); for i in 0..g1_count { let start_idx = i * g1_size; let division = polynomials::division(&data[start_idx..start_idx + g1_size], error); for j in 0..error.len() - 1 { interleaved_data[start_error_idx + j * groups_count_total + i] = division[256 - error.len() + j]; } } for i in 0..g2_count { let start_idx = g1_size * g1_count + i * g2_size; let division = polynomials::division(&data[start_idx..start_idx + g2_size], error); for j in 0..error.len() - 1 { interleaved_data[start_error_idx + j * groups_count_total + i + g1_count] = division[256 - error.len() + j]; } } let mut push_idx = 0; let max = core::cmp::max(g1_size, g2_size); for i in 0..max { if i < g1_size { for j in 0..g1_count { let idx = j * g1_size + i; interleaved_data[push_idx] = data[idx]; push_idx += 1; } } if i < g2_size { for j in 0..g2_count { let idx = j * g2_size + i + g1_size * g1_count; interleaved_data[push_idx] = data[idx]; push_idx += 1; } } } interleaved_data } fast_qr-0.13.1/src/qr.rs000064400000000000000000000172661046102023000131400ustar 00000000000000//! Module `qr` is the entrypoint to start making `QRCodes` use crate::module::Module; use core::fmt::{Debug, Formatter}; use core::ops::{Index, IndexMut}; use crate::datamasking::Mask; use crate::encode::Mode; #[cfg(not(feature = "wasm-bindgen"))] use crate::helpers; use crate::{encode, Version, ECL}; const QR_MAX_WIDTH: usize = 177; const QR_MAX_MODULES: usize = QR_MAX_WIDTH * QR_MAX_WIDTH; /// A `QRCode` can be created using [`QRBuilder`]. Simple API for simple usage. /// If you need to use `QRCode` directly, please file an [issue on /// github](https://github.com/erwanvivien/fast_qr) explaining your use case. /// /// Contains all needed information about the `QRCode`. /// This is the main struct of the crate. /// /// It contains the matrix of the `QRCode`, stored as a one-dimensional array. #[derive(Clone)] pub struct QRCode { /// This array length is of size `177 x 177`. It is using a fixed size /// array simply because of performance. /// /// # Other data type possible: /// - Templated Matrix was faster but crate size was huge. /// - Vector using `with_capacity`, really bad. pub data: [Module; QR_MAX_MODULES], /// Width & Height of QRCode. If manually set, should be `version * 4 + 17`, `version` going /// from 1 to 40 both included. pub size: usize, /// Version of the `QRCode`, impacts the size. /// /// `None` will optimize Version according to ECL and Mode pub version: Option, /// Defines how powerful `QRCode` redundancy should be or how much percent of a QRCode can be /// recovered. /// /// - `ECL::L`: 7% /// - `ECL::M`: 15% /// - `ECL::Q`: 25% /// - `ELC::H`: 30% /// /// `None` will set ECL to Quartile (`ELC::Q`) pub ecl: Option, /// Changes the final pattern used. /// /// None will find the best suited mask. pub mask: Option, /// Mode defines which data is being parsed, between Numeric, AlphaNumeric & Byte. /// /// `None` will optimize Mode according to user input. /// /// ## Note /// Kanji mode is not supported (yet). pub mode: Option, } impl Debug for QRCode { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { f.debug_struct("QRCode") .field("size", &self.size) .field("version", &self.version) .field("ecl", &self.ecl) .field("mask", &self.mask) .field("mode", &self.mode) .finish_non_exhaustive() } } impl QRCode { /// A default `QRCode` will have all it's fields as `None` and a default Matrix filled with `Module::LIGHT`. #[must_use] pub const fn default(size: usize) -> Self { QRCode { data: [Module::data(Module::LIGHT); QR_MAX_MODULES], size, version: None, ecl: None, mask: None, mode: None, } } } impl Index for QRCode { type Output = [Module]; fn index(&self, index: usize) -> &Self::Output { &self.data[index * self.size..(index + 1) * self.size] } } impl IndexMut for QRCode { fn index_mut(&mut self, index: usize) -> &mut Self::Output { &mut self.data[index * self.size..(index + 1) * self.size] } } /// Contains different error when [`QRCode`] could not be created pub enum QRCodeError { /// If data if too large to be encoded (refer to Table 7-11 of the spec or [an online table](https://fast-qr.com/blog/tables/ecl)) EncodedData, /// Specified version too small to contain data SpecifiedVersion, } // We don't want to use `std::error::Error` on wasm32 impl std::error::Error for QRCodeError {} impl std::fmt::Display for QRCodeError { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { match self { QRCodeError::EncodedData => f.write_str("Data too big to be encoded"), QRCodeError::SpecifiedVersion => { f.write_str("Specified version too low to contain data") } } } } impl Debug for QRCodeError { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { match self { QRCodeError::EncodedData => f.write_str("Data too big to be encoded"), QRCodeError::SpecifiedVersion => { f.write_str("Specified version too low to contain data") } } } } impl QRCode { /// Creates a new `QRCode` from a ECL / version /// /// # Errors /// - `QRCodeError::EncodedData` if `input` is too large to be encoded /// - `QRCodeError::SpecifiedVersion` if specified `version` is too small to contain data pub(crate) fn new( input: &[u8], ecl: Option, v: Option, mode: Option, mut mask: Option, ) -> Result { use crate::placement::create_matrix; let mode = mode.unwrap_or_else(|| encode::best_encoding(input)); let level = ecl.unwrap_or(ECL::Q); let version = match Version::get(mode, level, input.len()) { Some(version) => version, None => return Err(QRCodeError::EncodedData), }; let version = match v { Some(user_version) if user_version as usize >= version as usize => user_version, None => version, Some(_) => return Err(QRCodeError::SpecifiedVersion), }; let out = create_matrix(input, level, mode, version, &mut mask); Ok(out) } /// Prints the `QRCode` to the terminal #[must_use] #[cfg(not(feature = "wasm-bindgen"))] pub fn to_str(&self) -> String { helpers::print_matrix_with_margin(self) } /// Prints the `QRCode` to the terminal #[cfg(not(feature = "wasm-bindgen"))] pub fn print(&self) { println!("{}", helpers::print_matrix_with_margin(self)); } } /// Builder struct, makes it easier to create a [`QRCode`]. /// /// # Example /// ```rust /// use fast_qr::QRBuilder; /// use fast_qr::{Mask, ECL, Version}; /// /// // Creates a `QRCode` with a forced `version`, `ecl` and/or `mask` /// let input = String::from("Hello World!"); /// let qr = QRBuilder::new(input) /// // .version(Version::V05) /// // .ecl(ECL::H) /// // .mask(Mask::Checkerboard) /// .build(); /// ``` pub struct QRBuilder { input: Vec, ecl: Option, mode: Option, version: Option, mask: Option, } impl QRBuilder { /// Creates an instance of `QRBuilder` with default parameters #[must_use] pub fn new>>(input: I) -> QRBuilder { QRBuilder { input: input.into(), mask: None, mode: None, version: None, ecl: None, } } /// Forces the Mode pub fn mode(&mut self, mode: Mode) -> &mut Self { self.mode = Some(mode); self } /// Forces the Encoding Level pub fn ecl(&mut self, ecl: ECL) -> &mut Self { self.ecl = Some(ecl); self } /// Forces the version pub fn version(&mut self, version: Version) -> &mut Self { self.version = Some(version); self } /// Forces the mask, should very rarely be used pub fn mask(&mut self, mask: Mask) -> &mut Self { self.mask = Some(mask); self } /// Computes a [`QRCode`] with given parameters /// /// # Errors /// - `QRCodeError::EncodedData` if `input` is too large to be encoded. See [an online table](https://fast-qr.com/blog/tables/ecl) for more info. /// - `QRCodeError::SpecifiedVersion` if specified `version` is too small to contain data pub fn build(&self) -> Result { QRCode::new(&self.input, self.ecl, self.version, self.mode, self.mask) } } fast_qr-0.13.1/src/score.rs000064400000000000000000000110161046102023000136140ustar 00000000000000//! `QRCode` need a way to define if they are readable, using a //! scoring system. The lesser, the better. #![warn(missing_docs)] #[cfg(test)] use crate::default::transpose; use crate::module::{Module, ModuleType}; use crate::QRCode; use super::hardcode; #[cfg(test)] pub fn test_score_line(l: &[Module]) -> u32 { line(l).1 } #[cfg(test)] pub fn test_score_pattern(l: &[Module]) -> u32 { line(l).0 } #[cfg(test)] pub fn test_matrix_dark_modules(qr: &QRCode) -> u32 { dark_module_score(qr) } #[cfg(test)] pub fn test_matrix_pattern_and_line(qr: &QRCode) -> (u32, u32, u32) { let transpose = transpose(qr); matrix_pattern_and_line(qr, &transpose) } #[cfg(test)] pub fn test_matrix_score_squares(qr: &QRCode) -> u32 { matrix_score_squares(qr) } /// Computes scores for squares, any 2x2 square (black or white) /// add 3 to the score /// /// ### Opti: /// We don't want to access the 4 squares each time, so we score the left most /// ones and only fetch the next right ones fn matrix_score_squares(qr: &QRCode) -> u32 { let mut square_score = 0; for i in 0..qr.size - 1 { let mut count_data = 2; let line1 = &qr[i]; let line2 = &qr[i + 1]; let mut buffer = 0u8; buffer |= u8::from(line1[0].value()) << 2; buffer |= u8::from(line2[0].value()) << 3; for j in 0..qr.size - 1 { buffer >>= 2; buffer |= u8::from(line1[j + 1].value()) << 2; buffer |= u8::from(line2[j + 1].value()) << 3; if line1[j + 1].module_type() != ModuleType::Data || line2[j + 1].module_type() != ModuleType::Data { count_data = 0; } if count_data >= 2 && (buffer == 0b1111 || buffer == 0b0000) { square_score += 3; } count_data += 1; } } square_score } /// Computes scores for both patterns (`0b10111010000` or `0b00001011101`) /// /// ### Opti: /// We convert the line to a u11 (supposedly) so comparing it to a pattern is /// a simple comparison. fn line(line: &[Module]) -> (u32, u32) { const PATTERN_LEN: usize = 7; let mut line_score = 0; let mut patt_score = 0; let mut count = 1; let mut current = !line[0].value(); let mut buffer = 0; let mut count_data = 0; for &item in line { buffer = ((buffer << 1) | u16::from(item.value())) & 0b111_1111; count_data += 1; if item.value() != current { if count >= 5 { line_score += count - 2; } count = 0; current = item.value(); } if item.module_type() != ModuleType::Data { if count >= 5 { line_score += count - 2; } count_data = 0; count = 0; continue; } if count_data >= PATTERN_LEN && buffer == 0b101_1101 { patt_score += 40; } count += 1; } if count >= 5 { line_score += count - 2; } (patt_score, line_score) } /// Converts the matrix to lines & columns and feed it to `score_line` fn matrix_pattern_and_line(qr: &QRCode, qr_transpose: &QRCode) -> (u32, u32, u32) { let mut line_score = 0; let mut col_score = 0; let mut patt_score = 0; let n = qr.size; for i in 0..n { let l = line(&qr[i]); line_score += l.1; let c = line(&qr_transpose[i]); col_score += c.1; patt_score += l.0 + c.0; } (line_score, col_score, patt_score) } /// Computes the number of `ModuleType::Dark` modules fn dark_module_score(qr: &QRCode) -> u32 { let n = qr.size; let dark_modules = qr.data[..n * n] .iter() .filter(|m| m.value() == Module::DARK) .count(); let percent = (dark_modules * 100) / (n * n); u32::from(hardcode::PERCENT_SCORE[percent]) } /// Computes the score for the matrix /// - `matrix_pattern_and_line`: /// - 40 points for each [TFTTTFT] pattern (T: true / F: false) /// - N - 2 points for each line with N consecutive modules of the same color (N >= 5) /// - `matrix_score_squares`: 3 points for each 2x2 square (black or white) /// - `dark_module_score`: 10 points for each 5% of dark modules away from 50% pub fn score(qr: &QRCode, qr_transpose: &QRCode) -> u32 { let dark_score = dark_module_score(qr); let square_score = matrix_score_squares(qr); let (line_score, col_score, patt_score) = matrix_pattern_and_line(qr, qr_transpose); line_score + patt_score + col_score + dark_score + square_score } fast_qr-0.13.1/src/tests/bytes.rs000064400000000000000000000057441046102023000150040ustar 00000000000000// #[cfg(feature = "image")] // #[test] // fn it_can_output_to_bytes_from_image() { // use base64::engine::general_purpose; // use base64::Engine; // use crate::convert::image::ImageBuilder; // use crate::{QRBuilder, ECL}; // // Expected // let image_base64 = "iVBORw0KGgoAAAANSUhEUgAAACUAAAAlCAYAAADFniADAAAEVklEQVR4Ae3AA6AkWZbG8f937o3IzKdyS2Oubdu2bdu2bdu2bWmMnpZKr54yMyLu+Xa3anqmhztr1U+2zf8cAMi2+Z8DANk2/3MAINvmfw4AZNs8gCReENtIAsA295OEbSRhGwBJ2EYStpHEC2KbZwJAts0DSMI2z00StpHE/WwDIAnbSMI2AJIAsA2AJGzz3CRhm2cCQLbNA0jCNpK4n20kYRtJ2EYStpGEbSQBYJv7SQLANpKwjSTuZxtJ2OaZAJBt8wCSsI0k7mcbSdgGQBK2kYRtACRhGwBJ2EYStgGQhG0kcT/bSMI2zwSAbJsHkIRtJHE/20jCNs9NEs/NNpK4n20kYRtJ3M82krDNMwEg2+YBJGGb5yYJ20jiudkGQBK2AZCEbe4nCds8N0nY5pkAkG3zAJJ4QWwjCdtIwjaSsI0kbCMJ20jCNpKwjSReENs8EwCybf4VJAFgG0k8N9v8OwAg2+b5kMT9bCMJ20jCNi+IJGwjiefHNgCSuJ9tngkA2Tb/AknYRhLPj20kYRtJ2OaBJPH82EYStnkmAGTbPIAkbCMJANtIAsA2kviX2EYStpHEA9nmhQBAts0DSMI2krCNJABsI4n72UYSALaRhG0kcT/bAEjifraRhG0kYZsHAEC2zXORhG0kYRtJPJBtJGEbAEnY5vmRBIBtJGEbAEnczzbPBIBsm+ciCQDbSALANgCSsM39JGEbSdhGErYBkMQD2UYSALaRBIBtngkA2TYPIAkA20jCNpIAsI0k7mcbSdgGQBIAtpGEbSRhG0kA2OaFAEC2zQNIwjaSuJ9t7icJANsASMI2DyQJANtIwjb3kwSAbSRhmwcAQLbNc5EEgG0kcT/bAEgCwDaSsA2AJABs80CSsM39JHE/2zwAALJtHkAStpHE/WxzP0nYRhK2kQSAbSQBYJv7SeL5sY0kAGzzTADItnkASdgGQBIAtpGEbQAkYRtJ2EYStpHE/WwjCdsASALANpKwzfMBgGybB5CEbSRhGwBJ2EYStpHEA9kGQBL3s40kAGwjCdtIwjYAkrDNAwAg2+YBJGEbSQDYRhIAtpGEbSTxgthGEi+IbSRhm+cCgGybfwVJ2OZ+krCNJGwjifvZRhK2uZ8kAGwDIAnbPBMAsm0eQBIviG3uJwnbSOKBbCOJB7KNJGwjCdu8AADItnkASdjmuUnCNgCSeG62kQSAbSRxP9vcTxIAtnk+AJBt8wCSsI0k7mcbSdhGEgC2AZCEbe4nifvZRhIviG0kYZtnAkC2zQNIwjaSuJ9tJGEbSQDYRhIPZJv7SeKBbCMJ20gCwDbPBQDZNg8gCdtI4n62kYRtJHE/20jCNpKwjST+JbaRBIBtHgAA2TYPIAnbPDdJ2AZAErZ5IEk8kG0eSBK2kQSAbSRhmwcAQLbNA0jiBbHN/STx/NgGQBK2uZ8kbCMJ20jCNs8FANk2/3MAINvmfw4AZNv8zwGAbJv/OQD4R25RML8XljFMAAAAAElFTkSuQmCC"; // let expected_data_uri = format!("data:image/png;base64,{image_base64}"); // // Source // let qrcode = QRBuilder::new("https://example.com/") // .ecl(ECL::H) // .build() // .unwrap(); // // As bytes // let png_bytes = ImageBuilder::default().to_bytes(&qrcode).unwrap(); // // As base64 // let png_base64 = general_purpose::STANDARD.encode(png_bytes); // let data_uri = format!("data:image/png;base64,{png_base64}"); // // Verify // assert_eq!(data_uri, expected_data_uri); // } #[cfg(feature = "image")] #[test] fn it_can_fit_an_image() { use crate::convert::image::ImageBuilder; use crate::{QRBuilder, ECL}; // Expected let data = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/sample.png")); // Source let qrcode = QRBuilder::new("https://example.com/") .ecl(ECL::H) .build() .unwrap(); // As bytes let png_bytes = ImageBuilder::default() .fit_height(1000) .fit_width(800) .to_bytes(&qrcode) .unwrap(); // Verify assert_eq!( &png_bytes, data, "Fitted image doesn't match expected result" ); } fast_qr-0.13.1/src/tests/compact.rs000064400000000000000000000123611046102023000152750ustar 00000000000000use crate::compact::CompactQR; #[test] fn push8_lined() { let mut expected = [0u8; 64]; let mut res = CompactQR::with_len(64); res.push_u8(0); res.push_u8(1); res.push_u8(2); expected[1] = 1; expected[2] = 2; assert_eq!(res.len, 8 * 3, "expected 24, got {}", res.len); assert_eq!(res.get_data()[..4], expected[..4]); } #[test] fn push_bits_half() { let mut expected = [0u8; 64]; let mut res = CompactQR::with_len(64); res.push_bits(0b1111, 4); assert_eq!(res.len, 4, "expected 4, got {}", res.len); res.push_bits(0, 8); assert_eq!(res.len, 12, "expected 12, got {}", res.len); res.push_bits(0b1111, 4); assert_eq!(res.len, 16, "expected 16, got {}", res.len); expected[0] = 0b1111_0000; expected[1] = 0b0000_1111; assert_eq!(res.get_data()[..4], expected[..4]); } #[test] fn push_bits_random() { let mut expected = [0u8; 64]; let mut res = CompactQR::with_len(64); res.push_bits(0b1111, 2); expected[0] = 0b1100_0000; assert_eq!(res.len, 2, "expected 2, got {}", res.len); assert_eq!(res.get_data()[..4], expected[..4]); res.push_bits(0, 1); expected[0] = 0b1100_0000; assert_eq!(res.len, 3, "expected 3, got {}", res.len); assert_eq!(res.get_data()[..4], expected[..4]); res.push_bits(5, 3); expected[0] = 0b1101_0100; assert_eq!(res.len, 6, "expected 6, got {}", res.len); assert_eq!(res.get_data()[..4], expected[..4]); res.push_bits(0b1101, 2); expected[0] = 0b1101_0101; assert_eq!(res.len, 8, "expected 8, got {}", res.len); assert_eq!(res.get_data()[..4], expected[..4]); } #[test] fn push_bits_push8() { let mut expected = [0u8; 64]; let mut res = CompactQR::with_len(64); res.push_bits(0b1111, 3); expected[0] = 0b1110_0000; assert_eq!(res.get_data()[..4], expected[..4]); res.push_u8(0b1001_1110); expected[0] = 0b1111_0011; expected[1] = 0b1100_0000; assert_eq!(res.get_data()[..4], expected[..4]); } #[test] fn push_bits_push8_2() { let mut expected = [0u8; 64]; let mut res = CompactQR::with_len(64); res.push_bits(0b1111, 3); expected[0] = 0b1110_0000; assert_eq!(res.get_data()[..4], expected[..4]); res.push_u8(0b1001_1110); expected[0] = 0b1111_0011; expected[1] = 0b1100_0000; assert_eq!(res.get_data()[..4], expected[..4]); res.push_u8(0b1001_1110); expected[0] = 0b1111_0011; expected[1] = 0b1101_0011; expected[2] = 0b1100_0000; assert_eq!(res.get_data()[..4], expected[..4]); } #[test] fn push8_push_bits() { let mut expected = [0u8; 64]; let mut res = CompactQR::with_len(64); res.push_u8(0b1001_1110); expected[0] = 0b1001_1110; assert_eq!(res.get_data()[..4], expected[..4]); res.push_bits(0b1_1011_1001_1110, 13); expected[0] = 0b1001_1110; expected[1] = 0b1101_1100; expected[2] = 0b1111_0000; assert_eq!(res.get_data()[..4], expected[..4]); } #[test] fn push_slice() { let mut expected = [0u8; 64]; let mut res = CompactQR::with_len(64); res.push_u8_slice(&[0b1001_1110, 0b1001_1110, 0b1001_1110]); expected[0] = 0b1001_1110; expected[1] = 0b1001_1110; expected[2] = 0b1001_1110; assert_eq!(res.get_data()[..4], expected[..4]); } #[test] fn push_slice_off() { let mut expected = [0u8; 64]; let mut res = CompactQR::with_len(64); res.push_bits(0b1111, 3); expected[0] = 0b1110_0000; assert_eq!(res.get_data()[..4], expected[..4]); res.push_u8_slice(&[0b0000_0000, 0b1111_1111, 0b0000_0000]); expected[0] = 0b1110_0000; expected[1] = 0b0001_1111; expected[2] = 0b1110_0000; expected[3] = 0b0000_0000; assert_eq!(res.get_data()[..4], expected[..4]); } #[test] fn push_bitfs_off() { let mut expected = [0u8; 64]; let mut res = CompactQR::with_len(64); res.push_bits(0b0_0000_0000_0000_0000, 17); expected[0] |= 0b0000_0000; expected[1] |= 0b0000_0000; expected[2] |= 0b0000_0000; assert_eq!(res.len, 17); assert_eq!(res.get_data()[..8], expected[..8]); res.push_bits(0b1_1111_1111_1111_1111, 17); expected[2] |= 0b0111_1111; expected[3] |= 0b1111_1111; expected[4] |= 0b1100_0000; assert_eq!(res.get_data()[..8], expected[..8]); res.push_bits(0b0_0000_0000_0000_0000, 17); expected[4] |= 0b1100_0000; expected[5] |= 0b0000_0000; expected[6] |= 0b0000_0000; assert_eq!(res.get_data()[..8], expected[..8]); res.push_bits(0b1, 2); expected[5] |= 0b0000_0000; expected[6] |= 0b0000_1000; assert_eq!(res.get_data()[..8], expected[..8]); res.push_u8(0b1111_1111); expected[6] |= 0b0000_1111; expected[7] |= 0b1111_1000; assert_eq!(res.get_data()[..8], expected[..8]); } #[test] fn push_random() { let mut expected = [0u8; 64]; let mut res = CompactQR::with_len(64); res.push_bits(1, 1); expected[0] = 0b1000_0000; assert_eq!(res.get_data()[..8], expected[..8]); res.push_u8(0b1010_1010); expected[0] = 0b1101_0101; expected[1] = 0b0000_0000; assert_eq!(res.get_data()[..8], expected[..8]); res.push_bits(1, 1); expected[1] = 0b0100_0000; assert_eq!(res.get_data()[..8], expected[..8]); res.push_bits(1, 3); expected[1] = 0b0100_1000; assert_eq!(res.get_data()[..8], expected[..8]); } fast_qr-0.13.1/src/tests/datamasking.rs000064400000000000000000000155541046102023000161410ustar 00000000000000use crate::datamasking::Mask; use crate::QRCode; const F: bool = false; const T: bool = true; #[test] fn mask_checkerboard_test() { let mut qr = QRCode::default(10); crate::datamasking::mask(&mut qr, Mask::Checkerboard); #[rustfmt::skip] let qr_bool = [ &qr[0][..10], &qr[1][..10], &qr[2][..10], &qr[3][..10], &qr[4][..10], &qr[5][..10], &qr[6][..10], &qr[7][..10], &qr[8][..10], &qr[9][..10], ]; #[rustfmt::skip] assert_eq!( qr_bool, [ [T, F, T, F, T, F, T, F, T, F], [F, T, F, T, F, T, F, T, F, T], [T, F, T, F, T, F, T, F, T, F], [F, T, F, T, F, T, F, T, F, T], [T, F, T, F, T, F, T, F, T, F], [F, T, F, T, F, T, F, T, F, T], [T, F, T, F, T, F, T, F, T, F], [F, T, F, T, F, T, F, T, F, T], [T, F, T, F, T, F, T, F, T, F], [F, T, F, T, F, T, F, T, F, T], ] ); } #[test] fn mask_horizontal_test() { let mut qr = QRCode::default(10); crate::datamasking::mask(&mut qr, Mask::HorizontalLines); #[rustfmt::skip] let qr_bool = [ &qr[0][..10], &qr[1][..10], &qr[2][..10], &qr[3][..10], &qr[4][..10], &qr[5][..10], &qr[6][..10], &qr[7][..10], &qr[8][..10], &qr[9][..10], ]; #[rustfmt::skip] assert_eq!( qr_bool, [ [T, T, T, T, T, T, T, T, T, T], [F, F, F, F, F, F, F, F, F, F], [T, T, T, T, T, T, T, T, T, T], [F, F, F, F, F, F, F, F, F, F], [T, T, T, T, T, T, T, T, T, T], [F, F, F, F, F, F, F, F, F, F], [T, T, T, T, T, T, T, T, T, T], [F, F, F, F, F, F, F, F, F, F], [T, T, T, T, T, T, T, T, T, T], [F, F, F, F, F, F, F, F, F, F], ] ); } #[test] fn mask_vertical_test() { let mut qr = QRCode::default(10); crate::datamasking::mask(&mut qr, Mask::VerticalLines); #[rustfmt::skip] let qr_bool = [ &qr[0][..10], &qr[1][..10], &qr[2][..10], &qr[3][..10], &qr[4][..10], &qr[5][..10], &qr[6][..10], &qr[7][..10], &qr[8][..10], &qr[9][..10], ]; #[rustfmt::skip] assert_eq!( qr_bool, [ [T, F, F, T, F, F, T, F, F, T], [T, F, F, T, F, F, T, F, F, T], [T, F, F, T, F, F, T, F, F, T], [T, F, F, T, F, F, T, F, F, T], [T, F, F, T, F, F, T, F, F, T], [T, F, F, T, F, F, T, F, F, T], [T, F, F, T, F, F, T, F, F, T], [T, F, F, T, F, F, T, F, F, T], [T, F, F, T, F, F, T, F, F, T], [T, F, F, T, F, F, T, F, F, T], ] ); } #[test] fn mask_diagonal_test() { let mut qr = QRCode::default(10); crate::datamasking::mask(&mut qr, Mask::DiagonalLines); #[rustfmt::skip] let qr_bool = [ &qr[0][..10], &qr[1][..10], &qr[2][..10], &qr[3][..10], &qr[4][..10], &qr[5][..10], &qr[6][..10], &qr[7][..10], &qr[8][..10], &qr[9][..10], ]; #[rustfmt::skip] assert_eq!( qr_bool, [ [T, F, F, T, F, F, T, F, F, T], [F, F, T, F, F, T, F, F, T, F], [F, T, F, F, T, F, F, T, F, F], [T, F, F, T, F, F, T, F, F, T], [F, F, T, F, F, T, F, F, T, F], [F, T, F, F, T, F, F, T, F, F], [T, F, F, T, F, F, T, F, F, T], [F, F, T, F, F, T, F, F, T, F], [F, T, F, F, T, F, F, T, F, F], [T, F, F, T, F, F, T, F, F, T], ] ); } #[test] fn mask_large_checkerboard_test() { let mut qr = QRCode::default(10); crate::datamasking::mask(&mut qr, Mask::LargeCheckerboard); #[rustfmt::skip] let qr_bool = [ &qr[0][..10], &qr[1][..10], &qr[2][..10], &qr[3][..10], &qr[4][..10], &qr[5][..10], &qr[6][..10], &qr[7][..10], &qr[8][..10], &qr[9][..10], ]; #[rustfmt::skip] assert_eq!( qr_bool, [ [T, T, T, F, F, F, T, T, T, F], [T, T, T, F, F, F, T, T, T, F], [F, F, F, T, T, T, F, F, F, T], [F, F, F, T, T, T, F, F, F, T], [T, T, T, F, F, F, T, T, T, F], [T, T, T, F, F, F, T, T, T, F], [F, F, F, T, T, T, F, F, F, T], [F, F, F, T, T, T, F, F, F, T], [T, T, T, F, F, F, T, T, T, F], [T, T, T, F, F, F, T, T, T, F], ] ); } #[test] fn mask_field_test() { let mut qr = QRCode::default(10); crate::datamasking::mask(&mut qr, Mask::Fields); #[rustfmt::skip] let qr_bool = [ &qr[0][..10], &qr[1][..10], &qr[2][..10], &qr[3][..10], &qr[4][..10], &qr[5][..10], &qr[6][..10], &qr[7][..10], &qr[8][..10], &qr[9][..10], ]; #[rustfmt::skip] assert_eq!( qr_bool, [ [T, T, T, T, T, T, T, T, T, T], [T, F, F, F, F, F, T, F, F, F], [T, F, F, T, F, F, T, F, F, T], [T, F, T, F, T, F, T, F, T, F], [T, F, F, T, F, F, T, F, F, T], [T, F, F, F, F, F, T, F, F, F], [T, T, T, T, T, T, T, T, T, T], [T, F, F, F, F, F, T, F, F, F], [T, F, F, T, F, F, T, F, F, T], [T, F, T, F, T, F, T, F, T, F], ] ); } #[test] fn mask_diamond_test() { let mut qr = QRCode::default(10); crate::datamasking::mask(&mut qr, Mask::Diamonds); #[rustfmt::skip] let qr_bool = [ &qr[0][..10], &qr[1][..10], &qr[2][..10], &qr[3][..10], &qr[4][..10], &qr[5][..10], &qr[6][..10], &qr[7][..10], &qr[8][..10], &qr[9][..10], ]; #[rustfmt::skip] assert_eq!( qr_bool, [ [T, T, T, T, T, T, T, T, T, T], [T, T, T, F, F, F, T, T, T, F], [T, T, F, T, T, F, T, T, F, T], [T, F, T, F, T, F, T, F, T, F], [T, F, T, T, F, T, T, F, T, T], [T, F, F, F, T, T, T, F, F, F], [T, T, T, T, T, T, T, T, T, T], [T, T, T, F, F, F, T, T, T, F], [T, T, F, T, T, F, T, T, F, T], [T, F, T, F, T, F, T, F, T, F], ] ); } #[test] fn mask_meadow_test() { let mut qr = QRCode::default(10); crate::datamasking::mask(&mut qr, Mask::Meadow); #[rustfmt::skip] let qr_bool = [ &qr[0][..10], &qr[1][..10], &qr[2][..10], &qr[3][..10], &qr[4][..10], &qr[5][..10], &qr[6][..10], &qr[7][..10], &qr[8][..10], &qr[9][..10], ]; #[rustfmt::skip] assert_eq!( qr_bool, [ [T, F, T, F, T, F, T, F, T, F], [F, F, F, T, T, T, F, F, F, T], [T, F, F, F, T, T, T, F, F, F], [F, T, F, T, F, T, F, T, F, T], [T, T, T, F, F, F, T, T, T, F], [F, T, T, T, F, F, F, T, T, T], [T, F, T, F, T, F, T, F, T, F], [F, F, F, T, T, T, F, F, F, T], [T, F, F, F, T, T, T, F, F, F], [F, T, F, T, F, T, F, T, F, T], ] ); } fast_qr-0.13.1/src/tests/default.rs000064400000000000000000001543551046102023000153050ustar 00000000000000use crate::module::Module; use crate::QRCode; pub(crate) const F: bool = false; pub(crate) const T: bool = true; pub(crate) const DARK: fn(bool) -> Module = Module::dark; pub(crate) const DATA: fn(bool) -> Module = Module::data; pub(crate) const ALIG: fn(bool) -> Module = Module::alignment; pub(crate) const FORM: fn(bool) -> Module = Module::format; pub(crate) const VERS: fn(bool) -> Module = Module::version; pub(crate) const TIMG: fn(bool) -> Module = Module::timing; pub(crate) const FIND: fn(bool) -> Module = Module::finder_pattern; pub(crate) const EMPT: fn(bool) -> Module = Module::empty; #[test] fn from_bool_v1() { #[rustfmt::skip] const MAT_FAST_QR_COM_V1_BOOL: [[bool; 21]; 21] = [[true, true, true, true, true, true, true, false, false, false, true, true, true, false, true, true, true, true, true, true, true], [true, false, false, false, false, false, true, false, true, true, true, false, false, false, true, false, false, false, false, false, true], [true, false, true, true, true, false, true, false, false, true, false, false, false, false, true, false, true, true, true, false, true], [true, false, true, true, true, false, true, false, false, false, true, false, false, false, true, false, true, true, true, false, true], [true, false, true, true, true, false, true, false, true, false, true, false, true, false, true, false, true, true, true, false, true], [true, false, false, false, false, false, true, false, false, true, false, false, true, false, true, false, false, false, false, false, true], [true, true, true, true, true, true, true, false, true, false, true, false, true, false, true, true, true, true, true, true, true], [false, false, false, false, false, false, false, false, false, true, false, true, true, false, false, false, false, false, false, false, false], [true, false, true, false, true, false, true, false, false, true, true, true, false, false, false, false, true, false, false, true, false], [true, true, true, false, true, false, false, false, false, false, true, false, false, false, false, false, false, true, false, true, true], [true, false, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, false, true, false, true], [false, true, true, false, false, true, false, true, false, true, true, false, false, true, false, false, false, true, true, false, true], [true, false, true, true, false, false, true, false, false, true, false, false, true, false, false, false, false, false, false, false, true], [false, false, false, false, false, false, false, false, true, true, false, true, false, true, false, true, true, true, true, true, true], [true, true, true, true, true, true, true, false, false, true, false, true, false, true, true, false, false, true, true, false, false], [true, false, false, false, false, false, true, false, false, true, false, true, true, true, true, true, false, true, true, false, false], [true, false, true, true, true, false, true, false, true, true, false, true, false, false, false, false, false, false, false, true, true], [true, false, true, true, true, false, true, false, false, false, true, true, false, false, false, true, true, true, true, true, false], [true, false, true, true, true, false, true, false, true, true, true, false, true, true, false, false, false, false, false, false, true], [true, false, false, false, false, false, true, false, false, true, true, true, false, true, true, true, true, true, false, true, true], [true, true, true, true, true, true, true, false, true, true, false, true, false, false, false, true, true, true, true, false, true] ]; #[rustfmt::skip] let mat_fast_qr_com_v1: [[Module; 21]; 21] = [ [FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), FORM(F), DATA(F), DATA(T), DATA(T), DATA(T), EMPT(F), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T)], [FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(T), DATA(T), DATA(F), DATA(F), EMPT(F), FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(T), DATA(F), DATA(F), DATA(F), EMPT(F), FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(F), DATA(T), DATA(F), DATA(F), EMPT(F), FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(F), DATA(T), DATA(F), DATA(T), EMPT(F), FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T)], [FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(T), DATA(F), DATA(F), DATA(T), EMPT(F), FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T)], [FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), EMPT(F), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T)], [EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), FORM(F), DATA(T), DATA(F), DATA(T), DATA(T), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F)], [FORM(T), FORM(F), FORM(T), FORM(F), FORM(T), FORM(F), TIMG(T), FORM(F), FORM(F), DATA(T), DATA(T), DATA(T), DATA(F), FORM(F), FORM(F), FORM(F), FORM(T), FORM(F), FORM(F), FORM(T), FORM(F)], [DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), TIMG(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T)], [DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), TIMG(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T)], [DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), TIMG(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T)], [DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), TIMG(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T)], [EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), DARK(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T)], [FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), FORM(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F)], [FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T)], [FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T)], [FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), FORM(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T)] ]; let qr = crate::default::create_mat_from_bool(&MAT_FAST_QR_COM_V1_BOOL); for i in 0..qr.size { let row = &qr[i]; for (j, elem) in row.iter().enumerate() { assert_eq!(elem, &mat_fast_qr_com_v1[i][j], "mat[{i}][{j}]"); } } } #[test] fn from_bool_v3() { #[rustfmt::skip] const MAT_FAST_QR_COM_BOOL: [[bool; 29]; 29] = [ [true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, false, false, true, true, true, true, true, true, true], [true, false, false, false, false, false, true, false, false, false, false, false, false, true, true, false, false, true, true, true, false, false, true, false, false, false, false, false, true], [true, false, true, true, true, false, true, false, true, false, true, false, true, true, false, false, false, false, false, true, true, false, true, false, true, true, true, false, true], [true, false, true, true, true, false, true, false, false, true, true, true, true, false, true, false, false, true, false, true, false, false, true, false, true, true, true, false, true], [true, false, true, true, true, false, true, false, true, false, false, true, false, true, false, false, true, false, false, true, true, false, true, false, true, true, true, false, true], [true, false, false, false, false, false, true, false, false, false, true, true, false, true, true, true, true, false, true, false, true, false, true, false, false, false, false, false, true], [true, true, true, true, true, true, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, true, true, true, true, true, true], [false, false, false, false, false, false, false, false, true, false, true, false, false, true, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false], [false, false, false, false, false, true, true, false, false, false, true, true, true, false, true, false, false, false, true, false, true, false, true, false, true, false, true, false, true], [true, true, false, true, true, true, false, true, true, true, true, false, false, false, false, false, false, false, false, false, true, false, false, true, true, false, true, true, false], [false, true, false, false, true, false, true, false, true, false, true, false, true, true, false, false, false, true, true, false, true, true, true, true, false, true, false, false, false], [false, false, false, true, true, false, false, false, false, false, true, true, true, false, false, true, true, true, false, false, false, false, true, true, false, true, false, false, false], [true, true, false, true, true, true, true, false, true, false, true, true, false, false, false, true, true, false, true, true, true, true, true, false, false, false, false, true, false], [true, false, true, true, false, false, false, false, false, true, false, false, false, true, false, false, true, true, true, true, true, false, true, false, true, true, false, true, true], [true, true, false, false, false, false, true, true, true, false, false, false, false, false, false, true, false, true, false, false, false, false, true, true, false, false, false, false, false], [false, false, true, false, true, false, false, false, false, false, true, true, false, false, false, true, true, false, true, true, false, true, true, false, true, true, true, true, true], [false, false, true, false, true, false, true, true, false, false, true, false, true, false, true, true, false, false, true, false, false, true, false, false, false, true, true, false, true], [true, true, true, true, false, false, false, true, false, false, true, false, false, false, true, false, true, true, false, false, true, false, true, true, true, false, false, false, true], [true, true, true, true, true, true, true, true, true, false, false, false, false, true, true, true, false, false, true, false, true, false, false, false, false, true, false, false, true], [true, false, false, false, false, true, false, false, true, false, true, true, false, true, true, false, false, false, true, true, true, true, true, false, true, false, false, false, false], [true, false, false, true, false, false, true, false, false, false, true, true, false, true, false, false, true, true, false, true, true, true, true, true, true, false, true, false, false], [false, false, false, false, false, false, false, false, true, false, true, false, false, true, true, false, true, true, true, false, true, false, false, false, true, true, true, false, false], [true, true, true, true, true, true, true, false, false, false, false, true, true, false, false, false, true, true, true, true, true, false, true, false, true, false, false, true, false], [true, false, false, false, false, false, true, false, true, true, false, true, true, true, true, false, false, false, true, true, true, false, false, false, true, true, false, false, false], [true, false, true, true, true, false, true, false, false, true, true, false, true, false, false, true, true, false, true, true, true, true, true, true, true, false, false, false, true], [true, false, true, true, true, false, true, false, false, true, true, false, false, false, true, false, true, false, true, true, true, false, false, true, false, true, true, true, false], [true, false, true, true, true, false, true, false, false, true, true, false, false, false, false, true, true, false, true, true, true, true, true, true, true, false, true, true, false], [true, false, false, false, false, false, true, false, false, true, false, true, true, true, false, true, true, true, false, false, true, true, false, false, true, true, true, false, true], [true, true, true, true, true, true, true, false, false, false, true, true, false, false, true, true, true, true, true, false, false, false, true, false, true, false, true, false, false] ]; #[rustfmt::skip] let mat_fast_qr_com_v3: [[Module; 29]; 29] = [ [FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), FORM(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), EMPT(F), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T)], [FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), EMPT(F), FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), EMPT(F), FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), EMPT(F), FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), EMPT(F), FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T)], [FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), EMPT(F), FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T)], [FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), EMPT(F), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T)], [EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), FORM(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F)], [FORM(F), FORM(F), FORM(F), FORM(F), FORM(F), FORM(T), TIMG(T), FORM(F), FORM(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), FORM(F), FORM(T), FORM(F), FORM(T), FORM(F), FORM(T), FORM(F), FORM(T)], [DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), TIMG(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F)], [DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), TIMG(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F)], [DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), TIMG(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F)], [DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), TIMG(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F)], [DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), TIMG(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T)], [DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), TIMG(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F)], [DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), TIMG(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T)], [DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), TIMG(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T)], [DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), TIMG(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T)], [DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), TIMG(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T)], [DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), TIMG(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F)], [DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), TIMG(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(F), DATA(T), DATA(F), DATA(F)], [EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), DARK(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(T), DATA(T), DATA(F), DATA(F)], [FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), FORM(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), ALIG(T), ALIG(F), ALIG(T), ALIG(F), ALIG(T), DATA(F), DATA(F), DATA(T), DATA(F)], [FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(T), DATA(F), DATA(F), DATA(F)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(F), DATA(F), DATA(F), DATA(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F)], [FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T)], [FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), FORM(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F)] ]; let qr = crate::default::create_mat_from_bool(&MAT_FAST_QR_COM_BOOL); for i in 0..qr.size { let row = &qr[i]; for (j, elem) in row.iter().enumerate() { assert_eq!(elem, &mat_fast_qr_com_v3[i][j], "mat[{i}][{j}]"); } } } #[test] fn from_bool_v7() { #[rustfmt::skip] const MAT_FAST_QR_COM_V7_BOOL: [[bool; 45]; 45] = [ [true, true, true, true, true, true, true, false, true, false, false, false, false, true, true, false, true, true, false, true, true, true, true, false, false, true, true, true, false, true, true, true, false, false, false, false, true, false, true, true, true, true, true, true, true], [true, false, false, false, false, false, true, false, true, false, false, false, false, true, false, false, false, true, false, false, false, false, true, true, false, false, true, false, false, false, false, false, false, true, false, true, false, false, true, false, false, false, false, false, true], [true, false, true, true, true, false, true, false, true, false, true, false, true, false, false, true, false, false, false, false, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, true, false, false, true, false, true, true, true, false, true], [true, false, true, true, true, false, true, false, false, true, true, true, false, true, true, true, true, true, true, false, true, false, true, true, true, true, true, false, true, false, false, true, true, false, false, true, true, false, true, false, true, true, true, false, true], [true, false, true, true, true, false, true, false, false, false, true, false, true, false, false, false, true, false, false, true, true, true, true, true, true, true, false, false, true, true, false, false, true, true, true, true, true, false, true, false, true, true, true, false, true], [true, false, false, false, false, false, true, false, true, false, false, true, true, false, false, true, false, false, true, false, true, false, false, false, true, true, true, false, true, false, true, true, true, true, false, false, false, false, true, false, false, false, false, false, true], [true, true, true, true, true, true, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, true, true, true, true, true, true], [false, false, false, false, false, false, false, false, true, false, false, true, true, false, true, false, true, false, false, false, true, false, false, false, true, false, false, true, false, false, true, true, false, false, true, true, false, false, false, false, false, false, false, false, false], [false, false, true, true, true, false, true, false, true, true, true, true, false, true, true, true, false, false, false, false, true, true, true, true, true, true, false, true, true, true, true, false, false, false, true, true, true, true, true, true, false, false, true, true, true], [true, false, false, false, false, true, false, false, true, true, true, true, true, true, false, false, false, false, false, true, false, true, true, true, false, false, false, true, true, false, true, true, false, true, false, false, true, false, false, false, false, true, false, true, false], [false, false, true, true, false, false, true, true, true, true, false, false, false, true, false, true, true, false, true, false, true, true, false, true, false, false, true, false, true, true, true, false, false, true, true, true, true, true, false, true, false, false, false, false, false], [false, true, true, true, true, true, false, true, false, true, false, true, false, true, true, false, false, true, false, false, false, true, true, true, false, false, false, true, true, true, false, false, false, false, false, false, true, false, false, true, false, true, false, true, false], [false, false, false, true, false, true, true, false, false, true, false, true, true, true, true, true, true, true, false, false, false, false, false, true, true, false, false, false, false, false, false, true, true, true, true, false, true, false, false, false, true, false, true, false, false], [true, false, false, false, true, true, false, false, false, false, false, false, true, false, true, false, false, false, false, false, false, true, true, true, true, true, false, true, false, true, false, false, true, true, false, true, false, true, false, true, true, false, false, false, false], [false, false, true, true, false, false, true, true, false, false, true, false, false, false, true, false, true, false, false, true, true, false, false, false, true, false, false, true, true, false, true, true, true, true, true, false, false, true, true, false, true, false, true, true, true], [false, false, true, false, true, false, false, false, true, false, true, false, true, true, true, true, true, true, false, true, false, false, false, true, false, false, true, true, true, false, true, true, false, true, false, true, false, true, true, false, false, true, true, false, true], [true, true, true, true, false, true, true, true, true, true, false, false, false, true, false, false, true, true, false, true, true, true, false, true, true, true, true, true, true, true, true, false, false, false, false, true, false, false, true, true, false, true, false, true, true], [false, false, false, false, true, false, false, true, true, false, false, false, true, false, false, true, false, true, true, true, true, false, true, false, false, false, false, true, false, false, true, true, false, true, false, true, true, true, false, false, false, false, false, false, true], [true, false, true, false, true, false, true, true, false, true, false, false, false, true, true, false, false, true, false, false, false, false, false, false, true, false, false, false, true, true, true, false, false, false, false, true, true, false, true, true, false, true, true, true, false], [true, false, true, true, true, false, false, false, true, true, true, true, false, false, false, false, true, true, false, false, false, true, true, false, true, false, false, true, false, true, false, false, true, false, true, true, true, true, true, true, true, true, true, false, true], [true, false, false, true, true, true, true, true, true, true, true, true, false, true, true, true, true, false, false, false, true, true, true, true, true, true, false, false, true, false, false, true, false, true, true, false, true, true, true, true, true, false, false, false, true], [true, true, true, false, true, false, false, false, true, false, true, false, false, true, true, false, false, true, false, false, true, false, false, false, true, false, false, false, false, true, false, true, false, false, true, true, true, false, false, false, true, false, true, false, true], [true, true, true, false, true, false, true, false, true, true, false, false, false, true, false, false, false, true, true, false, true, false, true, false, true, true, false, false, false, false, true, false, true, true, false, false, true, false, true, false, true, true, true, true, false], [true, false, true, false, true, false, false, false, true, false, false, false, false, false, true, true, false, true, true, true, true, false, false, false, true, true, false, true, false, false, false, true, false, true, false, false, true, false, false, false, true, false, true, true, false], [true, false, true, true, true, true, true, true, true, true, true, false, false, false, false, true, false, true, false, false, true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false, true, true, true, true, true, true, true, true, false], [true, true, false, false, true, false, false, false, true, true, true, true, false, true, false, true, false, true, false, true, false, false, false, true, true, true, true, true, true, true, true, true, false, true, false, true, true, false, true, true, false, true, false, true, false], [true, true, false, true, true, true, true, false, false, false, false, false, true, false, false, true, false, true, true, false, true, true, false, false, false, true, false, true, true, true, false, false, false, false, false, true, false, true, true, false, false, false, false, false, false], [true, false, true, false, false, true, false, false, true, true, false, false, false, true, false, false, false, false, false, true, false, true, false, true, false, true, false, false, true, false, true, false, false, false, true, false, true, false, false, true, false, true, false, true, false], [true, false, false, false, false, true, true, true, false, true, true, true, false, true, true, false, false, false, true, true, false, false, true, false, true, false, false, false, false, false, true, true, true, false, true, false, false, false, false, false, true, false, true, false, false], [true, true, true, false, true, false, false, false, true, false, true, false, true, false, false, false, false, true, false, true, false, true, false, false, true, false, false, false, true, true, true, false, true, false, false, false, true, true, false, false, false, false, true, false, false], [true, false, true, true, true, true, true, true, true, false, false, true, true, true, true, false, true, true, true, true, false, false, false, true, false, true, false, true, false, false, true, true, true, false, true, false, true, false, false, true, false, true, true, true, true], [true, false, false, true, false, false, false, false, true, false, false, false, true, true, false, false, false, false, false, false, true, true, false, true, false, false, false, true, false, false, false, true, false, false, true, false, false, true, false, false, false, false, true, false, true], [true, false, true, true, false, true, true, true, false, false, false, false, false, true, true, false, false, true, false, true, true, false, false, false, false, true, false, false, true, true, false, false, false, false, true, true, true, true, true, true, false, true, true, true, true], [false, true, true, true, true, true, false, false, false, false, false, true, false, false, true, true, true, false, false, false, false, true, true, true, false, false, false, true, true, true, true, true, false, true, false, true, false, false, true, false, true, true, true, true, false], [false, false, false, false, true, false, true, true, false, true, true, true, true, false, true, false, true, true, true, false, true, false, false, false, false, false, true, false, false, true, true, false, false, true, false, true, false, true, true, true, true, false, true, false, false], [false, true, true, true, true, false, false, false, true, false, false, true, false, true, false, false, false, false, false, false, false, false, true, false, false, false, true, true, false, false, false, false, false, false, true, false, true, false, false, false, true, true, true, true, false], [true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, false, true, false, false, true, true, true, true, true, true, true, true, false, true, false, false, true, true, true, true, false, true, true, true, true, true, true, false, false, false], [false, false, false, false, false, false, false, false, true, false, false, true, false, false, false, true, true, true, true, false, true, false, false, false, true, false, false, true, true, false, true, false, true, false, true, true, true, false, false, false, true, false, true, false, true], [true, true, true, true, true, true, true, false, false, true, true, false, true, true, false, false, true, true, false, true, true, false, true, false, true, false, false, false, false, false, false, true, true, true, false, false, true, false, true, false, true, false, false, true, false], [true, false, false, false, false, false, true, false, false, false, false, true, true, false, false, false, false, true, true, false, true, false, false, false, true, true, false, false, false, true, false, false, true, true, false, false, true, false, false, false, true, true, true, true, true], [true, false, true, true, true, false, true, false, true, false, true, false, true, true, true, false, true, false, false, true, true, true, true, true, true, false, true, false, false, false, false, true, false, false, false, false, true, true, true, true, true, false, false, true, true], [true, false, true, true, true, false, true, false, true, true, true, true, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, true, false, false, false, false, false, true, false, false, false, false, false, false, false, true, false, true, false], [true, false, true, true, true, false, true, false, true, false, true, true, false, true, true, false, true, true, true, true, false, true, false, false, true, false, false, false, false, true, true, false, true, false, false, true, true, true, true, true, false, false, false, false, false], [true, false, false, false, false, false, true, false, false, false, false, true, false, false, false, true, false, false, false, false, false, true, true, true, false, true, false, false, true, true, false, false, false, false, true, false, true, false, false, false, false, true, false, false, false], [true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, true, true, true, true, false, false, false, false, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, false, false, true, true, false] ]; #[rustfmt::skip] let mat_fast_qr_com_v7: [[Module; 45]; 45] = [ [FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), FORM(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), VERS(F), VERS(F), VERS(T), EMPT(F), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T)], [FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), VERS(F), VERS(T), VERS(F), EMPT(F), FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), VERS(F), VERS(T), VERS(F), EMPT(F), FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), VERS(F), VERS(T), VERS(T), EMPT(F), FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), VERS(T), VERS(T), VERS(T), EMPT(F), FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T)], [FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), VERS(F), VERS(F), VERS(F), EMPT(F), FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T)], [FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), ALIG(T), ALIG(F), ALIG(T), ALIG(F), ALIG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), TIMG(F), TIMG(T), EMPT(F), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T)], [EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), FORM(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F)], [FORM(F), FORM(F), FORM(T), FORM(T), FORM(T), FORM(F), TIMG(T), FORM(F), FORM(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), FORM(T), FORM(T), FORM(T), FORM(F), FORM(F), FORM(T), FORM(T), FORM(T)], [DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), TIMG(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F)], [DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), TIMG(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F)], [DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), TIMG(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F)], [DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), TIMG(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F)], [DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), TIMG(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F)], [DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), TIMG(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T)], [DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), TIMG(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T)], [DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), TIMG(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T)], [DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), TIMG(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T)], [DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), TIMG(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F)], [DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), TIMG(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T)], [DATA(T), DATA(F), DATA(F), DATA(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(F), DATA(F), DATA(F), DATA(T)], [DATA(T), DATA(T), DATA(T), DATA(F), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(F), DATA(T), DATA(F), DATA(T)], [DATA(T), DATA(T), DATA(T), DATA(F), ALIG(T), ALIG(F), ALIG(T), ALIG(F), ALIG(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), ALIG(T), ALIG(F), ALIG(T), ALIG(F), ALIG(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), ALIG(T), ALIG(F), ALIG(T), ALIG(F), ALIG(T), DATA(T), DATA(T), DATA(T), DATA(F)], [DATA(T), DATA(F), DATA(T), DATA(F), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(F), DATA(T), DATA(T), DATA(F)], [DATA(T), DATA(F), DATA(T), DATA(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(T), DATA(T), DATA(T), DATA(F)], [DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), TIMG(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F)], [DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), TIMG(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F)], [DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), TIMG(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F)], [DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), TIMG(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F)], [DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), TIMG(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F)], [DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), TIMG(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T)], [DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), TIMG(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T)], [DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), TIMG(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T)], [DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), TIMG(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F)], [VERS(F), VERS(F), VERS(F), VERS(F), VERS(T), VERS(F), TIMG(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F)], [VERS(F), VERS(T), VERS(T), VERS(T), VERS(T), VERS(F), TIMG(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F)], [VERS(T), VERS(F), VERS(F), VERS(T), VERS(T), VERS(F), TIMG(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(T), DATA(F), DATA(F), DATA(F)], [EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), EMPT(F), DARK(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(F), DATA(T), DATA(F), DATA(T)], [FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), FORM(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), ALIG(T), ALIG(F), ALIG(T), ALIG(F), ALIG(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), ALIG(T), ALIG(F), ALIG(T), ALIG(F), ALIG(T), DATA(F), DATA(F), DATA(T), DATA(F)], [FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), ALIG(T), ALIG(F), ALIG(F), ALIG(F), ALIG(T), DATA(T), DATA(T), DATA(T), DATA(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), ALIG(T), ALIG(T), ALIG(T), ALIG(T), ALIG(T), DATA(F), DATA(F), DATA(T), DATA(T)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F)], [FIND(T), FIND(F), FIND(T), FIND(T), FIND(T), FIND(F), FIND(T), EMPT(F), FORM(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F)], [FIND(T), FIND(F), FIND(F), FIND(F), FIND(F), FIND(F), FIND(T), EMPT(F), FORM(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(F), DATA(F), DATA(F)], [FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), FORM(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(F), DATA(T), DATA(T), DATA(F)] ]; let qr = crate::default::create_mat_from_bool(&MAT_FAST_QR_COM_V7_BOOL); for i in 0..qr.size { let row = &qr[i]; for (j, elem) in row.iter().enumerate() { assert_eq!(elem, &mat_fast_qr_com_v7[i][j], "mat[{i}][{j}]"); } } } #[test] fn transpose() { let mut qr = QRCode::default(10); for i in 0..100 { qr.data[i] = Module(i as u8); } let transpose = crate::default::transpose(&qr); for i in 0..10 { for j in 0..10 { assert_eq!( transpose[j][i], qr[i][j], "transpose[{i}][{j}] doesn't match" ); } } } fast_qr-0.13.1/src/tests/encode.rs000064400000000000000000000151251046102023000151050ustar 00000000000000use crate::compact::{CompactQR, KEEP_LAST}; use crate::encode; use crate::encode::Mode; use crate::hardcode::cci_bits; #[test] fn best_encoding_numeric_0() { let res = encode::best_encoding(b"589492"); assert_eq!(Mode::Numeric, res); } #[test] fn best_encoding_numeric_1() { let res = encode::best_encoding(b"95904409521090298052194059450950249521940"); assert_eq!(Mode::Numeric, res); } #[test] fn best_encoding_alnum_0() { let res = encode::best_encoding(b"HELLO WORLD"); assert_eq!(Mode::Alphanumeric, res); } #[test] fn best_encoding_alnum_1() { let res = encode::best_encoding(b"HELLO WORLD MY NAME IS ERWAN VIVIEN: THIS IS A TEST//////"); assert_eq!(Mode::Alphanumeric, res); } #[test] fn best_encoding_byte_0() { let res = encode::best_encoding(b"589492h"); assert_eq!(Mode::Byte, res); } #[test] fn best_encoding_byte_1() { let res = encode::best_encoding(b"HELLO WORLD!"); assert_eq!(Mode::Byte, res); } #[test] fn best_encoding_byte_2() { let res = encode::best_encoding(b"HELLO WORLD MY NAME, IS ERWAN VIVIEN: THIS IS A TEST//////"); assert_eq!(Mode::Byte, res); } fn test_encode_header(compact: &CompactQR, input: &[u8], expected_mode: Mode) { let res = compact.get_data(); let mode = match res[0] >> 4 { 0b0001 => Mode::Numeric, 0b0010 => Mode::Alphanumeric, 0b0100 => Mode::Byte, _ => panic!("Invalid encoding mode"), }; assert_eq!( expected_mode, mode, "Encoding mode should be {:?}", expected_mode ); let cci = cci_bits(crate::Version::V01, mode) as u16; let character_count: u16 = { let first_nb_bits = 4; let second_nb_bits = cci - first_nb_bits; let first = ((res[0] & 0b0000_1111) as u16) << second_nb_bits; let second_mask = u8::MAX << (8 - second_nb_bits); let second = ((res[1] & second_mask) as u16) >> (8 - second_nb_bits); first | second }; assert_eq!( character_count, input.len() as u16, "Input length, should be {}", input.len() ); } #[test] fn encode_byte_1() { let mut compact = CompactQR::new(); const INPUT: &[u8] = b"Hello WORLD!"; encode::encode_byte(&mut compact, INPUT, 8); test_encode_header(&compact, INPUT, Mode::Byte); let res = compact.get_data(); for (i, b) in INPUT.iter().enumerate() { assert_eq!(res[1 + i] & 0b111, *b >> 4, "Left part at index {}", i); assert_eq!(res[2 + i] >> 4, *b & 0b1111, "Right part at index {}", i); } } #[test] fn encode_alphanumeric_1() { let mut compact = CompactQR::new(); const INPUT: &[u8] = b"HELLO WORLD"; encode::encode_alphanumeric(&mut compact, INPUT, 9); test_encode_header(&compact, INPUT, Mode::Alphanumeric); let keep_last = KEEP_LAST.map(|x| x as u16); let res = compact .get_data() .iter() .map(|&x| u16::from(x)) .collect::>(); // 13, 'HE' assert_eq!(res[1] & 0b0000_0111, (17 * 45 + 14) >> 8); assert_eq!(res[2] & 0b1111_1111, (17 * 45 + 14) & keep_last[8]); // 24, 'LL' assert_eq!(res[3] & 0b1111_1111, (21 * 45 + 21) >> 3); assert_eq!(res[4] & 0b1110_0000, (21 * 45 + 21) << 5 & keep_last[8]); // 35, 'O ' assert_eq!(res[4] & 0b0001_1111, (24 * 45 + 36) >> 6); assert_eq!(res[5] & 0b1111_1100, (24 * 45 + 36) << 2 & keep_last[8]); // 46, 'WO' assert_eq!(res[5] & 0b0000_0011, (32 * 45 + 24) >> 9); assert_eq!(res[6] & 0b1111_1111, (32 * 45 + 24) >> 1 & keep_last[8]); assert_eq!(res[7] & 0b1000_0000, (32 * 45 + 24) << 8 & keep_last[8]); // 57, 'RL' assert_eq!(res[7] & 0b0111_1111, (27 * 45 + 21) >> 4); assert_eq!(res[8] & 0b1111_0000, (27 * 45 + 21) << 4 & keep_last[8]); // 68, 'D' assert_eq!(res[8] & 0b0000_1111, (13) >> 2); assert_eq!(res[9] & 0b1100_0000, (13) << 6 & keep_last[8]); } #[test] fn encode_numeric_1() { let mut compact = CompactQR::new(); const INPUT: &[u8] = b"5894"; encode::encode_numeric(&mut compact, INPUT, 10); test_encode_header(&compact, INPUT, Mode::Numeric); let keep_last = KEEP_LAST.map(|x| x as u16); let res = compact .get_data() .iter() .map(|&x| u16::from(x)) .collect::>(); // 13, '589' assert_eq!(res[1] & 0b0000_0011, 589 >> 8); assert_eq!(res[2] & 0b1111_1111, (589 << 0) & keep_last[8]); // 24, '4' assert_eq!(res[3] & 0b1111_0000, (4 << 4) & keep_last[8]); } #[test] fn encode_numeric_2() { let mut compact = CompactQR::new(); const INPUT: &[u8] = b"58949"; encode::encode_numeric(&mut compact, INPUT, 10); test_encode_header(&compact, INPUT, Mode::Numeric); let keep_last = KEEP_LAST.map(|x| x as u16); let res = compact .get_data() .iter() .map(|&x| u16::from(x)) .collect::>(); // 13, '589' assert_eq!(res[1] & 0b0000_0011, 589 >> 8); assert_eq!(res[2] & 0b1111_1111, (589 << 0) & keep_last[8]); // 24, '49' assert_eq!(res[3] & 0b1111_1110, 49 << 1 & keep_last[8]); } #[test] fn encode_numeric_3() { let mut compact = CompactQR::new(); const INPUT: &[u8] = b"589491"; encode::encode_numeric(&mut compact, INPUT, 10); test_encode_header(&compact, INPUT, Mode::Numeric); let keep_last = KEEP_LAST.map(|x| x as u16); let res = compact .get_data() .iter() .map(|&x| u16::from(x)) .collect::>(); // 13, '589' assert_eq!(res[1] & 0b0000_0011, 589 >> 8); assert_eq!(res[2] & 0b1111_1111, (589 << 0) & keep_last[8]); // 24, '491' assert_eq!(res[3] & 0b1111_1111, (491 >> 2) & keep_last[8]); assert_eq!(res[4] & 0b1100_0000, (491 << 6) & keep_last[8]); } #[test] fn encode_numeric_4() { let mut compact = CompactQR::new(); const INPUT: &[u8] = b"200505150001"; encode::encode_numeric(&mut compact, INPUT, 10); test_encode_header(&compact, INPUT, Mode::Numeric); let keep_last = KEEP_LAST.map(|x| x as u16); let res = compact .get_data() .iter() .map(|&x| u16::from(x)) .collect::>(); // 13, '200' assert_eq!(res[1] & 0b0000_0011, 200 >> 8); assert_eq!(res[2] & 0b1111_1111, (200 << 0) & keep_last[8]); // 24, '505' assert_eq!(res[3] & 0b1111_1111, (505 >> 2) & keep_last[8]); assert_eq!(res[4] & 0b1100_0000, (505 << 6) & keep_last[8]); // 35, '150' assert_eq!(res[4] & 0b0011_1111, (150 >> 4) & keep_last[8]); assert_eq!(res[5] & 0b1111_0000, (150 << 4) & keep_last[8]); // 46, '001' assert_eq!(res[5] & 0b0000_1111, (1) >> 6); assert_eq!(res[6] & 0b1111_1100, (1) << 2 & keep_last[8]); } fast_qr-0.13.1/src/tests/error_correction.rs000064400000000000000000000075711046102023000172360ustar 00000000000000use crate::{hardcode, polynomials, Version, ECL}; #[test] fn error_code_computation_01() { let version = Version::V05; let quality = ECL::Q; let vec = [67, 85, 70, 134, 87, 38, 85, 194, 119, 50, 6, 18, 6, 103, 38]; let generator_polynomials = hardcode::get_polynomial(version, quality); let div = polynomials::division(&vec, generator_polynomials); assert_eq!( div[255 - generator_polynomials.len() + 1..], [213, 199, 11, 45, 115, 247, 241, 223, 229, 248, 154, 117, 154, 111, 86, 161, 111, 39] ) } #[test] fn error_code_computation_02() { let version = Version::V05; let quality = ECL::Q; let vec = [ 246, 246, 66, 7, 118, 134, 242, 7, 38, 86, 22, 198, 199, 146, 6, ]; let generator_polynomials = hardcode::get_polynomial(version, quality); let div = polynomials::division(&vec, generator_polynomials); assert_eq!( div[255 - generator_polynomials.len() + 1..], [87, 204, 96, 60, 202, 182, 124, 157, 200, 134, 27, 129, 209, 17, 163, 163, 120, 133] ) } #[test] fn error_code_computation_03() { let version = Version::V05; let quality = ECL::Q; let vec = [ 182, 230, 247, 119, 50, 7, 118, 134, 87, 38, 82, 6, 134, 151, 50, 7, ]; let generator_polynomials = hardcode::get_polynomial(version, quality); let div = polynomials::division(&vec, generator_polynomials); assert_eq!( div[255 - generator_polynomials.len() + 1..], [148, 116, 177, 212, 76, 133, 75, 242, 238, 76, 195, 230, 189, 10, 108, 240, 192, 141] ) } #[test] fn error_code_computation_04() { let version = Version::V05; let quality = ECL::Q; let vec = [ 70, 247, 118, 86, 194, 6, 151, 50, 16, 236, 17, 236, 17, 236, 17, 236, ]; let generator_polynomials = hardcode::get_polynomial(version, quality); let div = polynomials::division(&vec, generator_polynomials); assert_eq!( div[255 - generator_polynomials.len() + 1..], [235, 159, 5, 173, 24, 147, 59, 33, 106, 40, 255, 172, 82, 2, 131, 32, 178, 236] ) } #[test] fn error_code_computation_821043386() { let tmp1 = [ 29, 10, 145, 40, 0, 90, 126, 137, 221, 186, 137, 39, 208, 250, 199, 176, 202, 124, 200, 85, 63, 254, ]; let tmp2 = [ 0, 156, 45, 183, 29, 151, 219, 54, 96, 249, 24, 136, 5, 241, 175, 189, 28, 75, 234, 150, 148, 23, 9, 202, 162, 68, 250, 140, 24, 151, ]; let div = polynomials::division(&tmp1, &tmp2); assert_eq!( div[255 - 29..], ([ 0, 85, 37, 253, 234, 217, 13, 16, 62, 107, 80, 72, 22, 66, 240, 139, 57, 109, 195, 68, 121, 32, 206, 196, 117, 252, 175, 189, 167 ]) ) } #[test] fn error_code_computation_struct_31_0() { let tmp1 = [28, 195, 100, 36, 175, 11, 35, 243, 28, 137, 59, 182, 193]; let tmp2 = [ 0, 173, 125, 158, 2, 103, 182, 118, 17, 145, 201, 111, 28, 165, 53, 161, 21, 245, 142, 13, 102, 48, 227, 153, 145, 218, 70, ]; let div = polynomials::division(&tmp1, &tmp2); assert_eq!( div[255 - 26..], ([ 68, 150, 68, 205, 197, 78, 104, 100, 177, 0, 185, 7, 178, 106, 110, 170, 101, 222, 45, 74, 31, 75, 3, 126, 216, 208 ]) ) } #[test] fn error_code_computation_struct_31_1() { let tmp1 = [35, 37, 251, 189, 8, 169, 15, 34, 59, 137, 187, 114, 134]; let tmp2 = [ 0, 173, 125, 158, 2, 103, 182, 118, 17, 145, 201, 111, 28, 165, 53, 161, 21, 245, 142, 13, 102, 48, 227, 153, 145, 218, 70, ]; let div = polynomials::division(&tmp1, &tmp2); assert_eq!( div[255 - 26..], ([ 246, 74, 169, 24, 210, 247, 165, 59, 102, 186, 144, 234, 202, 247, 84, 191, 166, 28, 140, 190, 219, 81, 72, 34, 159, 0 ]) ) } #[test] fn division_small_1() { let a = polynomials::division(&[32, 9], &[0, 0]); assert_eq!(&a[254..], &[41]) } fast_qr-0.13.1/src/tests/mod.rs000064400000000000000000000002311046102023000144170ustar 00000000000000mod bytes; mod compact; mod datamasking; mod default; mod encode; mod error_correction; mod polynomials; mod score; mod structure; mod svg; mod version; fast_qr-0.13.1/src/tests/polynomials.rs000064400000000000000000001230031046102023000162110ustar 00000000000000/// Contains all possible generator polynomials (to compule error codewords) pub const GENERATOR_POLYNOMIALS: [&[u8]; 31] = [ &[0], &[0, 0], &[0, 25, 1], &[0, 198, 199, 3], &[0, 75, 249, 78, 6], &[0, 113, 164, 166, 119, 10], &[0, 166, 0, 134, 5, 176, 15], &[0, 87, 229, 146, 149, 238, 102, 21], &[0, 175, 238, 208, 249, 215, 252, 196, 28], &[0, 95, 246, 137, 231, 235, 149, 11, 123, 36], &[0, 251, 67, 46, 61, 118, 70, 64, 94, 32, 45], &[0, 220, 192, 91, 194, 172, 177, 209, 116, 227, 10, 55], &[0, 102, 43, 98, 121, 187, 113, 198, 143, 131, 87, 157, 66], &[ 0, 74, 152, 176, 100, 86, 100, 106, 104, 130, 218, 206, 140, 78, ], &[ 0, 199, 249, 155, 48, 190, 124, 218, 137, 216, 87, 207, 59, 22, 91, ], &[ 0, 8, 183, 61, 91, 202, 37, 51, 58, 58, 237, 140, 124, 5, 99, 105, ], &[ 0, 120, 104, 107, 109, 102, 161, 76, 3, 91, 191, 147, 169, 182, 194, 225, 120, ], &[ 0, 43, 139, 206, 78, 43, 239, 123, 206, 214, 147, 24, 99, 150, 39, 243, 163, 136, ], &[ 0, 215, 234, 158, 94, 184, 97, 118, 170, 79, 187, 152, 148, 252, 179, 5, 98, 96, 153, ], &[ 0, 67, 3, 105, 153, 52, 90, 83, 17, 150, 159, 44, 128, 153, 133, 252, 222, 138, 220, 171, ], &[ 0, 17, 60, 79, 50, 61, 163, 26, 187, 202, 180, 221, 225, 83, 239, 156, 164, 212, 212, 188, 190, ], &[ 0, 240, 233, 104, 247, 181, 140, 67, 98, 85, 200, 210, 115, 148, 137, 230, 36, 122, 254, 148, 175, 210, ], &[ 0, 210, 171, 247, 242, 93, 230, 14, 109, 221, 53, 200, 74, 8, 172, 98, 80, 219, 134, 160, 105, 165, 231, ], &[ 0, 171, 102, 146, 91, 49, 103, 65, 17, 193, 150, 14, 25, 183, 248, 94, 164, 224, 192, 1, 78, 56, 147, 253, ], &[ 0, 229, 121, 135, 48, 211, 117, 251, 126, 159, 180, 169, 152, 192, 226, 228, 218, 111, 0, 117, 232, 87, 96, 227, 21, ], &[ 0, 231, 181, 156, 39, 170, 26, 12, 59, 15, 148, 201, 54, 66, 237, 208, 99, 167, 144, 182, 95, 243, 129, 178, 252, 45, ], &[ 0, 173, 125, 158, 2, 103, 182, 118, 17, 145, 201, 111, 28, 165, 53, 161, 21, 245, 142, 13, 102, 48, 227, 153, 145, 218, 70, ], &[ 0, 79, 228, 8, 165, 227, 21, 180, 29, 9, 237, 70, 99, 45, 58, 138, 135, 73, 126, 172, 94, 216, 193, 157, 26, 17, 149, 96, ], &[ 0, 168, 223, 200, 104, 224, 234, 108, 180, 110, 190, 195, 147, 205, 27, 232, 201, 21, 43, 245, 87, 42, 195, 212, 119, 242, 37, 9, 123, ], &[ 0, 156, 45, 183, 29, 151, 219, 54, 96, 249, 24, 136, 5, 241, 175, 189, 28, 75, 234, 150, 148, 23, 9, 202, 162, 68, 250, 140, 24, 151, ], &[ 0, 41, 173, 145, 152, 216, 31, 179, 182, 50, 48, 110, 86, 239, 96, 222, 125, 42, 173, 226, 193, 224, 130, 156, 37, 251, 216, 238, 40, 192, 180, ], ]; #[test] fn generator_polynomials() { let poly = GENERATOR_POLYNOMIALS[7]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x7 + α87x6 + α229x5 + α146x4 + α149x3 + α238x2 + α102x + α21" ); let poly = GENERATOR_POLYNOMIALS[8]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x8 + α175x7 + α238x6 + α208x5 + α249x4 + α215x3 + α252x2 + α196x + α28" ); let poly = GENERATOR_POLYNOMIALS[9]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x9 + α95x8 + α246x7 + α137x6 + α231x5 + α235x4 + α149x3 + α11x2 + α123x + α36" ); let poly = GENERATOR_POLYNOMIALS[10]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x10 + α251x9 + α67x8 + α46x7 + α61x6 + α118x5 + α70x4 + α64x3 + α94x2 + α32x + α45" ); let poly = GENERATOR_POLYNOMIALS[11]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x11 + α220x10 + α192x9 + α91x8 + α194x7 + α172x6 + α177x5 + α209x4 + α116x3 + α227x2 + α10x + α55" ); let poly = GENERATOR_POLYNOMIALS[12]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x12 + α102x11 + α43x10 + α98x9 + α121x8 + α187x7 + α113x6 + α198x5 + α143x4 + α131x3 + α87x2 + α157x + α66" ); let poly = GENERATOR_POLYNOMIALS[13]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x13 + α74x12 + α152x11 + α176x10 + α100x9 + α86x8 + α100x7 + α106x6 + α104x5 + α130x4 + α218x3 + α206x2 + α140x + α78" ); let poly = GENERATOR_POLYNOMIALS[14]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x14 + α199x13 + α249x12 + α155x11 + α48x10 + α190x9 + α124x8 + α218x7 + α137x6 + α216x5 + α87x4 + α207x3 + α59x2 + α22x + α91" ); let poly = GENERATOR_POLYNOMIALS[15]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x15 + α8x14 + α183x13 + α61x12 + α91x11 + α202x10 + α37x9 + α51x8 + α58x7 + α58x6 + α237x5 + α140x4 + α124x3 + α5x2 + α99x + α105" ); let poly = GENERATOR_POLYNOMIALS[16]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x16 + α120x15 + α104x14 + α107x13 + α109x12 + α102x11 + α161x10 + α76x9 + α3x8 + α91x7 + α191x6 + α147x5 + α169x4 + α182x3 + α194x2 + α225x + α120" ); let poly = GENERATOR_POLYNOMIALS[17]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x17 + α43x16 + α139x15 + α206x14 + α78x13 + α43x12 + α239x11 + α123x10 + α206x9 + α214x8 + α147x7 + α24x6 + α99x5 + α150x4 + α39x3 + α243x2 + α163x + α136" ); let poly = GENERATOR_POLYNOMIALS[18]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x18 + α215x17 + α234x16 + α158x15 + α94x14 + α184x13 + α97x12 + α118x11 + α170x10 + α79x9 + α187x8 + α152x7 + α148x6 + α252x5 + α179x4 + α5x3 + α98x2 + α96x + α153" ); let poly = GENERATOR_POLYNOMIALS[19]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x19 + α67x18 + α3x17 + α105x16 + α153x15 + α52x14 + α90x13 + α83x12 + α17x11 + α150x10 + α159x9 + α44x8 + α128x7 + α153x6 + α133x5 + α252x4 + α222x3 + α138x2 + α220x + α171" ); let poly = GENERATOR_POLYNOMIALS[20]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x20 + α17x19 + α60x18 + α79x17 + α50x16 + α61x15 + α163x14 + α26x13 + α187x12 + α202x11 + α180x10 + α221x9 + α225x8 + α83x7 + α239x6 + α156x5 + α164x4 + α212x3 + α212x2 + α188x + α190" ); let poly = GENERATOR_POLYNOMIALS[21]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x21 + α240x20 + α233x19 + α104x18 + α247x17 + α181x16 + α140x15 + α67x14 + α98x13 + α85x12 + α200x11 + α210x10 + α115x9 + α148x8 + α137x7 + α230x6 + α36x5 + α122x4 + α254x3 + α148x2 + α175x + α210" ); let poly = GENERATOR_POLYNOMIALS[22]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x22 + α210x21 + α171x20 + α247x19 + α242x18 + α93x17 + α230x16 + α14x15 + α109x14 + α221x13 + α53x12 + α200x11 + α74x10 + α8x9 + α172x8 + α98x7 + α80x6 + α219x5 + α134x4 + α160x3 + α105x2 + α165x + α231" ); let poly = GENERATOR_POLYNOMIALS[23]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x23 + α171x22 + α102x21 + α146x20 + α91x19 + α49x18 + α103x17 + α65x16 + α17x15 + α193x14 + α150x13 + α14x12 + α25x11 + α183x10 + α248x9 + α94x8 + α164x7 + α224x6 + α192x5 + α1x4 + α78x3 + α56x2 + α147x + α253" ); let poly = GENERATOR_POLYNOMIALS[24]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x24 + α229x23 + α121x22 + α135x21 + α48x20 + α211x19 + α117x18 + α251x17 + α126x16 + α159x15 + α180x14 + α169x13 + α152x12 + α192x11 + α226x10 + α228x9 + α218x8 + α111x7 + α0x6 + α117x5 + α232x4 + α87x3 + α96x2 + α227x + α21" ); let poly = GENERATOR_POLYNOMIALS[25]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x25 + α231x24 + α181x23 + α156x22 + α39x21 + α170x20 + α26x19 + α12x18 + α59x17 + α15x16 + α148x15 + α201x14 + α54x13 + α66x12 + α237x11 + α208x10 + α99x9 + α167x8 + α144x7 + α182x6 + α95x5 + α243x4 + α129x3 + α178x2 + α252x + α45" ); let poly = GENERATOR_POLYNOMIALS[26]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x26 + α173x25 + α125x24 + α158x23 + α2x22 + α103x21 + α182x20 + α118x19 + α17x18 + α145x17 + α201x16 + α111x15 + α28x14 + α165x13 + α53x12 + α161x11 + α21x10 + α245x9 + α142x8 + α13x7 + α102x6 + α48x5 + α227x4 + α153x3 + α145x2 + α218x + α70" ); let poly = GENERATOR_POLYNOMIALS[27]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x27 + α79x26 + α228x25 + α8x24 + α165x23 + α227x22 + α21x21 + α180x20 + α29x19 + α9x18 + α237x17 + α70x16 + α99x15 + α45x14 + α58x13 + α138x12 + α135x11 + α73x10 + α126x9 + α172x8 + α94x7 + α216x6 + α193x5 + α157x4 + α26x3 + α17x2 + α149x + α96" ); let poly = GENERATOR_POLYNOMIALS[28]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x28 + α168x27 + α223x26 + α200x25 + α104x24 + α224x23 + α234x22 + α108x21 + α180x20 + α110x19 + α190x18 + α195x17 + α147x16 + α205x15 + α27x14 + α232x13 + α201x12 + α21x11 + α43x10 + α245x9 + α87x8 + α42x7 + α195x6 + α212x5 + α119x4 + α242x3 + α37x2 + α9x + α123" ); let poly = GENERATOR_POLYNOMIALS[29]; let poly_string = crate::polynomials::generated_to_string(poly); assert_eq!( poly_string, "α0x29 + α156x28 + α45x27 + α183x26 + α29x25 + α151x24 + α219x23 + α54x22 + α96x21 + α249x20 + α24x19 + α136x18 + α5x17 + α241x16 + α175x15 + α189x14 + α28x13 + α75x12 + α234x11 + α150x10 + α148x9 + α23x8 + α9x7 + α202x6 + α162x5 + α68x4 + α250x3 + α140x2 + α24x + α151" ) } mod generators { use super::GENERATOR_POLYNOMIALS; #[test] fn generator1() { let version = crate::version::Version::V01; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[7]); let version = crate::version::Version::V01; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[10]); let version = crate::version::Version::V01; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[13]); let version = crate::version::Version::V01; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[17]); } #[test] fn generator2() { let version = crate::version::Version::V02; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[10]); let version = crate::version::Version::V02; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[16]); let version = crate::version::Version::V02; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[22]); let version = crate::version::Version::V02; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); } #[test] fn generator3() { let version = crate::version::Version::V03; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[15]); let version = crate::version::Version::V03; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); let version = crate::version::Version::V03; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[18]); let version = crate::version::Version::V03; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[22]); } #[test] fn generator4() { let version = crate::version::Version::V04; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[20]); let version = crate::version::Version::V04; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[18]); let version = crate::version::Version::V04; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); let version = crate::version::Version::V04; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[16]); } #[test] fn generator5() { let version = crate::version::Version::V05; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); let version = crate::version::Version::V05; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); let version = crate::version::Version::V05; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[18]); let version = crate::version::Version::V05; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[22]); } #[test] fn generator6() { let version = crate::version::Version::V06; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[18]); let version = crate::version::Version::V06; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[16]); let version = crate::version::Version::V06; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); let version = crate::version::Version::V06; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); } #[test] fn generator7() { let version = crate::version::Version::V07; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[20]); let version = crate::version::Version::V07; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[18]); let version = crate::version::Version::V07; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[18]); let version = crate::version::Version::V07; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); } #[test] fn generator8() { let version = crate::version::Version::V08; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); let version = crate::version::Version::V08; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[22]); let version = crate::version::Version::V08; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[22]); let version = crate::version::Version::V08; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); } #[test] fn generator9() { let version = crate::version::Version::V09; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V09; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[22]); let version = crate::version::Version::V09; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[20]); let version = crate::version::Version::V09; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); } #[test] fn generator10() { let version = crate::version::Version::V10; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[18]); let version = crate::version::Version::V10; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); let version = crate::version::Version::V10; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); let version = crate::version::Version::V10; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); } #[test] fn generator11() { let version = crate::version::Version::V11; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[20]); let version = crate::version::Version::V11; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V11; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V11; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); } #[test] fn generator12() { let version = crate::version::Version::V12; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); let version = crate::version::Version::V12; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[22]); let version = crate::version::Version::V12; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); let version = crate::version::Version::V12; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); } #[test] fn generator13() { let version = crate::version::Version::V13; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); let version = crate::version::Version::V13; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[22]); let version = crate::version::Version::V13; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); let version = crate::version::Version::V13; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[22]); } #[test] fn generator14() { let version = crate::version::Version::V14; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V14; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); let version = crate::version::Version::V14; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[20]); let version = crate::version::Version::V14; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); } #[test] fn generator15() { let version = crate::version::Version::V15; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[22]); let version = crate::version::Version::V15; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); let version = crate::version::Version::V15; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V15; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); } #[test] fn generator16() { let version = crate::version::Version::V16; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); let version = crate::version::Version::V16; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V16; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); let version = crate::version::Version::V16; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator17() { let version = crate::version::Version::V17; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V17; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V17; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V17; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); } #[test] fn generator18() { let version = crate::version::Version::V18; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V18; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); let version = crate::version::Version::V18; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V18; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); } #[test] fn generator19() { let version = crate::version::Version::V19; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V19; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); let version = crate::version::Version::V19; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); let version = crate::version::Version::V19; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); } #[test] fn generator20() { let version = crate::version::Version::V20; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V20; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); let version = crate::version::Version::V20; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V20; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); } #[test] fn generator21() { let version = crate::version::Version::V21; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V21; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); let version = crate::version::Version::V21; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V21; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator22() { let version = crate::version::Version::V22; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V22; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V22; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V22; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[24]); } #[test] fn generator23() { let version = crate::version::Version::V23; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V23; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V23; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V23; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator24() { let version = crate::version::Version::V24; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V24; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V24; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V24; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator25() { let version = crate::version::Version::V25; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[26]); let version = crate::version::Version::V25; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V25; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V25; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator26() { let version = crate::version::Version::V26; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V26; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V26; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V26; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator27() { let version = crate::version::Version::V27; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V27; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V27; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V27; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator28() { let version = crate::version::Version::V28; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V28; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V28; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V28; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator29() { let version = crate::version::Version::V29; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V29; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V29; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V29; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator30() { let version = crate::version::Version::V30; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V30; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V30; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V30; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator31() { let version = crate::version::Version::V31; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V31; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V31; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V31; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator32() { let version = crate::version::Version::V32; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V32; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V32; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V32; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator33() { let version = crate::version::Version::V33; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V33; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V33; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V33; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator34() { let version = crate::version::Version::V34; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V34; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V34; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V34; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator35() { let version = crate::version::Version::V35; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V35; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V35; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V35; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator36() { let version = crate::version::Version::V36; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V36; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V36; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V36; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator37() { let version = crate::version::Version::V37; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V37; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V37; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V37; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator38() { let version = crate::version::Version::V38; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V38; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V38; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V38; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator39() { let version = crate::version::Version::V39; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V39; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V39; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V39; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } #[test] fn generator40() { let version = crate::version::Version::V40; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::L); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V40; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::M); assert_eq!(gen, GENERATOR_POLYNOMIALS[28]); let version = crate::version::Version::V40; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::Q); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); let version = crate::version::Version::V40; let gen = crate::hardcode::get_polynomial(version, crate::ecl::ECL::H); assert_eq!(gen, GENERATOR_POLYNOMIALS[30]); } } fast_qr-0.13.1/src/tests/score.rs000064400000000000000000001002261046102023000147600ustar 00000000000000use crate::default::create_mat_from_bool; use crate::module::Module; use crate::score::{ test_matrix_dark_modules, test_matrix_pattern_and_line, test_matrix_score_squares, test_score_line, test_score_pattern, }; use crate::tests::default::{DATA, EMPT, F, FIND, T}; #[rustfmt::skip] const MAT_EXAMPLE_COM: [[bool; 29]; 29] = [ [true, true, true, true, true, true, true, false, true, true, false, false, false, true, false, true, false, false, true, false, true, false, true, true, true, true, true, true, true], [true, false, false, false, false, false, true, false, true, true, true, false, false, true, false, true, false, false, true, true, false, false, true, false, false, false, false, false, true], [true, false, true, true, true, false, true, false, true, false, true, false, true, false, true, true, false, false, false, true, true, false, true, false, true, true, true, false, true], [true, false, true, true, true, false, true, false, false, true, false, true, false, false, true, false, false, true, false, true, false, false, true, false, true, true, true, false, true], [true, false, true, true, true, false, true, false, false, false, false, false, true, true, true, true, true, false, true, true, true, false, true, false, true, true, true, false, true], [true, false, false, false, false, false, true, false, true, true, true, true, true, false, false, true, false, false, true, false, false, false, true, false, false, false, false, false, true], [true, true, true, true, true, true, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, true, true, true, true, true, true], [false, false, false, false, false, false, false, false, true, true, false, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false], [false, false, true, true, true, false, true, false, true, false, false, false, false, false, false, false, true, false, true, true, true, true, true, true, false, false, true, true, true], [false, false, false, false, false, true, false, true, true, true, true, true, true, false, true, false, true, false, false, false, false, true, true, true, true, true, true, false, true], [true, false, true, true, false, true, true, false, true, true, true, true, true, true, true, true, true, false, true, false, true, true, true, true, false, false, false, false, false], [true, false, true, false, true, true, false, true, true, true, false, true, true, false, true, false, true, true, true, false, false, true, true, true, false, true, false, true, false], [false, true, false, true, false, true, true, true, true, false, true, false, false, true, false, false, false, false, false, false, true, true, false, true, false, false, true, true, true], [false, true, true, false, true, true, false, false, true, false, false, false, true, false, true, false, true, false, false, true, true, true, true, false, true, true, false, true, true], [true, true, false, true, false, true, true, false, true, true, true, false, true, false, false, true, true, false, true, false, true, false, true, true, false, false, false, false, false], [true, false, true, true, true, false, false, false, true, true, false, false, true, false, false, false, false, true, true, false, true, false, false, false, true, true, false, true, false], [false, true, true, false, true, true, true, false, false, true, true, false, true, false, false, true, true, false, false, false, false, true, false, false, false, true, true, true, false], [true, false, true, true, true, false, false, false, true, false, true, false, true, true, false, true, true, false, false, false, true, true, true, true, true, true, false, true, true], [true, false, false, true, true, false, true, false, false, true, false, true, false, true, false, true, true, true, false, true, false, false, true, true, false, true, false, false, false], [true, false, true, false, false, true, false, true, false, true, true, true, true, false, false, true, true, true, false, true, true, false, true, false, true, false, false, true, false], [true, false, true, true, false, true, true, false, true, false, true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, false, true, false, false], [false, false, false, false, false, false, false, false, true, false, false, false, true, false, true, false, true, true, true, false, true, false, false, false, true, true, false, false, true], [true, true, true, true, true, true, true, false, false, false, true, false, true, true, true, true, false, true, true, true, true, false, true, false, true, false, false, false, false], [true, false, false, false, false, false, true, false, false, true, true, true, true, true, false, true, true, false, true, true, true, false, false, false, true, true, false, false, false], [true, false, true, true, true, false, true, false, true, true, false, false, true, false, false, false, true, true, true, false, true, true, true, true, true, true, true, false, true], [true, false, true, true, true, false, true, false, true, true, false, true, true, true, true, false, false, false, true, true, true, true, false, true, false, true, true, false, false], [true, false, true, true, true, false, true, false, true, true, true, false, true, false, true, false, true, true, true, true, true, true, true, true, true, false, true, true, false], [true, false, false, false, false, false, true, false, false, true, false, false, false, false, true, true, true, true, false, false, false, false, true, false, true, true, false, true, false], [true, true, true, true, true, true, true, false, false, false, true, true, true, true, true, true, false, false, true, false, false, false, true, false, true, false, true, false, false] ]; #[test] fn example_com() { let mat = create_mat_from_bool(&MAT_EXAMPLE_COM); let (line_score, col_score, pattern_score) = test_matrix_pattern_and_line(&mat); let dark_score = test_matrix_dark_modules(&mat); let square_score = test_matrix_score_squares(&mat); // {"patternScore":160,"lineColScore":106,"squareScore":135,"darkScore":0} // {"patternScore":240,"lineColScore":117,"squareScore":138,"darkScore":0} assert_eq!(dark_score, 0, "dark score, expected 0"); assert_eq!(square_score, 138, "square score, expected 138"); assert_eq!(line_score + col_score, 117, "line col score, expected 117"); assert_eq!(pattern_score, 240, "pattern score, expected 240"); } #[rustfmt::skip] const MAT_FAST_QR_COM: [[bool; 29]; 29] = [ [true, true, true, true, true, true, true, false, true, true, true, true, true, true, true, true, true, true, true, true, false, false, true, true, true, true, true, true, true], [true, false, false, false, false, false, true, false, false, false, false, false, false, true, true, false, false, true, true, true, false, false, true, false, false, false, false, false, true], [true, false, true, true, true, false, true, false, true, false, true, false, true, true, false, false, false, false, false, true, true, false, true, false, true, true, true, false, true], [true, false, true, true, true, false, true, false, false, true, true, true, true, false, true, false, false, true, false, true, false, false, true, false, true, true, true, false, true], [true, false, true, true, true, false, true, false, true, false, false, true, false, true, false, false, true, false, false, true, true, false, true, false, true, true, true, false, true], [true, false, false, false, false, false, true, false, false, false, true, true, false, true, true, true, true, false, true, false, true, false, true, false, false, false, false, false, true], [true, true, true, true, true, true, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, true, true, true, true, true, true], [false, false, false, false, false, false, false, false, true, false, true, false, false, true, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false], [false, false, false, false, false, true, true, false, false, false, true, true, true, false, true, false, false, false, true, false, true, false, true, false, true, false, true, false, true], [true, true, false, true, true, true, false, true, true, true, true, false, false, false, false, false, false, false, false, false, true, false, false, true, true, false, true, true, false], [false, true, false, false, true, false, true, false, true, false, true, false, true, true, false, false, false, true, true, false, true, true, true, true, false, true, false, false, false], [false, false, false, true, true, false, false, false, false, false, true, true, true, false, false, true, true, true, false, false, false, false, true, true, false, true, false, false, false], [true, true, false, true, true, true, true, false, true, false, true, true, false, false, false, true, true, false, true, true, true, true, true, false, false, false, false, true, false], [true, false, true, true, false, false, false, false, false, true, false, false, false, true, false, false, true, true, true, true, true, false, true, false, true, true, false, true, true], [true, true, false, false, false, false, true, true, true, false, false, false, false, false, false, true, false, true, false, false, false, false, true, true, false, false, false, false, false], [false, false, true, false, true, false, false, false, false, false, true, true, false, false, false, true, true, false, true, true, false, true, true, false, true, true, true, true, true], [false, false, true, false, true, false, true, true, false, false, true, false, true, false, true, true, false, false, true, false, false, true, false, false, false, true, true, false, true], [true, true, true, true, false, false, false, true, false, false, true, false, false, false, true, false, true, true, false, false, true, false, true, true, true, false, false, false, true], [true, true, true, true, true, true, true, true, true, false, false, false, false, true, true, true, false, false, true, false, true, false, false, false, false, true, false, false, true], [true, false, false, false, false, true, false, false, true, false, true, true, false, true, true, false, false, false, true, true, true, true, true, false, true, false, false, false, false], [true, false, false, true, false, false, true, false, false, false, true, true, false, true, false, false, true, true, false, true, true, true, true, true, true, false, true, false, false], [false, false, false, false, false, false, false, false, true, false, true, false, false, true, true, false, true, true, true, false, true, false, false, false, true, true, true, false, false], [true, true, true, true, true, true, true, false, false, false, false, true, true, false, false, false, true, true, true, true, true, false, true, false, true, false, false, true, false], [true, false, false, false, false, false, true, false, true, true, false, true, true, true, true, false, false, false, true, true, true, false, false, false, true, true, false, false, false], [true, false, true, true, true, false, true, false, false, true, true, false, true, false, false, true, true, false, true, true, true, true, true, true, true, false, false, false, true], [true, false, true, true, true, false, true, false, false, true, true, false, false, false, true, false, true, false, true, true, true, false, false, true, false, true, true, true, false], [true, false, true, true, true, false, true, false, false, true, true, false, false, false, false, true, true, false, true, true, true, true, true, true, true, false, true, true, false], [true, false, false, false, false, false, true, false, false, true, false, true, true, true, false, true, true, true, false, false, true, true, false, false, true, true, true, false, true], [true, true, true, true, true, true, true, false, false, false, true, true, false, false, true, true, true, true, true, false, false, false, true, false, true, false, true, false, false] ]; #[test] fn fast_qr_com() { let mat = create_mat_from_bool(&MAT_FAST_QR_COM); let (line_score, col_score, pattern_score) = test_matrix_pattern_and_line(&mat); let dark_score = test_matrix_dark_modules(&mat); let square_score = test_matrix_score_squares(&mat); // {"patternScore":80,"lineColScore":108,"squareScore":174,"darkScore":0} assert_eq!(dark_score, 0, "dark score, expected 0"); assert_eq!(square_score, 174, "square score, expected 174"); assert_eq!(line_score + col_score, 108, "line col score, expected 108"); assert_eq!(pattern_score, 80, "pattern score, expected 80"); } #[rustfmt::skip] const MAT_XIAOJIBA_DEV: [[bool; 29]; 29] = [ [true, true, true, true, true, true, true, false, false, true, false, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true], [true, false, false, false, false, false, true, false, false, true, true, false, true, true, true, false, true, false, true, true, false, false, true, false, false, false, false, false, true], [true, false, true, true, true, false, true, false, true, true, true, false, true, false, true, true, true, false, false, true, false, false, true, false, true, true, true, false, true], [true, false, true, true, true, false, true, false, true, true, true, true, false, true, false, false, false, true, false, false, true, false, true, false, true, true, true, false, true], [true, false, true, true, true, false, true, false, false, true, false, true, true, true, false, false, true, false, true, true, false, false, true, false, true, true, true, false, true], [true, false, false, false, false, false, true, false, false, true, false, false, false, false, true, true, false, false, false, false, true, false, true, false, false, false, false, false, true], [true, true, true, true, true, true, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, true, true, true, true, true, true], [false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, false, true, true, true, true, true, false, false, false, false, false, false, false, false], [false, false, false, true, true, false, true, true, false, false, false, true, false, false, false, false, true, false, false, false, false, false, false, false, false, true, true, false, false], [true, true, false, true, true, false, false, true, true, false, true, true, false, true, true, true, false, false, true, false, false, false, false, true, true, false, false, true, false], [true, true, true, false, false, true, true, true, true, false, false, true, false, true, false, true, false, true, false, true, true, true, true, true, true, true, true, false, false], [true, true, true, false, false, true, false, true, false, true, false, false, true, true, false, false, false, true, false, true, true, false, false, false, true, true, false, false, true], [false, true, true, false, false, true, true, true, true, true, true, true, true, true, false, true, true, true, true, false, true, true, true, false, false, true, false, true, false], [true, false, false, false, false, true, false, true, false, false, false, true, false, true, true, false, false, true, true, false, false, false, true, false, true, false, true, false, true], [false, true, false, false, true, true, true, true, true, true, false, true, true, false, true, true, false, true, false, true, false, false, true, true, false, true, false, false, true], [true, true, false, true, false, true, false, false, true, true, true, false, false, false, false, false, false, true, true, false, true, true, true, false, true, true, true, false, false], [false, true, false, false, false, true, true, true, false, true, true, true, true, true, true, true, true, false, true, true, true, false, false, true, false, true, false, true, true], [true, true, true, false, true, false, false, false, true, true, false, false, true, true, false, true, true, false, false, false, false, true, false, false, true, false, false, false, false], [true, true, true, false, true, true, true, false, true, false, false, true, false, true, false, false, true, true, true, true, false, false, false, true, false, true, false, false, true], [true, true, true, true, true, false, false, false, false, true, true, true, true, false, false, false, false, false, false, false, false, true, true, true, false, false, true, true, false], [true, true, false, true, true, false, true, true, true, false, false, false, false, true, false, true, false, true, false, false, true, true, true, true, true, true, true, false, true], [false, false, false, false, false, false, false, false, true, false, false, false, true, false, false, false, false, true, true, true, true, false, false, false, true, true, true, false, false], [true, true, true, true, true, true, true, false, true, false, true, false, true, true, false, false, false, false, false, true, true, false, true, false, true, false, true, false, false], [true, false, false, false, false, false, true, false, false, true, true, false, false, false, false, true, false, false, false, true, true, false, false, false, true, true, false, true, false], [true, false, true, true, true, false, true, false, true, true, true, true, false, true, false, false, false, true, false, true, true, true, true, true, true, false, false, false, false], [true, false, true, true, true, false, true, false, true, false, true, false, true, true, false, true, true, true, true, false, false, false, false, true, false, true, true, true, false], [true, false, true, true, true, false, true, false, false, true, true, true, false, true, false, true, true, true, false, false, true, true, false, true, true, false, false, true, true], [true, false, false, false, false, false, true, false, false, true, false, true, true, false, false, true, true, true, true, false, false, true, true, false, true, false, true, false, true], [true, true, true, true, true, true, true, false, false, false, true, false, true, false, true, true, false, true, true, false, true, true, true, true, true, false, false, false, false] ]; #[rustfmt::skip] const XIAOJIBA_MOD: [[Module; 29]; 29] = [ [Module(3), Module(3), Module(3), Module(3), Module(3), Module(3), Module(3), Module(14), Module(8), Module(1), Module(0), Module(1), Module(0), Module(1), Module(1), Module(1), Module(1), Module(1), Module(0), Module(1), Module(1), Module(14), Module(3), Module(3), Module(3), Module(3), Module(3), Module(3), Module(3)], [Module(3), Module(2), Module(2), Module(2), Module(2), Module(2), Module(3), Module(14), Module(8), Module(1), Module(1), Module(0), Module(1), Module(1), Module(1), Module(0), Module(1), Module(0), Module(1), Module(1), Module(0), Module(14), Module(3), Module(2), Module(2), Module(2), Module(2), Module(2), Module(3)], [Module(3), Module(2), Module(3), Module(3), Module(3), Module(2), Module(3), Module(14), Module(9), Module(1), Module(1), Module(0), Module(1), Module(0), Module(1), Module(1), Module(1), Module(0), Module(0), Module(1), Module(0), Module(14), Module(3), Module(2), Module(3), Module(3), Module(3), Module(2), Module(3)], [Module(3), Module(2), Module(3), Module(3), Module(3), Module(2), Module(3), Module(14), Module(9), Module(1), Module(1), Module(1), Module(0), Module(1), Module(0), Module(0), Module(0), Module(1), Module(0), Module(0), Module(1), Module(14), Module(3), Module(2), Module(3), Module(3), Module(3), Module(2), Module(3)], [Module(3), Module(2), Module(3), Module(3), Module(3), Module(2), Module(3), Module(14), Module(8), Module(1), Module(0), Module(1), Module(1), Module(1), Module(0), Module(0), Module(1), Module(0), Module(1), Module(1), Module(0), Module(14), Module(3), Module(2), Module(3), Module(3), Module(3), Module(2), Module(3)], [Module(3), Module(2), Module(2), Module(2), Module(2), Module(2), Module(3), Module(14), Module(8), Module(1), Module(0), Module(0), Module(0), Module(0), Module(1), Module(1), Module(0), Module(0), Module(0), Module(0), Module(1), Module(14), Module(3), Module(2), Module(2), Module(2), Module(2), Module(2), Module(3)], [Module(3), Module(3), Module(3), Module(3), Module(3), Module(3), Module(3), Module(14), Module(7), Module(6), Module(7), Module(6), Module(7), Module(6), Module(7), Module(6), Module(7), Module(6), Module(7), Module(6), Module(7), Module(14), Module(3), Module(3), Module(3), Module(3), Module(3), Module(3), Module(3)], [Module(14), Module(14), Module(14), Module(14), Module(14), Module(14), Module(14), Module(14), Module(8), Module(0), Module(0), Module(0), Module(0), Module(0), Module(1), Module(0), Module(1), Module(1), Module(1), Module(1), Module(1), Module(14), Module(14), Module(14), Module(14), Module(14), Module(14), Module(14), Module(14)], [Module(8), Module(8), Module(8), Module(9), Module(9), Module(8), Module(7), Module(9), Module(8), Module(0), Module(0), Module(1), Module(0), Module(0), Module(0), Module(0), Module(1), Module(0), Module(0), Module(0), Module(0), Module(8), Module(8), Module(8), Module(8), Module(9), Module(9), Module(8), Module(8)], [Module(1), Module(1), Module(0), Module(1), Module(1), Module(0), Module(6), Module(1), Module(1), Module(0), Module(1), Module(1), Module(0), Module(1), Module(1), Module(1), Module(0), Module(0), Module(1), Module(0), Module(0), Module(0), Module(0), Module(1), Module(1), Module(0), Module(0), Module(1), Module(0)], [Module(1), Module(1), Module(1), Module(0), Module(0), Module(1), Module(7), Module(1), Module(1), Module(0), Module(0), Module(1), Module(0), Module(1), Module(0), Module(1), Module(0), Module(1), Module(0), Module(1), Module(1), Module(1), Module(1), Module(1), Module(1), Module(1), Module(1), Module(0), Module(0)], [Module(1), Module(1), Module(1), Module(0), Module(0), Module(1), Module(6), Module(1), Module(0), Module(1), Module(0), Module(0), Module(1), Module(1), Module(0), Module(0), Module(0), Module(1), Module(0), Module(1), Module(1), Module(0), Module(0), Module(0), Module(1), Module(1), Module(0), Module(0), Module(1)], [Module(0), Module(1), Module(1), Module(0), Module(0), Module(1), Module(7), Module(1), Module(1), Module(1), Module(1), Module(1), Module(1), Module(1), Module(0), Module(1), Module(1), Module(1), Module(1), Module(0), Module(1), Module(1), Module(1), Module(0), Module(0), Module(1), Module(0), Module(1), Module(0)], [Module(1), Module(0), Module(0), Module(0), Module(0), Module(1), Module(6), Module(1), Module(0), Module(0), Module(0), Module(1), Module(0), Module(1), Module(1), Module(0), Module(0), Module(1), Module(1), Module(0), Module(0), Module(0), Module(1), Module(0), Module(1), Module(0), Module(1), Module(0), Module(1)], [Module(0), Module(1), Module(0), Module(0), Module(1), Module(1), Module(7), Module(1), Module(1), Module(1), Module(0), Module(1), Module(1), Module(0), Module(1), Module(1), Module(0), Module(1), Module(0), Module(1), Module(0), Module(0), Module(1), Module(1), Module(0), Module(1), Module(0), Module(0), Module(1)], [Module(1), Module(1), Module(0), Module(1), Module(0), Module(1), Module(6), Module(0), Module(1), Module(1), Module(1), Module(0), Module(0), Module(0), Module(0), Module(0), Module(0), Module(1), Module(1), Module(0), Module(1), Module(1), Module(1), Module(0), Module(1), Module(1), Module(1), Module(0), Module(0)], [Module(0), Module(1), Module(0), Module(0), Module(0), Module(1), Module(7), Module(1), Module(0), Module(1), Module(1), Module(1), Module(1), Module(1), Module(1), Module(1), Module(1), Module(0), Module(1), Module(1), Module(1), Module(0), Module(0), Module(1), Module(0), Module(1), Module(0), Module(1), Module(1)], [Module(1), Module(1), Module(1), Module(0), Module(1), Module(0), Module(6), Module(0), Module(1), Module(1), Module(0), Module(0), Module(1), Module(1), Module(0), Module(1), Module(1), Module(0), Module(0), Module(0), Module(0), Module(1), Module(0), Module(0), Module(1), Module(0), Module(0), Module(0), Module(0)], [Module(1), Module(1), Module(1), Module(0), Module(1), Module(1), Module(7), Module(0), Module(1), Module(0), Module(0), Module(1), Module(0), Module(1), Module(0), Module(0), Module(1), Module(1), Module(1), Module(1), Module(0), Module(0), Module(0), Module(1), Module(0), Module(1), Module(0), Module(0), Module(1)], [Module(1), Module(1), Module(1), Module(1), Module(1), Module(0), Module(6), Module(0), Module(0), Module(1), Module(1), Module(1), Module(1), Module(0), Module(0), Module(0), Module(0), Module(0), Module(0), Module(0), Module(0), Module(1), Module(1), Module(1), Module(0), Module(0), Module(1), Module(1), Module(0)], [Module(1), Module(1), Module(0), Module(1), Module(1), Module(0), Module(7), Module(1), Module(1), Module(0), Module(0), Module(0), Module(0), Module(1), Module(0), Module(1), Module(0), Module(1), Module(0), Module(0), Module(5), Module(5), Module(5), Module(5), Module(5), Module(1), Module(1), Module(0), Module(1)], [Module(14), Module(14), Module(14), Module(14), Module(14), Module(14), Module(14), Module(14), Module(13), Module(0), Module(0), Module(0), Module(1), Module(0), Module(0), Module(0), Module(0), Module(1), Module(1), Module(1), Module(5), Module(4), Module(4), Module(4), Module(5), Module(1), Module(1), Module(0), Module(0)], [Module(3), Module(3), Module(3), Module(3), Module(3), Module(3), Module(3), Module(14), Module(9), Module(0), Module(1), Module(0), Module(1), Module(1), Module(0), Module(0), Module(0), Module(0), Module(0), Module(1), Module(5), Module(4), Module(5), Module(4), Module(5), Module(0), Module(1), Module(0), Module(0)], [Module(3), Module(2), Module(2), Module(2), Module(2), Module(2), Module(3), Module(14), Module(8), Module(1), Module(1), Module(0), Module(0), Module(0), Module(0), Module(1), Module(0), Module(0), Module(0), Module(1), Module(5), Module(4), Module(4), Module(4), Module(5), Module(1), Module(0), Module(1), Module(0)], [Module(3), Module(2), Module(3), Module(3), Module(3), Module(2), Module(3), Module(14), Module(9), Module(1), Module(1), Module(1), Module(0), Module(1), Module(0), Module(0), Module(0), Module(1), Module(0), Module(1), Module(5), Module(5), Module(5), Module(5), Module(5), Module(0), Module(0), Module(0), Module(0)], [Module(3), Module(2), Module(3), Module(3), Module(3), Module(2), Module(3), Module(14), Module(9), Module(0), Module(1), Module(0), Module(1), Module(1), Module(0), Module(1), Module(1), Module(1), Module(1), Module(0), Module(0), Module(0), Module(0), Module(1), Module(0), Module(1), Module(1), Module(1), Module(0)], [Module(3), Module(2), Module(3), Module(3), Module(3), Module(2), Module(3), Module(14), Module(8), Module(1), Module(1), Module(1), Module(0), Module(1), Module(0), Module(1), Module(1), Module(1), Module(0), Module(0), Module(1), Module(1), Module(0), Module(1), Module(1), Module(0), Module(0), Module(1), Module(1)], [Module(3), Module(2), Module(2), Module(2), Module(2), Module(2), Module(3), Module(14), Module(8), Module(1), Module(0), Module(1), Module(1), Module(0), Module(0), Module(1), Module(1), Module(1), Module(1), Module(0), Module(0), Module(1), Module(1), Module(0), Module(1), Module(0), Module(1), Module(0), Module(1)], [Module(3), Module(3), Module(3), Module(3), Module(3), Module(3), Module(3), Module(14), Module(8), Module(0), Module(1), Module(0), Module(1), Module(0), Module(1), Module(1), Module(0), Module(1), Module(1), Module(0), Module(1), Module(1), Module(1), Module(1), Module(1), Module(0), Module(0), Module(0), Module(0)] ]; #[test] fn xiaojiba_dev() { let mat = create_mat_from_bool(&MAT_XIAOJIBA_DEV); let (line_score, col_score, pattern_score) = test_matrix_pattern_and_line(&mat); let dark_score = test_matrix_dark_modules(&mat); let square_score = test_matrix_score_squares(&mat); // {"patternScore":160,"lineColScore":95,"squareScore":150,"darkScore":0} assert_eq!(dark_score, 0, "dark score, expected 0"); assert_eq!(square_score, 150, "square score, expected 150"); assert_eq!(line_score + col_score, 95, "line col score, expected 95"); assert_eq!(pattern_score, 160, "pattern score, expected 160"); } #[test] fn adjacent_line() { // Data module true, false, true, true, true, false, true let line = [ DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), ]; // Data module true true true true true true true let line_2 = [ DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), ]; // Data module true true true true true false true true true true true let line_3_not_data = [ EMPT(T), DATA(T), DATA(T), DATA(T), DATA(T), EMPT(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), ]; let line_4_xiaojiba_dev = [ FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), EMPT(F), DATA(F), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), EMPT(F), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), FIND(T), ]; assert_eq!(test_score_line(&line), 5, "line score, expected 5"); assert_eq!(test_score_line(&line_2), 5, "line score, expected 5"); assert_eq!( test_score_line(&line_3_not_data), 3, "line score, expected 3" ); assert_eq!( test_score_line(&line_4_xiaojiba_dev), 3, "line score, expected 3" ); } #[test] fn line_by_line_xiaojiba() { let scores = [ 3, 0, 0, 0, 0, 0, 0, // 7 6, 0, 0, 6, 0, 5, 0, // 14 0, 4, 6, 0, 0, 9, 0, // 21 0, 3, 0, 0, 0, 0, 0, 3, ]; // total: 45 for (i, line) in XIAOJIBA_MOD.iter().enumerate() { let score = scores[i]; assert_eq!(test_score_line(line), score, "line {i}, expected {score}",); } } #[test] fn col_by_col_xiaojiba() { let mut transposed = [[EMPT(T); 29]; 29]; for i in 0..29 { for j in i..29 { transposed[j][i] = XIAOJIBA_MOD[i][j]; transposed[i][j] = XIAOJIBA_MOD[j][i]; } } let scores = [ 0, 5, 0, 3, 0, 5, 0, // 7 4, 0, 4, 3, 0, 0, 3, // 14 9, 0, 4, 7, 0, 0, 0, // 21 0, 0, 0, 0, 0, 0, 0, 3, ]; // total: 50 for (i, col) in transposed.iter().enumerate() { let score = scores[i]; assert_eq!( test_score_line(col), score, "col {i}, expected {score}\n\n{:?}", col ); } } #[test] fn pattern() { // Module data: true false true true true false true let line = [ DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), ]; assert_eq!(test_score_pattern(&line), 40, "pattern, expected 40"); // Module data: true false true true true false true (double) let line = [ DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), ]; assert_eq!(test_score_pattern(&line), 80, "pattern, expected 80"); // Module data: true false true true true false true (double using middle) let line = [ DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), ]; assert_eq!(test_score_pattern(&line), 80, "pattern, expected 80"); // Module data: true false true true true false true (double using middle) let line = [ EMPT(F), DATA(T), DATA(F), DATA(T), DATA(T), DATA(T), DATA(F), DATA(T), EMPT(F), ]; assert_eq!(test_score_pattern(&line), 40, "pattern, expected 40"); } fast_qr-0.13.1/src/tests/structure.rs000064400000000000000000000552141046102023000157130ustar 00000000000000#[test] fn structure_codewords_data() { const VERSION: crate::version::Version = crate::version::Version::V05; const QUALITY: crate::ecl::ECL = crate::ecl::ECL::Q; let data_codewords = &[ 67, 85, 70, 134, 87, 38, 85, 194, 119, 50, 6, 18, 6, 103, 38, 246, 246, 66, 7, 118, 134, 242, 7, 38, 86, 22, 198, 199, 146, 6, 182, 230, 247, 119, 50, 7, 118, 134, 87, 38, 82, 6, 134, 151, 50, 7, 70, 247, 118, 86, 194, 6, 151, 50, 16, 236, 17, 236, 17, 236, 17, 236, ] .to_vec(); let structure = crate::polynomials::structure(data_codewords, QUALITY, VERSION); let max = VERSION.max_bytes(); let message = &structure[..data_codewords.len()]; let _errors = &structure[data_codewords.len()..max]; assert_eq!( message, [ 67, 246, 182, 70, 85, 246, 230, 247, 70, 66, 247, 118, 134, 7, 119, 86, 87, 118, 50, 194, 38, 134, 7, 6, 85, 242, 118, 151, 194, 7, 134, 50, 119, 38, 87, 16, 50, 86, 38, 236, 6, 22, 82, 17, 18, 198, 6, 236, 6, 199, 134, 17, 103, 146, 151, 236, 38, 6, 50, 17, 7, 236 ] .to_vec() ); } #[test] fn structure_codewords_error() { const VERSION: crate::version::Version = crate::version::Version::V05; const QUALITY: crate::ecl::ECL = crate::ecl::ECL::Q; let data_codewords = &[ 67, 85, 70, 134, 87, 38, 85, 194, 119, 50, 6, 18, 6, 103, 38, 246, 246, 66, 7, 118, 134, 242, 7, 38, 86, 22, 198, 199, 146, 6, 182, 230, 247, 119, 50, 7, 118, 134, 87, 38, 82, 6, 134, 151, 50, 7, 70, 247, 118, 86, 194, 6, 151, 50, 16, 236, 17, 236, 17, 236, 17, 236, ] .to_vec(); let structure = crate::polynomials::structure(data_codewords, QUALITY, VERSION); let max = VERSION.max_bytes(); let _message = &structure[..data_codewords.len()]; let errors = &structure[data_codewords.len()..max]; assert_eq!( errors, [ 213, 87, 148, 235, 199, 204, 116, 159, 11, 96, 177, 5, 45, 60, 212, 173, 115, 202, 76, 24, 247, 182, 133, 147, 241, 124, 75, 59, 223, 157, 242, 33, 229, 200, 238, 106, 248, 134, 76, 40, 154, 27, 195, 255, 117, 129, 230, 172, 154, 209, 189, 82, 111, 17, 10, 2, 86, 163, 108, 131, 161, 163, 240, 32, 111, 120, 192, 178, 39, 133, 141, 236 ] .to_vec() ); } #[test] fn structure_codewords_binary_repr() { const VERSION: crate::version::Version = crate::version::Version::V05; const QUALITY: crate::ecl::ECL = crate::ecl::ECL::Q; let data_codewords = &[ 67, 85, 70, 134, 87, 38, 85, 194, 119, 50, 6, 18, 6, 103, 38, 246, 246, 66, 7, 118, 134, 242, 7, 38, 86, 22, 198, 199, 146, 6, 182, 230, 247, 119, 50, 7, 118, 134, 87, 38, 82, 6, 134, 151, 50, 7, 70, 247, 118, 86, 194, 6, 151, 50, 16, 236, 17, 236, 17, 236, 17, 236, ] .to_vec(); let structure = crate::polynomials::structure(data_codewords, QUALITY, VERSION); assert_eq!( crate::helpers::binary_to_binarystring_version(structure, VERSION) .to_string(), "01000011111101101011011001000110010101011111011011100110111101110100011001000010111101110111011010000110000001110111011101010110010101110111011000110010110000100010011010000110000001110000011001010101111100100111011010010111110000100000011110000110001100100111011100100110010101110001000000110010010101100010011011101100000001100001011001010010000100010001001011000110000001101110110000000110110001111000011000010001011001111001001010010111111011000010011000000110001100100001000100000111111011001101010101010111100101001110101111000111110011000111010010011111000010110110000010110001000001010010110100111100110101001010110101110011110010100100110000011000111101111011011010000101100100111111000101111100010010110011101111011111100111011111001000100001111001011100100011101110011010101111100010000110010011000010100010011010000110111100001111111111011101011000000111100110101011001001101011010001101111010101001001101111000100010000101000000010010101101010001101101100100000111010000110100011111100000010000001101111011110001100000010110010001001111000010110001101111011000000000"); } // {'seed': 27, 'version': 10, 'quality': 2} // Download error: START // Download error: DONE #[test] fn structure_codewords_seed_27() { const VERSION: crate::version::Version = crate::version::Version::V10; const QUALITY: crate::ecl::ECL = crate::ecl::ECL::Q; let data_codewords = &[ 245, 73, 50, 18, 16, 65, 211, 138, 85, 64, 95, 213, 208, 103, 46, 63, 232, 61, 125, 210, 18, 186, 234, 163, 146, 167, 20, 156, 214, 108, 198, 106, 189, 13, 168, 112, 254, 89, 3, 216, 249, 208, 164, 122, 64, 35, 156, 240, 86, 156, 166, 58, 180, 208, 134, 36, 25, 249, 100, 192, 77, 233, 191, 203, 238, 9, 198, 174, 135, 21, 43, 117, 181, 38, 67, 138, 13, 44, 249, 247, 166, 3, 115, 199, 38, 88, 227, 146, 147, 106, 16, 78, 112, 223, 208, 119, 90, 3, 92, 40, 200, 67, 45, 123, 91, 224, 132, 15, 132, 63, 43, 53, 195, 188, 125, 142, 23, 85, 86, 195, 14, 100, 87, 162, 29, 77, 65, 203, 142, 178, 176, 21, 76, 116, 118, 72, 131, 30, 149, 5, 232, 72, 55, 226, 197, 122, 141, 138, 229, 247, 175, 30, 0, 151, ] .to_vec(); let structure = crate::polynomials::structure(data_codewords, QUALITY, VERSION); let max = VERSION.max_bytes(); let message = &structure[..data_codewords.len()]; let errors = &structure[data_codewords.len()..max]; assert_eq!(message.len(), 154); assert_eq!( message, [ 245, 210, 3, 249, 13, 119, 125, 118, 73, 18, 216, 100, 44, 90, 142, 72, 50, 186, 249, 192, 249, 3, 23, 131, 18, 234, 208, 77, 247, 92, 85, 30, 16, 163, 164, 233, 166, 40, 86, 149, 65, 146, 122, 191, 3, 200, 195, 5, 211, 167, 64, 203, 115, 67, 14, 232, 138, 20, 35, 238, 199, 45, 100, 72, 85, 156, 156, 9, 38, 123, 87, 55, 64, 214, 240, 198, 88, 91, 162, 226, 95, 108, 86, 174, 227, 224, 29, 197, 213, 198, 156, 135, 146, 132, 77, 122, 208, 106, 166, 21, 147, 15, 65, 141, 103, 189, 58, 43, 106, 132, 203, 138, 46, 13, 180, 117, 16, 63, 142, 229, 63, 168, 208, 181, 78, 43, 178, 247, 232, 112, 134, 38, 112, 53, 176, 175, 61, 254, 36, 67, 223, 195, 21, 30, 125, 89, 25, 138, 208, 188, 76, 0, 116, 151 ] .to_vec() ); assert_eq!(errors.len(), 192); assert_eq!( errors, [ 166, 190, 42, 17, 106, 180, 81, 84, 163, 36, 57, 172, 215, 224, 161, 223, 219, 74, 147, 240, 91, 28, 14, 127, 146, 36, 211, 64, 246, 42, 17, 150, 72, 236, 225, 250, 46, 245, 30, 57, 145, 91, 172, 166, 4, 18, 21, 1, 115, 26, 163, 248, 200, 75, 149, 43, 36, 172, 251, 114, 247, 245, 85, 119, 65, 95, 108, 229, 163, 41, 159, 62, 4, 100, 234, 207, 61, 185, 126, 225, 137, 55, 142, 43, 163, 130, 26, 19, 133, 184, 50, 239, 216, 5, 188, 67, 161, 185, 184, 209, 42, 200, 9, 232, 235, 12, 210, 133, 42, 66, 50, 92, 122, 66, 109, 39, 172, 232, 203, 67, 130, 80, 218, 224, 51, 73, 23, 5, 38, 190, 0, 244, 219, 48, 78, 31, 155, 110, 20, 29, 159, 22, 254, 144, 91, 126, 156, 224, 53, 189, 98, 116, 150, 212, 94, 101, 160, 71, 84, 232, 238, 96, 0, 133, 236, 216, 45, 188, 98, 193, 90, 37, 177, 216, 181, 77, 163, 23, 61, 77, 170, 12, 90, 29, 99, 125, 186, 179, 176, 186, 0, 78 ] .to_vec() ); } // {'seed': 31, 'version': 7, 'quality': 3} // Download error: START // Download error: DONE #[test] fn structure_codewords_seed_31() { const VERSION: crate::version::Version = crate::version::Version::V07; const QUALITY: crate::ecl::ECL = crate::ecl::ECL::H; let data_codewords = &[ 28, 195, 100, 36, 175, 11, 35, 243, 28, 137, 59, 182, 193, 35, 37, 251, 189, 8, 169, 15, 34, 59, 137, 187, 114, 134, 105, 52, 151, 23, 30, 5, 197, 240, 227, 103, 87, 50, 52, 84, 100, 93, 152, 244, 63, 53, 185, 55, 106, 149, 169, 140, 15, 244, 13, 214, 46, 91, 34, 52, 37, 214, 203, 253, 96, 7, ] .to_vec(); let structure = crate::polynomials::structure(data_codewords, QUALITY, VERSION); let max = VERSION.max_bytes(); let message = &structure[..data_codewords.len()]; let errors = &structure[data_codewords.len()..max]; assert_eq!(message.len(), 66); assert_eq!( message, [ 28, 35, 105, 84, 15, 195, 37, 52, 100, 244, 100, 251, 151, 93, 13, 36, 189, 23, 152, 214, 175, 8, 30, 244, 46, 11, 169, 5, 63, 91, 35, 15, 197, 53, 34, 243, 34, 240, 185, 52, 28, 59, 227, 55, 37, 137, 137, 103, 106, 214, 59, 187, 87, 149, 203, 182, 114, 50, 169, 253, 193, 134, 52, 140, 96, 7 ] .to_vec() ); assert_eq!(errors.len(), 130); assert_eq!( errors, [ 68, 246, 227, 150, 102, 150, 74, 149, 57, 126, 68, 169, 27, 171, 43, 205, 24, 71, 98, 193, 197, 210, 26, 1, 226, 78, 247, 175, 253, 205, 104, 165, 128, 9, 230, 100, 59, 66, 53, 21, 177, 102, 125, 48, 138, 0, 186, 249, 53, 115, 185, 144, 124, 103, 110, 7, 234, 168, 164, 76, 178, 202, 73, 222, 151, 106, 247, 42, 174, 81, 110, 84, 254, 204, 3, 170, 191, 173, 38, 202, 101, 166, 130, 46, 90, 222, 28, 25, 48, 33, 45, 140, 166, 16, 17, 74, 190, 194, 221, 95, 31, 219, 84, 191, 132, 75, 81, 128, 212, 153, 3, 72, 200, 114, 178, 126, 34, 40, 38, 11, 216, 159, 177, 42, 114, 208, 0, 97, 99, 248 ] .to_vec() ); } // {'seed': 51, 'version': 16, 'quality': 1} // Download error: START // Download error: DONE #[test] fn structure_codewords_seed_51() { const VERSION: crate::version::Version = crate::version::Version::V16; const QUALITY: crate::ecl::ECL = crate::ecl::ECL::M; let data_codewords = &[ 62, 210, 254, 59, 213, 141, 65, 237, 222, 101, 140, 247, 118, 187, 178, 140, 134, 161, 87, 150, 169, 92, 99, 71, 103, 178, 251, 1, 218, 29, 7, 137, 66, 8, 122, 173, 208, 241, 45, 88, 157, 76, 94, 114, 201, 203, 237, 219, 195, 166, 49, 195, 194, 7, 112, 244, 214, 43, 120, 3, 232, 15, 252, 27, 210, 201, 211, 188, 209, 202, 151, 27, 44, 140, 252, 242, 118, 238, 4, 174, 111, 238, 106, 233, 51, 250, 245, 94, 28, 124, 231, 248, 140, 199, 45, 150, 91, 253, 115, 126, 30, 132, 195, 112, 166, 2, 251, 111, 212, 138, 201, 10, 121, 238, 131, 164, 217, 138, 25, 134, 207, 208, 78, 236, 136, 212, 117, 214, 175, 7, 83, 107, 135, 22, 225, 149, 220, 148, 104, 143, 229, 219, 71, 57, 231, 186, 120, 150, 123, 54, 207, 250, 138, 13, 82, 119, 78, 137, 170, 152, 113, 251, 51, 141, 90, 226, 182, 75, 64, 123, 199, 37, 140, 163, 226, 108, 226, 200, 45, 28, 76, 118, 224, 245, 188, 2, 171, 169, 40, 173, 107, 185, 19, 142, 129, 128, 192, 245, 242, 72, 148, 180, 151, 171, 112, 186, 114, 122, 97, 4, 163, 198, 176, 71, 35, 200, 175, 252, 249, 198, 102, 103, 231, 219, 163, 98, 81, 81, 102, 146, 252, 167, 249, 175, 84, 141, 117, 104, 130, 190, 151, 83, 122, 155, 31, 1, 240, 33, 100, 222, 242, 55, 206, 105, 66, 13, 100, 195, 143, 84, 210, 12, 135, 70, 8, 238, 82, 193, 237, 0, 74, 244, 115, 18, 153, 123, 186, 136, 225, 200, 141, 36, 89, 211, 232, 70, 20, 188, 124, 237, 128, 151, 214, 0, 61, 170, 197, 111, 47, 186, 205, 200, 230, 27, 225, 145, 240, 164, 185, 237, 2, 157, 135, 157, 186, 196, 212, 40, 253, 220, 197, 148, 122, 162, 34, 39, 210, 133, 137, 104, 106, 52, 125, 240, 13, 216, 117, 117, 103, 19, 141, 251, 11, 30, 75, 129, 19, 144, 49, 218, 37, 167, 16, 154, 216, 131, 51, 250, 194, 209, 112, 91, 57, 203, 206, 242, 214, 124, 59, 21, 171, 17, 123, 247, 139, 53, 43, 205, 98, 49, 140, 57, 28, 41, 229, 208, 143, 23, 217, 120, 187, 207, 120, 134, 4, 2, 48, 4, 84, 212, 238, 76, 76, 21, 41, 134, 221, 200, 186, 77, 24, 34, 2, 47, 15, 121, 186, 199, 83, 21, 24, 194, 219, 174, 204, 142, 189, 98, 73, 8, 162, 129, 211, 105, 83, 173, 150, 15, 113, 42, 11, 4, 77, 124, 83, 15, 181, 136, 10, 111, 163, 84, 227, ] .to_vec(); let structure = crate::polynomials::structure(data_codewords, QUALITY, VERSION); let max = VERSION.max_bytes(); let message = &structure[..data_codewords.len()]; let errors = &structure[data_codewords.len()..max]; assert_eq!(message.len(), 453); assert_eq!( message, [ 62, 203, 231, 149, 76, 98, 74, 196, 91, 200, 210, 237, 248, 220, 118, 81, 244, 212, 57, 186, 254, 219, 140, 148, 224, 81, 115, 40, 203, 77, 59, 195, 199, 104, 245, 102, 18, 253, 206, 24, 213, 166, 45, 143, 188, 146, 153, 220, 242, 34, 141, 49, 150, 229, 2, 252, 123, 197, 214, 2, 65, 195, 91, 219, 171, 167, 186, 148, 124, 47, 237, 194, 253, 71, 169, 249, 136, 122, 59, 15, 222, 7, 115, 57, 40, 175, 225, 162, 21, 121, 101, 112, 126, 231, 173, 84, 200, 34, 171, 186, 140, 244, 30, 186, 107, 141, 141, 39, 17, 199, 247, 214, 132, 120, 185, 117, 36, 210, 123, 83, 118, 43, 195, 150, 19, 104, 89, 133, 247, 21, 187, 120, 112, 123, 142, 130, 211, 137, 139, 24, 178, 3, 166, 54, 129, 190, 232, 104, 53, 194, 140, 232, 2, 207, 128, 151, 70, 106, 43, 219, 134, 15, 251, 250, 192, 83, 20, 52, 205, 174, 161, 252, 111, 138, 245, 122, 188, 125, 98, 204, 87, 27, 212, 13, 242, 155, 124, 240, 49, 142, 150, 210, 138, 82, 72, 31, 237, 13, 140, 189, 169, 201, 201, 119, 148, 1, 128, 216, 57, 98, 92, 211, 10, 78, 180, 240, 151, 117, 28, 73, 99, 188, 121, 137, 151, 33, 214, 117, 41, 8, 71, 209, 238, 170, 171, 100, 0, 103, 229, 162, 103, 202, 131, 152, 112, 222, 61, 19, 208, 129, 178, 151, 164, 113, 186, 242, 170, 141, 143, 211, 251, 27, 217, 251, 114, 55, 197, 251, 23, 105, 1, 44, 138, 51, 122, 206, 111, 11, 217, 83, 218, 140, 25, 141, 97, 105, 47, 30, 120, 173, 29, 252, 134, 90, 4, 66, 186, 75, 187, 150, 7, 242, 207, 226, 163, 13, 205, 129, 207, 15, 137, 118, 208, 182, 198, 100, 200, 19, 120, 113, 66, 238, 78, 75, 176, 195, 230, 144, 134, 42, 8, 4, 236, 64, 71, 143, 27, 49, 4, 11, 122, 174, 136, 123, 35, 84, 225, 218, 2, 4, 173, 111, 212, 199, 200, 210, 145, 37, 48, 77, 208, 238, 117, 37, 175, 12, 240, 167, 4, 124, 241, 106, 214, 140, 252, 135, 164, 16, 84, 83, 45, 233, 175, 163, 249, 70, 185, 154, 212, 15, 88, 51, 7, 226, 198, 8, 237, 216, 238, 181, 157, 250, 83, 108, 102, 238, 2, 131, 76, 136, 76, 245, 107, 226, 103, 82, 157, 51, 76, 10, 94, 94, 135, 200, 231, 193, 135, 250, 21, 111, 114, 28, 22, 45, 219, 237, 157, 194, 41, 163, 201, 124, 225, 28, 163, 0, 186, 209, 134, 84, 112, 221, 227 ] .to_vec() ); assert_eq!(errors.len(), 280); assert_eq!( errors, [ 206, 181, 144, 198, 59, 152, 23, 133, 246, 151, 191, 8, 145, 23, 61, 92, 8, 228, 14, 72, 189, 36, 100, 176, 95, 7, 206, 184, 41, 5, 112, 9, 117, 6, 179, 114, 5, 161, 87, 152, 114, 5, 234, 189, 154, 165, 20, 24, 47, 35, 106, 44, 128, 95, 202, 101, 65, 70, 153, 118, 117, 34, 83, 37, 251, 34, 1, 203, 237, 210, 25, 19, 112, 195, 219, 199, 176, 136, 116, 227, 225, 82, 61, 70, 60, 91, 50, 175, 243, 220, 50, 162, 5, 182, 68, 198, 68, 242, 148, 52, 141, 251, 171, 9, 9, 150, 184, 252, 140, 122, 237, 79, 154, 132, 35, 250, 33, 14, 36, 35, 37, 177, 245, 185, 198, 8, 213, 7, 23, 97, 90, 159, 19, 103, 48, 69, 179, 199, 162, 135, 10, 24, 69, 157, 250, 54, 29, 173, 170, 65, 182, 211, 70, 141, 240, 92, 222, 167, 107, 183, 7, 176, 25, 40, 162, 122, 104, 143, 214, 21, 93, 38, 205, 74, 169, 120, 33, 9, 118, 158, 136, 186, 204, 130, 11, 182, 204, 126, 220, 90, 244, 123, 21, 127, 246, 37, 7, 169, 23, 202, 177, 154, 33, 149, 141, 164, 8, 195, 221, 111, 134, 167, 222, 171, 96, 225, 225, 78, 235, 229, 103, 185, 150, 145, 40, 80, 59, 218, 32, 110, 47, 199, 79, 10, 244, 204, 252, 88, 42, 107, 244, 231, 11, 81, 227, 203, 189, 182, 125, 108, 109, 209, 44, 162, 19, 94, 13, 196, 17, 152, 235, 20, 154, 34, 106, 197, 0, 230, 183, 244, 209, 205, 61, 207, 142, 191, 42, 163, 143, 142 ] .to_vec() ); } // {'seed': 57, 'version': 3, 'quality': 2} // Download error: START // Download error: DONE #[test] fn structure_codewords_seed_57() { const VERSION: crate::version::Version = crate::version::Version::V03; const QUALITY: crate::ecl::ECL = crate::ecl::ECL::Q; let data_codewords = &[ 150, 154, 4, 57, 131, 82, 250, 122, 74, 251, 249, 111, 162, 213, 226, 96, 5, 221, 188, 42, 132, 233, 154, 95, 96, 101, 250, 27, 167, 225, 185, 149, 174, 124, ] .to_vec(); let structure = crate::polynomials::structure(data_codewords, QUALITY, VERSION); let max = VERSION.max_bytes(); let message = &structure[..data_codewords.len()]; let errors = &structure[data_codewords.len()..max]; assert_eq!(message.len(), 34); assert_eq!( message, [ 150, 221, 154, 188, 4, 42, 57, 132, 131, 233, 82, 154, 250, 95, 122, 96, 74, 101, 251, 250, 249, 27, 111, 167, 162, 225, 213, 185, 226, 149, 96, 174, 5, 124 ] .to_vec() ); assert_eq!(errors.len(), 36); assert_eq!( errors, [ 206, 0, 168, 196, 17, 49, 126, 61, 120, 99, 183, 113, 218, 138, 137, 196, 118, 150, 204, 134, 53, 174, 77, 202, 129, 112, 167, 38, 240, 12, 36, 137, 50, 29, 32, 145 ] .to_vec() ); } #[test] fn placement() { let version = crate::version::Version::V02; let max_bytes = version.max_bytes(); let mut compact = crate::compact::CompactQR::with_len(max_bytes * 8 + version.missing_bits()); for i in 0..max_bytes { compact.push_u8((i * 11) as u8); } let mut mat = crate::default::create_matrix(version); crate::placement::test_place_on_matrix_data(&mut mat, &compact); let mut results = Vec::new(); for i in 0..44 { let tmp = (i * 11) as u8; results.push((tmp >> 7 & 1) != 0); results.push((tmp >> 6 & 1) != 0); results.push((tmp >> 5 & 1) != 0); results.push((tmp >> 4 & 1) != 0); results.push((tmp >> 3 & 1) != 0); results.push((tmp >> 2 & 1) != 0); results.push((tmp >> 1 & 1) != 0); results.push((tmp & 1) != 0); } // Manual testing { let mut start = 0; for i in 0..16 { assert_eq!(results[start + i * 2], mat[24 - i][24].value()); assert_eq!(results[start + i * 2 + 1], mat[24 - i][23].value()); } start += 16 * 2; for i in 0..16 { assert_eq!(results[start + i * 2], mat[9 + i][22].value()); assert_eq!(results[start + i * 2 + 1], mat[9 + i][21].value()); } start += 16 * 2; for i in 0..4 { assert_eq!(results[start + i * 2], mat[24 - i][20].value()); assert_eq!(results[start + i * 2 + 1], mat[24 - i][19].value()); } start += 4 * 2; for i in 0..7 { assert_eq!(results[start + i * 2], mat[24 - 9 - i][20].value()); assert_eq!(results[start + i * 2 + 1], mat[24 - 9 - i][19].value()); } start += 7 * 2; for i in 0..7 { assert_eq!(results[start + i * 2], mat[9 + i][18].value()); assert_eq!(results[start + i * 2 + 1], mat[9 + i][17].value()); } start += 7 * 2; for i in 0..4 { assert_eq!(results[start + i * 2], mat[21 + i][18].value()); assert_eq!(results[start + i * 2 + 1], mat[21 + i][17].value()); } start += 4 * 2; for i in 0..4 { assert_eq!(results[start + i * 2], mat[24 - i][16].value()); assert_eq!(results[start + i * 2 + 1], mat[24 - i][15].value()); } start += 4 * 2; for i in 0..5 { assert_eq!(results[start + i], mat[20 - i][15].value()); } start += 5; for i in 0..9 { assert_eq!(results[start + i * 2], mat[15 - i][16].value()); assert_eq!(results[start + i * 2 + 1], mat[15 - i][15].value()); } start += 9 * 2; for i in 0..6 { assert_eq!(results[start + i * 2], mat[5 - i][16].value()); assert_eq!(results[start + i * 2 + 1], mat[5 - i][15].value()); } start += 6 * 2; for i in 0..6 { assert_eq!(results[start + i * 2], mat[i][14].value()); assert_eq!(results[start + i * 2 + 1], mat[i][13].value()); } start += 6 * 2; for i in 0..18 { assert_eq!(results[start + i * 2], mat[7 + i][14].value()); assert_eq!(results[start + i * 2 + 1], mat[7 + i][13].value()); } start += 18 * 2; for i in 0..18 { assert_eq!(results[start + i * 2], mat[24 - i][12].value()); assert_eq!(results[start + i * 2 + 1], mat[24 - i][11].value()); } start += 18 * 2; for i in 0..6 { assert_eq!(results[start + i * 2], mat[5 - i][12].value()); assert_eq!(results[start + i * 2 + 1], mat[5 - i][11].value()); } start += 6 * 2; for i in 0..6 { assert_eq!(results[start + i * 2], mat[i][10].value()); assert_eq!(results[start + i * 2 + 1], mat[i][9].value()); } start += 6 * 2; for i in 0..18 { assert_eq!(results[start + i * 2], mat[7 + i][10].value()); assert_eq!(results[start + i * 2 + 1], mat[7 + i][9].value()); } start += 18 * 2; for i in 0..8 { assert_eq!(results[start + i * 2], mat[16 - i][8].value()); assert_eq!(results[start + i * 2 + 1], mat[16 - i][7].value()); } start += 8 * 2; for i in 0..8 { assert_eq!(results[start + i * 2], mat[9 + i][5].value()); assert_eq!(results[start + i * 2 + 1], mat[9 + i][4].value()); } start += 8 * 2; for i in 0..8 { assert_eq!(results[start + i * 2], mat[16 - i][3].value()); assert_eq!(results[start + i * 2 + 1], mat[16 - i][2].value()); } start += 8 * 2; for i in 0..4 { assert_eq!(results[start + i * 2], mat[9 + i][1].value()); assert_eq!(results[start + i * 2 + 1], mat[9 + i][0].value()); } assert_eq!(results[results.len() - 1], mat[13][1].value()); assert_eq!(false, mat[14][0].value()); assert_eq!(false, mat[14][1].value()); assert_eq!(false, mat[15][0].value()); assert_eq!(false, mat[15][1].value()); assert_eq!(false, mat[16][0].value()); assert_eq!(false, mat[16][1].value()); } } fast_qr-0.13.1/src/tests/svg.rs000064400000000000000000000026731046102023000144530ustar 00000000000000#[cfg(feature = "svg")] #[test] fn it_embeds_an_image_via_data_uri() { use crate::convert::svg::SvgBuilder; use crate::convert::Builder; use crate::{QRBuilder, ECL}; let image_base64 = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAAFUlEQVR4AWP4oyVDEhrGGkY1jGoAABACQhA+7XDPAAAAAElFTkSuQmCC"; let data_uri = format!("data:image/png;base64,{image_base64}"); let qrcode = QRBuilder::new("https://example.com/") .ecl(ECL::H) .build() .unwrap(); let svg = SvgBuilder::default() .image(data_uri.clone()) .to_str(&qrcode); let expected_href = format!(r#"href="{data_uri}""#); assert!(svg.contains(&expected_href)); } #[cfg(feature = "svg")] #[test] fn check_svg_is_not_inverted() { use crate::convert::svg::SvgBuilder; use crate::convert::Builder; use crate::{QRBuilder, Version, ECL}; let qrcode = QRBuilder::new("Test") .ecl(ECL::M) .version(Version::V01) .build() .unwrap(); const MARGIN: usize = 4; let svg = SvgBuilder::default().margin(MARGIN).to_str(&qrcode); let size = qrcode.size; for y in 0..size { for x in 0..size { let index = y * size + x; let expected = qrcode.data[index]; if expected.value() { let expected = format!(r#"M{x},{y}"#, x = x + MARGIN, y = y + MARGIN); assert!(svg.contains(&expected)); } } } } fast_qr-0.13.1/src/tests/version.rs000064400000000000000000003765461046102023000153560ustar 00000000000000use crate::{Mask, QRCode}; #[test] fn version_format_l_mask0() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Checkerboard); const VERSION: Option = Some(crate::version::Version::V05); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, true, false, true, true, true, true, true, false, false, false, true, false, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_l_mask1() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::HorizontalLines); const VERSION: Option = Some(crate::version::Version::V03); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, true, false, false, true, false, true, true, true, true, false, false, true, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_l_mask2() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::VerticalLines); const VERSION: Option = Some(crate::version::Version::V06); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, true, true, true, false, true, true, false, true, false, true, false, true, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_l_mask3() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::DiagonalLines); const VERSION: Option = Some(crate::version::Version::V03); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, true, true, false, false, false, true, false, false, true, true, true, false, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_l_mask4() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::LargeCheckerboard); const VERSION: Option = Some(crate::version::Version::V06); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, false, false, true, true, false, false, false, true, false, true, true, true, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_l_mask5() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Fields); const VERSION: Option = Some(crate::version::Version::V06); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, false, false, false, true, true, false, false, false, true, true, false, false, false, ]; { let l = mat.size; #[rustfmt::skip] #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_l_mask6() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Diamonds); const VERSION: Option = Some(crate::version::Version::V06); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, false, true, true, false, false, false, true, false, false, false, false, false, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_l_mask7() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Meadow); const VERSION: Option = Some(crate::version::Version::V05); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, false, true, false, false, true, false, true, true, true, false, true, true, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_m_mask0() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Checkerboard); const VERSION: Option = Some(crate::version::Version::V01); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, true, false, true, false, false, false, false, false, true, false, false, true, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_m_mask1() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::HorizontalLines); const VERSION: Option = Some(crate::version::Version::V04); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, true, false, false, false, true, false, false, true, false, false, true, false, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_m_mask2() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::VerticalLines); const VERSION: Option = Some(crate::version::Version::V02); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, true, true, true, true, false, false, true, true, true, true, true, false, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_m_mask3() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::DiagonalLines); const VERSION: Option = Some(crate::version::Version::V06); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, true, true, false, true, true, false, true, false, false, true, false, true, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_m_mask4() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::LargeCheckerboard); const VERSION: Option = Some(crate::version::Version::V01); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, false, false, true, false, true, true, true, true, true, true, false, false, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_m_mask5() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Fields); const VERSION: Option = Some(crate::version::Version::V02); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, false, false, false, false, false, true, true, false, false, true, true, true, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_m_mask6() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Diamonds); const VERSION: Option = Some(crate::version::Version::V01); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, false, true, true, true, true, true, false, false, true, false, true, true, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_m_mask7() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Meadow); const VERSION: Option = Some(crate::version::Version::V03); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, false, true, false, true, false, true, false, true, false, false, false, false, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_q_mask0() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Checkerboard); const VERSION: Option = Some(crate::version::Version::V04); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, true, false, true, false, true, false, true, false, true, true, true, true, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_q_mask1() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::HorizontalLines); const VERSION: Option = Some(crate::version::Version::V02); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, true, false, false, false, false, false, true, true, false, true, false, false, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_q_mask2() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::VerticalLines); const VERSION: Option = Some(crate::version::Version::V04); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, true, true, true, true, true, false, false, true, true, false, false, false, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_q_mask3() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::DiagonalLines); const VERSION: Option = Some(crate::version::Version::V05); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, true, true, false, true, false, false, false, false, false, false, true, true, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_q_mask4() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::LargeCheckerboard); const VERSION: Option = Some(crate::version::Version::V01); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, false, false, true, false, false, true, false, true, true, false, true, false, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_q_mask5() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Fields); const VERSION: Option = Some(crate::version::Version::V05); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, false, false, false, false, true, true, false, false, false, false, false, true, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_q_mask6() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Diamonds); const VERSION: Option = Some(crate::version::Version::V02); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, false, true, true, true, false, true, true, false, true, true, false, true, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_q_mask7() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Meadow); const VERSION: Option = Some(crate::version::Version::V01); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, false, true, false, true, true, true, true, true, false, true, true, false, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_h_mask0() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Checkerboard); const VERSION: Option = Some(crate::version::Version::V06); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, true, false, true, true, false, true, false, false, false, true, false, false, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_h_mask1() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::HorizontalLines); const VERSION: Option = Some(crate::version::Version::V02); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, true, false, false, true, true, true, false, true, true, true, true, true, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_h_mask2() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::VerticalLines); const VERSION: Option = Some(crate::version::Version::V04); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, true, true, true, false, false, true, true, true, false, false, true, true, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_h_mask3() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::DiagonalLines); const VERSION: Option = Some(crate::version::Version::V03); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, true, true, false, false, true, true, true, false, true, false, false, false, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_h_mask4() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::LargeCheckerboard); const VERSION: Option = Some(crate::version::Version::V02); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, false, false, true, true, true, false, true, true, false, false, false, true, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_h_mask5() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Fields); const VERSION: Option = Some(crate::version::Version::V04); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, false, false, false, true, false, false, true, false, true, false, true, false, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_h_mask6() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Diamonds); const VERSION: Option = Some(crate::version::Version::V02); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, false, true, true, false, true, false, false, false, false, true, true, false, false, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_h_mask7() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Meadow); const VERSION: Option = Some(crate::version::Version::V01); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, false, true, false, false, false, false, false, true, true, true, false, true, true, ]; { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); } } #[test] fn version_format_l_mask0_version23() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Checkerboard); const VERSION: Option = Some(crate::version::Version::V23); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, true, false, true, true, true, true, true, false, false, false, true, false, false, ]; let mut expected2: [bool; 18] = [ false, true, false, true, true, true, false, true, true, true, true, true, true, false, true, true, false, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_l_mask1_version29() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::HorizontalLines); const VERSION: Option = Some(crate::version::Version::V29); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, true, false, false, true, false, true, true, true, true, false, false, true, true, ]; let mut expected2: [bool; 18] = [ false, true, true, true, false, true, false, false, true, true, false, false, true, true, true, true, true, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_l_mask2_version40() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::VerticalLines); const VERSION: Option = Some(crate::version::Version::V40); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, true, true, true, false, true, true, false, true, false, true, false, true, false, ]; let mut expected2: [bool; 18] = [ true, false, true, false, false, false, true, true, false, false, false, true, true, false, true, false, false, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_l_mask3_version8() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::DiagonalLines); const VERSION: Option = Some(crate::version::Version::V08); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, true, true, false, false, false, true, false, false, true, true, true, false, true, ]; let mut expected2: [bool; 18] = [ false, false, true, false, false, false, false, true, false, true, true, false, true, true, true, true, false, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_l_mask4_version36() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::LargeCheckerboard); const VERSION: Option = Some(crate::version::Version::V36); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, false, false, true, true, false, false, false, true, false, true, true, true, true, ]; let mut expected2: [bool; 18] = [ true, false, false, true, false, false, true, false, true, true, false, false, false, false, true, false, true, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_l_mask5_version22() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Fields); const VERSION: Option = Some(crate::version::Version::V22); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, false, false, false, true, true, false, false, false, true, true, false, false, false, ]; let mut expected2: [bool; 18] = [ false, true, false, true, true, false, true, false, false, false, true, true, false, false, true, false, false, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_l_mask6_version10() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Diamonds); const VERSION: Option = Some(crate::version::Version::V10); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, false, true, true, false, false, false, true, false, false, false, false, false, true, ]; let mut expected2: [bool; 18] = [ false, false, true, false, true, false, false, true, false, false, true, true, false, true, false, false, true, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_l_mask7_version17() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Meadow); const VERSION: Option = Some(crate::version::Version::V17); const LEVEL: Option = Some(crate::ecl::ECL::L); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, true, false, true, false, false, true, false, true, true, true, false, true, true, false, ]; let mut expected2: [bool; 18] = [ false, true, false, false, false, true, false, true, false, false, false, true, false, true, true, true, false, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_m_mask0_version14() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Checkerboard); const VERSION: Option = Some(crate::version::Version::V14); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, true, false, true, false, false, false, false, false, true, false, false, true, false, ]; let mut expected2: [bool; 18] = [ false, false, true, true, true, false, false, true, true, false, false, false, false, false, true, true, false, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_m_mask1_version30() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::HorizontalLines); const VERSION: Option = Some(crate::version::Version::V30); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, true, false, false, false, true, false, false, true, false, false, true, false, true, ]; let mut expected2: [bool; 18] = [ false, true, true, true, true, false, true, true, false, true, false, true, true, true, false, true, false, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_m_mask2_version37() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::VerticalLines); const VERSION: Option = Some(crate::version::Version::V37); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, true, true, true, true, false, false, true, true, true, true, true, false, false, ]; let mut expected2: [bool; 18] = [ true, false, false, true, false, true, false, true, false, false, false, false, true, false, true, true, true, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_m_mask3_version22() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::DiagonalLines); const VERSION: Option = Some(crate::version::Version::V22); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, true, true, false, true, true, false, true, false, false, true, false, true, true, ]; let mut expected2: [bool; 18] = [ false, true, false, true, true, false, true, false, false, false, true, true, false, false, true, false, false, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_m_mask4_version31() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::LargeCheckerboard); const VERSION: Option = Some(crate::version::Version::V31); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, false, false, true, false, true, true, true, true, true, true, false, false, true, ]; let mut expected2: [bool; 18] = [ false, true, true, true, true, true, false, false, true, false, false, true, false, true, false, false, false, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_m_mask5_version13() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Fields); const VERSION: Option = Some(crate::version::Version::V13); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, false, false, false, false, false, true, true, false, false, true, true, true, false, ]; let mut expected2: [bool; 18] = [ false, false, true, true, false, true, true, false, false, false, false, true, false, false, false, true, true, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_m_mask6_version22() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Diamonds); const VERSION: Option = Some(crate::version::Version::V22); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, false, true, true, true, true, true, false, false, true, false, true, true, true, ]; let mut expected2: [bool; 18] = [ false, true, false, true, true, false, true, false, false, false, true, true, false, false, true, false, false, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_m_mask7_version7() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Meadow); const VERSION: Option = Some(crate::version::Version::V07); const LEVEL: Option = Some(crate::ecl::ECL::M); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ true, false, false, true, false, true, false, true, false, true, false, false, false, false, false, ]; let mut expected2: [bool; 18] = [ false, false, false, true, true, true, true, true, false, false, true, false, false, true, false, true, false, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_q_mask0_version20() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Checkerboard); const VERSION: Option = Some(crate::version::Version::V20); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, true, false, true, false, true, false, true, false, true, true, true, true, true, ]; let mut expected2: [bool; 18] = [ false, true, false, true, false, false, true, false, false, true, true, false, true, false, false, true, true, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_q_mask1_version33() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::HorizontalLines); const VERSION: Option = Some(crate::version::Version::V33); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, true, false, false, false, false, false, true, true, false, true, false, false, false, ]; let mut expected2: [bool; 18] = [ true, false, false, false, false, true, false, true, true, false, true, true, true, true, false, false, false, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_q_mask2_version24() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::VerticalLines); const VERSION: Option = Some(crate::version::Version::V24); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, true, true, true, true, true, false, false, true, true, false, false, false, true, ]; let mut expected2: [bool; 18] = [ false, true, true, false, false, false, true, true, true, false, true, true, false, false, false, true, false, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_q_mask3_version18() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::DiagonalLines); const VERSION: Option = Some(crate::version::Version::V18); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, true, true, false, true, false, false, false, false, false, false, true, true, false, ]; let mut expected2: [bool; 18] = [ false, true, false, false, true, false, true, false, true, false, false, false, false, true, false, true, true, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_q_mask4_version31() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::LargeCheckerboard); const VERSION: Option = Some(crate::version::Version::V31); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, false, false, true, false, false, true, false, true, true, false, true, false, false, ]; let mut expected2: [bool; 18] = [ false, true, true, true, true, true, false, false, true, false, false, true, false, true, false, false, false, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_q_mask5_version17() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Fields); const VERSION: Option = Some(crate::version::Version::V17); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, false, false, false, false, true, true, false, false, false, false, false, true, true, ]; let mut expected2: [bool; 18] = [ false, true, false, false, false, true, false, true, false, false, false, true, false, true, true, true, false, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_q_mask6_version11() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Diamonds); const VERSION: Option = Some(crate::version::Version::V11); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, false, true, true, true, false, true, true, false, true, true, false, true, false, ]; let mut expected2: [bool; 18] = [ false, false, true, false, true, true, true, false, true, true, true, true, true, true, false, true, true, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_q_mask7_version15() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Meadow); const VERSION: Option = Some(crate::version::Version::V15); const LEVEL: Option = Some(crate::ecl::ECL::Q); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, true, false, true, false, true, true, true, true, true, false, true, true, false, true, ]; let mut expected2: [bool; 18] = [ false, false, true, true, true, true, true, false, false, true, false, false, true, false, true, false, false, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_h_mask0_version35() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Checkerboard); const VERSION: Option = Some(crate::version::Version::V35); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, true, false, true, true, false, true, false, false, false, true, false, false, true, ]; let mut expected2: [bool; 18] = [ true, false, false, false, true, true, false, true, true, true, true, false, false, true, true, true, true, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_h_mask1_version15() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::HorizontalLines); const VERSION: Option = Some(crate::version::Version::V15); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, true, false, false, true, true, true, false, true, true, true, true, true, false, ]; let mut expected2: [bool; 18] = [ false, false, true, true, true, true, true, false, false, true, false, false, true, false, true, false, false, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_h_mask2_version15() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::VerticalLines); const VERSION: Option = Some(crate::version::Version::V15); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, true, true, true, false, false, true, true, true, false, false, true, true, true, ]; let mut expected2: [bool; 18] = [ false, false, true, true, true, true, true, false, false, true, false, false, true, false, true, false, false, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_h_mask3_version7() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::DiagonalLines); const VERSION: Option = Some(crate::version::Version::V07); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, true, true, false, false, true, true, true, false, true, false, false, false, false, ]; let mut expected2: [bool; 18] = [ false, false, false, true, true, true, true, true, false, false, true, false, false, true, false, true, false, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_h_mask4_version7() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::LargeCheckerboard); const VERSION: Option = Some(crate::version::Version::V07); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, false, false, true, true, true, false, true, true, false, false, false, true, false, ]; let mut expected2: [bool; 18] = [ false, false, false, true, true, true, true, true, false, false, true, false, false, true, false, true, false, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_h_mask5_version20() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Fields); const VERSION: Option = Some(crate::version::Version::V20); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, false, false, false, true, false, false, true, false, true, false, true, false, true, ]; let mut expected2: [bool; 18] = [ false, true, false, true, false, false, true, false, false, true, true, false, true, false, false, true, true, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_h_mask6_version20() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Diamonds); const VERSION: Option = Some(crate::version::Version::V20); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, false, true, true, false, true, false, false, false, false, true, true, false, false, ]; let mut expected2: [bool; 18] = [ false, true, false, true, false, false, true, false, false, true, true, false, true, false, false, true, true, false, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } #[test] fn version_format_h_mask7_version17() { const CONTENT: &str = "4"; const MASK: Option = Some(Mask::Meadow); const VERSION: Option = Some(crate::version::Version::V17); const LEVEL: Option = Some(crate::ecl::ECL::H); let q = QRCode::new(CONTENT.as_bytes(), LEVEL, VERSION, None, MASK); if q.is_err() { assert_eq!(true, false, "Couldn't create QR"); }; let mat = q.unwrap(); const EXPECTED: [bool; 15] = [ false, false, false, true, false, false, false, false, false, true, true, true, false, true, true, ]; let mut expected2: [bool; 18] = [ false, true, false, false, false, true, false, true, false, false, false, true, false, true, true, true, false, true, ]; expected2.reverse(); { let l = mat.size; #[rustfmt::skip] let tmp = [ mat[l - 1][8], mat[l - 2][8], mat[l - 3][8], mat[l - 4][8], mat[l - 5][8], mat[l - 6][8], mat[l - 7][8], mat[8][l - 8], mat[8][l - 7], mat[8][l - 6], mat[8][l - 5], mat[8][l - 4], mat[8][l - 3], mat[8][l - 2], mat[8][l - 1] ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); #[rustfmt::skip] let tmp = [ mat[8][0], mat[8][1], mat[8][2], mat[8][3], mat[8][4], mat[8][5], mat[8][7], mat[8][8], mat[7][8], mat[5][8], mat[4][8], mat[3][8], mat[2][8], mat[1][8], mat[0][8], ]; assert_eq!(tmp.map(|x| x.value()), EXPECTED); let tmp2 = [ mat[l - 11][0], mat[l - 10][0], mat[l - 9][0], mat[l - 11][1], mat[l - 10][1], mat[l - 9][1], mat[l - 11][2], mat[l - 10][2], mat[l - 9][2], mat[l - 11][3], mat[l - 10][3], mat[l - 9][3], mat[l - 11][4], mat[l - 10][4], mat[l - 9][4], mat[l - 11][5], mat[l - 10][5], mat[l - 9][5], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); let tmp2 = [ mat[0][l - 11], mat[0][l - 10], mat[0][l - 9], mat[1][l - 11], mat[1][l - 10], mat[1][l - 9], mat[2][l - 11], mat[2][l - 10], mat[2][l - 9], mat[3][l - 11], mat[3][l - 10], mat[3][l - 9], mat[4][l - 11], mat[4][l - 10], mat[4][l - 9], mat[5][l - 11], mat[5][l - 10], mat[5][l - 9], ]; assert_eq!(tmp2.map(|x| x.value()), expected2); } } fast_qr-0.13.1/src/version.rs000064400000000000000000000746101046102023000141770ustar 00000000000000//! Enum containing all possible `QRCode` versions use crate::ecl::ECL; use crate::encode::Mode; /// Enum containing all possible `QRCode` versions #[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "wasm-bindgen", wasm_bindgen::prelude::wasm_bindgen)] pub enum Version { /// Version n°01 V01 = 0, /// Version n°02 V02 = 1, /// Version n°03 V03 = 2, /// Version n°04 V04 = 3, /// Version n°05 V05 = 4, /// Version n°06 V06 = 5, /// Version n°07 V07 = 6, /// Version n°08 V08 = 7, /// Version n°09 V09 = 8, /// Version n°10 V10 = 9, /// Version n°11 V11 = 10, /// Version n°12 V12 = 11, /// Version n°13 V13 = 12, /// Version n°14 V14 = 13, /// Version n°15 V15 = 14, /// Version n°16 V16 = 15, /// Version n°17 V17 = 16, /// Version n°18 V18 = 17, /// Version n°19 V19 = 18, /// Version n°20 V20 = 19, /// Version n°21 V21 = 20, /// Version n°22 V22 = 21, /// Version n°23 V23 = 22, /// Version n°24 V24 = 23, /// Version n°25 V25 = 24, /// Version n°26 V26 = 25, /// Version n°27 V27 = 26, /// Version n°28 V28 = 27, /// Version n°29 V29 = 28, /// Version n°30 V30 = 29, /// Version n°31 V31 = 30, /// Version n°32 V32 = 31, /// Version n°33 V33 = 32, /// Version n°34 V34 = 33, /// Version n°35 V35 = 34, /// Version n°36 V36 = 35, /// Version n°37 V37 = 36, /// Version n°38 V38 = 37, /// Version n°39 V39 = 38, /// Version n°40 V40 = 39, } impl Version { /// Computes the best `Version` according to `mode`, `ecl` and `len` #[must_use] #[allow(clippy::too_many_lines)] pub(crate) const fn get(mode: Mode, ecl: ECL, len: usize) -> Option { use Version::{ V01, V02, V03, V04, V05, V06, V07, V08, V09, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34, V35, V36, V37, V38, V39, V40, }; match mode { Mode::Numeric => match ecl { ECL::L => match len { 0..=41 => Some(V01), 42..=77 => Some(V02), 78..=127 => Some(V03), 128..=187 => Some(V04), 188..=255 => Some(V05), 256..=322 => Some(V06), 323..=370 => Some(V07), 371..=461 => Some(V08), 462..=552 => Some(V09), 553..=652 => Some(V10), 653..=772 => Some(V11), 773..=883 => Some(V12), 884..=1022 => Some(V13), 1023..=1101 => Some(V14), 1102..=1250 => Some(V15), 1251..=1408 => Some(V16), 1409..=1548 => Some(V17), 1549..=1725 => Some(V18), 1726..=1903 => Some(V19), 1904..=2061 => Some(V20), 2062..=2232 => Some(V21), 2233..=2409 => Some(V22), 2410..=2620 => Some(V23), 2621..=2812 => Some(V24), 2813..=3057 => Some(V25), 3058..=3283 => Some(V26), 3284..=3517 => Some(V27), 3518..=3669 => Some(V28), 3670..=3909 => Some(V29), 3910..=4158 => Some(V30), 4159..=4417 => Some(V31), 4418..=4686 => Some(V32), 4687..=4965 => Some(V33), 4966..=5253 => Some(V34), 5254..=5529 => Some(V35), 5530..=5836 => Some(V36), 5837..=6153 => Some(V37), 6154..=6479 => Some(V38), 6480..=6743 => Some(V39), 6744..=7089 => Some(V40), _ => None, }, ECL::M => match len { 0..=34 => Some(V01), 35..=63 => Some(V02), 64..=101 => Some(V03), 102..=149 => Some(V04), 150..=202 => Some(V05), 203..=255 => Some(V06), 256..=293 => Some(V07), 294..=365 => Some(V08), 366..=432 => Some(V09), 433..=513 => Some(V10), 514..=604 => Some(V11), 605..=691 => Some(V12), 692..=796 => Some(V13), 797..=871 => Some(V14), 872..=991 => Some(V15), 992..=1082 => Some(V16), 1083..=1212 => Some(V17), 1213..=1346 => Some(V18), 1347..=1500 => Some(V19), 1501..=1600 => Some(V20), 1601..=1708 => Some(V21), 1709..=1872 => Some(V22), 1873..=2059 => Some(V23), 2060..=2188 => Some(V24), 2189..=2395 => Some(V25), 2396..=2544 => Some(V26), 2545..=2701 => Some(V27), 2702..=2857 => Some(V28), 2858..=3035 => Some(V29), 3036..=3289 => Some(V30), 3290..=3486 => Some(V31), 3487..=3693 => Some(V32), 3694..=3909 => Some(V33), 3910..=4134 => Some(V34), 4135..=4343 => Some(V35), 4344..=4588 => Some(V36), 4589..=4775 => Some(V37), 4776..=5039 => Some(V38), 5040..=5313 => Some(V39), 5314..=5596 => Some(V40), _ => None, }, ECL::Q => match len { 0..=27 => Some(V01), 28..=48 => Some(V02), 49..=77 => Some(V03), 78..=111 => Some(V04), 112..=144 => Some(V05), 145..=178 => Some(V06), 179..=207 => Some(V07), 208..=259 => Some(V08), 260..=312 => Some(V09), 313..=364 => Some(V10), 365..=427 => Some(V11), 428..=489 => Some(V12), 490..=580 => Some(V13), 581..=621 => Some(V14), 622..=703 => Some(V15), 704..=775 => Some(V16), 776..=876 => Some(V17), 877..=948 => Some(V18), 949..=1063 => Some(V19), 1064..=1159 => Some(V20), 1160..=1224 => Some(V21), 1225..=1358 => Some(V22), 1359..=1468 => Some(V23), 1469..=1588 => Some(V24), 1589..=1718 => Some(V25), 1719..=1804 => Some(V26), 1805..=1933 => Some(V27), 1934..=2085 => Some(V28), 2086..=2181 => Some(V29), 2182..=2358 => Some(V30), 2359..=2473 => Some(V31), 2474..=2670 => Some(V32), 2671..=2805 => Some(V33), 2806..=2949 => Some(V34), 2950..=3081 => Some(V35), 3082..=3244 => Some(V36), 3245..=3417 => Some(V37), 3418..=3599 => Some(V38), 3600..=3791 => Some(V39), 3792..=3993 => Some(V40), _ => None, }, ECL::H => match len { 0..=17 => Some(V01), 18..=34 => Some(V02), 35..=58 => Some(V03), 59..=82 => Some(V04), 83..=106 => Some(V05), 107..=139 => Some(V06), 140..=154 => Some(V07), 155..=202 => Some(V08), 203..=235 => Some(V09), 236..=288 => Some(V10), 289..=331 => Some(V11), 332..=374 => Some(V12), 375..=427 => Some(V13), 428..=468 => Some(V14), 469..=530 => Some(V15), 531..=602 => Some(V16), 603..=674 => Some(V17), 675..=746 => Some(V18), 747..=813 => Some(V19), 814..=919 => Some(V20), 920..=969 => Some(V21), 970..=1056 => Some(V22), 1057..=1108 => Some(V23), 1109..=1228 => Some(V24), 1229..=1286 => Some(V25), 1287..=1425 => Some(V26), 1426..=1501 => Some(V27), 1502..=1581 => Some(V28), 1582..=1677 => Some(V29), 1678..=1782 => Some(V30), 1783..=1897 => Some(V31), 1898..=2022 => Some(V32), 2023..=2157 => Some(V33), 2158..=2301 => Some(V34), 2302..=2361 => Some(V35), 2362..=2524 => Some(V36), 2525..=2625 => Some(V37), 2626..=2735 => Some(V38), 2736..=2927 => Some(V39), 2928..=3057 => Some(V40), _ => None, }, }, Mode::Alphanumeric => match ecl { ECL::L => match len { 0..=25 => Some(V01), 26..=47 => Some(V02), 48..=77 => Some(V03), 78..=114 => Some(V04), 115..=154 => Some(V05), 155..=195 => Some(V06), 196..=224 => Some(V07), 225..=279 => Some(V08), 280..=335 => Some(V09), 336..=395 => Some(V10), 396..=468 => Some(V11), 469..=535 => Some(V12), 536..=619 => Some(V13), 620..=667 => Some(V14), 668..=758 => Some(V15), 759..=854 => Some(V16), 855..=938 => Some(V17), 939..=1046 => Some(V18), 1047..=1153 => Some(V19), 1154..=1249 => Some(V20), 1250..=1352 => Some(V21), 1353..=1460 => Some(V22), 1461..=1588 => Some(V23), 1589..=1704 => Some(V24), 1705..=1853 => Some(V25), 1854..=1990 => Some(V26), 1991..=2132 => Some(V27), 2133..=2223 => Some(V28), 2224..=2369 => Some(V29), 2370..=2520 => Some(V30), 2521..=2677 => Some(V31), 2678..=2840 => Some(V32), 2841..=3009 => Some(V33), 3010..=3183 => Some(V34), 3184..=3351 => Some(V35), 3352..=3537 => Some(V36), 3538..=3729 => Some(V37), 3730..=3927 => Some(V38), 3928..=4087 => Some(V39), 4088..=4296 => Some(V40), _ => None, }, ECL::M => match len { 0..=20 => Some(V01), 21..=38 => Some(V02), 39..=61 => Some(V03), 62..=90 => Some(V04), 91..=122 => Some(V05), 123..=154 => Some(V06), 155..=178 => Some(V07), 179..=221 => Some(V08), 222..=262 => Some(V09), 263..=311 => Some(V10), 312..=366 => Some(V11), 367..=419 => Some(V12), 420..=483 => Some(V13), 484..=528 => Some(V14), 529..=600 => Some(V15), 601..=656 => Some(V16), 657..=734 => Some(V17), 735..=816 => Some(V18), 817..=909 => Some(V19), 910..=970 => Some(V20), 971..=1035 => Some(V21), 1036..=1134 => Some(V22), 1135..=1248 => Some(V23), 1249..=1326 => Some(V24), 1327..=1451 => Some(V25), 1452..=1542 => Some(V26), 1543..=1637 => Some(V27), 1638..=1732 => Some(V28), 1733..=1839 => Some(V29), 1840..=1994 => Some(V30), 1995..=2113 => Some(V31), 2114..=2238 => Some(V32), 2239..=2369 => Some(V33), 2370..=2506 => Some(V34), 2507..=2632 => Some(V35), 2633..=2780 => Some(V36), 2781..=2894 => Some(V37), 2895..=3054 => Some(V38), 3055..=3220 => Some(V39), 3221..=3391 => Some(V40), _ => None, }, ECL::Q => match len { 0..=16 => Some(V01), 17..=29 => Some(V02), 30..=47 => Some(V03), 48..=67 => Some(V04), 68..=87 => Some(V05), 88..=108 => Some(V06), 109..=125 => Some(V07), 126..=157 => Some(V08), 158..=189 => Some(V09), 190..=221 => Some(V10), 222..=259 => Some(V11), 260..=296 => Some(V12), 297..=352 => Some(V13), 353..=376 => Some(V14), 377..=426 => Some(V15), 427..=470 => Some(V16), 471..=531 => Some(V17), 532..=574 => Some(V18), 575..=644 => Some(V19), 645..=702 => Some(V20), 703..=742 => Some(V21), 743..=823 => Some(V22), 824..=890 => Some(V23), 891..=963 => Some(V24), 964..=1041 => Some(V25), 1042..=1094 => Some(V26), 1095..=1172 => Some(V27), 1173..=1263 => Some(V28), 1264..=1322 => Some(V29), 1323..=1429 => Some(V30), 1430..=1499 => Some(V31), 1500..=1618 => Some(V32), 1619..=1700 => Some(V33), 1701..=1787 => Some(V34), 1788..=1867 => Some(V35), 1868..=1966 => Some(V36), 1967..=2071 => Some(V37), 2072..=2181 => Some(V38), 2182..=2298 => Some(V39), 2299..=2420 => Some(V40), _ => None, }, ECL::H => match len { 0..=10 => Some(V01), 11..=20 => Some(V02), 21..=35 => Some(V03), 36..=50 => Some(V04), 51..=64 => Some(V05), 65..=84 => Some(V06), 85..=93 => Some(V07), 94..=122 => Some(V08), 123..=143 => Some(V09), 144..=174 => Some(V10), 175..=200 => Some(V11), 201..=227 => Some(V12), 228..=259 => Some(V13), 260..=283 => Some(V14), 284..=321 => Some(V15), 322..=365 => Some(V16), 366..=408 => Some(V17), 409..=452 => Some(V18), 453..=493 => Some(V19), 494..=557 => Some(V20), 558..=587 => Some(V21), 588..=640 => Some(V22), 641..=672 => Some(V23), 673..=744 => Some(V24), 745..=779 => Some(V25), 780..=864 => Some(V26), 865..=910 => Some(V27), 911..=958 => Some(V28), 959..=1016 => Some(V29), 1017..=1080 => Some(V30), 1081..=1150 => Some(V31), 1151..=1226 => Some(V32), 1227..=1307 => Some(V33), 1308..=1394 => Some(V34), 1395..=1431 => Some(V35), 1432..=1530 => Some(V36), 1531..=1591 => Some(V37), 1592..=1658 => Some(V38), 1659..=1774 => Some(V39), 1775..=1852 => Some(V40), _ => None, }, }, Mode::Byte => match ecl { ECL::L => match len { 0..=17 => Some(V01), 18..=32 => Some(V02), 33..=53 => Some(V03), 54..=78 => Some(V04), 79..=106 => Some(V05), 107..=134 => Some(V06), 135..=154 => Some(V07), 155..=192 => Some(V08), 193..=230 => Some(V09), 231..=271 => Some(V10), 272..=321 => Some(V11), 322..=367 => Some(V12), 368..=425 => Some(V13), 426..=458 => Some(V14), 459..=520 => Some(V15), 521..=586 => Some(V16), 587..=644 => Some(V17), 645..=718 => Some(V18), 719..=792 => Some(V19), 793..=858 => Some(V20), 859..=929 => Some(V21), 930..=1003 => Some(V22), 1004..=1091 => Some(V23), 1092..=1171 => Some(V24), 1172..=1273 => Some(V25), 1274..=1367 => Some(V26), 1368..=1465 => Some(V27), 1466..=1528 => Some(V28), 1529..=1628 => Some(V29), 1629..=1732 => Some(V30), 1733..=1840 => Some(V31), 1841..=1952 => Some(V32), 1953..=2068 => Some(V33), 2069..=2188 => Some(V34), 2189..=2303 => Some(V35), 2304..=2431 => Some(V36), 2432..=2563 => Some(V37), 2564..=2699 => Some(V38), 2700..=2809 => Some(V39), 2810..=2953 => Some(V40), _ => None, }, ECL::M => match len { 0..=14 => Some(V01), 15..=26 => Some(V02), 27..=42 => Some(V03), 43..=62 => Some(V04), 63..=84 => Some(V05), 85..=106 => Some(V06), 107..=122 => Some(V07), 123..=152 => Some(V08), 153..=180 => Some(V09), 181..=213 => Some(V10), 214..=251 => Some(V11), 252..=287 => Some(V12), 288..=331 => Some(V13), 332..=362 => Some(V14), 363..=412 => Some(V15), 413..=450 => Some(V16), 451..=504 => Some(V17), 505..=560 => Some(V18), 561..=624 => Some(V19), 625..=666 => Some(V20), 667..=711 => Some(V21), 712..=779 => Some(V22), 780..=857 => Some(V23), 858..=911 => Some(V24), 912..=997 => Some(V25), 998..=1059 => Some(V26), 1060..=1125 => Some(V27), 1126..=1190 => Some(V28), 1191..=1264 => Some(V29), 1265..=1370 => Some(V30), 1371..=1452 => Some(V31), 1453..=1538 => Some(V32), 1539..=1628 => Some(V33), 1629..=1722 => Some(V34), 1723..=1809 => Some(V35), 1810..=1911 => Some(V36), 1912..=1989 => Some(V37), 1990..=2099 => Some(V38), 2100..=2213 => Some(V39), 2214..=2331 => Some(V40), _ => None, }, ECL::Q => match len { 0..=11 => Some(V01), 12..=20 => Some(V02), 21..=32 => Some(V03), 33..=46 => Some(V04), 47..=60 => Some(V05), 61..=74 => Some(V06), 75..=86 => Some(V07), 87..=108 => Some(V08), 109..=130 => Some(V09), 131..=151 => Some(V10), 152..=177 => Some(V11), 178..=203 => Some(V12), 204..=241 => Some(V13), 242..=258 => Some(V14), 259..=292 => Some(V15), 293..=322 => Some(V16), 323..=364 => Some(V17), 365..=394 => Some(V18), 395..=442 => Some(V19), 443..=482 => Some(V20), 483..=509 => Some(V21), 510..=565 => Some(V22), 566..=611 => Some(V23), 612..=661 => Some(V24), 662..=715 => Some(V25), 716..=751 => Some(V26), 752..=805 => Some(V27), 806..=868 => Some(V28), 869..=908 => Some(V29), 909..=982 => Some(V30), 983..=1030 => Some(V31), 1031..=1112 => Some(V32), 1113..=1168 => Some(V33), 1169..=1228 => Some(V34), 1229..=1283 => Some(V35), 1284..=1351 => Some(V36), 1352..=1423 => Some(V37), 1424..=1499 => Some(V38), 1500..=1579 => Some(V39), 1580..=1663 => Some(V40), _ => None, }, ECL::H => match len { 0..=7 => Some(V01), 8..=14 => Some(V02), 15..=24 => Some(V03), 25..=34 => Some(V04), 35..=44 => Some(V05), 45..=58 => Some(V06), 59..=64 => Some(V07), 65..=84 => Some(V08), 85..=98 => Some(V09), 99..=119 => Some(V10), 120..=137 => Some(V11), 138..=155 => Some(V12), 156..=177 => Some(V13), 178..=194 => Some(V14), 195..=220 => Some(V15), 221..=250 => Some(V16), 251..=280 => Some(V17), 281..=310 => Some(V18), 311..=338 => Some(V19), 339..=382 => Some(V20), 383..=403 => Some(V21), 404..=439 => Some(V22), 440..=461 => Some(V23), 462..=511 => Some(V24), 512..=535 => Some(V25), 536..=593 => Some(V26), 594..=625 => Some(V27), 626..=658 => Some(V28), 659..=698 => Some(V29), 699..=742 => Some(V30), 743..=790 => Some(V31), 791..=842 => Some(V32), 843..=898 => Some(V33), 899..=958 => Some(V34), 959..=983 => Some(V35), 984..=1051 => Some(V36), 1052..=1093 => Some(V37), 1094..=1139 => Some(V38), 1140..=1219 => Some(V39), 1220..=1273 => Some(V40), _ => None, }, }, } } /// Returns `Version` based on the size of the [`crate::QRCode`] /// /// # Panics /// Function panics if `n` is not included in `(21..=177).step_by(4)` #[must_use] #[cfg(any(test, feature = "svg", feature = "image", debug_assertions))] pub(crate) const fn from_n(n: usize) -> Self { use Version::{ V01, V02, V03, V04, V05, V06, V07, V08, V09, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34, V35, V36, V37, V38, V39, V40, }; match n { 21 => V01, 25 => V02, 29 => V03, 33 => V04, 37 => V05, 41 => V06, 45 => V07, 49 => V08, 53 => V09, 57 => V10, 61 => V11, 65 => V12, 69 => V13, 73 => V14, 77 => V15, 81 => V16, 85 => V17, 89 => V18, 93 => V19, 97 => V20, 101 => V21, 105 => V22, 109 => V23, 113 => V24, 117 => V25, 121 => V26, 125 => V27, 129 => V28, 133 => V29, 137 => V30, 141 => V31, 145 => V32, 149 => V33, 153 => V34, 157 => V35, 161 => V36, 165 => V37, 169 => V38, 173 => V39, 177 => V40, _ => panic!("Invalid matrix size"), } } /// Returns `QRCode`'s **missing padding bits count** at the very end #[must_use] pub(crate) const fn missing_bits(self) -> usize { use Version::{ V01, V02, V03, V04, V05, V06, V07, V08, V09, V10, V11, V12, V13, V14, V15, V16, V17, V18, V19, V20, V21, V22, V23, V24, V25, V26, V27, V28, V29, V30, V31, V32, V33, V34, V35, V36, V37, V38, V39, V40, }; match self { V01 | V07 | V08 | V09 | V10 | V11 | V12 | V13 | V35 | V36 | V37 | V38 | V39 | V40 => 0, V14 | V15 | V16 | V17 | V18 | V19 | V20 | V28 | V29 | V30 | V31 | V32 | V33 | V34 => 3, V21 | V22 | V23 | V24 | V25 | V26 | V27 => 4, V02 | V03 | V04 | V05 | V06 => 7, } } /// Returns the **max bytes** that can contain a `QRCode` for a specified version #[must_use] pub(crate) const fn max_bytes(self) -> usize { const MAX_BYTES: [usize; 40] = [ 26, 44, 70, 100, 134, 172, 196, 242, 292, 346, 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085, 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185, 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706, ]; MAX_BYTES[self as usize] } /// Returns the **version information** we need to put for `QRCode` larger or equal to version 7 #[must_use] pub(crate) const fn information(self) -> u32 { const VERSION_INFORMATION: [u32; 40] = [ 0, 0, 0, 0, 0, 0, 0b00_0111_1100_1001_0100, 0b00_1000_0101_1011_1100, 0b00_1001_1010_1001_1001, 0b00_1010_0100_1101_0011, 0b00_1011_1011_1111_0110, 0b00_1100_0111_0110_0010, 0b00_1101_1000_0100_0111, 0b00_1110_0110_0000_1101, 0b00_1111_1001_0010_1000, 0b01_0000_1011_0111_1000, 0b01_0001_0100_0101_1101, 0b01_0010_1010_0001_0111, 0b01_0011_0101_0011_0010, 0b01_0100_1001_1010_0110, 0b01_0101_0110_1000_0011, 0b01_0110_1000_1100_1001, 0b01_0111_0111_1110_1100, 0b01_1000_1110_1100_0100, 0b01_1001_0001_1110_0001, 0b01_1010_1111_1010_1011, 0b01_1011_0000_1000_1110, 0b01_1100_1100_0001_1010, 0b01_1101_0011_0011_1111, 0b01_1110_1101_0111_0101, 0b01_1111_0010_0101_0000, 0b10_0000_1001_1101_0101, 0b10_0001_0110_1111_0000, 0b10_0010_1000_1011_1010, 0b10_0011_0111_1001_1111, 0b10_0100_1011_0000_1011, 0b10_0101_0100_0010_1110, 0b10_0110_1010_0110_0100, 0b10_0111_0101_0100_0001, 0b10_1000_1100_0110_1001, ]; VERSION_INFORMATION[self as usize] } /// Returns **alignments** positions #[must_use] pub(crate) const fn alignment_patterns_grid(self) -> &'static [usize] { const ALIGNMENT_PATTERNS_GRID: [&[usize]; 40] = [ &[], &[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], &[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], ]; ALIGNMENT_PATTERNS_GRID[self as usize] } /// Returns the size of a `QRCode` for said version. #[must_use] pub(crate) const fn size(self) -> usize { self as usize * 4 + 21 } } fast_qr-0.13.1/src/wasm.rs000064400000000000000000000151141046102023000134530ustar 00000000000000use crate::QRCode; #[cfg(feature = "svg")] use crate::{convert, Version, ECL}; #[cfg(feature = "wasm-bindgen")] use wasm_bindgen::prelude::*; fn bool_to_u8(qr: QRCode) -> Vec { let dim = qr.size; qr.data[..dim * dim] .iter() .map(|x| u8::from(x.value())) .collect() } /// Generate a QR code from a string. All parameters are automatically set. #[cfg_attr(feature = "wasm-bindgen", wasm_bindgen)] #[must_use] pub fn qr(content: &str) -> Vec { let qrcode = QRCode::new(content.as_bytes(), None, None, None, None); qrcode.map(bool_to_u8).unwrap_or(Vec::new()) } /// Configuration for the SVG output. #[cfg(feature = "svg")] #[cfg_attr(feature = "wasm-bindgen", wasm_bindgen)] #[derive(Debug, Clone)] pub struct SvgOptions { shape: convert::Shape, module_color: Vec, margin: usize, ecl: Option, version: Option, background_color: Vec, image: String, image_background_color: Vec, image_background_shape: convert::ImageBackgroundShape, image_size: Option, image_gap: Option, image_position: Vec, } #[cfg_attr(feature = "wasm-bindgen", wasm_bindgen)] #[cfg(feature = "svg")] impl SvgOptions { fn color_to_code(color: String) -> Vec { let mut color = color; if color.starts_with('#') { color.remove(0); } let color = color.as_bytes(); let color = color.chunks_exact(2); let color = color.map(|x| u8::from_str_radix(std::str::from_utf8(x).unwrap(), 16).unwrap()); let mut color = color.collect::>(); if color.len() == 3 { color.push(255); } color } /// Updates the shape of the QRCode modules. pub fn shape(self, shape: convert::Shape) -> Self { Self { shape, ..self } } /// Updates the module color of the QRCode. Tales a string in the format `#RRGGBB[AA]`. pub fn module_color(self, module_color: String) -> Self { let code = Self::color_to_code(module_color); if code.len() != 4 { return self; } Self { module_color: code, ..self } } /// Updates the margin of the QRCode. pub fn margin(self, margin: usize) -> Self { Self { margin, ..self } } /// Updates the background color of the QRCode. Tales a string in the format `#RRGGBB[AA]`. pub fn background_color(self, background_color: String) -> Self { let code = Self::color_to_code(background_color); if code.len() != 4 { return self; } Self { background_color: code, ..self } } /// Updates the image of the QRCode. Takes base64 or a url. pub fn image(self, image: String) -> Self { Self { image, ..self } } /// Updates the background color of the image. Takes a string in the format `#RRGGBB[AA]`. pub fn image_background_color(self, image_background_color: String) -> Self { let code = Self::color_to_code(image_background_color); if code.len() != 4 { return self; } Self { image_background_color: code, ..self } } /// Updates the shape of the image background. Takes an convert::ImageBackgroundShape. pub fn image_background_shape( self, image_background_shape: convert::ImageBackgroundShape, ) -> Self { Self { image_background_shape, ..self } } /// Updates the size of the image. (unit being module size). pub fn image_size(self, size: f64) -> Self { Self { image_size: Some(size), ..self } } /// Updates the gap between background color and the image. (unit being module size). pub fn image_gap(self, gap: f64) -> Self { Self { image_gap: Some(gap), ..self } } /// Updates the position of the image. Takes an array [x, y] (unit being module size). pub fn image_position(self, image_position: Vec) -> Self { if image_position.len() != 2 { return self; } Self { image_position, ..self } } /// Updates the error correction level of the QRCode (can increase the size of the QRCode) pub fn ecl(self, ecl: ECL) -> Self { Self { ecl: Some(ecl), ..self } } /// Forces the version of the QRCode pub fn version(self, version: Version) -> Self { Self { version: Some(version), ..self } } } #[cfg_attr(feature = "wasm-bindgen", wasm_bindgen)] #[cfg(feature = "svg")] impl SvgOptions { /// Creates a new SvgOptions object. #[cfg_attr(feature = "wasm-bindgen", wasm_bindgen(constructor))] pub fn new() -> Self { Self { shape: convert::Shape::Square, module_color: vec![0, 0, 0, 255], margin: 4, ecl: None, version: None, background_color: vec![255, 255, 255, 255], image: String::new(), image_background_color: vec![255, 255, 255, 255], image_background_shape: convert::ImageBackgroundShape::Square, image_size: None, image_gap: None, image_position: vec![], } } } /// Generate a QR code from a string. All parameters are automatically set. #[cfg_attr(feature = "wasm-bindgen", wasm_bindgen)] #[cfg(feature = "svg")] pub fn qr_svg(content: &str, options: SvgOptions) -> String { use crate::convert::svg::SvgBuilder; use crate::convert::Builder; let qrcode = QRCode::new(content.as_bytes(), options.ecl, options.version, None, None); let mut builder = SvgBuilder::default(); builder.shape(options.shape); builder.margin(options.margin); builder.background_color(options.background_color); builder.module_color(options.module_color); if !options.image.is_empty() { builder.image(options.image); } builder.image_background_color(options.image_background_color); builder.image_background_shape(options.image_background_shape); if let Some(image_size) = options.image_size { builder.image_size(image_size); } if let Some(image_gap) = options.image_gap { builder.image_gap(image_gap); } if options.image_position.len() == 2 { let x = options.image_position[0]; let y = options.image_position[1]; builder.image_position(x, y); } qrcode .map(|qrcode| builder.to_str(&qrcode)) .unwrap_or(String::new()) }