WicDecoderProvider decodes through a pull chain (decoder, Fant scaler to MaxLongEdge, format converter) read in bounded row bands. Integer sources are requested as 64bppRGBA and linearised with the exact sRGB EOTF (Linear16); float/fixed sources as 128bppRGBAFloat (scRGB, already linear). The Exif orientation (photo policy, then raw IFD queries) is applied while de-interleaving instead of through IWICBitmapFlipRotator, which Microsoft documents as quadratic over scanline decoders. CodecInventory enumerates installed decoders (CreateComponentEnumerator), probes HEVC/AV1 decoders with MFTEnumEx and identifies the Raw Image Extension by package family, since it shares the in-box RAW codec's CLSID. It maps every ImageFileFormat to its decoder, native flag and the Store extensions (product ids, ms-windows-store links) that would unlock it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
67 lines
2.7 KiB
C#
67 lines
2.7 KiB
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace Titano.Core.Windows.Codecs;
|
|
|
|
/// <summary>
|
|
/// Detects HEVC and AV1 decoders with <c>MFTEnumEx</c>, the check Microsoft documents for the codecs that HEIC and
|
|
/// AVIF decoding through WIC depend on (HEVC / AV1 Video Extensions or a vendor hardware decoder).
|
|
/// </summary>
|
|
internal static unsafe partial class VideoDecoderProbe
|
|
{
|
|
/// <summary>MFVideoFormat_HEVC (FOURCC 'HEVC').</summary>
|
|
public static readonly Guid Hevc = new("43564548-0000-0010-8000-00aa00389b71");
|
|
|
|
/// <summary>MFVideoFormat_AV1 (FOURCC 'AV01').</summary>
|
|
public static readonly Guid Av1 = new("31305641-0000-0010-8000-00aa00389b71");
|
|
|
|
private static readonly Guid VideoDecoderCategory = new("d6c02d4b-6833-45b4-971a-05a4b04bab91");
|
|
private static readonly Guid MediaTypeVideo = new("73646976-0000-0010-8000-00aa00389b71");
|
|
|
|
private const uint MF_VERSION = 0x00020070;
|
|
private const uint MFSTARTUP_LITE = 0x1;
|
|
private const uint MFT_ENUM_FLAG_SYNCMFT = 0x1, MFT_ENUM_FLAG_ASYNCMFT = 0x2, MFT_ENUM_FLAG_HARDWARE = 0x4, MFT_ENUM_FLAG_SORTANDFILTER = 0x40;
|
|
|
|
/// <summary>True when at least one decoder MFT accepts the video <paramref name="subtype"/>.</summary>
|
|
public static bool HasDecoder(Guid subtype)
|
|
{
|
|
try
|
|
{
|
|
if (MFStartup(MF_VERSION, MFSTARTUP_LITE) < 0) return false;
|
|
try
|
|
{
|
|
var input = new MftRegisterTypeInfo { MajorType = MediaTypeVideo, Subtype = subtype };
|
|
const uint flags = MFT_ENUM_FLAG_SYNCMFT | MFT_ENUM_FLAG_ASYNCMFT | MFT_ENUM_FLAG_HARDWARE | MFT_ENUM_FLAG_SORTANDFILTER;
|
|
if (MFTEnumEx(VideoDecoderCategory, flags, &input, null, out var activates, out var count) < 0) return false;
|
|
for (var i = 0; i < count; i++) Marshal.Release(((nint*)activates)[i]);
|
|
Marshal.FreeCoTaskMem(activates);
|
|
return count > 0;
|
|
}
|
|
finally
|
|
{
|
|
MFShutdown();
|
|
}
|
|
}
|
|
catch (DllNotFoundException)
|
|
{
|
|
// Windows "N" editions ship without Media Foundation unless the Media Feature Pack is installed.
|
|
return false;
|
|
}
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
private struct MftRegisterTypeInfo
|
|
{
|
|
public Guid MajorType;
|
|
public Guid Subtype;
|
|
}
|
|
|
|
[LibraryImport("mfplat.dll")]
|
|
private static partial int MFStartup(uint version, uint flags);
|
|
|
|
[LibraryImport("mfplat.dll")]
|
|
private static partial int MFShutdown();
|
|
|
|
[LibraryImport("mfplat.dll")]
|
|
private static partial int MFTEnumEx(Guid category, uint flags, MftRegisterTypeInfo* inputType, MftRegisterTypeInfo* outputType, out nint activates, out uint count);
|
|
}
|