diff --git a/src/ImageSharp/Formats/Heif/HeifDecoderCore.cs b/src/ImageSharp/Formats/Heif/HeifDecoderCore.cs
index 1c65d6e00..4481aadf7 100644
--- a/src/ImageSharp/Formats/Heif/HeifDecoderCore.cs
+++ b/src/ImageSharp/Formats/Heif/HeifDecoderCore.cs
@@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Formats.Heif;
///
/// Performs the HEIF decoding operation.
///
-internal sealed class HeifDecoderCore : IImageDecoderInternals
+internal sealed class HeifDecoderCore : ImageDecoderCore
{
///
/// The general configuration.
@@ -42,8 +42,8 @@ internal sealed class HeifDecoderCore : IImageDecoderInternals
///
/// The decoder options.
public HeifDecoderCore(DecoderOptions options)
+ : base(options)
{
- this.Options = options;
this.configuration = options.Configuration;
this.metadata = new ImageMetadata();
this.items = new List();
@@ -51,14 +51,7 @@ internal sealed class HeifDecoderCore : IImageDecoderInternals
}
///
- public DecoderOptions Options { get; }
-
- ///
- public Size Dimensions { get; }
-
- ///
- public Image Decode(BufferedReadStream stream, CancellationToken cancellationToken)
- where TPixel : unmanaged, IPixel
+ protected override Image Decode(BufferedReadStream stream, CancellationToken cancellationToken)
{
if (!this.CheckFileTypeBox(stream))
{
@@ -106,7 +99,7 @@ internal sealed class HeifDecoderCore : IImageDecoderInternals
}
///
- 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)
diff --git a/src/ImageSharp/Formats/Heif/HeifEncoderCore.cs b/src/ImageSharp/Formats/Heif/HeifEncoderCore.cs
index 898576811..519aa3200 100644
--- a/src/ImageSharp/Formats/Heif/HeifEncoderCore.cs
+++ b/src/ImageSharp/Formats/Heif/HeifEncoderCore.cs
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Formats.Heif;
///
/// Image encoder for writing an image to a stream as a HEIF image.
///
-internal sealed class HeifEncoderCore : IImageEncoderInternals
+internal sealed class HeifEncoderCore
{
///
/// 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();
diff --git a/src/ImageSharp/Formats/Heif/HeifMetadata.cs b/src/ImageSharp/Formats/Heif/HeifMetadata.cs
index 725389f0e..6bbf8b49e 100644
--- a/src/ImageSharp/Formats/Heif/HeifMetadata.cs
+++ b/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;
///
/// Provides HEIF specific metadata information for the image.
///
-public class HeifMetadata : IDeepCloneable
+public class HeifMetadata : IFormatMetadata
{
///
/// Initializes a new instance of the class.
@@ -28,5 +30,39 @@ public class HeifMetadata : IDeepCloneable
public HeifCompressionMethod CompressionMethod { get; set; }
///
- public IDeepCloneable DeepClone() => new HeifMetadata(this);
+ public static HeifMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata)
+ {
+ return new HeifMetadata
+ {
+ CompressionMethod = HeifCompressionMethod.LegacyJpeg
+ };
+ }
+
+ ///
+ 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,
+ };
+ }
+
+ ///
+ public FormatConnectingMetadata ToFormatConnectingMetadata()
+ => new()
+ {
+ PixelTypeInfo = this.GetPixelTypeInfo(),
+ };
+
+ ///
+ IDeepCloneable IDeepCloneable.DeepClone() => this.DeepClone();
+
+ ///
+ public HeifMetadata DeepClone() => new(this);
}
diff --git a/src/ImageSharp/ImageSharp.csproj b/src/ImageSharp/ImageSharp.csproj
index 156c32840..1d83fbe4a 100644
--- a/src/ImageSharp/ImageSharp.csproj
+++ b/src/ImageSharp/ImageSharp.csproj
@@ -56,6 +56,7 @@
True
True
Heif4CharCode.tt
+
True
True
@@ -162,6 +163,7 @@
TextTemplatingFileGenerator
Heif4CharCode.cs
+
ImageMetadataExtensions.cs
TextTemplatingFileGenerator
diff --git a/tests/ImageSharp.Tests/Formats/Heif/HeifEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Heif/HeifEncoderTests.cs
index c7e0e8832..8826b2103 100644
--- a/tests/ImageSharp.Tests/Formats/Heif/HeifEncoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Heif/HeifEncoderTests.cs
@@ -17,7 +17,7 @@ public class HeifEncoderTests
public static void Encode(TestImageProvider provider, HeifCompressionMethod compressionMethod)
where TPixel : unmanaged, IPixel
{
- using Image image = provider.GetImage(new MagickReferenceDecoder());
+ using Image image = provider.GetImage(new MagickReferenceDecoder(HeifFormat.Instance));
using MemoryStream stream = new();
HeifEncoder encoder = new();
image.Save(stream, encoder);