decode method

void decode(
  1. InputBuffer p,
  2. List<int> out
)

Implementation

void decode(InputBuffer p, List<int> out) {
  _out = out;
  final outLen = out.length;
  _outPointer = 0;
  _data = p.buffer as Uint8List;
  _dataLength = _data.length;
  _bytePointer = p.offset;

  if (_data[0] == 0x00 && _data[1] == 0x01) {
    throw ImageException('Invalid LZW Data');
  }

  _initializeStringTable();

  //_bitPointer = 0;
  _nextData = 0;
  _nextBits = 0;

  var oldCode = 0;
  //int num = 0;

  var code = _getNextCode();
  while ((code != 257) && _outPointer < outLen) {
    if (code == 256) {
      _initializeStringTable();
      //num++;
      code = _getNextCode();
      _bufferLength = 0;
      if (code == 257) {
        break;
      }

      _out[_outPointer++] = code;
      oldCode = code;
    } else {
      if (code < _tableIndex!) {
        _getString(code);
        for (var i = _bufferLength - 1; i >= 0; --i) {
          _out[_outPointer++] = _buffer[i];
        }
        _addString(oldCode, _buffer[_bufferLength - 1]);
        oldCode = code;
      } else {
        _getString(oldCode);
        for (var i = _bufferLength - 1; i >= 0; --i) {
          _out[_outPointer++] = _buffer[i];
        }
        _out[_outPointer++] = _buffer[_bufferLength - 1];
        _addString(oldCode, _buffer[_bufferLength - 1]);

        oldCode = code;
      }
    }

    //num++;
    code = _getNextCode();
  }
}