Skip to content

Commit

Permalink
Merge pull request #53 from RexWzh/rex-dev
Browse files Browse the repository at this point in the history
interact with ZBar
  • Loading branch information
RexWzh authored Feb 14, 2023
2 parents a958ca3 + db469f3 commit fb3c3bb
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 24 deletions.
12 changes: 1 addition & 11 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QRCoders"
uuid = "f42e9828-16f3-11ed-2883-9126170b272d"
authors = ["Jérémie Gillet <[email protected]> and contributors"]
version = "1.4.4"
version = "1.4.5"

[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Expand All @@ -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"]
6 changes: 3 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
2 changes: 1 addition & 1 deletion src/export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 6 additions & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")

Expand Down
101 changes: 101 additions & 0 deletions test/tst_zbar.jl
Original file line number Diff line number Diff line change
@@ -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

2 comments on commit fb3c3bb

@RexWzh
Copy link
Member Author

@RexWzh RexWzh commented on fb3c3bb Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/77638

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.4.5 -m "<description of version>" fb3c3bb973b327e157834c6433e5549869cef30f
git push origin v1.4.5

Please sign in to comment.