/// <inheritdoc/> public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream) where TPixel : unmanaged, IPixel <TPixel> { Guard.NotNull(stream, nameof(stream)); var decoder = new TgaDecoderCore(configuration, this); return(decoder.Decode <TPixel>(configuration, stream)); }
/// <inheritdoc/> public Task <Image <TPixel> > DecodeAsync <TPixel>(Configuration configuration, Stream stream, CancellationToken cancellationToken) where TPixel : unmanaged, IPixel <TPixel> { Guard.NotNull(stream, nameof(stream)); var decoder = new TgaDecoderCore(configuration, this); return(decoder.DecodeAsync <TPixel>(configuration, stream, cancellationToken)); }
/// <inheritdoc/> public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream) where TPixel : unmanaged, IPixel <TPixel> { Guard.NotNull(stream, nameof(stream)); var decoder = new TgaDecoderCore(configuration, this); try { return(decoder.Decode <TPixel>(stream)); } catch (InvalidMemoryOperationException ex) { Size dims = decoder.Dimensions; // 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: {dims.Width}x{dims.Height}.", ex); } }
/// <inheritdoc/> public Image <TPixel> Decode <TPixel>(Configuration configuration, Stream stream) where TPixel : unmanaged, IPixel <TPixel> { Guard.NotNull(stream, nameof(stream)); var decoder = new TgaDecoderCore(configuration, this); try { return(decoder.Decode <TPixel>(stream)); } catch (InvalidMemoryOperationException ex) { Size dims = decoder.Dimensions; TgaThrowHelper.ThrowInvalidImageContentException($"Can not decode image. Failed to allocate buffers for possibly degenerate dimensions: {dims.Width}x{dims.Height}.", ex); // Not reachable, as the previous statement will throw a exception. return(null); } }