mirror of https://github.com/SixLabors/ImageSharp
32 changed files with 1558 additions and 1690 deletions
@ -1,61 +1,46 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Apache License, Version 2.0.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
using System.IO; |
|
||||
using System.Threading; |
|
||||
using System.Threading.Tasks; |
|
||||
using SixLabors.ImageSharp.PixelFormats; |
using SixLabors.ImageSharp.PixelFormats; |
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.OpenExr |
namespace SixLabors.ImageSharp.Formats.OpenExr; |
||||
{ |
|
||||
/// <summary>
|
/// <summary>
|
||||
/// Image decoder for generating an image out of a OpenExr stream.
|
/// Image decoder for generating an image out of a OpenExr stream.
|
||||
/// </summary>
|
/// </summary>
|
||||
public sealed class ExrDecoder : IImageDecoder, IExrDecoderOptions, IImageInfoDetector |
public class ExrDecoder : IImageDecoderSpecialized<ExrDecoderOptions> |
||||
{ |
{ |
||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream) |
IImageInfo IImageInfoDetector.Identify(DecoderOptions options, Stream stream, CancellationToken cancellationToken) |
||||
where TPixel : unmanaged, IPixel<TPixel> |
|
||||
{ |
{ |
||||
|
Guard.NotNull(options, nameof(options)); |
||||
Guard.NotNull(stream, nameof(stream)); |
Guard.NotNull(stream, nameof(stream)); |
||||
|
|
||||
var decoder = new ExrDecoderCore(configuration, this); |
return new ExrDecoderCore(new() { GeneralOptions = options }).Identify(options.Configuration, stream, cancellationToken); |
||||
return decoder.Decode<TPixel>(configuration, stream); |
|
||||
} |
} |
||||
|
|
||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||
public Image Decode(Configuration configuration, Stream stream) |
Image<TPixel> IImageDecoder.Decode<TPixel>(DecoderOptions options, Stream stream, CancellationToken cancellationToken) |
||||
=> this.Decode<Rgba32>(configuration, stream); |
=> ((IImageDecoderSpecialized<ExrDecoderOptions>)this).Decode<TPixel>(new() { GeneralOptions = options }, stream, cancellationToken); |
||||
|
|
||||
/// <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 ExrDecoderCore(configuration, this); |
|
||||
return decoder.DecodeAsync<TPixel>(configuration, stream, cancellationToken); |
|
||||
} |
|
||||
|
|
||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||
public async Task<Image> DecodeAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken) |
Image IImageDecoder.Decode(DecoderOptions options, Stream stream, CancellationToken cancellationToken) |
||||
=> await this.DecodeAsync<Rgba32>(configuration, stream, cancellationToken) |
=> ((IImageDecoderSpecialized<ExrDecoderOptions>)this).Decode(new() { GeneralOptions = options }, stream, cancellationToken); |
||||
.ConfigureAwait(false); |
|
||||
|
|
||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||
public IImageInfo Identify(Configuration configuration, Stream stream) |
Image<TPixel> IImageDecoderSpecialized<ExrDecoderOptions>.Decode<TPixel>(ExrDecoderOptions options, Stream stream, CancellationToken cancellationToken) |
||||
{ |
{ |
||||
|
Guard.NotNull(options, nameof(options)); |
||||
Guard.NotNull(stream, nameof(stream)); |
Guard.NotNull(stream, nameof(stream)); |
||||
|
|
||||
return new ExrDecoderCore(configuration, this).Identify(configuration, stream); |
Image<TPixel> image = new ExrDecoderCore(options).Decode<TPixel>(options.GeneralOptions.Configuration, stream, cancellationToken); |
||||
} |
|
||||
|
|
||||
/// <inheritdoc/>
|
ImageDecoderUtilities.Resize(options.GeneralOptions, image); |
||||
public Task<IImageInfo> IdentifyAsync(Configuration configuration, Stream stream, CancellationToken cancellationToken) |
|
||||
{ |
|
||||
Guard.NotNull(stream, nameof(stream)); |
|
||||
|
|
||||
return new ExrDecoderCore(configuration, this).IdentifyAsync(configuration, stream, cancellationToken); |
return image; |
||||
} |
|
||||
} |
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
Image IImageDecoderSpecialized<ExrDecoderOptions>.Decode(ExrDecoderOptions options, Stream stream, CancellationToken cancellationToken) |
||||
|
=> ((IImageDecoderSpecialized<ExrDecoderOptions>)this).Decode<Rgba32>(options, stream, cancellationToken); |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,13 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.OpenExr; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Image decoder options for decoding OpenExr streams.
|
||||
|
/// </summary>
|
||||
|
public sealed class ExrDecoderOptions : ISpecializedDecoderOptions |
||||
|
{ |
||||
|
/// <inheritdoc/>
|
||||
|
public DecoderOptions GeneralOptions { get; set; } = new(); |
||||
|
} |
||||
@ -1,12 +0,0 @@ |
|||||
// Copyright (c) Six Labors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.OpenExr |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Image decoder options for decoding OpenExr streams.
|
|
||||
/// </summary>
|
|
||||
internal interface IExrDecoderOptions |
|
||||
{ |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue