Source/NFX/Media/TagCodes/QR/QREncoderMatrix.cs
/// <summary>
/// According to JISX0510:2004 (p.30) tbl 12 in 8.5.1
/// Calculate data and correction bytes for block
/// </summary>
/// <param name="numTotalBytes">Total bytes count</param>
/// <param name="numDataBytes">Data bytes count</param>
/// <param name="numRSBlocks">Reed/Solomon blocks count</param>
/// <param name="blockID">Block Id</param>
/// <param name="numDataBytesInBlock">Data bytes count in this block</param>
/// <param name="numECBytesInBlock">Correction bytes count in this block</param>
According to JISX0510:2004 (p.30) tbl 12 in 8.5.1
Calculate data and correction bytes for block
According to JISX0510 : 2004 ( p . 30 ) tbl 12 in 8 . 5 . 1 Calculate data and correction bytes for block
public static void GetNumDataBytesAndNumCorrectionBytesByBlockID(int numTotalBytes, int numDataBytes, int numRSBlocks,
                                                         int blockID, int[] numDataBytesInBlock, int[] numECBytesInBlock)
      {
        if (blockID >= numRSBlocks)
          throw new NFXException(StringConsts.ARGUMENT_ERROR + typeof(QREncoderMatrix).Name + ".getNumDataBytesAndNumECBytesForBlockID(blockID<numRSBlocks)");
        int numRsBlocksInGroup2 = numTotalBytes % numRSBlocks;
        int numRsBlocksInGroup1 = numRSBlocks - numRsBlocksInGroup2;
        int numTotalBytesInGroup1 = numTotalBytes / numRSBlocks;
        int numTotalBytesInGroup2 = numTotalBytesInGroup1 + 1;
        int numDataBytesInGroup1 = numDataBytes / numRSBlocks;
        int numDataBytesInGroup2 = numDataBytesInGroup1 + 1;
        int numEcBytesInGroup1 = numTotalBytesInGroup1 - numDataBytesInGroup1;
        int numEcBytesInGroup2 = numTotalBytesInGroup2 - numDataBytesInGroup2;
        if (numEcBytesInGroup1 != numEcBytesInGroup2)
          throw new NFXException(StringConsts.CODE_LOGIC_ERROR + typeof(QREncoderMatrix).Name +
            ".getNumDataBytesAndNumECBytesForBlockID: numEcBytesInGroup1!=numEcBytesInGroup2");
        if (numRSBlocks != numRsBlocksInGroup1 + numRsBlocksInGroup2)
          throw new NFXException(StringConsts.CODE_LOGIC_ERROR + typeof(QREncoderMatrix).Name +
            ".getNumDataBytesAndNumECBytesForBlockID: numRSBlocks != numRsBlocksInGroup1 + numRsBlocksInGroup2");
        if (numTotalBytes !=
            ((numDataBytesInGroup1 + numEcBytesInGroup1) *
                numRsBlocksInGroup1) +
                ((numDataBytesInGroup2 + numEcBytesInGroup2) *
                    numRsBlocksInGroup2))
          throw new NFXException(StringConsts.CODE_LOGIC_ERROR + typeof(QREncoderMatrix).Name +
            ".getNumDataBytesAndNumECBytesForBlockID: numTotalBytes!=((numDataBytesInGroup1+numEcBytesInGroup1)*numRsBlocksInGroup1)+((numDataBytesInGroup2+numEcBytesInGroup2)*numRsBlocksInGroup2)");
        if (blockID < numRsBlocksInGroup1)
        {
          numDataBytesInBlock[0] = numDataBytesInGroup1;
          numECBytesInBlock[0] = numEcBytesInGroup1;
        }
        else
        {
          numDataBytesInBlock[0] = numDataBytesInGroup2;
          numECBytesInBlock[0] = numEcBytesInGroup2;
        }
      }
public static void GetNumDataBytesAndNumCorrectionBytesByBlockID ( int numTotalBytes , int numDataBytes , int numRSBlocks , int blockID , int [ ] numDataBytesInBlock , int [ ] numECBytesInBlock ) { if ( blockID >= numRSBlocks ) throw new NFXException ( StringConsts . ARGUMENT_ERROR + typeof ( QREncoderMatrix ) . Name + " " ) ; int numRsBlocksInGroup2 = numTotalBytes % numRSBlocks ; int numRsBlocksInGroup1 = numRSBlocks - numRsBlocksInGroup2 ; int numTotalBytesInGroup1 = numTotalBytes / numRSBlocks ; int numTotalBytesInGroup2 = numTotalBytesInGroup1 + 1 ; int numDataBytesInGroup1 = numDataBytes / numRSBlocks ; int numDataBytesInGroup2 = numDataBytesInGroup1 + 1 ; int numEcBytesInGroup1 = numTotalBytesInGroup1 - numDataBytesInGroup1 ; int numEcBytesInGroup2 = numTotalBytesInGroup2 - numDataBytesInGroup2 ; if ( numEcBytesInGroup1 != numEcBytesInGroup2 ) throw new NFXException ( StringConsts . CODE_LOGIC_ERROR + typeof ( QREncoderMatrix ) . Name + " " ) ; if ( numRSBlocks != numRsBlocksInGroup1 + numRsBlocksInGroup2 ) throw new NFXException ( StringConsts . CODE_LOGIC_ERROR + typeof ( QREncoderMatrix ) . Name + " " ) ; if ( numTotalBytes != ( ( numDataBytesInGroup1 + numEcBytesInGroup1 ) * numRsBlocksInGroup1 ) + ( ( numDataBytesInGroup2 + numEcBytesInGroup2 ) * numRsBlocksInGroup2 ) ) throw new NFXException ( StringConsts . CODE_LOGIC_ERROR + typeof ( QREncoderMatrix ) . Name + " " ) ; if ( blockID < numRsBlocksInGroup1 ) { numDataBytesInBlock [ 0 ] = numDataBytesInGroup1 ; numECBytesInBlock [ 0 ] = numEcBytesInGroup1 ; } else { numDataBytesInBlock [ 0 ] = numDataBytesInGroup2 ; numECBytesInBlock [ 0 ] = numEcBytesInGroup2 ; } }
According to JISX0510:2004 (p.30) tbl 12 in 8.5.1
Calculate data and correction bytes for block
According to JISX0510 : 2004 ( p . 30 ) tbl 12 in 8 . 5 . 1 Calculate data and correction bytes for block
numTotalBytes
int
Total bytes count
Total bytes count
numDataBytes
int
Data bytes count
Data bytes count
numRSBlocks
int
Reed/Solomon blocks count
Reed / Solomon blocks count
blockID
int
None
numDataBytesInBlock
int[]
Data bytes count in this block
Data bytes count in this block
numECBytesInBlock
int[]
Correction bytes count in this block
Correction bytes count in this block