🚿 simplify MAX_BITS/getMaxBits() - the 0-index will just be ignored

This commit is contained in:
smiley
2022-07-15 19:39:37 +02:00
parent 23388e14ad
commit 105ac96915
+44 -46
View File
@@ -12,7 +12,7 @@ namespace chillerlan\QRCode\Common;
use chillerlan\QRCode\QRCodeException;
use function array_column, array_combine, array_keys;
use function array_column;
/**
* This class encapsulates the four error correction levels defined by the QR code standard.
@@ -36,47 +36,48 @@ final class EccLevel{
* @var int [][]
*/
private const MAX_BITS = [
// v => [ L, M, Q, H] // modules
1 => [ 152, 128, 104, 72], // 21
2 => [ 272, 224, 176, 128], // 25
3 => [ 440, 352, 272, 208], // 29
4 => [ 640, 512, 384, 288], // 33
5 => [ 864, 688, 496, 368], // 37
6 => [ 1088, 864, 608, 480], // 41
7 => [ 1248, 992, 704, 528], // 45
8 => [ 1552, 1232, 880, 688], // 49
9 => [ 1856, 1456, 1056, 800], // 53
10 => [ 2192, 1728, 1232, 976], // 57
11 => [ 2592, 2032, 1440, 1120], // 61
12 => [ 2960, 2320, 1648, 1264], // 65
13 => [ 3424, 2672, 1952, 1440], // 69 NICE!
14 => [ 3688, 2920, 2088, 1576], // 73
15 => [ 4184, 3320, 2360, 1784], // 77
16 => [ 4712, 3624, 2600, 2024], // 81
17 => [ 5176, 4056, 2936, 2264], // 85
18 => [ 5768, 4504, 3176, 2504], // 89
19 => [ 6360, 5016, 3560, 2728], // 93
20 => [ 6888, 5352, 3880, 3080], // 97
21 => [ 7456, 5712, 4096, 3248], // 101
22 => [ 8048, 6256, 4544, 3536], // 105
23 => [ 8752, 6880, 4912, 3712], // 109
24 => [ 9392, 7312, 5312, 4112], // 113
25 => [10208, 8000, 5744, 4304], // 117
26 => [10960, 8496, 6032, 4768], // 121
27 => [11744, 9024, 6464, 5024], // 125
28 => [12248, 9544, 6968, 5288], // 129
29 => [13048, 10136, 7288, 5608], // 133
30 => [13880, 10984, 7880, 5960], // 137
31 => [14744, 11640, 8264, 6344], // 141
32 => [15640, 12328, 8920, 6760], // 145
33 => [16568, 13048, 9368, 7208], // 149
34 => [17528, 13800, 9848, 7688], // 153
35 => [18448, 14496, 10288, 7888], // 157
36 => [19472, 15312, 10832, 8432], // 161
37 => [20528, 15936, 11408, 8768], // 165
38 => [21616, 16816, 12016, 9136], // 169
39 => [22496, 17728, 12656, 9776], // 173
40 => [23648, 18672, 13328, 10208], // 177
// [ L, M, Q, H] // v => modules
[ null, null, null, null], // 0 => will be ignored, index starts at 1
[ 152, 128, 104, 72], // 1 => 21
[ 272, 224, 176, 128], // 2 => 25
[ 440, 352, 272, 208], // 3 => 29
[ 640, 512, 384, 288], // 4 => 33
[ 864, 688, 496, 368], // 5 => 37
[ 1088, 864, 608, 480], // 6 => 41
[ 1248, 992, 704, 528], // 7 => 45
[ 1552, 1232, 880, 688], // 8 => 49
[ 1856, 1456, 1056, 800], // 9 => 53
[ 2192, 1728, 1232, 976], // 10 => 57
[ 2592, 2032, 1440, 1120], // 11 => 61
[ 2960, 2320, 1648, 1264], // 12 => 65
[ 3424, 2672, 1952, 1440], // 13 => 69 NICE!
[ 3688, 2920, 2088, 1576], // 14 => 73
[ 4184, 3320, 2360, 1784], // 15 => 77
[ 4712, 3624, 2600, 2024], // 16 => 81
[ 5176, 4056, 2936, 2264], // 17 => 85
[ 5768, 4504, 3176, 2504], // 18 => 89
[ 6360, 5016, 3560, 2728], // 19 => 93
[ 6888, 5352, 3880, 3080], // 20 => 97
[ 7456, 5712, 4096, 3248], // 21 => 101
[ 8048, 6256, 4544, 3536], // 22 => 105
[ 8752, 6880, 4912, 3712], // 23 => 109
[ 9392, 7312, 5312, 4112], // 24 => 113
[10208, 8000, 5744, 4304], // 25 => 117
[10960, 8496, 6032, 4768], // 26 => 121
[11744, 9024, 6464, 5024], // 27 => 125
[12248, 9544, 6968, 5288], // 28 => 129
[13048, 10136, 7288, 5608], // 29 => 133
[13880, 10984, 7880, 5960], // 30 => 137
[14744, 11640, 8264, 6344], // 31 => 141
[15640, 12328, 8920, 6760], // 32 => 145
[16568, 13048, 9368, 7208], // 33 => 149
[17528, 13800, 9848, 7688], // 34 => 153
[18448, 14496, 10288, 7888], // 35 => 157
[19472, 15312, 10832, 8432], // 36 => 161
[20528, 15936, 11408, 8768], // 37 => 165
[21616, 16816, 12016, 9136], // 38 => 169
[22496, 17728, 12656, 9776], // 39 => 173
[23648, 18672, 13328, 10208], // 40 => 177
];
/**
@@ -203,10 +204,7 @@ final class EccLevel{
* @return int[]
*/
public function getMaxBits():array{
return array_combine(
array_keys(self::MAX_BITS),
array_column(self::MAX_BITS, $this->getOrdinal())
);
return array_column(self::MAX_BITS, $this->getOrdinal());
}
}