decodeAnimation method

  1. @override
Animation? decodeAnimation(
  1. List<int> bytes
)

Decode all of the frames from an animation. If the file is not an animation, a single frame animation is returned. If there was a problem decoding the file, null is returned.

Implementation

@override
Animation? decodeAnimation(List<int> bytes) {
  if (startDecode(bytes) == null) {
    return null;
  }

  final anim = Animation();
  anim.width = _info!.width;
  anim.height = _info!.height;

  if (!_info!.isAnimated) {
    final image = decodeFrame(0)!;
    anim.addFrame(image);
    return anim;
  }

  int? dispose = PngFrame.APNG_DISPOSE_OP_BACKGROUND;
  var lastImage = Image(_info!.width, _info!.height);
  for (var i = 0; i < _info!.numFrames; ++i) {
    //_frame = i;
    lastImage = Image.from(lastImage);

    final frame = _info!.frames[i];
    final image = decodeFrame(i);
    if (image == null) {
      continue;
    }

    if (dispose == PngFrame.APNG_DISPOSE_OP_BACKGROUND ||
        dispose == PngFrame.APNG_DISPOSE_OP_PREVIOUS) {
      lastImage.fill(_info!.backgroundColor);
    }
    copyInto(lastImage, image,
        dstX: frame.xOffset,
        dstY: frame.yOffset,
        blend: frame.blend == PngFrame.APNG_BLEND_OP_OVER);
    anim.addFrame(lastImage);

    dispose = frame.dispose;
  }

  return anim;
}