Browse Source

Fix build errors

pull/3096/head
Brian Popow 4 years ago
parent
commit
ea1aaa79c4
  1. 8
      src/ImageSharp/Formats/OpenExr/Compression/Compressors/NoneExrCompression.cs
  2. 8
      src/ImageSharp/Formats/OpenExr/Compression/Compressors/RunLengthCompression.cs
  3. 10
      src/ImageSharp/Formats/OpenExr/Compression/Compressors/ZipExrCompression.cs
  4. 8
      src/ImageSharp/Formats/OpenExr/Compression/ExrBaseCompression.cs
  5. 8
      src/ImageSharp/Formats/OpenExr/Compression/ExrBaseDecompressor.cs
  6. 7
      src/ImageSharp/Formats/OpenExr/Compression/ExrCompressionType.cs
  7. 7
      src/ImageSharp/Formats/OpenExr/Compression/ExrDecompressorFactory.cs
  8. 8
      src/ImageSharp/Formats/OpenExr/ExrAttribute.cs
  9. 7
      src/ImageSharp/Formats/OpenExr/ExrBox2i.cs
  10. 7
      src/ImageSharp/Formats/OpenExr/ExrChannelInfo.cs
  11. 7
      src/ImageSharp/Formats/OpenExr/ExrConfigurationModule.cs
  12. 7
      src/ImageSharp/Formats/OpenExr/ExrConstants.cs
  13. 55
      src/ImageSharp/Formats/OpenExr/ExrDecoder.cs
  14. 28
      src/ImageSharp/Formats/OpenExr/ExrDecoderCore.cs
  15. 13
      src/ImageSharp/Formats/OpenExr/ExrDecoderOptions.cs
  16. 14
      src/ImageSharp/Formats/OpenExr/ExrEncoder.cs
  17. 11
      src/ImageSharp/Formats/OpenExr/ExrEncoderCore.cs
  18. 8
      src/ImageSharp/Formats/OpenExr/ExrFormat.cs
  19. 8
      src/ImageSharp/Formats/OpenExr/ExrHeaderAttributes.cs
  20. 7
      src/ImageSharp/Formats/OpenExr/ExrImageDataType.cs
  21. 8
      src/ImageSharp/Formats/OpenExr/ExrImageFormatDetector.cs
  22. 7
      src/ImageSharp/Formats/OpenExr/ExrImageType.cs
  23. 7
      src/ImageSharp/Formats/OpenExr/ExrLineOrder.cs
  24. 7
      src/ImageSharp/Formats/OpenExr/ExrMetadata.cs
  25. 7
      src/ImageSharp/Formats/OpenExr/ExrPixelType.cs
  26. 8
      src/ImageSharp/Formats/OpenExr/ExrThrowHelper.cs
  27. 12
      src/ImageSharp/Formats/OpenExr/IExrDecoderOptions.cs
  28. 7
      src/ImageSharp/Formats/OpenExr/IExrEncoderOptions.cs
  29. 7
      src/ImageSharp/Formats/OpenExr/MetadataExtensions.cs
  30. 26
      src/ImageSharp/IO/BufferedReadStream.cs
  31. 97
      tests/ImageSharp.Tests/Formats/Exr/ImageExtensionsTest.cs
  32. 5
      tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs

8
src/ImageSharp/Formats/OpenExr/Compression/Compressors/NoneExrCompression.cs

@ -1,12 +1,11 @@
// 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;
using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.OpenExr.Compression.Compressors namespace SixLabors.ImageSharp.Formats.OpenExr.Compression.Compressors;
{
internal class NoneExrCompression : ExrBaseDecompressor internal class NoneExrCompression : ExrBaseDecompressor
{ {
public NoneExrCompression(MemoryAllocator allocator, uint uncompressedBytes) public NoneExrCompression(MemoryAllocator allocator, uint uncompressedBytes)
@ -21,4 +20,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr.Compression.Compressors
{ {
} }
} }
}

8
src/ImageSharp/Formats/OpenExr/Compression/Compressors/RunLengthCompression.cs

