convert method

  1. @override
Barcode2DMatrix convert(
  1. Uint8List data
)
override

Actual barcode computation method, returns a matrix of bool which represents the presence or absence of a pixel

Implementation

@override
Barcode2DMatrix convert(Uint8List data) {
  final dataWords = _highlevelEncode(data);

  final dim = _calcDimensions(
    dataWords.length,
    _errorCorrectionWordCount(securityLevel),
  );
  if (dim.columns < _minCols ||
      dim.columns > _maxCols ||
      dim.rows < _minRows ||
      dim.rows > _maxRows) {
    throw const BarcodeException('Unable to fit data in barcode');
  }

  final codeWords = _encodeData(
    dataWords.toList(),
    dim.columns,
    securityLevel,
  );

  final grid = <List<int>>[];
  for (var i = 0; i < codeWords.length; i += dim.columns) {
    grid.add(codeWords.sublist(i, min(i + dim.columns, codeWords.length)));
  }

  final codes = <List<int>>[];

  var rowNum = 0;
  for (final row in grid) {
    final table = rowNum % 3;
    final rowCodes = <int>[];

    rowCodes.add(startWord);
    rowCodes.add(
      _getCodeword(
        table,
        _getLeftCodeWord(rowNum, dim.rows, dim.columns, securityLevel),
      ),
    );

    for (final word in row) {
      rowCodes.add(_getCodeword(table, word));
    }

    rowCodes.add(
      _getCodeword(
        table,
        _getRightCodeWord(rowNum, dim.rows, dim.columns, securityLevel),
      ),
    );
    rowCodes.add(stopWord);

    codes.add(rowCodes);

    rowNum++;
  }

  final width = (dim.columns + 4) * 17 + 1;

  return Barcode2DMatrix(
    width,
    dim.rows,
    moduleHeight,
    _renderBarcode(codes),
  );
}