Source/NFX/Media/TagCodes/QR/QREncoderMatrix.cs
/// <summary>
/// According to JISX0510:2004 8.6 p.37 bits are mixed mixes with their correction bytes.
/// </summary>
/// <param name="bits">Data bits</param>
/// <param name="numTotalBytes">Total bytes count</param>
/// <param name="numDataBytes">Data bytes count</param>
/// <param name="rsBlocksQty">Reed/Solomon blocks count</param>
/// <returns>Mixed bits</returns>
According to JISX0510:2004 8.6 p.37 bits are mixed mixes with their correction bytes.
According to JISX0510 : 2004 8 . 6 p . 37 bits are mixed mixes with their correction bytes .
public static BitList MixWithCorrectionBytes(BitList bits, int numTotalBytes, int numDataBytes, int rsBlocksQty)
      {
        if (bits.ByteSize != numDataBytes)
          throw new NFXException(StringConsts.ARGUMENT_ERROR + typeof(QREncoderMatrix).Name + ".interleaveWithECBytes(bits.ByteSize != numDataBytes)");
        int dataBytesOffset = 0;
        int maxNumDataBytes = 0;
        int maxNumEcBytes = 0;
        var blocks = new List<QRDataNCorrection>(rsBlocksQty);
        for (int i = 0; i < rsBlocksQty; ++i)
        {
          int[] numDataBytesInBlock = new int[1];
          int[] numEcBytesInBlock = new int[1];
          GetNumDataBytesAndNumCorrectionBytesByBlockID( numTotalBytes, numDataBytes, rsBlocksQty, i, numDataBytesInBlock, numEcBytesInBlock);
          int size = numDataBytesInBlock[0];
          byte[] dataBytes = new byte[size];
          bits.GetBytes(dataBytes, 8 * dataBytesOffset, 0, size);
          byte[] ecBytes = GetCorrectionBytes(dataBytes, numEcBytesInBlock[0]);
          blocks.Add(new QRDataNCorrection(dataBytes, ecBytes));
          maxNumDataBytes = Math.Max(maxNumDataBytes, size);
          maxNumEcBytes = Math.Max(maxNumEcBytes, ecBytes.Length);
          dataBytesOffset += numDataBytesInBlock[0];
        }
        if (numDataBytes != dataBytesOffset)
          throw new NFXException(StringConsts.CODE_LOGIC_ERROR + typeof(QREncoderMatrix).Name + ".interleaveWithECBytes: numDataBytes!=dataBytesOffset");
        BitList result = new BitList();
        for (int i = 0; i < maxNumDataBytes; ++i)
          foreach (QRDataNCorrection block in blocks)
          {
            byte[] dataBytes = block.Data;
            if (i < dataBytes.Length)
              result.AppendBits(dataBytes[i], 8);
          }
        for (int i = 0; i < maxNumEcBytes; ++i)
          foreach (QRDataNCorrection block in blocks)
          {
            byte[] ecBytes = block.Correction;
            if (i < ecBytes.Length)
              result.AppendBits(ecBytes[i], 8);
          }
        if (numTotalBytes != result.ByteSize)
          throw new NFXException(StringConsts.CODE_LOGIC_ERROR + typeof(QREncoderMatrix).Name + ".interleaveWithECBytes: numTotalBytes!=result.ByteSize");
        return result;
      }
public static BitList MixWithCorrectionBytes ( BitList bits , int numTotalBytes , int numDataBytes , int rsBlocksQty ) { if ( bits . ByteSize != numDataBytes ) throw new NFXException ( StringConsts . ARGUMENT_ERROR + typeof ( QREncoderMatrix ) . Name + " " ) ; int dataBytesOffset = 0 ; int maxNumDataBytes = 0 ; int maxNumEcBytes = 0 ; var blocks = new List < QRDataNCorrection > ( rsBlocksQty ) ; for ( int i = 0 ; i < rsBlocksQty ; ++ i ) { int [ ] numDataBytesInBlock = new int [ 1 ] ; int [ ] numEcBytesInBlock = new int [ 1 ] ; GetNumDataBytesAndNumCorrectionBytesByBlockID ( numTotalBytes , numDataBytes , rsBlocksQty , i , numDataBytesInBlock , numEcBytesInBlock ) ; int size = numDataBytesInBlock [ 0 ] ; byte [ ] dataBytes = new byte [ size ] ; bits . GetBytes ( dataBytes , 8 * dataBytesOffset , 0 , size ) ; byte [ ] ecBytes = GetCorrectionBytes ( dataBytes , numEcBytesInBlock [ 0 ] ) ; blocks . Add ( new QRDataNCorrection ( dataBytes , ecBytes ) ) ; maxNumDataBytes = Math . Max ( maxNumDataBytes , size ) ; maxNumEcBytes = Math . Max ( maxNumEcBytes , ecBytes . Length ) ; dataBytesOffset += numDataBytesInBlock [ 0 ] ; } if ( numDataBytes != dataBytesOffset ) throw new NFXException ( StringConsts . CODE_LOGIC_ERROR + typeof ( QREncoderMatrix ) . Name + " " ) ; BitList result = new BitList ( ) ; for ( int i = 0 ; i < maxNumDataBytes ; ++ i ) foreach ( QRDataNCorrection block in blocks ) { byte [ ] dataBytes = block . Data ; if ( i < dataBytes . Length ) result . AppendBits ( dataBytes [ i ] , 8 ) ; } for ( int i = 0 ; i < maxNumEcBytes ; ++ i ) foreach ( QRDataNCorrection block in blocks ) { byte [ ] ecBytes = block . Correction ; if ( i < ecBytes . Length ) result . AppendBits ( ecBytes [ i ] , 8 ) ; } if ( numTotalBytes != result . ByteSize ) throw new NFXException ( StringConsts . CODE_LOGIC_ERROR + typeof ( QREncoderMatrix ) . Name + " " ) ; return result ; }
According to JISX0510:2004 8.6 p.37 bits are mixed mixes with their correction bytes.
According to JISX0510 : 2004 8 . 6 p . 37 bits are mixed mixes with their correction bytes .
// Split data bytes into blocks. Generate error correction bytes.
None
bits
BitList
None
numTotalBytes
int
Total bytes count
Total bytes count
numDataBytes
int
Data bytes count
Data bytes count
rsBlocksQty
int
Reed/Solomon blocks count
Reed / Solomon blocks count