{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE RecordWildCards #-}

module Codec.QRCode.Code.Data
  ( qrSize
  , QRInternal
  , calcVersionAndErrorLevel
  , appendEndAndPadding
  , appendErrorCorrection
  ) where

import           Codec.QRCode.Base

import qualified Data.Vector.Unboxed                       as UV

import           Codec.QRCode.Code.ReedSolomonEncoder
import qualified Codec.QRCode.Data.ByteStreamBuilder       as BSB
import           Codec.QRCode.Data.ErrorLevel
import           Codec.QRCode.Data.Mask
import           Codec.QRCode.Data.QRCodeOptions
import           Codec.QRCode.Data.QRIntermediate.Internal
import           Codec.QRCode.Data.QRSegment.Internal
import           Codec.QRCode.Data.Result
import           Codec.QRCode.Data.Version

-- | Calculates the size of a QR code (in modules) based on the version.
qrSize :: Version -> Int
{-# INLINE qrSize #-}
qrSize :: Version -> Int
qrSize Version
ver = Int
17 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Version -> Int
unVersion Version
ver Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
4

-- | The data all encoder pass around
type QRInternal t = (Version, ErrorLevel, t, Maybe Mask)

-- | Determine `Version` and `ErrorLevel` based on the `QRCodeOptions` and the data to encode.
calcVersionAndErrorLevel :: QRCodeOptions -> QRSegment -> Result QRIntermediate
calcVersionAndErrorLevel :: QRCodeOptions -> QRSegment -> Result QRIntermediate
calcVersionAndErrorLevel QRCodeOptions{Bool
Int
Maybe Mask
ErrorLevel
qroMask :: QRCodeOptions -> Maybe Mask
qroBoostErrorLevel :: QRCodeOptions -> Bool
qroErrorLevel :: QRCodeOptions -> ErrorLevel
qroMaxVersion :: QRCodeOptions -> Int
qroMinVersion :: QRCodeOptions -> Int
qroMask :: Maybe Mask
qroBoostErrorLevel :: Bool
qroErrorLevel :: ErrorLevel
qroMaxVersion :: Int
qroMinVersion :: Int
..} QRSegment
input =
  -- Run though all tree `VersionRange`s and return the first matching.
  -- This ensures that the input stream is only encoded once per `VersionRange` and not for each `Version`.
  (VersionRange -> Result QRIntermediate)
-> [VersionRange] -> Result QRIntermediate
forall a b. (a -> Result b) -> [a] -> Result b
firstSuccess VersionRange -> Result QRIntermediate
checkSizeVR [Item [VersionRange]
forall a. Bounded a => a
minBound .. Item [VersionRange]
forall a. Bounded a => a
maxBound]
  where
    -- Run though all `Version`s of the `VersionRange` which are permitted by the options and return the first matching.
    checkSizeVR :: VersionRange -> Result QRIntermediate
    checkSizeVR :: VersionRange -> Result QRIntermediate
checkSizeVR VersionRange
vr = do
      let
        versions :: [Version]
versions = VersionRange -> Int -> Int -> [Version]
versionsInRangeLimitedBy VersionRange
vr Int
qroMinVersion Int
qroMaxVersion
      Bool -> Result ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not ([Version] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Version]
versions))
      ByteStreamBuilder
stream <- QRSegment -> VersionRange -> Result ByteStreamBuilder
unQRSegment QRSegment
input VersionRange
vr
      Bool -> Result ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Bool
not (ByteStreamBuilder -> Bool
BSB.null ByteStreamBuilder
stream))
      (Version -> Result QRIntermediate)
-> [Version] -> Result QRIntermediate
forall a b. (a -> Result b) -> [a] -> Result b
firstSuccess (ByteStreamBuilder -> Version -> Result QRIntermediate
checkSize ByteStreamBuilder
stream) [Version]
versions
    -- Check if the data fits into a specific `Version`.
    checkSize :: BSB.ByteStreamBuilder -> Version -> Result QRIntermediate
    checkSize :: ByteStreamBuilder -> Version -> Result QRIntermediate
