clause method

  1. @override
CommandClause clause()
override

Implementation

@override
CommandClause clause() {
  int byteWidth;
  var processer = Pbita(
    command: 'cpcl',
    threshold: _threshold,
    compress: _compress,
    reverse: _reverse,
  );
  var info = processer.processWithBytes(Uint8List.fromList(_image));
  var fimage = info.result;
  if (fimage == null) {
    throw Exception('Wrong image data');
  }
  int width = fimage.width;
  int height = fimage.height;
  if ((width % 8 == 0)) {
    byteWidth = width ~/ 8;
  } else {
    byteWidth = (width / 8 + 1).toInt();
  }
  Command command = Commander.make()
      .pushClause(
        CPCLCommand(header: header())
            .appendNumber(byteWidth)
            .appendNumber(height)
            .appendNumber(_compress ? _startX ~/ 8 : _startX)
            .appendNumber(_startY)
            .appendNumber(_compress ? fimage.data.length : null)
            .clause(),
        newline: false,
      )
      .pushText(" ", newline: false)
      .pushBinary(fimage.data, newline: false)
      .newline()
      .command();

  return Raw.binary(command.binary()).clause();
}