@ -1,13 +1,12 @@
// 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;
using System.Buffers; using System.Buffers;
using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.OpenExr.Compression.Compressors namespace SixLabors.ImageSharp.Formats.OpenExr.Compression.Compressors;
{
internal class RunLengthCompression : ExrBaseDecompressor internal class RunLengthCompression : ExrBaseDecompressor
{ {
private readonly IMemoryOwner<byte> tmpBuffer; private readonly IMemoryOwner<byte> tmpBuffer;
@ -91,4 +90,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr.Compression.Compressors
protected override void Dispose(bool disposing) => this.tmpBuffer.Dispose(); protected override void Dispose(bool disposing) => this.tmpBuffer.Dispose();
} }
}

10
src/ImageSharp/Formats/OpenExr/Compression/Compressors/ZipExrCompression.cs

@ -1,15 +1,14 @@
// 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;
using System.Buffers; using System.Buffers;
using System.IO.Compression; using System.IO.Compression;
using SixLabors.ImageSharp.Compression.Zlib; using SixLabors.ImageSharp.Compression.Zlib;
using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.OpenExr.Compression.Compressors namespace SixLabors.ImageSharp.Formats.OpenExr.Compression.Compressors;
{
internal class ZipExrCompression : ExrBaseDecompressor internal class ZipExrCompression : ExrBaseDecompressor
{ {
private readonly IMemoryOwner<byte> tmpBuffer; private readonly IMemoryOwner<byte> tmpBuffer;
@ -22,7 +21,7 @@ namespace SixLabors.ImageSharp.Formats.OpenExr.Compression.Compressors
Span<byte> uncompressed = this.tmpBuffer.GetSpan(); Span<byte> uncompressed = this.tmpBuffer.GetSpan();
long pos = stream.Position; long pos = stream.Position;
using var deframeStream = new ZlibInflateStream( using ZlibInflateStream deframeStream = new(
stream, stream,
() => () =>
{ {
@ -55,4 +54,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr.Compression.Compressors
protected override void Dispose(bool disposing) => this.tmpBuffer.Dispose(); protected override void Dispose(bool disposing) => this.tmpBuffer.Dispose();
} }
}

8
src/ImageSharp/Formats/OpenExr/Compression/ExrBaseCompression.cs

@ -1,11 +1,10 @@
// 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;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.OpenExr.Compression namespace SixLabors.ImageSharp.Formats.OpenExr.Compression;
{
internal abstract class ExrBaseCompression : IDisposable internal abstract class ExrBaseCompression : IDisposable
{ {
private bool isDisposed; private bool isDisposed;
@ -40,4 +39,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr.Compression
protected abstract void Dispose(bool disposing); protected abstract void Dispose(bool disposing);
} }
}

8
src/ImageSharp/Formats/OpenExr/Compression/ExrBaseDecompressor.cs

@ -1,12 +1,11 @@
// 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;
using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.OpenExr.Compression namespace SixLabors.ImageSharp.Formats.OpenExr.Compression;
{
internal abstract class ExrBaseDecompressor : ExrBaseCompression internal abstract class ExrBaseDecompressor : ExrBaseCompression
{ {
protected ExrBaseDecompressor(MemoryAllocator allocator, uint bytePerRow) protected ExrBaseDecompressor(MemoryAllocator allocator, uint bytePerRow)
@ -39,4 +38,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr.Compression
} }
} }
} }
}

7
src/ImageSharp/Formats/OpenExr/Compression/ExrCompressionType.cs

@ -1,8 +1,8 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.OpenExr.Compression;
namespace SixLabors.ImageSharp.Formats.OpenExr.Compression
{
internal enum ExrCompressionType internal enum ExrCompressionType
{ {
/// <summary> /// <summary>
@ -58,4 +58,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr.Compression
/// </summary> /// </summary>
B44A = 7 B44A = 7
} }
}

7
src/ImageSharp/Formats/OpenExr/Compression/ExrDecompressorFactory.cs

