startDecode method Null safety

  1. @override
WebPInfo? startDecode(
  1. List<int> bytes
)
override

Validate the file is a WebP image and get information about it. If the file is not a valid WebP image, null is returned.

Implementation

@override
WebPInfo? startDecode(List<int> bytes) {
  _input = InputBuffer(bytes);

  if (!_getHeader(_input!)) {
    return null;
  }

  _info = InternalWebPInfo();
  if (!_getInfo(_input!, _info)) {
    return null;
  }

  switch (_info!.format) {
    case WebPInfo.FORMAT_ANIMATED:
      _info!.numFrames = _info!.frames.length;
      return _info;
    case WebPInfo.FORMAT_LOSSLESS:
      _input!.offset = _info!.vp8Position;
      final vp8l = VP8L(_input!, _info!);
      if (!vp8l.decodeHeader()) {
        return null;
      }
      _info!.numFrames = _info!.frames.length;
      return _info;
    case WebPInfo.FORMAT_LOSSY:
      _input!.offset = _info!.vp8Position;
      final vp8 = VP8(_input!, _info!);
      if (!vp8.decodeHeader()) {
        return null;
      }
      _info!.numFrames = _info!.frames.length;
      return _info;
  }

  return null;
}