// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Buffers.Binary;
using System.Diagnostics.CodeAnalysis;
namespace SixLabors.ImageSharp.Formats.Heic;
///
/// Detects HEIC file headers.
///
public sealed class HeicImageFormatDetector : IImageFormatDetector
{
///
public int HeaderSize => 12;
///
public bool TryDetectFormat(ReadOnlySpan header, [NotNullWhen(true)] out IImageFormat? format)
{
format = IsSupportedFileFormat(header) ? HeicFormat.Instance : null;
return format != null;
}
private static bool IsSupportedFileFormat(ReadOnlySpan header) =>
BinaryPrimitives.ReadUInt32BigEndian(header.Slice(4)) == FourCharacterCode.ftyp &&
BinaryPrimitives.ReadUInt32BigEndian(header.Slice(8)) == FourCharacterCode.heic;
}