-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update packages and add some simple WIC component enumeration
- Loading branch information
1 parent
f236f3a
commit 63bf46b
Showing
12 changed files
with
134 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/thirtytwo/Win32/Graphics/Imaging/ComponentEnumerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using Windows.Win32.System.Com; | ||
|
||
namespace Windows.Win32.Graphics.Imaging; | ||
|
||
public unsafe class ComponentEnumerator : DirectDrawBase<IEnumUnknown> | ||
{ | ||
public ComponentEnumerator(IEnumUnknown* pointer) : base(pointer) { } | ||
|
||
public ComponentEnumerator(WICComponentType componentType) | ||
: base(CreateComponentEnumerator(Application.ImagingFactory, componentType)) | ||
{ | ||
} | ||
|
||
public static IEnumUnknown* CreateComponentEnumerator(ImagingFactory factory, WICComponentType componentType) | ||
{ | ||
IEnumUnknown* enumerator; | ||
factory.Pointer->CreateComponentEnumerator( | ||
(uint)componentType, | ||
(uint)WICComponentEnumerateOptions.WICComponentEnumerateDefault, | ||
&enumerator).ThrowOnFailure(); | ||
|
||
GC.KeepAlive(factory); | ||
return enumerator; | ||
} | ||
|
||
public static implicit operator IEnumUnknown*(ComponentEnumerator d) => d.Pointer; | ||
|
||
public bool Next([NotNullWhen(true)] out ComponentInfo? componentInfo) | ||
{ | ||
componentInfo = null; | ||
IEnumUnknown* enumerator = this; | ||
if (enumerator is null) | ||
{ | ||
return false; | ||
} | ||
|
||
uint fetched; | ||
using ComScope<IUnknown> unknown = new(null); | ||
HRESULT result = enumerator->Next(1, unknown, &fetched); | ||
if (result != HRESULT.S_OK || fetched != 1) | ||
{ | ||
return false; | ||
} | ||
|
||
componentInfo = new(unknown.Pointer->QueryInterface<IWICComponentInfo>()); | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Windows.Win32.Graphics.Imaging; | ||
|
||
public unsafe class ComponentInfo : DirectDrawBase<IWICComponentInfo> | ||
{ | ||
public ComponentInfo(IWICComponentInfo* pointer) : base(pointer) { } | ||
|
||
public ComponentInfo(Guid componentClassId) | ||
: base(CreateComponentInfo(Application.ImagingFactory, componentClassId)) | ||
{ | ||
} | ||
|
||
public static IWICComponentInfo* CreateComponentInfo(ImagingFactory factory, Guid componentClassId) | ||
{ | ||
IWICComponentInfo* info; | ||
factory.Pointer->CreateComponentInfo(&componentClassId, &info).ThrowOnFailure(); | ||
GC.KeepAlive(factory); | ||
return info; | ||
} | ||
|
||
public string FriendlyName | ||
{ | ||
get | ||
{ | ||
uint length; | ||
Pointer->GetFriendlyName(0, null, &length).ThrowOnFailure(); | ||
char* name = stackalloc char[(int)length]; | ||
Pointer->GetFriendlyName(length, name, &length).ThrowOnFailure(); | ||
return new string(name); | ||
} | ||
} | ||
|
||
public static implicit operator IWICComponentInfo*(ComponentInfo d) => d.Pointer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/thirtytwo_tests/Win32/Graphics/Imaging/ComponentInfoTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) Jeremy W. Kuhne. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Windows.Win32.Graphics.Imaging; | ||
|
||
public class ComponentInfoTests | ||
{ | ||
[Fact] | ||
public void EnumerateDecoders() | ||
{ | ||
ComponentEnumerator enumerator = new(WICComponentType.WICDecoder); | ||
while (enumerator.Next(out ComponentInfo? info)) | ||
{ | ||
Assert.NotNull(info); | ||
Assert.NotNull(info.FriendlyName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters