Skip to content

Commit f2b2293

Browse files
committed
WicNetExplorer: added animation for Webp & Gif files
1 parent e99d912 commit f2b2293

File tree

11 files changed

+389
-114
lines changed

11 files changed

+389
-114
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Reflection;
22

3-
[assembly: AssemblyVersion("1.8.4.1")]
4-
[assembly: AssemblyFileVersion("1.8.4.1")]
5-
[assembly: AssemblyInformationalVersion("1.8.4.1")]
3+
[assembly: AssemblyVersion("1.8.5.0")]
4+
[assembly: AssemblyFileVersion("1.8.5.0")]
5+
[assembly: AssemblyInformationalVersion("1.8.5.0")]

WicNet/WicBitmapDecoder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public WicBitmapDecoder(object comObject)
2121
public int FrameCount => _comObject.GetFrameCount();
2222
public Guid ContainerFormat => _comObject.GetContainerFormat();
2323

24-
public WicBitmapSource GetFrame(int index = 0) => new WicBitmapSource(_comObject.GetFrame(index));
24+
public WicBitmapSource GetFrame(int index = 0) => new WicBitmapSource(_comObject.GetFrame(index)) { DecoderFrameCount = FrameCount };
2525

2626
public WicBitmapSource GetPreview()
2727
{
@@ -56,7 +56,9 @@ public IEnumerable<WicBitmapSource> EnumerateFrames()
5656
{
5757
for (var i = 0; i < FrameCount; i++)
5858
{
59-
yield return GetFrame(i);
59+
var frame = GetFrame(i);
60+
frame.DecoderFrameCount = FrameCount;
61+
yield return frame;
6062
}
6163
}
6264

WicNet/WicBitmapSource.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public WicBitmapSource(int width, int height, Guid pixelFormat, WICBitmapCreateC
2424
}
2525

2626
public IComObject<IWICBitmapSource> ComObject => _comObject;
27+
public int DecoderFrameCount { get; internal set; } = 1;
2728
public WicIntSize Size => new WicIntSize(Width, Height);
2829
public WICRect Bounds => new WICRect(0, 0, Width, Height);
2930
public int DefaultStride => Utilities.Extensions.GetStride(Width, WicPixelFormat.BitsPerPixel);
@@ -433,19 +434,31 @@ public void Scale(int? width, int? height, WICBitmapInterpolationMode mode = WIC
433434
public static WicBitmapSource Load(string filePath, int frameIndex = 0, WICDecodeOptions options = WICDecodeOptions.WICDecodeMetadataCacheOnDemand, Guid? guidVendor = null)
434435
{
435436
using (var decoder = WicBitmapDecoder.Load(filePath, guidVendor: guidVendor, options: options))
436-
return decoder.GetFrame(frameIndex);
437+
{
438+
var frame = decoder.GetFrame(frameIndex);
439+
frame.DecoderFrameCount = decoder.FrameCount;
440+
return frame;
441+
}
437442
}
438443

439444
public static WicBitmapSource Load(IntPtr fileHandle, int frameIndex = 0, WICDecodeOptions options = WICDecodeOptions.WICDecodeMetadataCacheOnDemand, Guid? guidVendor = null)
440445
{
441446
using (var decoder = WicBitmapDecoder.Load(fileHandle, guidVendor: guidVendor, options: options))
442-
return decoder.GetFrame(frameIndex);
447+
{
448+
var frame = decoder.GetFrame(frameIndex);
449+
frame.DecoderFrameCount = decoder.FrameCount;
450+
return frame;
451+
}
443452
}
444453

445454
public static WicBitmapSource Load(Stream stream, int frameIndex = 0, WICDecodeOptions options = WICDecodeOptions.WICDecodeMetadataCacheOnDemand, Guid? guidVendor = null)
446455
{
447456
using (var decoder = WicBitmapDecoder.Load(stream, guidVendor: guidVendor, options: options))
448-
return decoder.GetFrame(frameIndex);
457+
{
458+
var frame = decoder.GetFrame(frameIndex);
459+
frame.DecoderFrameCount = decoder.FrameCount;
460+
return frame;
461+
}
449462
}
450463

451464
public IComObject<ID2D1RenderTarget> CreateRenderTarget(D2D1_RENDER_TARGET_PROPERTIES? renderTargetProperties = null) => CreateRenderTarget<ID2D1RenderTarget>(renderTargetProperties);

WicNetCore/WicBitmapDecoder.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public sealed class WicBitmapDecoder(IComObject<IWICBitmapDecoder> comObject) :
55
public uint FrameCount => NativeObject.GetFrameCount();
66
public Guid ContainerFormat => NativeObject.GetContainerFormat();
77

8-
public WicBitmapSource GetFrame(uint index = 0) => new(NativeObject.GetFrame(index));
8+
public WicBitmapSource GetFrame(uint index = 0) => new(NativeObject.GetFrame(index)) { DecoderFrameCount = FrameCount };
99

1010
public WicBitmapSource? GetPreview()
1111
{
@@ -40,7 +40,9 @@ public IEnumerable<WicBitmapSource> EnumerateFrames()
4040
{
4141
for (uint i = 0; i < FrameCount; i++)
4242
{
43-
yield return GetFrame(i);
43+
var frame = GetFrame(i);
44+
frame.DecoderFrameCount = FrameCount;
45+
yield return frame;
4446
}
4547
}
4648

WicNetCore/WicBitmapSource.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public WicBitmapSource(uint width, uint height, Guid pixelFormat, WICBitmapCreat
1414
{
1515
}
1616

17+
public uint DecoderFrameCount { get; internal set; } = 1;
1718
public D2D_SIZE_U Size => new(Width, Height);
1819
public D2D_RECT_U Bounds => new() { right = Width, bottom = Height };
1920
public uint DefaultStride => Utilities.Extensions.GetStride(Width, WicPixelFormat?.BitsPerPixel ?? 0);
@@ -401,19 +402,25 @@ public void Scale(int? width, int? height, WICBitmapInterpolationMode mode = WIC
401402
public static WicBitmapSource Load(string filePath, uint frameIndex = 0, WICDecodeOptions options = WICDecodeOptions.WICDecodeMetadataCacheOnDemand)
402403
{
403404
using var decoder = WicBitmapDecoder.Load(filePath, options: options);
404-
return decoder.GetFrame(frameIndex);
405+
var frame = decoder.GetFrame(frameIndex);
406+
frame.DecoderFrameCount = decoder.FrameCount;
407+
return frame;
405408
}
406409

407410
public static WicBitmapSource Load(nuint fileHandle, uint frameIndex = 0, WICDecodeOptions options = WICDecodeOptions.WICDecodeMetadataCacheOnDemand)
408411
{
409412
using var decoder = WicBitmapDecoder.Load(fileHandle, options: options);
410-
return decoder.GetFrame(frameIndex);
413+
var frame = decoder.GetFrame(frameIndex);
414+
frame.DecoderFrameCount = decoder.FrameCount;
415+
return frame;
411416
}
412417

413418
public static WicBitmapSource Load(Stream stream, uint frameIndex = 0, WICDecodeOptions options = WICDecodeOptions.WICDecodeMetadataCacheOnDemand)
414419
{
415420
using var decoder = WicBitmapDecoder.Load(stream, options: options);
416-
return decoder.GetFrame(frameIndex);
421+
var frame = decoder.GetFrame(frameIndex);
422+
frame.DecoderFrameCount = decoder.FrameCount;
423+
return frame;
417424
}
418425

419426
[SupportedOSPlatform("windows6.1")]

WicNetExplorer/D2DCompositionControl.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ public class D2DCompositionControl : Control, ID2DControl
2020
{
2121
// device independent resources
2222
private static readonly Lazy<IDispatcherQueueController> _dispatcherQueueController = new(() => DispatcherQueueController.Create());
23-
private static readonly Lazy<object> _d3d11Device = new(() => Utilities.Extensions.D3D11CreateDevice());
23+
private static readonly Lazy<object> _d3d11Device = new(() => Utilities.Extensions.D3D11CreateDevice(
24+
#if DEBUG
25+
D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_DEBUG | D3D11_CREATE_DEVICE_FLAG.D3D11_CREATE_DEVICE_BGRA_SUPPORT
26+
#endif
27+
));
2428
private static readonly Lazy<IComObject<ID2D1Factory1>> _d2dFactory = new(() => D2D1Functions.D2D1CreateFactory<ID2D1Factory1>());
2529
private static readonly Lazy<CompositionGraphicsDevice> _graphicsDevice = new(CreateCompositionGraphicsDevice);
2630

0 commit comments

Comments
 (0)