Skip to content

Commit

Permalink
Merge pull request #45 from RexWzh/rex-dev
Browse files Browse the repository at this point in the history
Plot images
  • Loading branch information
RexWzh authored Nov 23, 2022
2 parents de75100 + 88bddea commit e2f3ae5
Show file tree
Hide file tree
Showing 12 changed files with 343 additions and 183 deletions.
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
name = "QRCoders"
uuid = "f42e9828-16f3-11ed-2883-9126170b272d"
authors = ["Jérémie Gillet <[email protected]> and contributors"]
version = "1.3.1"
version = "1.4.0"

[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"

[compat]
FileIO = "1"
ImageCore = "0.8, 0.9"
ImageIO = "0.4, 0.5, 0.6"
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"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"

[targets]
test = ["ImageTransformations", "QRDecoders", "Test", "Random", "StatsBase", "TestImages"]
test = ["ImageTransformations", "QRDecoders", "Test", "Random", "TestImages"]
11 changes: 4 additions & 7 deletions src/QRCoders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module QRCoders
using ImageCore
using FileIO
using UnicodePlots
using StatsBase

export
# create QR code
Expand All @@ -18,14 +19,13 @@ export
# get information about QR code
getmode, getversion, qrwidth,
getindexes, getsegments,
# data type of Reed Solomon code
Poly, geterrcode,
# polynomial operations
Poly, geterrcode, generator_matrix,
# error type
EncodeError,
# QR code style
unicodeplot, unicodeplotbychar,
imagebyerrcor, animatebyerrcor,
generator_matrix
imageinqrcode, getfreeinfo, getimagescore

# Data types in QRCoders
include("types.jl")
Expand All @@ -49,7 +49,4 @@ include("styles/style.jl")
# Generate and export QR code
include("export.jl")

# Tools for equation solving
include("styles/equation.jl")

end # module
3 changes: 2 additions & 1 deletion src/encode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,5 @@ function addborder(matrix::AbstractMatrix, width::Int)
background = falses(size(matrix) .+ (width*2, width*2))
background[width+1:end-width, width+1:end-width] = matrix
return background
end
end
addborder(width::Int) = matrix -> addborder(matrix, width) # currying
1 change: 1 addition & 0 deletions src/export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function exportbitmat( matrix::BitMatrix
end
save(path, .! _resize(matrix, pixels))
end
exportbitmat(path::AbstractString) = matrix -> exportbitmat(matrix, path)

"""
exportqrcode( message::AbstractString
Expand Down
38 changes: 20 additions & 18 deletions src/styles/locate.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# 2. Locate message bits
## 2.1 extract indexes of message bits
# Locate message bits

## extract indexes of message bits

"""
getindexes(v::Int)
Extract indexes of message bits from the QR code of version `v`.
The procedure is similar to `placedata!` in `matrix.jl`.
Note: The procedure is similar to `placedata!` in `matrix.jl`.
"""
function getindexes(v::Int)
mat, n = emptymatrix(v), 17 + 4 * v
inds = Vector{Int}(undef, msgbitslen[v])
inds = Vector{CartesianIndex{2}}(undef, msgbitslen[v])
col, row, ind = n, n + 1, 1
while col > 0
# Skip the column with the timing pattern
Expand All @@ -23,11 +24,11 @@ function getindexes(v::Int)
# recode index if the matrix element is nothing
for _ in 1:n
if isnothing(mat[row, col])
inds[ind] = (col - 1) * n + row
inds[ind] = CartesianIndex(row, col)
ind += 1
end
if isnothing(mat[row, col - 1])
inds[ind] = (col - 2) * n + row
inds[ind] = CartesianIndex(row, col - 1)
ind += 1
end
row += δrow
Expand All @@ -39,32 +40,33 @@ function getindexes(v::Int)
"The number of indexes is not correct."))
return inds
end
getindexes(code::QRCode) = getindexes(code.version)

## 2.2 split indexes into several segments(de-interleave)
## split indexes into several segments(de-interleave)
"""
getecinfo(v::Int, eclevel::ErrCorrLevel)
Get the error correction information.
"""
getecinfo(v::Int, eclevel::ErrCorrLevel) = @views ecblockinfo[eclevel][v, :]
getecinfo(code::QRCode) = getecinfo(code.version, code.eclevel)

"""
getsegments(v::Int, mode::Mode, eclevel::ErrCorrLevel)
getsegments(code::QRCode)
Get indexes segments of the corresponding settings.
Each of the segments has atmost 8 * 255 elements.
Get indexes segments of the QR code.
The procedure is similar to `deinterleave` in `QRDecoders.jl`.
Note: The procedure is similar to `deinterleave` in `QRDecoders.jl`.
"""
getsegments(code::QRCode) = getsegments(code.version, code.eclevel)
function getsegments(v::Int, eclevel::ErrCorrLevel)
# initialize
## get information about error correction
necwords, nb1, nc1, nb2, nc2 = getecinfo(v, eclevel)
## initialize blocks
expand(x) = (8 * x - 7):8 * x
segments = vcat([Vector{Int}(undef, 8 * nc1) for _ in 1:nb1],
[Vector{Int}(undef, 8 * nc2) for _ in 1:nb2])
ecsegments = [Vector{Int}(undef, 8 * necwords) for _ in 1:nb1 + nb2]
segments = vcat([Vector{Vector{CartesianIndex{2}}}(undef, nc1) for _ in 1:nb1],
[Vector{Vector{CartesianIndex{2}}}(undef, nc2) for _ in 1:nb2])
ecsegments = [Vector{Vector{CartesianIndex{2}}}(undef, necwords) for _ in 1:nb1 + nb2]
# get segments from the QR code
## indexes of message bits
inds = getindexes(v)
Expand All @@ -77,16 +79,16 @@ function getsegments(v::Int, eclevel::ErrCorrLevel)
ind = length(inds) >> 3 # number of bytes
### error correction bytes
@inbounds for i in necwords:-1:1, j in (nb1 + nb2):-1:1
ecsegments[j][expand(i)] = @view(inds[expand(ind)])
ecsegments[j][i] = @view(inds[ind * 8 - 7:ind * 8])
ind -= 1
end
### message bytes
@inbounds for i in nc2:-1:(1 + nc1), j in (nb1 + nb2):-1:(nb1 + 1)
segments[j][expand(i)] = @view(inds[expand(ind)])
segments[j][i] = @view(inds[ind * 8 - 7:ind * 8])
ind -= 1
end
@inbounds for i in nc1:-1:1, j in (nb1 + nb2):-1:1
segments[j][expand(i)] = @view(inds[expand(ind)])
segments[j][i] = @view(inds[ind * 8 - 7:ind * 8])
ind -= 1
end
ind != 0 && throw(ArgumentError("getsegments: not all data is recorded"))
Expand Down
Loading

2 comments on commit e2f3ae5

@RexWzh
Copy link
Member Author

@RexWzh RexWzh commented on e2f3ae5 Nov 23, 2022

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/72756

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.0 -m "<description of version>" e2f3ae5d29de44bb1843710c10e89bf5ad13e943
git push origin v1.4.0

Please sign in to comment.