checkSize ByteStreamBuilder
bs Version
v = do
      let
        bsl :: Int
bsl = ByteStreamBuilder -> Int
BSB.length ByteStreamBuilder
bs
      -- Try all allowed `ErrorLevel`s and chose the one with most error correction which fits the data.
      ErrorLevel
el <- (ErrorLevel -> Bool) -> [ErrorLevel] -> Result ErrorLevel
forall a. (a -> Bool) -> [a] -> Result a
firstMatch (\ErrorLevel
e -> Int
bsl Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Version -> ErrorLevel -> Int
numDataCodeWords Version
v ErrorLevel
e) [ErrorLevel]
errorLevels
      QRIntermediate -> Result QRIntermediate
forall (f :: * -> *) a. Applicative f => a -> f a
pure (QRIntermediate -> Result QRIntermediate)
-> QRIntermediate -> Result QRIntermediate
forall a b. (a -> b) -> a -> b
$
        Version
-> ErrorLevel
-> Int
-> ByteStreamBuilder
-> Maybe Mask
-> QRIntermediate
QRIntermediate Version
v ErrorLevel
el Int
bsl ByteStreamBuilder
bs Maybe Mask
qroMask
    -- Allowed `ErrorLevel`s: Either just one, or the specified and all with "better" error correction if boost is selected.
    errorLevels :: [ErrorLevel]
    errorLevels :: [ErrorLevel]
errorLevels
      | Bool
qroBoostErrorLevel = [Item [ErrorLevel]
ErrorLevel
H, Item [ErrorLevel]
ErrorLevel
Q .. Item [ErrorLevel]
ErrorLevel
qroErrorLevel]
      | Bool
otherwise = [Item [ErrorLevel]
ErrorLevel
qroErrorLevel]
    -- Helper to pick the first successful calculation.
    firstSuccess :: (a -> Result b) -> [a] -> Result b
    firstSuccess :: (a -> Result b) -> [a] -> Result b
firstSuccess a -> Result b
fn = (a -> Result b -> Result b) -> Result b -> [a] -> Result b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Result b -> Result b -> Result b
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>) (Result b -> Result b -> Result b)
-> (a -> Result b) -> a -> Result b -> Result b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Result b
fn) Result b
forall (f :: * -> *) a. Alternative f => f a
empty
    -- Helper to pick the first matching result.
    firstMatch :: (a -> Bool) -> [a] -> Result a
    firstMatch :: (a -> Bool) -> [a] -> Result a
firstMatch a -> Bool
fn = (a -> Result a) -> [a] -> Result a
forall a b. (a -> Result b) -> [a] -> Result b
firstSuccess (\a
e -> Result a -> Result a -> Bool -> Result a
forall a. a -> a -> Bool -> a
bool Result a
forall (f :: * -> *) a. Alternative f => f a
empty (a -> Result a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
e) (a -> Bool
fn a
e))

-- | Add the End marker, pad to a full byte (with 0) and pad all further unused bytes (with 0xEC11).
appendEndAndPadding :: QRIntermediate -> QRInternal BSB.ByteStreamBuilder
appendEndAndPadding :: QRIntermediate -> QRInternal ByteStreamBuilder
appendEndAndPadding (QRIntermediate Version
v ErrorLevel
e Int
bsl ByteStreamBuilder
bs Maybe Mask
mmask) =
  let
    -- Capacity of the data part
    capacity :: Int
capacity = Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Version -> ErrorLevel -> Int
numDataCodeWords Version
v ErrorLevel
e
    -- The number of End bits to add (may be less than 4 if there is not enough space)
    endLen :: Int
endLen = Int
4 Int -> Int -> Int
forall a. Ord a => a -> a -> a
`min` (Int
capacity Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
bsl)
    -- Pad until a full Byte
    pad0Len :: Int
