startDecode method

  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 WebPFormat.animated:
      _info!.numFrames = _info!.frames.length;
      return _info;
    case WebPFormat.lossless:
      _input!.offset = _info!.vp8Position;
      final vp8l = VP8L(_input!, _info!);
      if (!vp8l.decodeHeader()) {
        return null;
      }
      _info!.numFrames = _info!.frames.length;
      return _info;
    case WebPFormat.lossy:
      _input!.offset = _info!.vp8Position;
      final vp8 = VP8(_input!, _info!);
      if (!vp8.decodeHeader()) {
        return null;
      }
      _info!.numFrames = _info!.frames.length;
      return _info;
    case WebPFormat.undefined:
      throw ImageException("Unknown format for WebP");
  }
}