@ -1,11 +1,11 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.OpenExr.Compression.Compressors; using SixLabors.ImageSharp.Formats.OpenExr.Compression.Compressors;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
namespace SixLabors.ImageSharp.Formats.OpenExr.Compression namespace SixLabors.ImageSharp.Formats.OpenExr.Compression;
{
internal static class ExrDecompressorFactory internal static class ExrDecompressorFactory
{ {
public static ExrBaseDecompressor Create(ExrCompressionType method, MemoryAllocator memoryAllocator, uint uncompressedBytes) public static ExrBaseDecompressor Create(ExrCompressionType method, MemoryAllocator memoryAllocator, uint uncompressedBytes)
@ -25,4 +25,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr.Compression
} }
} }
} }
}

8
src/ImageSharp/Formats/OpenExr/ExrAttribute.cs

@ -1,10 +1,10 @@
// 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.Diagnostics; using System.Diagnostics;
namespace SixLabors.ImageSharp.Formats.OpenExr namespace SixLabors.ImageSharp.Formats.OpenExr;
{
[DebuggerDisplay("Name: {Name}, Type: {Type}, Length: {Length}")] [DebuggerDisplay("Name: {Name}, Type: {Type}, Length: {Length}")]
internal class ExrAttribute internal class ExrAttribute
{ {
@ -23,4 +23,4 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
public int Length { get; } public int Length { get; }
} }
}

7
src/ImageSharp/Formats/OpenExr/ExrBox2i.cs

@ -1,10 +1,10 @@
// 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.Diagnostics; using System.Diagnostics;
namespace SixLabors.ImageSharp.Formats.OpenExr namespace SixLabors.ImageSharp.Formats.OpenExr;
{
[DebuggerDisplay("xMin: {XMin}, yMin: {YMin}, xMax: {XMax}, yMax: {YMax}")] [DebuggerDisplay("xMin: {XMin}, yMin: {YMin}, xMax: {XMax}, yMax: {YMax}")]
internal struct ExrBox2i internal struct ExrBox2i
{ {
@ -24,4 +24,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
public int YMax { get; } public int YMax { get; }
} }
}

7
src/ImageSharp/Formats/OpenExr/ExrChannelInfo.cs

@ -1,11 +1,11 @@
// 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.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace SixLabors.ImageSharp.Formats.OpenExr namespace SixLabors.ImageSharp.Formats.OpenExr;
{
[DebuggerDisplay("Name: {ChannelName}, PixelType: {PixelType}")] [DebuggerDisplay("Name: {ChannelName}, PixelType: {PixelType}")]
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
internal readonly struct ExrChannelInfo internal readonly struct ExrChannelInfo
@ -29,4 +29,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
public int YSampling { get; } public int YSampling { get; }
} }
}

7
src/ImageSharp/Formats/OpenExr/ExrConfigurationModule.cs

@ -1,8 +1,8 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.OpenExr;
namespace SixLabors.ImageSharp.Formats.OpenExr
{
/// <summary> /// <summary>
/// Registers the image encoders, decoders and mime type detectors for the OpenExr format. /// Registers the image encoders, decoders and mime type detectors for the OpenExr format.
/// </summary> /// </summary>
@ -16,4 +16,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
configuration.ImageFormatsManager.AddImageFormatDetector(new ExrImageFormatDetector()); configuration.ImageFormatsManager.AddImageFormatDetector(new ExrImageFormatDetector());
} }
} }
}

7
src/ImageSharp/Formats/OpenExr/ExrConstants.cs

@ -1,10 +1,8 @@
// 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.Collections.Generic; namespace SixLabors.ImageSharp.Formats.OpenExr;
namespace SixLabors.ImageSharp.Formats.OpenExr
{
/// <summary> /// <summary>
/// Defines constants relating to OpenExr images. /// Defines constants relating to OpenExr images.
/// </summary> /// </summary>
@ -82,4 +80,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
public const string Luminance = "Y"; public const string Luminance = "Y";
} }
} }
}

55
src/ImageSharp/Formats/OpenExr/ExrDecoder.cs

@ -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);
} }

28
src/ImageSharp/Formats/OpenExr/ExrDecoderCore.cs