pad0Len = Int -> Int
forall a. Num a => a -> a
negate (Int
bsl Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
endLen) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
8
    -- Pad all other unused Bytes
    padEC11Len :: Int
padEC11Len = Int
capacity Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Int
bsl Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
endLen Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
pad0Len)
  in
    (Version
v, ErrorLevel
e, ByteStreamBuilder
bs ByteStreamBuilder -> ByteStreamBuilder -> ByteStreamBuilder
forall a. Semigroup a => a -> a -> a
<> Int -> Int -> ByteStreamBuilder
BSB.encodeBits (Int
endLen Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
pad0Len) Int
0 ByteStreamBuilder -> ByteStreamBuilder -> ByteStreamBuilder
forall a. Semigroup a => a -> a -> a
<> [Word8] -> ByteStreamBuilder
BSB.fromList (Int -> [Word8] -> [Word8]
forall a. Int -> [a] -> [a]
take (Int
padEC11Len Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
8) ([Word8] -> [Word8]
forall a. [a] -> [a]
cycle [Item [Word8]
0xec, Item [Word8]
0x11])), Maybe Mask
mmask)

-- | Append the appropriate error correction to the data.
appendErrorCorrection :: QRInternal BSB.ByteStreamBuilder -> QRInternal [Word8]
appendErrorCorrection :: QRInternal ByteStreamBuilder -> QRInternal [Word8]
appendErrorCorrection (Version
v, ErrorLevel
e, ByteStreamBuilder
bs, Maybe Mask
mmask) =
  let
    numBlocks :: Int
numBlocks = Version -> ErrorLevel -> Int
numErrorCorrectionBlocks Version
v ErrorLevel
e
    blockEccLen :: Int
blockEccLen = Version -> ErrorLevel -> Int
eccCodeWordsPerBlock Version
v ErrorLevel
e
    rawCodeWords :: Int
rawCodeWords = Version -> Int
numRawDataModules Version
v Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
8
    numShortBlocks :: Int
numShortBlocks = Int
numBlocks Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Int
rawCodeWords Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
numBlocks)
    shortBlockLen :: Int
shortBlockLen = Int
rawCodeWords Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
numBlocks
    generatorPolynomial :: RsGeneratorPolynomial
generatorPolynomial = Int -> RsGeneratorPolynomial
rsGeneratorPolynomial Int
blockEccLen
    dataBlockLens :: [Int]
dataBlockLens = [Int
shortBlockLen Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
blockEccLen Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int -> Int -> Bool -> Int
forall a. a -> a -> Bool -> a
bool Int
0 Int
1 (Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
numShortBlocks) | Int
x <- [Item [Int]
0 .. Int
numBlocks Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]]
    dataBlocks :: [[Word8]]
dataBlocks = ([Word8], [[Word8]]) -> [[Word8]]
forall a b. (a, b) -> b
snd (([Word8], [[Word8]]) -> [[Word8]])
-> ([Word8], [[Word8]]) -> [[Word8]]
forall a b. (a -> b) -> a -> b
$ ([Word8] -> Int -> ([Word8], [Word8]))
-> [Word8] -> [Int] -> ([Word8], [[Word8]])
forall (t :: * -> *) a b c.
Traversable t =>
(a -> b -> (a, c)) -> a -> t b -> (a, t c)
mapAccumL (\[Word8]
da Int
len -> ([Word8], [Word8]) -> ([Word8], [Word8])
forall a b. (a, b) -> (b, a)
swap (Int -> [Word8] -> ([Word8], [Word8])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
len [Word8]
da)) (ByteStreamBuilder -> [Word8]
BSB.toList ByteStreamBuilder
bs) [Int]
dataBlockLens
    eccBlocks :: [[Word8]]
eccBlocks = ([Word8] -> [Word8]) -> [[Word8]] -> [[Word8]]
forall a b. (a -> b) -> [a] -> [b]
map (RsGeneratorPolynomial -> [Word8] -> [Word8]
rsEncode RsGeneratorPolynomial
generatorPolynomial) [[Word8]]
dataBlocks
    interleaved :: [[Word8]]
