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.
  var bytes = data is Uint8List ? data : Uint8List.fromList(data);

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

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

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

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

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

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

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

  var bmp = BmpDecoder();
  if (bmp.isValidFile(bytes)) {
    return bmp;
  }

  var tga = TgaDecoder();
  if (tga.isValidFile(bytes)) {
    return tga;
  }

  return null;
}