decodeAnimation method

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

Decode all of the frames of an animated webp. For single image webps, this will return an animation with a single frame.

Implementation

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

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

  if (_info!.hasAnimation) {
    var lastImage = Image(_info!.width, _info!.height);
    for (var i = 0; i < _info!.numFrames; ++i) {
      _info!.frame = i;
      lastImage = Image.from(lastImage);

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

      if (frame.clearFrame) {
        lastImage.fill(0);
      }
      copyInto(lastImage, image, dstX: frame.x, dstY: frame.y);

      lastImage.duration = frame.duration;
      anim.addFrame(lastImage);
    }
  } else {
    final image = decodeImage(bytes);
    if (image == null) {
      return null;
    }

    anim.addFrame(image);
  }

  return anim;
}