@ -1,22 +1,18 @@
// 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;
using System.Buffers; using System.Buffers;
using System.Buffers.Binary; using System.Buffers.Binary;
using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading;
using SixLabors.ImageSharp.Formats.OpenExr.Compression; using SixLabors.ImageSharp.Formats.OpenExr.Compression;
using SixLabors.ImageSharp.Formats.Pbm;
using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.OpenExr namespace SixLabors.ImageSharp.Formats.OpenExr;
{
/// <summary> /// <summary>
/// Performs the OpenExr decoding operation. /// Performs the OpenExr decoding operation.
/// </summary> /// </summary>
@ -33,9 +29,9 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
private readonly MemoryAllocator memoryAllocator; private readonly MemoryAllocator memoryAllocator;
/// <summary> /// <summary>
/// The bitmap decoder options. /// The global configuration.
/// </summary> /// </summary>
private readonly IExrDecoderOptions options; private readonly Configuration configuration;
/// <summary> /// <summary>
/// The metadata. /// The metadata.
@ -45,17 +41,16 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ExrDecoderCore"/> class. /// Initializes a new instance of the <see cref="ExrDecoderCore"/> class.
/// </summary> /// </summary>
/// <param name="configuration">The configuration.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
public ExrDecoderCore(Configuration configuration, IExrDecoderOptions options) public ExrDecoderCore(ExrDecoderOptions options)
{ {
this.Configuration = configuration; this.Options = options.GeneralOptions;
this.memoryAllocator = configuration.MemoryAllocator; this.configuration = options.GeneralOptions.Configuration;
this.options = options; this.memoryAllocator = this.configuration.MemoryAllocator;
} }
/// <inheritdoc /> /// <inheritdoc />
public Configuration Configuration { get; } public DecoderOptions Options { get; }
/// <summary> /// <summary>
/// Gets the dimensions of the image. /// Gets the dimensions of the image.
@ -85,7 +80,7 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
ExrPixelType pixelType = this.ValidateChannels(); ExrPixelType pixelType = this.ValidateChannels();
this.ReadImageDataType(); this.ReadImageDataType();
var image = new Image<TPixel>(this.Configuration, this.Width, this.Height, this.metadata); Image<TPixel> image = new Image<TPixel>(this.configuration, this.Width, this.Height, this.metadata);
Buffer2D<TPixel> pixels = image.GetRootFramePixelBuffer(); Buffer2D<TPixel> pixels = image.GetRootFramePixelBuffer();
switch (pixelType) switch (pixelType)
@ -762,4 +757,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
return BinaryPrimitives.ReadInt32LittleEndian(this.buffer); return BinaryPrimitives.ReadInt32LittleEndian(this.buffer);
} }
} }
}

13
src/ImageSharp/Formats/OpenExr/ExrDecoderOptions.cs

@ -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();
}

14
src/ImageSharp/Formats/OpenExr/ExrEncoder.cs

@ -1,14 +1,11 @@
// 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.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.OpenExr namespace SixLabors.ImageSharp.Formats.OpenExr;
{
/// <summary> /// <summary>
/// Image encoder for writing an image to a stream in the OpenExr Format. /// Image encoder for writing an image to a stream in the OpenExr Format.
/// </summary> /// </summary>
@ -23,7 +20,7 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
public void Encode<TPixel>(Image<TPixel> image, Stream stream) public void Encode<TPixel>(Image<TPixel> image, Stream stream)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
var encoder = new ExrEncoderCore(this, image.GetMemoryAllocator()); ExrEncoderCore encoder = new(this, image.GetMemoryAllocator());
encoder.Encode(image, stream); encoder.Encode(image, stream);
} }
@ -31,8 +28,7 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
public Task EncodeAsync<TPixel>(Image<TPixel> image, Stream stream, CancellationToken cancellationToken) public Task EncodeAsync<TPixel>(Image<TPixel> image, Stream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
var encoder = new ExrEncoderCore(this, image.GetMemoryAllocator()); ExrEncoderCore encoder = new(this, image.GetMemoryAllocator());
return encoder.EncodeAsync(image, stream, cancellationToken); return encoder.EncodeAsync(image, stream, cancellationToken);
} }
} }
}

11
src/ImageSharp/Formats/OpenExr/ExrEncoderCore.cs

@ -1,20 +1,16 @@
// 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;
using System.Buffers; using System.Buffers;
using System.Buffers.Binary; using System.Buffers.Binary;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading;
using SixLabors.ImageSharp.Formats.OpenExr.Compression; using SixLabors.ImageSharp.Formats.OpenExr.Compression;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.OpenExr namespace SixLabors.ImageSharp.Formats.OpenExr;
{
/// <summary> /// <summary>
/// Image encoder for writing an image to a stream in the OpenExr format. /// Image encoder for writing an image to a stream in the OpenExr format.
/// </summary> /// </summary>
@ -419,4 +415,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
stream.Write(this.buffer.AsSpan(0, 4)); stream.Write(this.buffer.AsSpan(0, 4));
} }
} }
}

8
src/ImageSharp/Formats/OpenExr/ExrFormat.cs

@ -1,11 +1,8 @@
// 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.Collections.Generic; namespace SixLabors.ImageSharp.Formats.OpenExr;
using SixLabors.ImageSharp.Formats.Bmp;
namespace SixLabors.ImageSharp.Formats.OpenExr
{
/// <summary> /// <summary>
/// Registers the image encoders, decoders and mime type detectors for the OpenExr format. /// Registers the image encoders, decoders and mime type detectors for the OpenExr format.
/// </summary> /// </summary>
@ -35,4 +32,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
/// <inheritdoc/> /// <inheritdoc/>
public ExrMetadata CreateDefaultFormatMetadata() => new(); public ExrMetadata CreateDefaultFormatMetadata() => new();
} }
}

8
src/ImageSharp/Formats/OpenExr/ExrHeaderAttributes.cs

@ -1,11 +1,10 @@
// 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.Collections.Generic;
using SixLabors.ImageSharp.Formats.OpenExr.Compression; using SixLabors.ImageSharp.Formats.OpenExr.Compression;
namespace SixLabors.ImageSharp.Formats.OpenExr namespace SixLabors.ImageSharp.Formats.OpenExr;
{
internal class ExrHeaderAttributes internal class ExrHeaderAttributes
{ {
public IList<ExrChannelInfo> Channels { get; set; } public IList<ExrChannelInfo> Channels { get; set; }
@ -75,4 +74,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
return true; return true;
} }
} }
}

7
src/ImageSharp/Formats/OpenExr/ExrImageDataType.cs

@ -1,8 +1,8 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.OpenExr;
namespace SixLabors.ImageSharp.Formats.OpenExr
{
internal enum ExrImageDataType internal enum ExrImageDataType
{ {
Unknown = 0, Unknown = 0,
@ -13,4 +13,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
Gray = 3, Gray = 3,
} }
}

8
src/ImageSharp/Formats/OpenExr/ExrImageFormatDetector.cs

@ -1,11 +1,10 @@
// 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;
using System.Buffers.Binary; using System.Buffers.Binary;
namespace SixLabors.ImageSharp.Formats.OpenExr namespace SixLabors.ImageSharp.Formats.OpenExr;
{
/// <summary> /// <summary>
/// Detects OpenExr file headers. /// Detects OpenExr file headers.
/// </summary> /// </summary>
@ -28,4 +27,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
return false; return false;
} }
} }
}

7
src/ImageSharp/Formats/OpenExr/ExrImageType.cs

@ -1,12 +1,11 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.OpenExr;
namespace SixLabors.ImageSharp.Formats.OpenExr
{
internal enum ExrImageType internal enum ExrImageType
{ {
ScanLine = 0, ScanLine = 0,
Tiled = 1 Tiled = 1
} }
}

7
src/ImageSharp/Formats/OpenExr/ExrLineOrder.cs

@ -1,8 +1,8 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.OpenExr;
namespace SixLabors.ImageSharp.Formats.OpenExr
{
internal enum ExrLineOrder : byte internal enum ExrLineOrder : byte
{ {
IncreasingY = 0, IncreasingY = 0,
@ -11,4 +11,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
RandomY = 2 RandomY = 2
} }
}

7
src/ImageSharp/Formats/OpenExr/ExrMetadata.cs

