findDecoderForData function

Decoder findDecoderForData (
  1. List<int> data
)

Find a Decoder that is able to decode the given image data. Use this is you don't know the type of image it is.

Implementation

Decoder findDecoderForData(List<int> data) {
  // The various decoders will be creating a Uint8List for their InputStream
  // if the data isn't already that type, so do it once here to avoid having to
  // do it multiple times.
  Uint8List bytes = Uint8List.fromList(data);

  JpegDecoder jpg = JpegDecoder();
  if (jpg.isValidFile(bytes)) {
    return jpg;
  }

  PngDecoder png = PngDecoder();
  if (png.isValidFile(bytes)) {
    return png;
  }

  GifDecoder gif = GifDecoder();
  if (gif.isValidFile(bytes)) {
    return gif;
  }

  WebPDecoder webp = WebPDecoder();
  if (webp.isValidFile(bytes)) {
    return webp;
  }

  TiffDecoder tiff = TiffDecoder();
  if (tiff.isValidFile(bytes)) {
    return tiff;
  }

  PsdDecoder psd = PsdDecoder();
  if (psd.isValidFile(bytes)) {
    return psd;
  }

  ExrDecoder exr = ExrDecoder();
  if (exr.isValidFile(bytes)) {
    return exr;
  }

  return null;
}