Browse Source

Merge in required changes from upstream

pull/2633/head
Ynse Hoornenborg 2 years ago
parent
commit
b8322fc554
  1. 17
      src/ImageSharp/Formats/Heif/HeifDecoderCore.cs
  2. 4
      src/ImageSharp/Formats/Heif/HeifEncoderCore.cs
  3. 40
      src/ImageSharp/Formats/Heif/HeifMetadata.cs
  4. 2
      src/ImageSharp/ImageSharp.csproj
  5. 2
      tests/ImageSharp.Tests/Formats/Heif/HeifEncoderTests.cs

17
src/ImageSharp/Formats/Heif/HeifDecoderCore.cs

@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Heif;
/// <summary>
/// Performs the HEIF decoding operation.
/// </summary>
internal sealed class HeifDecoderCore : IImageDecoderInternals
internal sealed class HeifDecoderCore : ImageDecoderCore
{
/// <summary>
/// The general configuration.
@ -42,8 +42,8 @@ internal sealed class HeifDecoderCore : IImageDecoderInternals
/// </summary>
/// <param name="options">The decoder options.</param>
public HeifDecoderCore(DecoderOptions options)
: base(options)
{
this.Options = options;
this.configuration = options.Configuration;
this.metadata = new ImageMetadata();
this.items = new List<HeifItem>();
@ -51,14 +51,7 @@ internal sealed class HeifDecoderCore : IImageDecoderInternals
}
/// <inheritdoc/>
public DecoderOptions Options { get; }
/// <inheritdoc/>
public Size Dimensions { get; }
/// <inheritdoc/>
public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
where TPixel : unmanaged, IPixel<TPixel>
protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken cancellationToken)
{
if (!this.CheckFileTypeBox(stream))
{
@ -106,7 +99,7 @@ internal sealed class HeifDecoderCore : IImageDecoderInternals
}
/// <inheritdoc/>
public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
protected override ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellationToken)
{
this.CheckFileTypeBox(stream);
@ -134,7 +127,7 @@ internal sealed class HeifDecoderCore : IImageDecoderInternals
this.UpdateMetadata(this.metadata, item);
return new ImageInfo(new PixelTypeInfo(item.BitsPerPixel), new(item.Extent.Width, item.Extent.Height), this.metadata);
return new ImageInfo(new(item.Extent.Width, item.Extent.Height), this.metadata);
}
private bool CheckFileTypeBox(BufferedReadStream stream)

4
src/ImageSharp/Formats/Heif/HeifEncoderCore.cs

@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Formats.Heif;
/// <summary>
/// Image encoder for writing an image to a stream as a HEIF image.
/// </summary>
internal sealed class HeifEncoderCore : IImageEncoderInternals
internal sealed class HeifEncoderCore
{
/// <summary>
/// The global configuration.
@ -326,7 +326,7 @@ internal sealed class HeifEncoderCore : IImageEncoderInternals
using MemoryStream stream = new();
JpegEncoder encoder = new()
{
ColorType = JpegEncodingColor.YCbCrRatio420
ColorType = JpegColorType.YCbCrRatio420
};
await image.SaveAsJpegAsync(stream, encoder, cancellationToken);
return stream.ToArray();

40
src/ImageSharp/Formats/Heif/HeifMetadata.cs

@ -1,12 +1,14 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Formats.Heif;
/// <summary>
/// Provides HEIF specific metadata information for the image.
/// </summary>
public class HeifMetadata : IDeepCloneable
public class HeifMetadata : IFormatMetadata<HeifMetadata>
{
/// <summary>
/// Initializes a new instance of the <see cref="HeifMetadata"/> class.
@ -28,5 +30,39 @@ public class HeifMetadata : IDeepCloneable
public HeifCompressionMethod CompressionMethod { get; set; }
/// <inheritdoc/>
public IDeepCloneable DeepClone() => new HeifMetadata(this);
public static HeifMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata)
{
return new HeifMetadata
{
CompressionMethod = HeifCompressionMethod.LegacyJpeg
};
}
/// <inheritdoc/>
public PixelTypeInfo GetPixelTypeInfo()
{
int bpp = 8;
PixelColorType colorType = PixelColorType.RGB;
PixelComponentInfo info = PixelComponentInfo.Create(3, bpp, 8, 8, 8);
return new PixelTypeInfo(bpp)
{
AlphaRepresentation = PixelAlphaRepresentation.None,
ColorType = colorType,
ComponentInfo = info,
};
}
/// <inheritdoc/>
public FormatConnectingMetadata ToFormatConnectingMetadata()
=> new()
{
PixelTypeInfo = this.GetPixelTypeInfo(),
};
/// <inheritdoc/>
IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone();
/// <inheritdoc/>
public HeifMetadata DeepClone() => new(this);
}

2
src/ImageSharp/ImageSharp.csproj

@ -56,6 +56,7 @@
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Heif4CharCode.tt</DependentUpon>
</Compile>
<Compile Update="Formats\_Generated\ImageMetadataExtensions.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
@ -162,6 +163,7 @@
<None Update="Formats\Heif\Heif4CharCode.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Heif4CharCode.cs</LastGenOutput>
</None>
<None Update="Formats\_Generated\ImageMetadataExtensions.tt">
<LastGenOutput>ImageMetadataExtensions.cs</LastGenOutput>
<Generator>TextTemplatingFileGenerator</Generator>

2
tests/ImageSharp.Tests/Formats/Heif/HeifEncoderTests.cs

@ -17,7 +17,7 @@ public class HeifEncoderTests
public static void Encode<TPixel>(TestImageProvider<TPixel> provider, HeifCompressionMethod compressionMethod)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(new MagickReferenceDecoder());
using Image<TPixel> image = provider.GetImage(new MagickReferenceDecoder(HeifFormat.Instance));
using MemoryStream stream = new();
HeifEncoder encoder = new();
image.Save(stream, encoder);

Loading…
Cancel
Save