@ -1,8 +1,8 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.OpenExr;
namespace SixLabors.ImageSharp.Formats.OpenExr
{
/// <summary> /// <summary>
/// Provides OpenExr specific metadata information for the image. /// Provides OpenExr specific metadata information for the image.
/// </summary> /// </summary>
@ -29,4 +29,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
/// <inheritdoc/> /// <inheritdoc/>
public IDeepCloneable DeepClone() => new ExrMetadata(this); public IDeepCloneable DeepClone() => new ExrMetadata(this);
} }
}

7
src/ImageSharp/Formats/OpenExr/ExrPixelType.cs

@ -1,8 +1,8 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.OpenExr;
namespace SixLabors.ImageSharp.Formats.OpenExr
{
/// <summary> /// <summary>
/// The different pixel formats for a OpenEXR image. /// The different pixel formats for a OpenEXR image.
/// </summary> /// </summary>
@ -23,4 +23,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
/// </summary> /// </summary>
Float = 2 Float = 2
} }
}

8
src/ImageSharp/Formats/OpenExr/ExrThrowHelper.cs

@ -1,11 +1,10 @@
// 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;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Formats.OpenExr namespace SixLabors.ImageSharp.Formats.OpenExr;
{
/// <summary> /// <summary>
/// Cold path optimizations for throwing exr format based exceptions. /// Cold path optimizations for throwing exr format based exceptions.
/// </summary> /// </summary>
@ -29,4 +28,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
[MethodImpl(InliningOptions.ColdPath)] [MethodImpl(InliningOptions.ColdPath)]
public static void ThrowInvalidImageHeader(string msg) => throw new InvalidImageContentException(msg); public static void ThrowInvalidImageHeader(string msg) => throw new InvalidImageContentException(msg);
} }
}

12
src/ImageSharp/Formats/OpenExr/IExrDecoderOptions.cs

@ -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
{
}
}

7
src/ImageSharp/Formats/OpenExr/IExrEncoderOptions.cs

@ -1,8 +1,8 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Formats.OpenExr;
namespace SixLabors.ImageSharp.Formats.OpenExr
{
/// <summary> /// <summary>
/// Configuration options for use during OpenExr encoding. /// Configuration options for use during OpenExr encoding.
/// </summary> /// </summary>
@ -13,4 +13,3 @@ namespace SixLabors.ImageSharp.Formats.OpenExr
/// </summary> /// </summary>
ExrPixelType? PixelType { get; } ExrPixelType? PixelType { get; }
} }
}

7
src/ImageSharp/Formats/OpenExr/MetadataExtensions.cs

@ -1,11 +1,11 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.OpenExr; using SixLabors.ImageSharp.Formats.OpenExr;
using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.Metadata;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp;
{
/// <summary> /// <summary>
/// Extension methods for the <see cref="ImageMetadata"/> type. /// Extension methods for the <see cref="ImageMetadata"/> type.
/// </summary> /// </summary>
@ -18,4 +18,3 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="ExrMetadata"/>.</returns> /// <returns>The <see cref="ExrMetadata"/>.</returns>
public static ExrMetadata GetExrMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(ExrFormat.Instance); public static ExrMetadata GetExrMetadata(this ImageMetadata metadata) => metadata.GetFormatMetadata(ExrFormat.Instance);
} }
}

26
src/ImageSharp/IO/BufferedReadStream.cs

@ -2,6 +2,7 @@
// Licensed under the Six Labors Split License. // Licensed under the Six Labors Split License.
using System.Buffers; using System.Buffers;
using System.Buffers.Binary;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.IO; namespace SixLabors.ImageSharp.IO;
@ -153,6 +154,31 @@ internal sealed class BufferedReadStream : Stream
} }
} }
/// <summary>
/// Reads a float value.
/// </summary>
/// <returns>The value.</returns>
public float ReadSingle(byte[] data)
{
int offset = 0;
int bytesToRead = 4;
while (bytesToRead > 0)
{
int bytesRead = this.Read(data, offset, bytesToRead);
if (bytesRead == 0)
{
throw new ImageFormatException("Not enough data to read a float value from the stream");
}
bytesToRead -= bytesRead;
offset += bytesRead;
}
int intValue = BinaryPrimitives.ReadInt32BigEndian(data);
return Unsafe.As<int, float>(ref intValue);
}
/// <inheritdoc/> /// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int Read(byte[] buffer, int offset, int count) public override int Read(byte[] buffer, int offset, int count)

