Move WIC test helpers to separate file
このコミットが含まれているのは:
1 親
93708e0527
コミット
8b48c6f729
6ファイル変更
+290
-169
検索条件に一致するファイルはありません
@@ -3,6 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<IsPackable>false</IsPackable>
|
||||
<NoWarn>$(NoWarn);CS0419;CA1416</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1Interop.Tests.Extensions;
|
||||
using ComputeSharp.D2D1Interop.Tests.Helpers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
#pragma warning disable CA1416
|
||||
|
||||
namespace ComputeSharp.D2D1Interop.Tests;
|
||||
|
||||
[TestClass]
|
||||
@@ -75,117 +73,9 @@ public class EndToEndTests
|
||||
options: D2D1_DEVICE_CONTEXT_OPTIONS.D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
|
||||
deviceContext: d2D1DeviceContext.GetAddressOf()).Assert();
|
||||
|
||||
using ComPtr<IWICImagingFactory2> wicImagingFactory2 = default;
|
||||
|
||||
// Create a Windows Imaging Component (WIC) factory
|
||||
Windows.CoCreateInstance(
|
||||
rclsid: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_WICImagingFactory2)),
|
||||
pUnkOuter: null,
|
||||
dwClsContext: (uint)CLSCTX.CLSCTX_INPROC_SERVER,
|
||||
riid: Windows.__uuidof<IWICImagingFactory2>(),
|
||||
ppv: (void**)wicImagingFactory2.GetAddressOf()).Assert();
|
||||
|
||||
const string imagePathSource = @"C:\Users\Sergi\Pictures\crysis2.png";
|
||||
|
||||
using ComPtr<IWICBitmapDecoder> wicBitmapDecoder = default;
|
||||
|
||||
// Get the bitmap decoder for the target file
|
||||
fixed (char* p = imagePathSource)
|
||||
{
|
||||
wicImagingFactory2.Get()->CreateDecoderFromFilename(
|
||||
wzFilename: (ushort*)p,
|
||||
pguidVendor: null,
|
||||
dwDesiredAccess: Windows.GENERIC_READ,
|
||||
metadataOptions: WICDecodeOptions.WICDecodeMetadataCacheOnDemand,
|
||||
ppIDecoder: wicBitmapDecoder.GetAddressOf()).Assert();
|
||||
}
|
||||
|
||||
using ComPtr<IWICBitmapFrameDecode> wicBitmapFrameDecode = default;
|
||||
|
||||
// Get the first frame of the loaded image (if more are present, they will be ignored)
|
||||
wicBitmapDecoder.Get()->GetFrame(0, wicBitmapFrameDecode.GetAddressOf()).Assert();
|
||||
|
||||
uint width;
|
||||
uint height;
|
||||
|
||||
// Extract the image size info
|
||||
wicBitmapFrameDecode.Get()->GetSize(&width, &height).Assert();
|
||||
|
||||
Guid wicTargetPixelFormatGuid = GUID.GUID_WICPixelFormat32bppPBGRA;
|
||||
Guid wicActualPixelFormatGuid;
|
||||
|
||||
// Get the current and target pixel format info
|
||||
wicBitmapFrameDecode.Get()->GetPixelFormat(&wicActualPixelFormatGuid).Assert();
|
||||
|
||||
using ComPtr<IWICBitmap> wicBitmap = default;
|
||||
|
||||
// Create the target bitmap
|
||||
wicImagingFactory2.Get()->CreateBitmap(
|
||||
uiWidth: width,
|
||||
uiHeight: height,
|
||||
pixelFormat: &wicTargetPixelFormatGuid,
|
||||
option: WICBitmapCreateCacheOption.WICBitmapCacheOnLoad,
|
||||
ppIBitmap: wicBitmap.GetAddressOf()).Assert();
|
||||
|
||||
WICRect wicRect;
|
||||
wicRect.X = 0;
|
||||
wicRect.Y = 0;
|
||||
wicRect.Width = (int)width;
|
||||
wicRect.Height = (int)height;
|
||||
|
||||
using (ComPtr<IWICBitmapLock> wicBitmapLock = default)
|
||||
{
|
||||
// Lock the bitmap
|
||||
wicBitmap.Get()->Lock(
|
||||
prcLock: &wicRect,
|
||||
flags: (uint)WICBitmapLockFlags.WICBitmapLockWrite,
|
||||
ppILock: wicBitmapLock.GetAddressOf()).Assert();
|
||||
|
||||
uint wicBitmapStride;
|
||||
|
||||
// Get the stride
|
||||
wicBitmapLock.Get()->GetStride(&wicBitmapStride).Assert();
|
||||
|
||||
uint wicBitmapSize;
|
||||
byte* wicBitmapPointer;
|
||||
|
||||
// Get the bitmap size and pointer
|
||||
wicBitmapLock.Get()->GetDataPointer(&wicBitmapSize, &wicBitmapPointer).Assert();
|
||||
|
||||
// Check if a pixel format conversion is needed
|
||||
if (wicTargetPixelFormatGuid == wicActualPixelFormatGuid)
|
||||
{
|
||||
// No conversion is needed, just copy the pixels directly
|
||||
wicBitmapFrameDecode.Get()->CopyPixels(
|
||||
prc: &wicRect,
|
||||
cbStride: wicBitmapStride,
|
||||
cbBufferSize: wicBitmapSize,
|
||||
pbBuffer: wicBitmapPointer).Assert();
|
||||
}
|
||||
else
|
||||
{
|
||||
using ComPtr<IWICFormatConverter> wicFormatConverter = default;
|
||||
|
||||
// Create a format converter
|
||||
wicImagingFactory2.Get()->CreateFormatConverter(wicFormatConverter.GetAddressOf()).Assert();
|
||||
|
||||
// Get a format converter to decode the pixel data
|
||||
wicFormatConverter.Get()->Initialize(
|
||||
pISource: (IWICBitmapSource*)wicBitmapFrameDecode.Get(),
|
||||
dstFormat: &wicTargetPixelFormatGuid,
|
||||
dither: WICBitmapDitherType.WICBitmapDitherTypeNone,
|
||||
pIPalette: null,
|
||||
alphaThresholdPercent: 0,
|
||||
paletteTranslate: WICBitmapPaletteType.WICBitmapPaletteTypeCustom).Assert();
|
||||
|
||||
// Decode the pixel data into the upload buffer
|
||||
wicFormatConverter.Get()->CopyPixels(
|
||||
prc: &wicRect,
|
||||
cbStride: wicBitmapStride,
|
||||
cbBufferSize: wicBitmapSize,
|
||||
pbBuffer: wicBitmapPointer).Assert();
|
||||
}
|
||||
}
|
||||
using ComPtr<IWICBitmap> wicBitmap = WICHelper.LoadBitmapFromFile(imagePathSource, out uint width, out uint height);
|
||||
|
||||
D2D_SIZE_U d2DSize;
|
||||
d2DSize.width = width;
|
||||
@@ -291,52 +181,9 @@ public class EndToEndTests
|
||||
options: D2D1_MAP_OPTIONS.D2D1_MAP_OPTIONS_READ,
|
||||
mappedRect: &d2D1MappedRect).Assert();
|
||||
|
||||
using ComPtr<IWICBitmapEncoder> wicBitmapEncoder = default;
|
||||
|
||||
// Create the image encoder
|
||||
wicImagingFactory2.Get()->CreateEncoder(
|
||||
guidContainerFormat: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in GUID.GUID_ContainerFormatPng)),
|
||||
pguidVendor: null,
|
||||
ppIEncoder: wicBitmapEncoder.GetAddressOf()).Assert();
|
||||
|
||||
using ComPtr<IWICStream> wicStream = default;
|
||||
|
||||
// Create and initialize a stream to the target file
|
||||
wicImagingFactory2.Get()->CreateStream(wicStream.GetAddressOf()).Assert();
|
||||
|
||||
const string imagePathDestination = @"C:\Users\Sergi\Pictures\crysis2_inverted.png";
|
||||
|
||||
fixed (char* p = imagePathDestination)
|
||||
{
|
||||
// Initialize the stream to the target file
|
||||
wicStream.Get()->InitializeFromFilename((ushort*)p, Windows.GENERIC_WRITE);
|
||||
}
|
||||
|
||||
// Initialize the encoder
|
||||
wicBitmapEncoder.Get()->Initialize(
|
||||
pIStream: (IStream*)wicStream.Get(),
|
||||
cacheOption: WICBitmapEncoderCacheOption.WICBitmapEncoderNoCache).Assert();
|
||||
|
||||
using ComPtr<IWICBitmapFrameEncode> wicBitmapFrameEncode = default;
|
||||
|
||||
// Create the image frame and initialize it
|
||||
wicBitmapEncoder.Get()->CreateNewFrame(wicBitmapFrameEncode.GetAddressOf(), null).Assert();
|
||||
|
||||
// Set the encoding properties
|
||||
wicBitmapFrameEncode.Get()->Initialize(null).Assert();
|
||||
wicBitmapFrameEncode.Get()->SetSize(width, height).Assert();
|
||||
wicBitmapFrameEncode.Get()->SetPixelFormat(&wicTargetPixelFormatGuid).Assert();
|
||||
|
||||
// Encode the target image
|
||||
wicBitmapFrameEncode.Get()->WritePixels(
|
||||
lineCount: height,
|
||||
cbStride: d2D1MappedRect.pitch,
|
||||
cbBufferSize: d2D1MappedRect.pitch * height,
|
||||
pbPixels: d2D1MappedRect.bits).Assert();
|
||||
|
||||
// Flush the changes
|
||||
wicBitmapFrameEncode.Get()->Commit();
|
||||
wicBitmapEncoder.Get()->Commit();
|
||||
WICHelper.SaveBitmapToFile(imagePathDestination, width, height, d2D1MappedRect.pitch, d2D1MappedRect.bits);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,15 +199,4 @@ public readonly partial struct InvertShader : ID2D1PixelShader
|
||||
|
||||
return new(rgb, 1);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class Extensions
|
||||
{
|
||||
public static void Assert(this HRESULT hresult)
|
||||
{
|
||||
if (hresult != 0)
|
||||
{
|
||||
Marshal.ThrowExceptionForHR(hresult);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1Interop.Tests.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Helper methods for working with the <see cref="ComPtr{T}"/> type.
|
||||
/// </summary>
|
||||
/// <remarks>Trimmed down version of the same file in <c>ComputeSharp</c>.</remarks>
|
||||
internal static class ComPtrExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Moves the current <see cref="ComPtr{T}"/> instance and resets it without releasing the reference.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to wrap in the current <see cref="ComPtr{T}"/> instance.</typeparam>
|
||||
/// <param name="ptr">The input <see cref="ComPtr{T}"/> instance to move.</param>
|
||||
/// <returns>The moved <see cref="ComPtr{T}"/> instance.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ComPtr<T> Move<T>(this in ComPtr<T> ptr)
|
||||
where T : unmanaged, IUnknown.Interface
|
||||
{
|
||||
ComPtr<T> copy = default;
|
||||
|
||||
Unsafe.AsRef(in ptr).Swap(ref copy);
|
||||
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1Interop.Tests.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
/// <remarks>Trimmed down version of the same file in <c>ComputeSharp</c>.</remarks>
|
||||
[DebuggerStepThrough]
|
||||
internal static class HResultExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws a <see cref="Win32Exception"/> if <paramref name="result"/> represents an error.
|
||||
/// </summary>
|
||||
/// <param name="result">The input <see cref="HRESULT"/> to check.</param>
|
||||
/// <exception cref="Win32Exception">Thrown if <paramref name="result"/> represents an error.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Assert(this HRESULT result)
|
||||
{
|
||||
if ((int)result < 0)
|
||||
{
|
||||
ThrowWin32Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a <see cref="Win32Exception"/> if <paramref name="result"/> represents an error.
|
||||
/// </summary>
|
||||
/// <param name="result">The input <see cref="int"/> to check.</param>
|
||||
/// <exception cref="Win32Exception">Thrown if <paramref name="result"/> represents an error.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Assert(this int result)
|
||||
{
|
||||
if (result < 0)
|
||||
{
|
||||
ThrowWin32Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a <see cref="Win32Exception"/>.
|
||||
/// </summary>
|
||||
/// <param name="result">The input return code.</param>
|
||||
[DoesNotReturn]
|
||||
private static void ThrowWin32Exception(int result)
|
||||
{
|
||||
throw new Win32Exception(result);
|
||||
}
|
||||
}
|
||||
@@ -56,12 +56,12 @@ partial struct PixelShaderEffect
|
||||
private RECT inputRect;
|
||||
|
||||
/// <summary>
|
||||
/// The <c>ID2D1DrawInfo</c> instance currently in use.
|
||||
/// The <see cref="ID2D1DrawInfo"/> instance currently in use.
|
||||
/// </summary>
|
||||
private ID2D1DrawInfo* d2D1DrawInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <c>ID2D1DrawInfo</c> instance currently in use.
|
||||
/// Gets the <see cref="ID2D1DrawInfo"/> instance currently in use.
|
||||
/// </summary>
|
||||
public ID2D1DrawInfo* D2D1DrawInfo => this.d2D1DrawInfo;
|
||||
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1Interop.Tests.Extensions;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.D2D1Interop.Tests.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> that uses the WIC APIs to load and decode images.
|
||||
/// </summary>
|
||||
internal static class WICHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Loads an <see cref="IWICBitmap"/> instance from a given path.
|
||||
/// </summary>
|
||||
/// <param name="filename">The path to load the image from.</param>
|
||||
/// <param name="width">The resulting image width.</param>
|
||||
/// <param name="height">The resulting image height.</param>
|
||||
/// <returns>The resulting <see cref="IWICBitmap"/> instance.</returns>
|
||||
public static unsafe ComPtr<IWICBitmap> LoadBitmapFromFile(string filename, out uint width, out uint height)
|
||||
{
|
||||
using ComPtr<IWICImagingFactory2> wicImagingFactory2 = default;
|
||||
|
||||
// Create a Windows Imaging Component (WIC) factory
|
||||
Windows.CoCreateInstance(
|
||||
rclsid: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_WICImagingFactory2)),
|
||||
pUnkOuter: null,
|
||||
dwClsContext: (uint)CLSCTX.CLSCTX_INPROC_SERVER,
|
||||
riid: Windows.__uuidof<IWICImagingFactory2>(),
|
||||
ppv: (void**)wicImagingFactory2.GetAddressOf()).Assert();
|
||||
|
||||
using ComPtr<IWICBitmapDecoder> wicBitmapDecoder = default;
|
||||
|
||||
// Get the bitmap decoder for the target file
|
||||
fixed (char* p = filename)
|
||||
{
|
||||
wicImagingFactory2.Get()->CreateDecoderFromFilename(
|
||||
wzFilename: (ushort*)p,
|
||||
pguidVendor: null,
|
||||
dwDesiredAccess: Windows.GENERIC_READ,
|
||||
metadataOptions: WICDecodeOptions.WICDecodeMetadataCacheOnDemand,
|
||||
ppIDecoder: wicBitmapDecoder.GetAddressOf()).Assert();
|
||||
}
|
||||
|
||||
using ComPtr<IWICBitmapFrameDecode> wicBitmapFrameDecode = default;
|
||||
|
||||
// Get the first frame of the loaded image (if more are present, they will be ignored)
|
||||
wicBitmapDecoder.Get()->GetFrame(0, wicBitmapFrameDecode.GetAddressOf()).Assert();
|
||||
|
||||
fixed (uint* widthPtr = &width)
|
||||
fixed (uint* heightPtr = &height)
|
||||
{
|
||||
// Extract the image size info
|
||||
wicBitmapFrameDecode.Get()->GetSize(widthPtr, heightPtr).Assert();
|
||||
}
|
||||
|
||||
Guid wicTargetPixelFormatGuid = GUID.GUID_WICPixelFormat32bppPBGRA;
|
||||
Guid wicActualPixelFormatGuid;
|
||||
|
||||
// Get the current and target pixel format info
|
||||
wicBitmapFrameDecode.Get()->GetPixelFormat(&wicActualPixelFormatGuid).Assert();
|
||||
|
||||
using ComPtr<IWICBitmap> wicBitmap = default;
|
||||
|
||||
// Create the target bitmap
|
||||
wicImagingFactory2.Get()->CreateBitmap(
|
||||
uiWidth: width,
|
||||
uiHeight: height,
|
||||
pixelFormat: &wicTargetPixelFormatGuid,
|
||||
option: WICBitmapCreateCacheOption.WICBitmapCacheOnLoad,
|
||||
ppIBitmap: wicBitmap.GetAddressOf()).Assert();
|
||||
|
||||
WICRect wicRect;
|
||||
wicRect.X = 0;
|
||||
wicRect.Y = 0;
|
||||
wicRect.Width = (int)width;
|
||||
wicRect.Height = (int)height;
|
||||
|
||||
using (ComPtr<IWICBitmapLock> wicBitmapLock = default)
|
||||
{
|
||||
// Lock the bitmap
|
||||
wicBitmap.Get()->Lock(
|
||||
prcLock: &wicRect,
|
||||
flags: (uint)WICBitmapLockFlags.WICBitmapLockWrite,
|
||||
ppILock: wicBitmapLock.GetAddressOf()).Assert();
|
||||
|
||||
uint wicBitmapStride;
|
||||
|
||||
// Get the stride
|
||||
wicBitmapLock.Get()->GetStride(&wicBitmapStride).Assert();
|
||||
|
||||
uint wicBitmapSize;
|
||||
byte* wicBitmapPointer;
|
||||
|
||||
// Get the bitmap size and pointer
|
||||
wicBitmapLock.Get()->GetDataPointer(&wicBitmapSize, &wicBitmapPointer).Assert();
|
||||
|
||||
// Check if a pixel format conversion is needed
|
||||
if (wicTargetPixelFormatGuid == wicActualPixelFormatGuid)
|
||||
{
|
||||
// No conversion is needed, just copy the pixels directly
|
||||
wicBitmapFrameDecode.Get()->CopyPixels(
|
||||
prc: &wicRect,
|
||||
cbStride: wicBitmapStride,
|
||||
cbBufferSize: wicBitmapSize,
|
||||
pbBuffer: wicBitmapPointer).Assert();
|
||||
}
|
||||
else
|
||||
{
|
||||
using ComPtr<IWICFormatConverter> wicFormatConverter = default;
|
||||
|
||||
// Create a format converter
|
||||
wicImagingFactory2.Get()->CreateFormatConverter(wicFormatConverter.GetAddressOf()).Assert();
|
||||
|
||||
// Get a format converter to decode the pixel data
|
||||
wicFormatConverter.Get()->Initialize(
|
||||
pISource: (IWICBitmapSource*)wicBitmapFrameDecode.Get(),
|
||||
dstFormat: &wicTargetPixelFormatGuid,
|
||||
dither: WICBitmapDitherType.WICBitmapDitherTypeNone,
|
||||
pIPalette: null,
|
||||
alphaThresholdPercent: 0,
|
||||
paletteTranslate: WICBitmapPaletteType.WICBitmapPaletteTypeCustom).Assert();
|
||||
|
||||
// Decode the pixel data into the upload buffer
|
||||
wicFormatConverter.Get()->CopyPixels(
|
||||
prc: &wicRect,
|
||||
cbStride: wicBitmapStride,
|
||||
cbBufferSize: wicBitmapSize,
|
||||
pbBuffer: wicBitmapPointer).Assert();
|
||||
}
|
||||
}
|
||||
|
||||
return wicBitmap.Move();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves a given image buffer to a target path.
|
||||
/// </summary>
|
||||
/// <param name="filename">The path to save the image to.</param>
|
||||
/// <param name="width">The image width.</param>
|
||||
/// <param name="height">The image height.</param>
|
||||
/// <param name="strideInBytes">The image stride in bytes.</param>
|
||||
/// <param name="buffer">The image pixel buffer.</param>
|
||||
public static unsafe void SaveBitmapToFile(string filename, uint width, uint height, uint strideInBytes, byte* buffer)
|
||||
{
|
||||
using ComPtr<IWICImagingFactory2> wicImagingFactory2 = default;
|
||||
|
||||
// Create a Windows Imaging Component (WIC) factory
|
||||
Windows.CoCreateInstance(
|
||||
rclsid: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_WICImagingFactory2)),
|
||||
pUnkOuter: null,
|
||||
dwClsContext: (uint)CLSCTX.CLSCTX_INPROC_SERVER,
|
||||
riid: Windows.__uuidof<IWICImagingFactory2>(),
|
||||
ppv: (void**)wicImagingFactory2.GetAddressOf()).Assert();
|
||||
|
||||
using ComPtr<IWICBitmapEncoder> wicBitmapEncoder = default;
|
||||
|
||||
// Create the image encoder
|
||||
wicImagingFactory2.Get()->CreateEncoder(
|
||||
guidContainerFormat: (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in GUID.GUID_ContainerFormatPng)),
|
||||
pguidVendor: null,
|
||||
ppIEncoder: wicBitmapEncoder.GetAddressOf()).Assert();
|
||||
|
||||
using ComPtr<IWICStream> wicStream = default;
|
||||
|
||||
// Create and initialize a stream to the target file
|
||||
wicImagingFactory2.Get()->CreateStream(wicStream.GetAddressOf()).Assert();
|
||||
|
||||
fixed (char* p = filename)
|
||||
{
|
||||
// Initialize the stream to the target file
|
||||
wicStream.Get()->InitializeFromFilename((ushort*)p, Windows.GENERIC_WRITE);
|
||||
}
|
||||
|
||||
// Initialize the encoder
|
||||
wicBitmapEncoder.Get()->Initialize(
|
||||
pIStream: (IStream*)wicStream.Get(),
|
||||
cacheOption: WICBitmapEncoderCacheOption.WICBitmapEncoderNoCache).Assert();
|
||||
|
||||
using ComPtr<IWICBitmapFrameEncode> wicBitmapFrameEncode = default;
|
||||
|
||||
// Create the image frame and initialize it
|
||||
wicBitmapEncoder.Get()->CreateNewFrame(wicBitmapFrameEncode.GetAddressOf(), null).Assert();
|
||||
|
||||
Guid wicTargetPixelFormatGuid = GUID.GUID_WICPixelFormat32bppPBGRA;
|
||||
|
||||
// Set the encoding properties
|
||||
wicBitmapFrameEncode.Get()->Initialize(null).Assert();
|
||||
wicBitmapFrameEncode.Get()->SetSize(width, height).Assert();
|
||||
wicBitmapFrameEncode.Get()->SetPixelFormat(&wicTargetPixelFormatGuid).Assert();
|
||||
|
||||
// Encode the target image
|
||||
wicBitmapFrameEncode.Get()->WritePixels(
|
||||
lineCount: height,
|
||||
cbStride: strideInBytes,
|
||||
cbBufferSize: strideInBytes * height,
|
||||
pbPixels: buffer).Assert();
|
||||
|
||||
// Flush the changes
|
||||
wicBitmapFrameEncode.Get()->Commit();
|
||||
wicBitmapEncoder.Get()->Commit();
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする