public static ImageDecoderEnumerator CreateDecoderEnumerator(
            IImagingConfig imagingConfig,
            Stream stream,
            DecoderOptions?decoderOptions       = null,
            CancellationToken cancellationToken = default)
        {
            if (imagingConfig == null)
            {
                throw new ArgumentNullException(nameof(imagingConfig));
            }

            var           prefixStream = imagingConfig.CreateStreamWithHeaderPrefix(stream);
            Memory <byte> prefix       = prefixStream.GetPrefix(cancellationToken);
            ImageFormat?  format       = DetectFormat(imagingConfig, prefix.Span);

            if (format == null)
            {
                if (prefix.Length == 0)
                {
                    throw new UnknownImageFormatException(
                              "No bytes were read from the stream.");
                }
                else
                {
                    throw new UnknownImageFormatException(
                              $"Failed to recognize any format from the first {prefix.Length} bytes.");
                }
            }

            IImageDecoder decoder = imagingConfig.CreateDecoder(prefixStream, format, decoderOptions);

            return(new ImageDecoderEnumerator(decoder, cancellationToken));
        }
        public static ImageInfo Identify(
            IImagingConfig config, Stream stream, CancellationToken cancellationToken = default)
        {
            using var prefixedStream = config.CreateStreamWithHeaderPrefix(stream);
            Memory <byte> prefix = prefixedStream.GetPrefix(cancellationToken);

            ImageFormat?format = DetectFormat(config, prefix.Span);

            if (format == null)
            {
                throw new UnknownImageFormatException();
            }

            var infoDetector = config.GetInfoDetector(format);

            return(infoDetector.Identify(config, prefixedStream, cancellationToken));
        }