/// <inheritdoc/> public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream) where TPixel : unmanaged, IPixel <TPixel> { Guard.NotNull(stream, nameof(stream)); using var decoder = new JpegDecoderCore(configuration, this); return(decoder.Decode <TPixel>(configuration, stream)); }
/// <inheritdoc/> public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream) where TPixel : struct, IPixel <TPixel> { Guard.NotNull(stream, nameof(stream)); using (var decoder = new JpegDecoderCore(configuration, this)) { return(decoder.Decode <TPixel>(stream)); } }
/// <inheritdoc/> public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream) where TPixel : struct, IPixel <TPixel> { Guard.NotNull(stream, nameof(stream)); using var decoder = new JpegDecoderCore(configuration, this); try { return(decoder.Decode <TPixel>(stream)); } catch (InvalidMemoryOperationException ex) { (int w, int h) = (decoder.ImageWidth, decoder.ImageHeight); // TODO: use InvalidImageContentException here, if we decide to define it // https://github.com/SixLabors/ImageSharp/issues/1110 throw new ImageFormatException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {w}x{h}.", ex); } }
/// <inheritdoc/> public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream) where TPixel : unmanaged, IPixel <TPixel> { Guard.NotNull(stream, nameof(stream)); using var decoder = new JpegDecoderCore(configuration, this); try { return(decoder.Decode <TPixel>(stream)); } catch (InvalidMemoryOperationException ex) { (int w, int h) = (decoder.ImageWidth, decoder.ImageHeight); JpegThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {w}x{h}.", ex); // Not reachable, as the previous statement will throw a exception. return(null); } }