addFrame method Null safety

void addFrame(
  1. Image image
)

Implementation

void addFrame(Image image) {
  xOffset = image.xOffset;
  yOffset = image.xOffset;
  delay = image.duration;
  disposeMethod = image.disposeMethod;
  blendMethod = image.blendMethod;

  if (output == null) {
    output = OutputBuffer(bigEndian: true);

    channels = image.channels;
    _width = image.width;
    _height = image.height;

    _writeHeader(_width, _height);

    _writeICCPChunk(output, image.iccProfile);

    if (isAnimated) {
      _writeAnimationControlChunk();
    }
  }

  // Include room for the filter bytes (1 byte per row).
  final filteredImage = Uint8List(
      (image.width * image.height * image.numberOfChannels) + image.height);

  _filter(image, filteredImage);

  final compressed = ZLibEncoder().encode(filteredImage, level: level);

  if (isAnimated) {
    _writeFrameControlChunk();
    sequenceNumber++;
  }

  if (sequenceNumber <= 1) {
    _writeChunk(output!, 'IDAT', compressed);
  } else {
    // fdAT chunk
    final fdat = OutputBuffer(bigEndian: true);
    fdat.writeUint32(sequenceNumber);
    fdat.writeBytes(compressed);
    _writeChunk(output!, 'fdAT', fdat.getBytes());

    sequenceNumber++;
  }
}