interleaved = [[Word8]] -> [[Word8]]
forall a. [[a]] -> [[a]]
transpose [[Word8]]
dataBlocks [[Word8]] -> [[Word8]] -> [[Word8]]
forall a. [a] -> [a] -> [a]
++ [[Word8]] -> [[Word8]]
forall a. [[a]] -> [[a]]
transpose [[Word8]]
eccBlocks
  in
    (Version
v, ErrorLevel
e, [[Word8]] -> [Word8]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[Word8]]
interleaved, Maybe Mask
mmask)

-- Returns the number of 8-bit data (i.e. not error correction) code words contained in any
-- QR Code of the given version number and error correction level, with remainder bits discarded.
numDataCodeWords :: Version -> ErrorLevel -> Int
{-# INLINABLE numDataCodeWords #-}
numDataCodeWords :: Version -> ErrorLevel -> Int
numDataCodeWords Version
v ErrorLevel
e =
  Version -> Int
numRawDataModules Version
v Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
8
  Int -> Int -> Int
forall a. Num a => a -> a -> a
- Version -> ErrorLevel -> Int
eccCodeWordsPerBlock Version
v ErrorLevel
e
  Int -> Int -> Int
forall a. Num a => a -> a -> a
* Version -> ErrorLevel -> Int
numErrorCorrectionBlocks Version
v ErrorLevel
e

-- Returns the number of bits that can be stored in a QR Code of the given version number, after
-- all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
numRawDataModules :: Version -> Int
numRawDataModules :: Version -> Int
numRawDataModules Version
ver =
  let
    size :: Int
size = Version -> Int
qrSize Version
ver
    v2 :: Int
v2
      | Version -> Int
unVersion Version
ver Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
2 = Int
0
      | Bool
otherwise =
        let
          numAlign :: Int
numAlign = Version -> Int
unVersion Version
ver Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
7 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
2
        in
           - (Int
numAlign Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
numAlign Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
25 -- Subtract alignment patterns not overlapping with timing patterns
           Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Int
numAlign Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
2) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
20 -- Subtract alignment patterns that overlap with timing patterns
    v7 :: Int
v7
      | Version -> Int
unVersion Version
ver Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
7 = Int
0
      | Bool
otherwise = - Int
18 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
2 -- Subtract version information
  in
    Int
size Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
size -- Number of modules in the whole QR symbol square
    Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
64 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
3 --  Subtract the three finders with separators
    Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Int
15 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) --  Subtract the format information and black module
    Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Int
size Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
16) Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
2 -- Subtract the timing patterns
    Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
v2
    Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
v7

