Skip to content

Commit

Permalink
refactor: move table.cr to under ecc folder
Browse files Browse the repository at this point in the history
  • Loading branch information
soya-daizu committed Jul 5, 2023
1 parent fde3f19 commit 262c581
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion spec/rsdeflator_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Goban

version = QR::Version.new(3)
ecl = ECC::Level::Quartile
ecc_codewords = EC_CODEWORDS_PER_BLOCK_QR[ecl.to_s][version.to_i] * EC_BLOCKS_QR[ecl.to_s][version.to_i]
ecc_codewords = ECC::EC_CODEWORDS_PER_BLOCK_QR[ecl.to_s][version.to_i] * ECC::EC_BLOCKS_QR[ecl.to_s][version.to_i]
(ecc_codewords // 2).times do |i|
corrupted[i] = Random.rand(256).to_u8
end
Expand Down
8 changes: 4 additions & 4 deletions src/goban/ecc/rsdeflator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ module Goban::ECC

case version
when QR::Version
ec_blocks_count = EC_BLOCKS_QR[ecl.to_s][version.to_i]
ec_block_size = EC_CODEWORDS_PER_BLOCK_QR[ecl.to_s][version.to_i]
ec_blocks_count = ECC::EC_BLOCKS_QR[ecl.to_s][version.to_i]
ec_block_size = ECC::EC_CODEWORDS_PER_BLOCK_QR[ecl.to_s][version.to_i]
when RMQR::Version
ec_blocks_count = EC_BLOCKS_RMQR[ecl.to_s][version.to_i + 1]
ec_block_size = EC_CODEWORDS_PER_BLOCK_RMQR[ecl.to_s][version.to_i + 1]
ec_blocks_count = ECC::EC_BLOCKS_RMQR[ecl.to_s][version.to_i + 1]
ec_block_size = ECC::EC_CODEWORDS_PER_BLOCK_RMQR[ecl.to_s][version.to_i + 1]
else
raise InternalError.new("Unknown QR Type")
end
Expand Down
10 changes: 5 additions & 5 deletions src/goban/ecc/rsinflator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ module Goban::ECC

case version
when QR::Version
ec_blocks_count = EC_BLOCKS_QR[ecl.to_s][version.to_i]
ec_block_size = EC_CODEWORDS_PER_BLOCK_QR[ecl.to_s][version.to_i]
ec_blocks_count = ECC::EC_BLOCKS_QR[ecl.to_s][version.to_i]
ec_block_size = ECC::EC_CODEWORDS_PER_BLOCK_QR[ecl.to_s][version.to_i]
when RMQR::Version
ec_blocks_count = EC_BLOCKS_RMQR[ecl.to_s][version.to_i + 1]
ec_block_size = EC_CODEWORDS_PER_BLOCK_RMQR[ecl.to_s][version.to_i + 1]
ec_blocks_count = ECC::EC_BLOCKS_RMQR[ecl.to_s][version.to_i + 1]
ec_block_size = ECC::EC_CODEWORDS_PER_BLOCK_RMQR[ecl.to_s][version.to_i + 1]
else
raise InternalError.new("Unknown QR Type")
end
Expand Down Expand Up @@ -63,7 +63,7 @@ module Goban::ECC
def inflate_codewords(codewords : Slice(UInt8), version : MQR::Version, ecl : Level)
raise InputError.new("Codewords size mismatch") if codewords.size != version.max_data_codewords(ecl)

ec_block_size = EC_CODEWORDS_MQR[ecl.to_s][version.to_i]
ec_block_size = ECC::EC_CODEWORDS_MQR[ecl.to_s][version.to_i]
raw_codewords_count = version.raw_max_data_codewords

result = Slice(UInt8).new(raw_codewords_count)
Expand Down
12 changes: 6 additions & 6 deletions src/goban/tables.cr → src/goban/ecc/tables.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Goban
module Goban::ECC
EC_CODEWORDS_PER_BLOCK_QR = {
# Version: (note that index 0 is for padding, and is set to an illegal value)
# 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40
Expand All @@ -10,11 +10,11 @@ module Goban

EC_BLOCKS_QR = {
# Version: (note that index 0 is for padding, and is set to an illegal value)
# 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40
Low: {-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25},
Medium: {-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49},
Quartile: {-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68},
High: {-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81},
# 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40
Low: {-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25},
Medium: {-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49},
Quartile: {-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68},
High: {-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81},
}

EC_CODEWORDS_MQR = {
Expand Down
2 changes: 1 addition & 1 deletion src/goban/mqr.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "./abstract/*"
require "./mqr/*"
require "./ecc/*"
require "./mqr/*"

module Goban
# Object that represents an encoded Micro QR Code symbol.
Expand Down
4 changes: 2 additions & 2 deletions src/goban/mqr/version.cr
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Goban::MQR < Goban::AbstractQR
# symbol of this version. This does not include the number of error correction
# codewords.
def max_data_codewords(ecl : ECC::Level)
ecc_codewords = EC_CODEWORDS_MQR[ecl.to_s][@value]
ecc_codewords = ECC::EC_CODEWORDS_MQR[ecl.to_s][@value]
raise InputError.new("Invalid EC level or version") if ecc_codewords < 0
raw_max_data_codewords - ecc_codewords
end
Expand All @@ -61,7 +61,7 @@ struct Goban::MQR < Goban::AbstractQR
# symbol of this version. This does not include the number of error correction
# codewords.
def max_data_bits(ecl : ECC::Level)
ecc_codewords = EC_CODEWORDS_MQR[ecl.to_s][@value]
ecc_codewords = ECC::EC_CODEWORDS_MQR[ecl.to_s][@value]
raise InputError.new("Invalid EC level or version") if ecc_codewords < 0
raw_data_mods_count - ecc_codewords * 8
end
Expand Down
2 changes: 1 addition & 1 deletion src/goban/qr.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "./abstract/*"
require "./qr/*"
require "./ecc/*"
require "./qr/*"

module Goban
# Object that represents an encoded QR Code symbol.
Expand Down
2 changes: 1 addition & 1 deletion src/goban/qr/version.cr
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct Goban::QR < Goban::AbstractQR
# symbol of this version. This does not include the number of error correction
# codewords.
def max_data_codewords(ecl : ECC::Level)
ecc_codewords = EC_CODEWORDS_PER_BLOCK_QR[ecl.to_s][@value] * EC_BLOCKS_QR[ecl.to_s][@value]
ecc_codewords = ECC::EC_CODEWORDS_PER_BLOCK_QR[ecl.to_s][@value] * ECC::EC_BLOCKS_QR[ecl.to_s][@value]
raise InputError.new("Invalid EC level or version") if ecc_codewords < 0
raw_max_data_codewords - ecc_codewords
end
Expand Down
2 changes: 1 addition & 1 deletion src/goban/rmqr.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "./abstract/*"
require "./rmqr/*"
require "./ecc/*"
require "./rmqr/*"

module Goban
# Object that represents an encoded rMQR Code symbol.
Expand Down
2 changes: 1 addition & 1 deletion src/goban/rmqr/version.cr
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ struct Goban::RMQR < Goban::AbstractQR
# symbol of this version. This does not include the number of error correction
# codewords.
def max_data_codewords(ecl : ECC::Level)
ecc_codewords = EC_CODEWORDS_PER_BLOCK_RMQR[ecl.to_s][@value.value + 1] * EC_BLOCKS_RMQR[ecl.to_s][@value.value + 1]
ecc_codewords = ECC::EC_CODEWORDS_PER_BLOCK_RMQR[ecl.to_s][@value.value + 1] * ECC::EC_BLOCKS_RMQR[ecl.to_s][@value.value + 1]
raise InputError.new("Invalid EC level or version") if ecc_codewords < 0
raw_max_data_codewords - ecc_codewords
end
Expand Down

0 comments on commit 262c581

Please sign in to comment.