decodeFrame method

  1. @override
Image? decodeFrame(
  1. int frame
)
override

Decode a single frame from the data that was set with startDecode. If frame is out of the range of available frames, null is returned. Non animated image files will only have frame 0. An Image is returned, which provides the image, and top-left coordinates of the image, as animated frames may only occupy a subset of the canvas.

Implementation

@override
Image? decodeFrame(int frame) {
  if (_input == null || _info == null) {
    return null;
  }

  if (_info!.hasAnimation) {
    if (frame >= _info!.frames.length || frame < 0) {
      return null;
    }

    final f = _info!.frames[frame] as InternalWebPFrame;
    final frameData = _input!.subset(f.frameSize, position: f.framePosition);

    return _decodeFrame(frameData, frame: frame);
  }

  if (_info!.format == WebPFormat.lossless) {
    final data = _input!.subset(_info!.vp8Size, position: _info!.vp8Position);
    return VP8L(data, _info!).decode();
  } else if (_info!.format == WebPFormat.lossy) {
    final data = _input!.subset(_info!.vp8Size, position: _info!.vp8Position);
    return VP8(data, _info!).decode();
  }

  return null;
}