feat(windows): add WIC decoder provider and codec inventory
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
This commit is contained in:
15 files changed
+1555
No files matched your search
@@ -0,0 +1,27 @@
|
||||
namespace Titano.Core.Windows.Wic;
|
||||
|
||||
/// <summary>
|
||||
/// Where each stored pixel (x, y) of a <c>width</c>×<c>height</c> image lands once Exif orientation 1–8 is applied,
|
||||
/// as a linear index <c>Origin + x·StepX + y·StepY</c> into the row-major oriented image. Applying the orientation
|
||||
/// while de-interleaving costs nothing extra, unlike a WIC flip-rotator over a scanline decoder.
|
||||
/// </summary>
|
||||
internal readonly record struct OrientationMap(int Width, int Height, int Origin, int StepX, int StepY)
|
||||
{
|
||||
/// <summary>Orientations 5–8 swap width and height.</summary>
|
||||
public static bool SwapsAxes(int orientation) => orientation is >= 5 and <= 8;
|
||||
|
||||
/// <summary>Map for a stored <paramref name="width"/>×<paramref name="height"/> image; unknown values act as 1.</summary>
|
||||
public static OrientationMap Create(int orientation, int width, int height) => orientation switch
|
||||
{
|
||||
2 => new(width, height, width - 1, -1, width), // mirror horizontal
|
||||
3 => new(width, height, (height * width) - 1, -1, -width), // rotate 180°
|
||||
4 => new(width, height, (height - 1) * width, 1, -width), // mirror vertical
|
||||
5 => new(height, width, 0, height, 1), // transpose
|
||||
6 => new(height, width, height - 1, height, -1), // rotate 90° clockwise
|
||||
7 => new(height, width, (width * height) - 1, -height, -1), // transverse
|
||||
8 => new(height, width, (width - 1) * height, -height, 1), // rotate 90° counter-clockwise
|
||||
_ => new(width, height, 0, 1, width),
|
||||
};
|
||||
|
||||
public int IndexOf(int x, int y) => Origin + (x * StepX) + (y * StepY);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Windows.Codecs;
|
||||
using Titano.Core.Windows.Interop;
|
||||
|
||||
namespace Titano.Core.Windows.Wic;
|
||||
|
||||
/// <summary>Enumerates installed WIC decoders through <c>IWICImagingFactory::CreateComponentEnumerator</c>.</summary>
|
||||
internal static class WicComponents
|
||||
{
|
||||
private const uint ComponentDecoder = 0x1;
|
||||
private const uint EnumerateRefresh = 0x1;
|
||||
private const uint EnumerateUnsigned = 0x40000000;
|
||||
|
||||
/// <summary>
|
||||
/// Every enabled decoder, signed or not (third-party camera codecs are often unsigned and WIC still uses them).
|
||||
/// <paramref name="refresh"/> makes WIC re-read the registrations, e.g. after a Store extension was installed.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<WicDecoderInfo> EnumerateDecoders(bool refresh)
|
||||
{
|
||||
Win32Com.EnsureInitialized();
|
||||
var decoders = new List<WicDecoderInfo>();
|
||||
var enumerator = WicFactory.Instance.CreateComponentEnumerator(ComponentDecoder, EnumerateUnsigned | (refresh ? EnumerateRefresh : 0));
|
||||
try
|
||||
{
|
||||
while (enumerator.Next(1, out var unknown, out var fetched) == 0 && fetched == 1)
|
||||
{
|
||||
object? component = null;
|
||||
try
|
||||
{
|
||||
component = Marshal.GetObjectForIUnknown(unknown);
|
||||
if (component is IWICBitmapDecoderInfo info) decoders.Add(Read(info));
|
||||
}
|
||||
catch (COMException ex)
|
||||
{
|
||||
Log.Warning("wic", "Skipped a WIC decoder whose registration could not be read", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.Release(unknown);
|
||||
Win32Com.Release(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
Win32Com.Release(enumerator);
|
||||
}
|
||||
return decoders;
|
||||
}
|
||||
|
||||
/// <summary>Reads a component-info string through the "ask for the length, then fill" protocol.</summary>
|
||||
public static unsafe string ReadString(WicStringGetter getter)
|
||||
{
|
||||
if (getter(0, null, out var length) < 0 || length <= 1) return string.Empty;
|
||||
var buffer = new char[length];
|
||||
int hr;
|
||||
fixed (char* p = buffer)
|
||||
{
|
||||
hr = getter(length, p, out length);
|
||||
}
|
||||
if (hr < 0) return string.Empty;
|
||||
var text = buffer.AsSpan(0, (int)Math.Min(length, (uint)buffer.Length));
|
||||
var end = text.IndexOf('\0');
|
||||
return new string(end >= 0 ? text[..end] : text);
|
||||
}
|
||||
|
||||
// Lambdas call through the interface normally rather than binding delegates to COM methods.
|
||||
private static unsafe WicDecoderInfo Read(IWICBitmapDecoderInfo info) => new(
|
||||
FriendlyName: ReadString((uint capacity, char* buffer, out uint length) => info.GetFriendlyName(capacity, buffer, out length)),
|
||||
Clsid: info.GetCLSID(),
|
||||
ContainerFormat: info.GetContainerFormat(),
|
||||
Vendor: info.GetVendorGUID(),
|
||||
Version: ReadString((uint capacity, char* buffer, out uint length) => info.GetVersion(capacity, buffer, out length)),
|
||||
FileExtensions: WicDecoderInfo.ParseExtensions(
|
||||
ReadString((uint capacity, char* buffer, out uint length) => info.GetFileExtensions(capacity, buffer, out length))),
|
||||
Extension: null);
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
using System.Buffers;
|
||||
using System.Runtime.InteropServices;
|
||||
using Titano.Core.Imaging;
|
||||
using Titano.Core.Windows.Codecs;
|
||||
using Titano.Core.Windows.Interop;
|
||||
|
||||
namespace Titano.Core.Windows.Wic;
|
||||
|
||||
/// <summary>
|
||||
/// Native decoding through the Windows Imaging Component (BRIEF §8.2 tier 1) for every format with an installed
|
||||
/// WIC decoder (see <see cref="CodecInventory"/>). Thread-safe: each call builds its own pull chain
|
||||
/// (decoder → Fant scaler → format converter) on the calling thread, which joins the MTA if it has no apartment.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Pixels are requested as 64bppRGBA and linearised with the exact sRGB EOTF (<see cref="ColorSpace.Linear16"/>):
|
||||
/// WIC integer formats are sRGB-encoded, the 16-bit request keeps 16-bit PNG/TIFF precision, and the result matches
|
||||
/// the managed decoders bit for bit, whereas WIC's own integer→float conversion uses its own gamma approximation.
|
||||
/// Sources whose native format is floating or fixed point (scRGB: JPEG XR, HDR) are requested as 128bppRGBAFloat
|
||||
/// and copied unchanged, keeping highlights above 1. Alpha is discarded. The Exif orientation is applied while
|
||||
/// de-interleaving (<see cref="OrientationMap"/>).
|
||||
/// </remarks>
|
||||
public sealed class WicDecoderProvider : IImageDecoderProvider
|
||||
{
|
||||
private const int WINCODEC_ERR_COMPONENTNOTFOUND = unchecked((int)0x88982F50);
|
||||
private const int WICBitmapInterpolationModeFant = 3;
|
||||
private const int WICBitmapDitherTypeNone = 0;
|
||||
private const int WICBitmapPaletteTypeCustom = 0;
|
||||
private const uint NumericFixedPoint = 4, NumericFloat = 5;
|
||||
private const int BandBytes = 4 << 20;
|
||||
|
||||
/// <summary>The photo-policy query covers every WIC container; the raw paths catch decoders without the policy.</summary>
|
||||
private static readonly string[] OrientationQueries = ["System.Photo.Orientation", "/app1/ifd/{ushort=274}", "/ifd/{ushort=274}"];
|
||||
|
||||
/// <param name="inventory">Codec snapshot deciding <see cref="TierFor"/>; detected now when omitted.</param>
|
||||
public WicDecoderProvider(CodecInventory? inventory = null) => Inventory = inventory ?? CodecInventory.Detect();
|
||||
|
||||
public string Name => "wic";
|
||||
|
||||
public CodecInventory Inventory { get; }
|
||||
|
||||
public DecodeTier? TierFor(ImageFileFormat format) => Inventory.IsNative(format) ? DecodeTier.Native : null;
|
||||
|
||||
/// <summary>
|
||||
/// Decodes the first frame. Returns null when WIC cannot natively decode this format here, when the request
|
||||
/// forces the embedded preview, or when no installed decoder recognises the content. Corrupt files raise the
|
||||
/// WIC <see cref="COMException"/>; unreadable files the matching <see cref="IOException"/>.
|
||||
/// </summary>
|
||||
public DecodedImage? Decode(DecodeRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
if (request.ForcePreview || TierFor(ImageFormatInfo.FromPath(request.Path).Format) is null) return null;
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
Win32Com.EnsureInitialized();
|
||||
var factory = WicFactory.Instance;
|
||||
var stream = ShellStream.OpenRead(request.Path);
|
||||
IWICBitmapDecoder? decoder = null;
|
||||
IWICBitmapFrameDecode? frame = null;
|
||||
IWICBitmapScaler? scaler = null;
|
||||
IWICFormatConverter? converter = null;
|
||||
try
|
||||
{
|
||||
var hr = factory.CreateDecoderFromStream(stream, 0, WicDecodeOptions.MetadataCacheOnDemand, out decoder);
|
||||
if (hr == WINCODEC_ERR_COMPONENTNOTFOUND) return null;
|
||||
Marshal.ThrowExceptionForHR(hr);
|
||||
frame = decoder!.GetFrame(0);
|
||||
frame.GetSize(out var width, out var height);
|
||||
var orientation = request.ApplyOrientation ? ReadOrientation(frame) : 1;
|
||||
|
||||
var (targetWidth, targetHeight) = TargetSize(width, height, request.MaxLongEdge);
|
||||
IWICBitmapSource source = frame;
|
||||
if (targetWidth != width || targetHeight != height)
|
||||
{
|
||||
scaler = factory.CreateBitmapScaler();
|
||||
scaler.Initialize(frame, targetWidth, targetHeight, WICBitmapInterpolationModeFant);
|
||||
source = scaler;
|
||||
}
|
||||
|
||||
converter = factory.CreateFormatConverter();
|
||||
var sourceFormat = source.GetPixelFormat();
|
||||
var floating = IsFloatingPoint(factory, frame.GetPixelFormat()) && CanConvert(converter, sourceFormat, WicGuids.PixelFormat128bppRGBAFloat);
|
||||
var targetFormat = floating ? WicGuids.PixelFormat128bppRGBAFloat : WicGuids.PixelFormat64bppRGBA;
|
||||
converter.Initialize(source, ref targetFormat, WICBitmapDitherTypeNone, 0, 0.0, WICBitmapPaletteTypeCustom);
|
||||
|
||||
var map = OrientationMap.Create(orientation, (int)targetWidth, (int)targetHeight);
|
||||
var pixels = CopyToPlanes(converter, (int)targetWidth, (int)targetHeight, floating, map, cancellationToken);
|
||||
var swap = OrientationMap.SwapsAxes(orientation);
|
||||
return new DecodedImage(pixels, DecodeTier.Native, Name, (int)(swap ? height : width), (int)(swap ? width : height));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Win32Com.Release(converter);
|
||||
Win32Com.Release(scaler);
|
||||
Win32Com.Release(frame);
|
||||
Win32Com.Release(decoder);
|
||||
Marshal.Release(stream);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Size after fitting the long edge into <paramref name="maxLongEdge"/> (never upscales; 0 = native).</summary>
|
||||
internal static (uint Width, uint Height) TargetSize(uint width, uint height, int maxLongEdge)
|
||||
{
|
||||
var longEdge = Math.Max(width, height);
|
||||
if (maxLongEdge <= 0 || longEdge <= (uint)maxLongEdge) return (width, height);
|
||||
var scale = (double)maxLongEdge / longEdge;
|
||||
return ((uint)Math.Max(1, Math.Round(width * scale)), (uint)Math.Max(1, Math.Round(height * scale)));
|
||||
}
|
||||
|
||||
private static int ReadOrientation(IWICBitmapFrameDecode frame)
|
||||
{
|
||||
if (frame.GetMetadataQueryReader(out var reader) < 0 || reader is null) return 1;
|
||||
try
|
||||
{
|
||||
foreach (var query in OrientationQueries)
|
||||
{
|
||||
var value = default(PropVariant);
|
||||
if (reader.GetMetadataByName(query, ref value) < 0) continue;
|
||||
try
|
||||
{
|
||||
if (value.TryGetInt32(out var orientation) && orientation is >= 1 and <= 8) return orientation;
|
||||
}
|
||||
finally
|
||||
{
|
||||
PropVariant.Clear(ref value);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Win32Com.Release(reader);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>True for fixed- and floating-point (scRGB) pixel formats; unknown formats count as integer.</summary>
|
||||
private static bool IsFloatingPoint(IWICImagingFactory factory, Guid pixelFormat)
|
||||
{
|
||||
IWICComponentInfo? info = null;
|
||||
try
|
||||
{
|
||||
info = factory.CreateComponentInfo(ref pixelFormat);
|
||||
return info is IWICPixelFormatInfo2 format && format.GetNumericRepresentation() is NumericFixedPoint or NumericFloat;
|
||||
}
|
||||
catch (COMException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Win32Com.Release(info);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool CanConvert(IWICFormatConverter converter, Guid from, Guid to)
|
||||
{
|
||||
converter.CanConvert(ref from, ref to, out var canConvert);
|
||||
return canConvert != 0;
|
||||
}
|
||||
|
||||
/// <summary>Pulls the converted pixels in bands of rows (bounded memory) and writes oriented linear planes.</summary>
|
||||
private static unsafe ImageBuffer CopyToPlanes(IWICBitmapSource source, int width, int height, bool floating, OrientationMap map, CancellationToken cancellationToken)
|
||||
{
|
||||
var stride = checked(width * (floating ? 16 : 8));
|
||||
var bandRows = Math.Clamp(BandBytes / stride, 1, height);
|
||||
var image = new ImageBuffer(map.Width, map.Height, 3, clear: false);
|
||||
var band = ArrayPool<byte>.Shared.Rent(checked(stride * bandRows));
|
||||
try
|
||||
{
|
||||
var r = image.Plane(0);
|
||||
var g = image.Plane(1);
|
||||
var b = image.Plane(2);
|
||||
fixed (byte* bandPointer = band)
|
||||
{
|
||||
for (var top = 0; top < height; top += bandRows)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var rows = Math.Min(bandRows, height - top);
|
||||
var rect = new WicRect { X = 0, Y = top, Width = width, Height = rows };
|
||||
source.CopyPixels(ref rect, (uint)stride, (uint)(stride * rows), (nint)bandPointer);
|
||||
for (var row = 0; row < rows; row++)
|
||||
{
|
||||
var line = new ReadOnlySpan<byte>(bandPointer + (row * stride), stride);
|
||||
var index = map.IndexOf(0, top + row);
|
||||
if (floating) WriteFloatRow(MemoryMarshal.Cast<byte, float>(line), index, map.StepX, r, g, b);
|
||||
else WriteSrgb16Row(MemoryMarshal.Cast<byte, ushort>(line), index, map.StepX, r, g, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
catch
|
||||
{
|
||||
image.Dispose();
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(band);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteSrgb16Row(ReadOnlySpan<ushort> rgba, int index, int step, Span<float> r, Span<float> g, Span<float> b)
|
||||
{
|
||||
for (var i = 0; i < rgba.Length; i += 4, index += step)
|
||||
{
|
||||
r[index] = ColorSpace.Linear16(rgba[i]);
|
||||
g[index] = ColorSpace.Linear16(rgba[i + 1]);
|
||||
b[index] = ColorSpace.Linear16(rgba[i + 2]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteFloatRow(ReadOnlySpan<float> rgba, int index, int step, Span<float> r, Span<float> g, Span<float> b)
|
||||
{
|
||||
// scRGB can carry negative (out-of-gamut) components; the pipeline's range starts at 0.
|
||||
for (var i = 0; i < rgba.Length; i += 4, index += step)
|
||||
{
|
||||
r[index] = MathF.Max(rgba[i], 0f);
|
||||
g[index] = MathF.Max(rgba[i + 1], 0f);
|
||||
b[index] = MathF.Max(rgba[i + 2], 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Titano.Core.Windows.Interop;
|
||||
|
||||
namespace Titano.Core.Windows.Wic;
|
||||
|
||||
/// <summary>Process-wide WIC imaging factory (free-threaded; safe to call from any thread).</summary>
|
||||
internal static class WicFactory
|
||||
{
|
||||
private static readonly Lazy<IWICImagingFactory> Shared = new(Create);
|
||||
|
||||
public static IWICImagingFactory Instance => Shared.Value;
|
||||
|
||||
private static IWICImagingFactory Create()
|
||||
{
|
||||
// Create it in the MTA: a factory born on a UI thread's STA could make worker threads marshal every
|
||||
// call into that apartment.
|
||||
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
|
||||
return Task.Run(Create).GetAwaiter().GetResult();
|
||||
|
||||
var iid = typeof(IWICImagingFactory).GUID;
|
||||
var hr = Win32Com.TryCreateInstance(WicGuids.ImagingFactory2, iid, out var instance);
|
||||
// WICImagingFactory2 is missing only on Windows 7 without the platform update.
|
||||
if (hr == Win32Com.REGDB_E_CLASSNOTREG) hr = Win32Com.TryCreateInstance(WicGuids.ImagingFactory1, iid, out instance);
|
||||
Marshal.ThrowExceptionForHR(hr);
|
||||
return (IWICImagingFactory)instance!;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace Titano.Core.Windows.Wic;
|
||||
|
||||
/// <summary>Class, vendor and pixel-format identifiers from wincodec.h.</summary>
|
||||
internal static class WicGuids
|
||||
{
|
||||
public static readonly Guid ImagingFactory1 = new("cacaf262-9370-4615-a13b-9f5539da4c0a");
|
||||
public static readonly Guid ImagingFactory2 = new("317d06e8-5f24-433d-bdf7-79ce68d8abc2");
|
||||
|
||||
/// <summary>CLSID_WICRAWDecoder: the camera RAW decoder (Raw Image Extension; also the CLSID of the older in-box codec).</summary>
|
||||
public static readonly Guid RawDecoder = new("41945702-8302-44a6-9445-ac98e8afa086");
|
||||
|
||||
/// <summary>CLSID_WICHeifDecoder (HEIF Image Extensions; decodes HEVC- and AV1-coded HEIF).</summary>
|
||||
public static readonly Guid HeifDecoder = new("e9a4a80a-44fe-4de4-8971-7150b10a5199");
|
||||
|
||||
/// <summary>CLSID_WICWebpDecoder (WebP Image Extensions).</summary>
|
||||
public static readonly Guid WebpDecoder = new("7693e886-51c9-4070-8419-9f70738ec8fa");
|
||||
|
||||
public static readonly Guid VendorMicrosoft = new("f0e749ca-edef-4589-a73a-ee0e626a2a2b");
|
||||
public static readonly Guid VendorMicrosoftBuiltIn = new("257a30fd-06b6-462b-aea4-63f70b86e533");
|
||||
|
||||
/// <summary>16-bit unsigned RGBA, sRGB-encoded like every WIC integer format.</summary>
|
||||
public static readonly Guid PixelFormat64bppRGBA = new("6fddc324-4e03-4bfe-b185-3d77768dc916");
|
||||
|
||||
/// <summary>32-bit float RGBA, scRGB (linear light, Rec.709 primaries) like every WIC float format.</summary>
|
||||
public static readonly Guid PixelFormat128bppRGBAFloat = new("6fddc324-4e03-4bfe-b185-3d77768dc919");
|
||||
}
|
||||
@@ -0,0 +1,354 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Titano.Core.Windows.Interop;
|
||||
|
||||
namespace Titano.Core.Windows.Wic;
|
||||
|
||||
// Windows Imaging Component interfaces, vtable order as in wincodec.h / objidl.h.
|
||||
// [ComImport] interfaces do not inherit vtable slots from their C# base, so every derived interface
|
||||
// redeclares the base methods (with `new`) in their native order before its own. Interfaces are declared
|
||||
// up to the last slot Titano calls (a vtable prefix is valid); intermediate slots Titano never calls keep
|
||||
// their native shape with pointer-sized placeholders for interfaces it does not model. Methods whose
|
||||
// failure is an expected outcome use [PreserveSig]; the others throw COMException on a failed HRESULT.
|
||||
|
||||
/// <summary>WICDecodeOptions.</summary>
|
||||
internal enum WicDecodeOptions
|
||||
{
|
||||
MetadataCacheOnDemand = 0,
|
||||
MetadataCacheOnLoad = 1,
|
||||
}
|
||||
|
||||
/// <summary>WICRect.</summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal struct WicRect
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
public int Width;
|
||||
public int Height;
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("ec5ec8a9-c395-4314-9c77-54d7a935ff70")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IWICImagingFactory
|
||||
{
|
||||
[PreserveSig]
|
||||
int CreateDecoderFromFilename(nint fileName, nint vendor, uint desiredAccess, WicDecodeOptions options, out nint decoder);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateDecoderFromStream(nint stream, nint vendor, WicDecodeOptions options, out IWICBitmapDecoder? decoder);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateDecoderFromFileHandle(nint file, nint vendor, WicDecodeOptions options, out nint decoder);
|
||||
|
||||
IWICComponentInfo CreateComponentInfo(ref Guid clsid);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateDecoder(ref Guid containerFormat, nint vendor, out nint decoder);
|
||||
|
||||
/// <summary>Returns an owned IWICBitmapEncoder pointer (used by the tests to synthesise JPEG fixtures).</summary>
|
||||
[PreserveSig]
|
||||
int CreateEncoder(ref Guid containerFormat, nint vendor, out nint encoder);
|
||||
|
||||
[PreserveSig]
|
||||
int CreatePalette(out nint palette);
|
||||
|
||||
IWICFormatConverter CreateFormatConverter();
|
||||
|
||||
IWICBitmapScaler CreateBitmapScaler();
|
||||
|
||||
[PreserveSig]
|
||||
int CreateBitmapClipper(out nint clipper);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateBitmapFlipRotator(out nint flipRotator);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateStream(out nint stream);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateColorContext(out nint colorContext);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateColorTransformer(out nint colorTransform);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateBitmap(uint width, uint height, ref Guid pixelFormat, int cacheOption, out nint bitmap);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateBitmapFromSource(nint source, int cacheOption, out nint bitmap);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateBitmapFromSourceRect(nint source, uint x, uint y, uint width, uint height, out nint bitmap);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateBitmapFromMemory(uint width, uint height, ref Guid pixelFormat, uint stride, uint bufferSize, nint buffer, out nint bitmap);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateBitmapFromHBITMAP(nint bitmapHandle, nint paletteHandle, int alphaOption, out nint bitmap);
|
||||
|
||||
[PreserveSig]
|
||||
int CreateBitmapFromHICON(nint iconHandle, out nint bitmap);
|
||||
|
||||
IEnumUnknown CreateComponentEnumerator(uint componentTypes, uint options);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("00000100-0000-0000-c000-000000000046")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IEnumUnknown
|
||||
{
|
||||
/// <summary>S_OK when <paramref name="count"/> items were fetched, S_FALSE at the end.</summary>
|
||||
[PreserveSig]
|
||||
int Next(uint count, out nint element, out uint fetched);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("9edde9e7-8dee-47ea-99df-e6faf2ed44bf")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IWICBitmapDecoder
|
||||
{
|
||||
[PreserveSig]
|
||||
int QueryCapability(nint stream, out uint capability);
|
||||
|
||||
[PreserveSig]
|
||||
int Initialize(nint stream, WicDecodeOptions options);
|
||||
|
||||
Guid GetContainerFormat();
|
||||
|
||||
[PreserveSig]
|
||||
int GetDecoderInfo(out nint decoderInfo);
|
||||
|
||||
[PreserveSig]
|
||||
int CopyPalette(nint palette);
|
||||
|
||||
[PreserveSig]
|
||||
int GetMetadataQueryReader(out nint reader);
|
||||
|
||||
[PreserveSig]
|
||||
int GetPreview(out nint preview);
|
||||
|
||||
[PreserveSig]
|
||||
int GetColorContexts(uint count, nint colorContexts, out uint actualCount);
|
||||
|
||||
[PreserveSig]
|
||||
int GetThumbnail(out nint thumbnail);
|
||||
|
||||
uint GetFrameCount();
|
||||
|
||||
IWICBitmapFrameDecode GetFrame(uint index);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("00000120-a8f2-4877-ba0a-fd2b6645fb94")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IWICBitmapSource
|
||||
{
|
||||
void GetSize(out uint width, out uint height);
|
||||
|
||||
Guid GetPixelFormat();
|
||||
|
||||
void GetResolution(out double dpiX, out double dpiY);
|
||||
|
||||
[PreserveSig]
|
||||
int CopyPalette(nint palette);
|
||||
|
||||
void CopyPixels(ref WicRect rect, uint stride, uint bufferSize, nint buffer);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("3b16811b-6a43-4ec9-a813-3d930c13b940")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IWICBitmapFrameDecode : IWICBitmapSource
|
||||
{
|
||||
new void GetSize(out uint width, out uint height);
|
||||
|
||||
new Guid GetPixelFormat();
|
||||
|
||||
new void GetResolution(out double dpiX, out double dpiY);
|
||||
|
||||
[PreserveSig]
|
||||
new int CopyPalette(nint palette);
|
||||
|
||||
new void CopyPixels(ref WicRect rect, uint stride, uint bufferSize, nint buffer);
|
||||
|
||||
/// <summary>Fails (e.g. WINCODEC_ERR_UNSUPPORTEDOPERATION) for formats without metadata.</summary>
|
||||
[PreserveSig]
|
||||
int GetMetadataQueryReader(out IWICMetadataQueryReader? reader);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("00000301-a8f2-4877-ba0a-fd2b6645fb94")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IWICFormatConverter : IWICBitmapSource
|
||||
{
|
||||
new void GetSize(out uint width, out uint height);
|
||||
|
||||
new Guid GetPixelFormat();
|
||||
|
||||
new void GetResolution(out double dpiX, out double dpiY);
|
||||
|
||||
[PreserveSig]
|
||||
new int CopyPalette(nint palette);
|
||||
|
||||
new void CopyPixels(ref WicRect rect, uint stride, uint bufferSize, nint buffer);
|
||||
|
||||
void Initialize(IWICBitmapSource source, ref Guid destinationFormat, int dither, nint palette, double alphaThresholdPercent, int paletteTranslate);
|
||||
|
||||
void CanConvert(ref Guid sourceFormat, ref Guid destinationFormat, out int canConvert);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("00000302-a8f2-4877-ba0a-fd2b6645fb94")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IWICBitmapScaler : IWICBitmapSource
|
||||
{
|
||||
new void GetSize(out uint width, out uint height);
|
||||
|
||||
new Guid GetPixelFormat();
|
||||
|
||||
new void GetResolution(out double dpiX, out double dpiY);
|
||||
|
||||
[PreserveSig]
|
||||
new int CopyPalette(nint palette);
|
||||
|
||||
new void CopyPixels(ref WicRect rect, uint stride, uint bufferSize, nint buffer);
|
||||
|
||||
void Initialize(IWICBitmapSource source, uint width, uint height, int interpolationMode);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("30989668-e1c9-4597-b395-458eedb808df")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal interface IWICMetadataQueryReader
|
||||
{
|
||||
Guid GetContainerFormat();
|
||||
|
||||
[PreserveSig]
|
||||
int GetLocation(uint capacity, nint buffer, out uint length);
|
||||
|
||||
/// <summary>Fails with WINCODEC_ERR_PROPERTYNOTFOUND when the query matches nothing.</summary>
|
||||
[PreserveSig]
|
||||
int GetMetadataByName([MarshalAs(UnmanagedType.LPWStr)] string name, ref PropVariant value);
|
||||
}
|
||||
|
||||
/// <summary>String getters of the component-info family: capacity 0 + null buffer returns the required length.</summary>
|
||||
internal unsafe delegate int WicStringGetter(uint capacity, char* buffer, out uint length);
|
||||
|
||||
[ComImport]
|
||||
[Guid("23bc3f0a-698b-4357-886b-f24d50671334")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal unsafe interface IWICComponentInfo
|
||||
{
|
||||
uint GetComponentType();
|
||||
|
||||
Guid GetCLSID();
|
||||
|
||||
uint GetSigningStatus();
|
||||
|
||||
[PreserveSig]
|
||||
int GetAuthor(uint capacity, char* buffer, out uint length);
|
||||
|
||||
Guid GetVendorGUID();
|
||||
|
||||
[PreserveSig]
|
||||
int GetVersion(uint capacity, char* buffer, out uint length);
|
||||
|
||||
[PreserveSig]
|
||||
int GetSpecVersion(uint capacity, char* buffer, out uint length);
|
||||
|
||||
[PreserveSig]
|
||||
int GetFriendlyName(uint capacity, char* buffer, out uint length);
|
||||
}
|
||||
|
||||
/// <summary>IWICPixelFormatInfo2 (IWICComponentInfo → IWICPixelFormatInfo → IWICPixelFormatInfo2).</summary>
|
||||
[ComImport]
|
||||
[Guid("a9db33a2-af5f-43c7-b679-74f5984b5aa4")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal unsafe interface IWICPixelFormatInfo2 : IWICComponentInfo
|
||||
{
|
||||
new uint GetComponentType();
|
||||
|
||||
new Guid GetCLSID();
|
||||
|
||||
new uint GetSigningStatus();
|
||||
|
||||
[PreserveSig]
|
||||
new int GetAuthor(uint capacity, char* buffer, out uint length);
|
||||
|
||||
new Guid GetVendorGUID();
|
||||
|
||||
[PreserveSig]
|
||||
new int GetVersion(uint capacity, char* buffer, out uint length);
|
||||
|
||||
[PreserveSig]
|
||||
new int GetSpecVersion(uint capacity, char* buffer, out uint length);
|
||||
|
||||
[PreserveSig]
|
||||
new int GetFriendlyName(uint capacity, char* buffer, out uint length);
|
||||
|
||||
Guid GetFormatGUID();
|
||||
|
||||
[PreserveSig]
|
||||
int GetColorContext(out nint colorContext);
|
||||
|
||||
uint GetBitsPerPixel();
|
||||
|
||||
uint GetChannelCount();
|
||||
|
||||
[PreserveSig]
|
||||
int GetChannelMask(uint channel, uint maskSize, nint mask, out uint actualSize);
|
||||
|
||||
void SupportsTransparency(out int supportsTransparency);
|
||||
|
||||
/// <summary>WICPixelFormatNumericRepresentation: 2 unsigned integer, 4 fixed point, 5 float.</summary>
|
||||
uint GetNumericRepresentation();
|
||||
}
|
||||
|
||||
/// <summary>IWICBitmapDecoderInfo (IWICComponentInfo → IWICBitmapCodecInfo → IWICBitmapDecoderInfo).</summary>
|
||||
[ComImport]
|
||||
[Guid("d8cd007f-d08f-4191-9bfc-236ea7f0e4b5")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
internal unsafe interface IWICBitmapDecoderInfo : IWICComponentInfo
|
||||
{
|
||||
new uint GetComponentType();
|
||||
|
||||
new Guid GetCLSID();
|
||||
|
||||
new uint GetSigningStatus();
|
||||
|
||||
[PreserveSig]
|
||||
new int GetAuthor(uint capacity, char* buffer, out uint length);
|
||||
|
||||
new Guid GetVendorGUID();
|
||||
|
||||
[PreserveSig]
|
||||
new int GetVersion(uint capacity, char* buffer, out uint length);
|
||||
|
||||
[PreserveSig]
|
||||
new int GetSpecVersion(uint capacity, char* buffer, out uint length);
|
||||
|
||||
[PreserveSig]
|
||||
new int GetFriendlyName(uint capacity, char* buffer, out uint length);
|
||||
|
||||
Guid GetContainerFormat();
|
||||
|
||||
[PreserveSig]
|
||||
int GetPixelFormats(uint count, nint pixelFormats, out uint actualCount);
|
||||
|
||||
[PreserveSig]
|
||||
int GetColorManagementVersion(uint capacity, char* buffer, out uint length);
|
||||
|
||||
[PreserveSig]
|
||||
int GetDeviceManufacturer(uint capacity, char* buffer, out uint length);
|
||||
|
||||
[PreserveSig]
|
||||
int GetDeviceModels(uint capacity, char* buffer, out uint length);
|
||||
|
||||
[PreserveSig]
|
||||
int GetMimeTypes(uint capacity, char* buffer, out uint length);
|
||||
|
||||
/// <summary>Comma-separated list such as ".jpg,.jpeg,.jpe,.jfif".</summary>
|
||||
[PreserveSig]
|
||||
int GetFileExtensions(uint capacity, char* buffer, out uint length);
|
||||
}
|
||||
Reference in new issue
Block a user