97
tests/ImageSharp.Tests/Formats/Exr/ImageExtensionsTest.cs

@ -1,86 +1,15 @@
// Copyright (c) Six Labors. // Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System.IO;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.OpenExr; using SixLabors.ImageSharp.Formats.OpenExr;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.Exr namespace SixLabors.ImageSharp.Tests.Formats.Exr;
{
[Trait("Format", "Exr")] [Trait("Format", "Exr")]
public class ImageExtensionsTest public class ImageExtensionsTest
{ {
[Fact]
public void SaveAsExr_Path()
{
string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageExtensionsTest));
string file = Path.Combine(dir, "SaveAsExr_Path.exr");
using (var image = new Image<Rgba32>(10, 10))
{
image.SaveAsOpenExr(file);
}
using (Image.Load(file, out IImageFormat mime))
{
Assert.Equal("image/x-exr", mime.DefaultMimeType);
}
}
[Fact]
public async Task SaveAsExrAsync_Path()
{
string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageExtensionsTest));
string file = Path.Combine(dir, "SaveAsExrAsync_Path.exr");
using (var image = new Image<Rgba32>(10, 10))
{
await image.SaveAsOpenExrAsync(file);
}
using (Image.Load(file, out IImageFormat mime))
{
Assert.Equal("image/x-exr", mime.DefaultMimeType);
}
}
[Fact]
public void SaveAsExr_Path_Encoder()
{
string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageExtensions));
string file = Path.Combine(dir, "SaveAsExr_Path_Encoder.exr");
using (var image = new Image<Rgba32>(10, 10))
{
image.SaveAsOpenExr(file, new ExrEncoder());
}
using (Image.Load(file, out IImageFormat mime))
{
Assert.Equal("image/x-exr", mime.DefaultMimeType);
}
}
[Fact]
public async Task SaveAsExrAsync_Path_Encoder()
{
string dir = TestEnvironment.CreateOutputDirectory(nameof(ImageExtensions));
string file = Path.Combine(dir, "SaveAsExrAsync_Path_Encoder.tiff");
using (var image = new Image<Rgba32>(10, 10))
{
await image.SaveAsOpenExrAsync(file, new ExrEncoder());
}
using (Image.Load(file, out IImageFormat mime))
{
Assert.Equal("image/x-exr", mime.DefaultMimeType);
}
}
[Fact] [Fact]
public void SaveAsExr_Stream() public void SaveAsExr_Stream()
{ {
@ -88,25 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Exr
using (var image = new Image<Rgba32>(10, 10)) using (var image = new Image<Rgba32>(10, 10))
{ {
image.SaveAsOpenExr(memoryStream); image.SaveAsOpenExr(memoryStream, new ExrEncoder());
}
memoryStream.Position = 0;
using (Image.Load(memoryStream, out IImageFormat mime))
{
Assert.Equal("image/x-exr", mime.DefaultMimeType);
}
}
[Fact]
public async Task SaveAsExrAsync_StreamAsync()
{
using var memoryStream = new MemoryStream();
using (var image = new Image<Rgba32>(10, 10))
{
await image.SaveAsOpenExrAsync(memoryStream);
} }
memoryStream.Position = 0; memoryStream.Position = 0;
@ -153,4 +64,4 @@ namespace SixLabors.ImageSharp.Tests.Formats.Exr
} }
} }
} }
}

5
tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs

@ -144,11 +144,6 @@ public class GeneralFormatTests
{ {
image.SaveAsTiff(output); image.SaveAsTiff(output);
} }
using (FileStream output = File.OpenWrite(Path.Combine(path, $"{file.FileNameWithoutExtension}.exr")))
{
image.SaveAsOpenExr(output);
}
} }
} }

Loading…
Cancel
Save