startDecode method

  1. @override
GifInfo? startDecode(
  1. Uint8List bytes
)
override

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

Implementation

@override
GifInfo? startDecode(Uint8List bytes) {
  _input = InputBuffer(bytes);

  info = GifInfo();
  if (!_getInfo()) {
    return null;
  }

  try {
    while (!_input!.isEOS) {
      final recordType = _input!.readByte();
      switch (recordType) {
        case imageDescRecordType:
          final gifImage = _skipImage();
          if (gifImage == null) {
            return info;
          }
          gifImage
            ..duration = _duration
            ..disposal = _disposalMethod;
          if (_transparentFlag != 0) {
            if (gifImage.colorMap == null && info!.globalColorMap != null) {
              gifImage.colorMap = GifColorMap.from(info!.globalColorMap!);
            }
            if (gifImage.colorMap != null) {
              gifImage.colorMap!.transparent = _transparent;
            }
          }
          info!.frames.add(gifImage);
          break;
        case extensionRecordType:
          final extCode = _input!.readByte();
          if (extCode == applicationExt) {
            _readApplicationExt(_input!);
          } else if (extCode == graphicControlExt) {
            _readGraphicsControlExt(_input!);
          } else {
            _skipRemainder();
          }
          break;
        case terminateRecordType:
          //_numFrames = info.numFrames;
          return info;
        default:
          break;
      }
    }
  } catch (error) {
    //
  }

  //_numFrames = info.numFrames;
  return info;
}