eccCodeWordsPerBlock :: Version -> ErrorLevel -> Int
{-# INLINE eccCodeWordsPerBlock #-}
eccCodeWordsPerBlock :: Version -> ErrorLevel -> Int
eccCodeWordsPerBlock Version
v ErrorLevel
e = Vector Int
eccCodeWordsPerBlockData Vector Int -> Int -> Int
forall a. Unbox a => Vector a -> Int -> a
UV.! (ErrorLevel -> Int
forall a. Enum a => a -> Int
fromEnum ErrorLevel
e Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
40 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Version -> Int
unVersion Version
v Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)

eccCodeWordsPerBlockData :: UV.Vector Int
{-# NOINLINE eccCodeWordsPerBlockData #-}
eccCodeWordsPerBlockData :: Vector Int
eccCodeWordsPerBlockData =
  [ --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      Error correction level
      Item (Vector Int)
7, Item (Vector Int)
10, Item (Vector Int)
15, Item (Vector Int)
20, Item (Vector Int)
26, Item (Vector Int)
18, Item (Vector Int)
20, Item (Vector Int)
24, Item (Vector Int)
30, Item (Vector Int)
18, Item (Vector Int)
20, Item (Vector Int)
24, Item (Vector Int)
26, Item (Vector Int)
30, Item (Vector Int)
22, Item (Vector Int)
24, Item (Vector Int)
28, Item (Vector Int)
30, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
26, Item (Vector Int)
28, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30,  -- Low
     Item (Vector Int)
10, Item (Vector Int)
16, Item (Vector Int)
26, Item (Vector Int)
18, Item (Vector Int)
24, Item (Vector Int)
16, Item (Vector Int)
18, Item (Vector Int)
22, Item (Vector Int)
22, Item (Vector Int)
26, Item (Vector Int)
30, Item (Vector Int)
22, Item (Vector Int)
22, Item (Vector Int)
24, Item (Vector Int)
24, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
26, Item (Vector Int)
26, Item (Vector Int)
26, Item (Vector Int)
26, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
28,  -- Medium
     Item (Vector Int)
13, Item (Vector Int)
22, Item (Vector Int)
18, Item (Vector Int)
26, Item (Vector Int)
18, Item (Vector Int)
24, Item (Vector Int)
18, Item (Vector Int)
22, Item (Vector Int)
20, Item (Vector Int)
24, Item (Vector Int)
28, Item (Vector Int)
26, Item (Vector Int)
24, Item (Vector Int)
20, Item (Vector Int)
30, Item (Vector Int)
24, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
26, Item (Vector Int)
30, Item (Vector Int)
28, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
28, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30,  -- Quartile
     Item (Vector Int)
17, Item (Vector Int)
28, Item (Vector Int)
22, Item (Vector Int)
16, Item (Vector Int)
22, Item (Vector Int)
28, Item (Vector Int)
26, Item (Vector Int)
26, Item (Vector Int)
24, Item (Vector Int)
28, Item (Vector Int)
24, Item (Vector Int)
28, Item (Vector Int)
22, Item (Vector Int)
24, Item (Vector Int)
24, Item (Vector Int)
30, Item (Vector Int)
28, Item (Vector Int)
28, Item (Vector Int)
26, Item (Vector Int)
28, Item (Vector Int)
30, Item (Vector Int)
24, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30, Item (Vector Int)
30   -- High
  ]

numErrorCorrectionBlocks :: Version -> ErrorLevel -> Int
{-# INLINE numErrorCorrectionBlocks #-}
numErrorCorrectionBlocks :: Version -> ErrorLevel -> Int
numErrorCorrectionBlocks Version
v ErrorLevel
e = Vector Int
numErrorCorrectionBlocksData Vector Int -> Int -> Int
forall a. Unbox a => Vector a -> Int -> a
UV.! (ErrorLevel -> Int
forall a. Enum a => a -> Int
fromEnum ErrorLevel
e Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
40 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Version -> Int
unVersion Version
v Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)

numErrorCorrectionBlocksData :: UV.Vector Int
{-# NOINLINE numErrorCorrectionBlocksData #-}
numErrorCorrectionBlocksData :: Vector Int
numErrorCorrectionBlocksData =
  [ --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      Error correction level
      Item (Vector Int)
1, Item (Vector Int)
1, Item (Vector Int)
1, Item (Vector Int)
1, Item (Vector Int)
1, Item (Vector Int)
2, Item (Vector Int)
2, Item (Vector Int)
2, Item (Vector Int)
2,  Item (Vector Int)
4,  Item (Vector Int)
4,  Item (Vector Int)
4,  Item (Vector Int)
4,  Item (Vector Int)
4,  Item (Vector Int)
6,  Item (Vector Int)
6,  Item (Vector Int)
6,  Item (Vector Int)
6,  Item (Vector Int)
7,  Item (Vector Int)
8,  Item (Vector Int)
8,  Item (Vector Int)
9,  Item (Vector Int)
9, Item (Vector Int)
10, Item (Vector Int)
12, Item (Vector Int)
12, Item (Vector Int)
12, Item (Vector Int)
13, Item (Vector Int)
14, Item (Vector Int)
15, Item (Vector Int)
16, Item (Vector Int)
17, Item (Vector Int)
18, Item (Vector Int)
19, Item (Vector Int)
19, Item (Vector Int)
20, Item (Vector Int)
21, Item (Vector Int)
22, Item (Vector Int)
24, Item (Vector Int)
25,  -- Low
      Item (Vector Int)
1, Item (Vector Int)
1, Item (Vector Int)
1, Item (Vector Int)
2, Item (Vector Int)
2, Item (Vector Int)
4, Item (Vector Int)
4, Item (Vector Int)
4, Item (Vector Int)
5,  Item (Vector Int)
5,  Item (Vector Int)
5,  Item (Vector Int)
8,  Item (Vector Int)
9,  Item (Vector Int)
9, Item (Vector Int)
10, Item (Vector Int)
10, Item (Vector Int)
11, Item (Vector Int)
13, Item (Vector Int)
14, Item (Vector Int)
16, Item (Vector Int)
17, Item (Vector Int)
17, Item (Vector Int)
18, Item (Vector Int)
20, Item (Vector Int)
21, Item (Vector Int)
23, Item (Vector Int)
25, Item (Vector Int)
26, Item (Vector Int)
28, Item (Vector Int)
29, Item (Vector Int)
31, Item (Vector Int)
33, Item (Vector Int)
35, Item (Vector Int)
37, Item (Vector Int)
38, Item (Vector Int)
40, Item (Vector Int)
43, Item (Vector Int)
45, Item (Vector Int)
47, Item (Vector Int)
49,  -- Medium
      Item (Vector Int)
1, Item (Vector Int)
1, Item (Vector Int)
2, Item (Vector Int)
2, Item (Vector Int)
4, Item (Vector Int)
4, Item (Vector Int)
6, Item (Vector Int)
6, Item (Vector Int)
8,  Item (Vector Int)
8,  Item (Vector Int)
8, Item (Vector Int)
10, Item (Vector Int)
12, Item (Vector Int)
16, Item (Vector Int)
12, Item (Vector Int)
17, Item (Vector Int)
16, Item (Vector Int)
18, Item (Vector Int)
21, Item (Vector Int)
20, Item (Vector Int)
23, Item (Vector Int)
23, Item (Vector Int)
25, Item (Vector Int)
27, Item (Vector Int)
29, Item (Vector Int)
34, Item (Vector Int)
34, Item (Vector Int)
35, Item (Vector Int)
38, Item (Vector Int)
40, Item (Vector Int)
43, Item (Vector Int)
45, Item (Vector Int)
48, Item (Vector Int)
51, Item (Vector Int)
53, Item (Vector Int)
56, Item (Vector Int)
59, Item (Vector Int)
62, Item (Vector Int)
65, Item (Vector Int)
68,  -- Quartile
      Item (Vector Int)
1, Item (Vector Int)
1, Item (Vector Int)
2, Item (Vector Int)
4, Item (Vector Int)
4, Item (Vector Int)
4, Item (Vector Int)
5, Item (Vector Int)
6, Item (Vector Int)
8,  Item (Vector Int)
8, Item (Vector Int)
11, Item (Vector Int)
11, Item (Vector Int)
16, Item (Vector Int)
16, Item (Vector Int)
18, Item (Vector Int)
16, Item (Vector Int)
19, Item (Vector Int)
21, Item (Vector Int)
25, Item (Vector Int)
25, Item (Vector Int)
25, Item (Vector Int)
34, Item (Vector Int)
30, Item (Vector Int)
32, Item (Vector Int)
35, Item (Vector Int)
37, Item (Vector Int)
40, Item (Vector Int)
42, Item (Vector Int)
45, Item (Vector Int)
48, Item (Vector Int)
51, Item (Vector Int)
54, Item (Vector Int)
57, Item (Vector Int)
60, Item (Vector Int)
63, Item (Vector Int)
66, Item (Vector Int)
70, Item (Vector Int)
74, Item (Vector Int)
77, Item (Vector Int)
81   -- High
  ]