diff --git a/Project.toml b/Project.toml index 2a08ee2..ab8e2ff 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "QRCoders" uuid = "f42e9828-16f3-11ed-2883-9126170b272d" authors = ["Jérémie Gillet and contributors"] -version = "1.4.4" +version = "1.4.5" [deps] FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" @@ -19,13 +19,3 @@ ImageMagick = "1" StatsBase = "0.33" UnicodePlots = "2.7 - 2.12" julia = "1.3" - -[extras] -ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795" -QRDecoders = "d4999880-6331-4276-8b7d-7ee1f305cff8" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990" - -[targets] -test = ["ImageTransformations", "QRDecoders", "Test", "Random", "TestImages"] diff --git a/docs/make.jl b/docs/make.jl index 9891c7c..962a026 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -9,7 +9,7 @@ makedocs( deploydocs( repo = "github.com/JuliaImages/QRCoders.jl.git", - devurl = "master", - versions = ["v#.#", "stable" => "v^", "dev" => "master"], - # push_preview = true, + devurl = "dev", + devbranch = "master", + versions = ["v#.#", "stable" => "v^", "dev" => "dev"], ) diff --git a/src/export.jl b/src/export.jl index 0d95b7a..d815555 100644 --- a/src/export.jl +++ b/src/export.jl @@ -102,7 +102,7 @@ end Export the `BitMatrix` `matrix` to an image with file path `path`. """ -function exportbitmat( matrix::BitMatrix +function exportbitmat( matrix::AbstractMatrix{Bool} , path::AbstractString ; targetsize::Int=0 , pixels::Int=160) diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..3321c7d --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,14 @@ +[deps] +FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" +ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" +ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795" +QRDecoders = "d4999880-6331-4276-8b7d-7ee1f305cff8" +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990" +ZBar = "ae056753-435e-4d6b-8005-e923ff6e8938" + +[compat] +julia = "1.6" +ZBar = "0.1.1" \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 117a498..b5d0d10 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,13 +1,7 @@ -using QRCoders -using Test -using FileIO -using Random -using ImageCore -using ImageTransformations -using TestImages -using StatsBase +using Test, Random, StatsBase +using FileIO, ImageCore, TestImages, ImageTransformations +using QRCoders, QRDecoders, ZBar using QRDecoders.Syndrome: fillerasures! -using QRDecoders using QRCoders: # build @@ -49,6 +43,9 @@ imgpath = "testimages/" eclevels = [Low(), Medium(), Quartile(), High()] modes = [Numeric(), Alphanumeric(), Byte(), Kanji()] +# interact with ZBar.jl +include("tst_zbar.jl") + # decompose QR matrix include("tst_locate.jl") diff --git a/test/tst_zbar.jl b/test/tst_zbar.jl new file mode 100644 index 0000000..13c3572 --- /dev/null +++ b/test/tst_zbar.jl @@ -0,0 +1,101 @@ +# interact with ZBar.jl + +#= +Note for ZBar.jl + 1. `decodeimg` works for multiple QR codes in one image(some message failed in `--xml` mode) + 2. `decodesingle` works for single QR code in one image(some message might be misleading in `--noxml` mode) +=# + +testzbar = "testimages/zbar/" +mkpath(testzbar) + +@testset "Decode mode" begin + # Numeric mode + txt = join(rand(0:9, 10)) + exportqrcode(txt, "$testzbar/numeric.png") + @test decodesingle("$testzbar/numeric.png") == txt + @test decodeimg("$testzbar/numeric.png")[1] == txt + txtall = join(0:9) + exportqrcode(txtall, "$testzbar/allnumeric.png") + @test decodesingle("$testzbar/allnumeric.png") == txtall + @test decodeimg("$testzbar/allnumeric.png")[1] == txtall + + # Alphanumeric mode + txt = join(rand(keys(alphanumeric), 10)) + exportqrcode(txt, "$testzbar/alphanum.png") + @test decodesingle("$testzbar/alphanum.png") == txt + @test decodeimg("$testzbar/alphanum.png")[1] == txt + txtall = join(keys(alphanumeric)) + exportqrcode(txtall, "$testzbar/allalphanum.png") + @test decodesingle("$testzbar/allalphanum.png") == txtall + @test decodeimg("$testzbar/allalphanum.png")[1] == txtall + + # Byte mode -- ASCII + txt = join(rand(Char.(0:127), 10)) + exportqrcode(txt, "$testzbar/byte-ascii.png") + @test decodesingle("$testzbar/byte-ascii.png") == txt + ## decodeimg misdecode some message + @test_broken decodeimg("$testzbar/byte-ascii.png")[1] == txt + + txtall = join(Char.(0:127)) + exportqrcode(txtall, "$testzbar/allbyte-ascii.png") + @test decodesingle("$testzbar/allbyte-ascii.png") == txtall + ## decodeimg misdecode some message + @test_broken decodeimg("$testzbar/allbyte-ascii.png")[1] == txtall + + # Byte mode -- 128-255 + txt = "©®±²³" + exportqrcode(txt, "$testzbar/byte-128-255.png") + ## zbar use different encoding for 0xf0-0xff + @test_broken decodesingle("$testzbar/byte-128-255.png") == txt + @test_broken decodeimg("$testzbar/byte-128-255.png")[1] == txt + + # UTF8 -- ZBar do not support UTF8 + txt = "你好" + exportqrcode(txt, "$testzbar/utf8.png") + @test_broken decodesingle("$testzbar/utf8.png") == txt + @test_broken decodeimg("$testzbar/utf8.png")[1] == txt + + # Kanji mode + txt = "茗荷" + exportqrcode(txt, "$testzbar/kanji.png") + @test decodesingle("$testzbar/kanji.png") == txt + ## decodeimg misdecode some message + @test_broken decodeimg("$testzbar/kanji.png")[1] == txt +end + + +@testset "Same message by different encoding" begin + # ASCII vs 128-255 + txt = "©®±²³" + exportqrcode(txt, "$testzbar/ascii-128-255.png") + ## zbar use different encoding for 0xf0-0xff + @test_broken decodesingle("$testzbar/ascii-128-255.png") == txt + @test_broken decodeimg("$testzbar/ascii-128-255.png")[1] == txt + + # ASCII vs UTF8 + txt = "你好" + exportqrcode(txt, "$testzbar/ascii-utf8.png") + @test_broken decodesingle("$testzbar/ascii-utf8.png") == txt + @test_broken decodeimg("$testzbar/ascii-utf8.png")[1] == txt +end + +@testset "Same message with different setting" begin + message = "Hello, world!" + for v in 1:5, eclevel in eclevels, mask in 0:7 + exportqrcode(message, "$testzbar/v$(v)-m$(mask).png"; version=v, eclevel=eclevel, mask=mask) + @test decodesingle("$testzbar/v$(v)-m$(mask).png") == message == decodeimg("$testzbar/v$(v)-m$(mask).png")[1] + end + for v in vcat(1:33, [35, 36, 40]) + exportqrcode(message, "$testzbar/version$v.png", version=v) + @test decodesingle("$testzbar/version$v.png") == message + @test decodeimg("$testzbar/version$v.png")[1] == message + end + + # ZBar fail to detect QR code when the version is too large + for v in [34, 37, 38, 39] + exportqrcode(message, "$testzbar/version$v.png", version=v) + @test_broken decodesingle("$testzbar/version$v.png") == message + @test_broken decodeimg("$testzbar/version$v.png")[1] == message + end +end \ No newline at end of file