/// <summary> /// Encode the given symbol info to a bit matrix. /// </summary> /// <param name="placement">The DataMatrix placement.</param> /// <param name="symbolInfo">The symbol info to encode.</param> /// <returns>The bit matrix generated.</returns> private static BitMatrix encodeLowLevel(DefaultPlacement placement, SymbolInfo symbolInfo) { int symbolWidth = symbolInfo.getSymbolDataWidth(); int symbolHeight = symbolInfo.getSymbolDataHeight(); var matrix = new ByteMatrix(symbolInfo.getSymbolWidth(), symbolInfo.getSymbolHeight()); int matrixY = 0; for (int y = 0; y < symbolHeight; y++) { // Fill the top edge with alternate 0 / 1 int matrixX; if ((y % symbolInfo.matrixHeight) == 0) { matrixX = 0; for (int x = 0; x < symbolInfo.getSymbolWidth(); x++) { matrix.set(matrixX, matrixY, (x % 2) == 0); matrixX++; } matrixY++; } matrixX = 0; for (int x = 0; x < symbolWidth; x++) { // Fill the right edge with full 1 if ((x % symbolInfo.matrixWidth) == 0) { matrix.set(matrixX, matrixY, true); matrixX++; } matrix.set(matrixX, matrixY, placement.getBit(x, y)); matrixX++; // Fill the right edge with alternate 0 / 1 if ((x % symbolInfo.matrixWidth) == symbolInfo.matrixWidth - 1) { matrix.set(matrixX, matrixY, (y % 2) == 0); matrixX++; } } matrixY++; // Fill the bottom edge with full 1 if ((y % symbolInfo.matrixHeight) == symbolInfo.matrixHeight - 1) { matrixX = 0; for (int x = 0; x < symbolInfo.getSymbolWidth(); x++) { matrix.set(matrixX, matrixY, true); matrixX++; } matrixY++; } } return convertByteMatrixToBitMatrix(matrix); }
/** * Overrides the symbol info set used by this class. Used for testing purposes. * * @param override the symbol info set to use */ public static void overrideSymbolSet(SymbolInfo[] @override) { symbols = @override; }
public void updateSymbolInfo(int len) { if (this.symbolInfo == null || len > this.symbolInfo.dataCapacity) { this.symbolInfo = SymbolInfo.lookup(len, shape, minSize, maxSize, true); } }
public void resetSymbolInfo() { this.symbolInfo = null; }
/// <summary> /// Creates the ECC200 error correction for an encoded message. /// </summary> /// <param name="codewords">The codewords.</param> /// <param name="symbolInfo">information about the symbol to be encoded</param> /// <returns>the codewords with interleaved error correction.</returns> public static String encodeECC200(String codewords, SymbolInfo symbolInfo) { if (codewords.Length != symbolInfo.dataCapacity) { throw new ArgumentException( "The number of codewords does not match the selected symbol"); } var sb = new StringBuilder(symbolInfo.dataCapacity + symbolInfo.errorCodewords); sb.Append(codewords); int blockCount = symbolInfo.getInterleavedBlockCount(); if (blockCount == 1) { String ecc = createECCBlock(codewords, symbolInfo.errorCodewords); sb.Append(ecc); } else { sb.Length = sb.Capacity; int[] dataSizes = new int[blockCount]; int[] errorSizes = new int[blockCount]; int[] startPos = new int[blockCount]; for (int i = 0; i < blockCount; i++) { dataSizes[i] = symbolInfo.getDataLengthForInterleavedBlock(i + 1); errorSizes[i] = symbolInfo.getErrorLengthForInterleavedBlock(i + 1); startPos[i] = 0; if (i > 0) { startPos[i] = startPos[i - 1] + dataSizes[i]; } } for (int block = 0; block < blockCount; block++) { var temp = new StringBuilder(dataSizes[block]); for (int d = block; d < symbolInfo.dataCapacity; d += blockCount) { temp.Append(codewords[d]); } String ecc = createECCBlock(temp.ToString(), errorSizes[block]); int pos = 0; for (int e = block; e < errorSizes[block] * blockCount; e += blockCount) { sb[symbolInfo.dataCapacity + e] = ecc[pos++]; } } } return sb.ToString(); }
public void resetSymbolInfo() { this.symbolInfo = null; }