Skip to content

Commit

Permalink
Use SourceGenerator for native code of MagickGeometry and change from…
Browse files Browse the repository at this point in the history
… double to nint/nuint.
  • Loading branch information
dlemstra committed Jun 23, 2024
1 parent 7520c43 commit d794c2b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 262 deletions.
273 changes: 17 additions & 256 deletions src/Magick.NET/Native/Types/MagickGeometry.cs
Original file line number Diff line number Diff line change
@@ -1,269 +1,30 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.
// <auto-generated/>
#nullable enable

using System;
using System.Security;
using System.Runtime.InteropServices;
using ImageMagick.SourceGenerator;

namespace ImageMagick;

/// <content />
public partial class MagickGeometry
{
[SuppressUnmanagedCodeSecurity]
private static unsafe class NativeMethods
[NativeInterop(NativeToManaged = true)]
private partial class NativeMagickGeometry : NativeInstance
{
#if PLATFORM_x64 || PLATFORM_AnyCPU
public static class X64
{
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MagickGeometry_Create();
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickGeometry_Dispose(IntPtr instance);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern double MagickGeometry_X_Get(IntPtr instance);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern double MagickGeometry_Y_Get(IntPtr instance);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern double MagickGeometry_Width_Get(IntPtr instance);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern double MagickGeometry_Height_Get(IntPtr instance);
[DllImport(NativeLibrary.X64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr MagickGeometry_Initialize(IntPtr Instance, IntPtr value);
}
#endif
#if PLATFORM_arm64 || PLATFORM_AnyCPU
public static class ARM64
{
[DllImport(NativeLibrary.ARM64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MagickGeometry_Create();
[DllImport(NativeLibrary.ARM64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickGeometry_Dispose(IntPtr instance);
[DllImport(NativeLibrary.ARM64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern double MagickGeometry_X_Get(IntPtr instance);
[DllImport(NativeLibrary.ARM64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern double MagickGeometry_Y_Get(IntPtr instance);
[DllImport(NativeLibrary.ARM64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern double MagickGeometry_Width_Get(IntPtr instance);
[DllImport(NativeLibrary.ARM64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern double MagickGeometry_Height_Get(IntPtr instance);
[DllImport(NativeLibrary.ARM64Name, CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr MagickGeometry_Initialize(IntPtr Instance, IntPtr value);
}
#endif
#if PLATFORM_x86 || PLATFORM_AnyCPU
public static class X86
{
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr MagickGeometry_Create();
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern void MagickGeometry_Dispose(IntPtr instance);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern double MagickGeometry_X_Get(IntPtr instance);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern double MagickGeometry_Y_Get(IntPtr instance);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern double MagickGeometry_Width_Get(IntPtr instance);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern double MagickGeometry_Height_Get(IntPtr instance);
[DllImport(NativeLibrary.X86Name, CallingConvention = CallingConvention.Cdecl)]
public static extern UIntPtr MagickGeometry_Initialize(IntPtr Instance, IntPtr value);
}
#endif
}
private unsafe sealed partial class NativeMagickGeometry : NativeInstance
{
static NativeMagickGeometry() { Environment.Initialize(); }
protected override void Dispose(IntPtr instance)
{
#if PLATFORM_AnyCPU
if (Runtime.IsArm64)
#endif
#if PLATFORM_arm64 || PLATFORM_AnyCPU
NativeMethods.ARM64.MagickGeometry_Dispose(instance);
#endif
#if PLATFORM_AnyCPU
else if (Runtime.Is64Bit)
#endif
#if PLATFORM_x64 || PLATFORM_AnyCPU
NativeMethods.X64.MagickGeometry_Dispose(instance);
#endif
#if PLATFORM_AnyCPU
else
#endif
#if PLATFORM_x86 || PLATFORM_AnyCPU
NativeMethods.X86.MagickGeometry_Dispose(instance);
#endif
}
public NativeMagickGeometry()
{
#if PLATFORM_AnyCPU
if (Runtime.IsArm64)
#endif
#if PLATFORM_arm64 || PLATFORM_AnyCPU
Instance = NativeMethods.ARM64.MagickGeometry_Create();
#endif
#if PLATFORM_AnyCPU
else if (Runtime.Is64Bit)
#endif
#if PLATFORM_x64 || PLATFORM_AnyCPU
Instance = NativeMethods.X64.MagickGeometry_Create();
#endif
#if PLATFORM_AnyCPU
else
#endif
#if PLATFORM_x86 || PLATFORM_AnyCPU
Instance = NativeMethods.X86.MagickGeometry_Create();
#endif
if (Instance == IntPtr.Zero)
throw new InvalidOperationException();
}
public NativeMagickGeometry(IntPtr instance)
{
Instance = instance;
}
protected override string TypeName
{
get
{
return nameof(MagickGeometry);
}
}
public double X
{
get
{
double result;
#if PLATFORM_AnyCPU
if (Runtime.IsArm64)
#endif
#if PLATFORM_arm64 || PLATFORM_AnyCPU
result = NativeMethods.ARM64.MagickGeometry_X_Get(Instance);
#endif
#if PLATFORM_AnyCPU
else if (Runtime.Is64Bit)
#endif
#if PLATFORM_x64 || PLATFORM_AnyCPU
result = NativeMethods.X64.MagickGeometry_X_Get(Instance);
#endif
#if PLATFORM_AnyCPU
else
#endif
#if PLATFORM_x86 || PLATFORM_AnyCPU
result = NativeMethods.X86.MagickGeometry_X_Get(Instance);
#endif
return result;
}
}
public double Y
{
get
{
double result;
#if PLATFORM_AnyCPU
if (Runtime.IsArm64)
#endif
#if PLATFORM_arm64 || PLATFORM_AnyCPU
result = NativeMethods.ARM64.MagickGeometry_Y_Get(Instance);
#endif
#if PLATFORM_AnyCPU
else if (Runtime.Is64Bit)
#endif
#if PLATFORM_x64 || PLATFORM_AnyCPU
result = NativeMethods.X64.MagickGeometry_Y_Get(Instance);
#endif
#if PLATFORM_AnyCPU
else
#endif
#if PLATFORM_x86 || PLATFORM_AnyCPU
result = NativeMethods.X86.MagickGeometry_Y_Get(Instance);
#endif
return result;
}
}
public double Width
{
get
{
double result;
#if PLATFORM_AnyCPU
if (Runtime.IsArm64)
#endif
#if PLATFORM_arm64 || PLATFORM_AnyCPU
result = NativeMethods.ARM64.MagickGeometry_Width_Get(Instance);
#endif
#if PLATFORM_AnyCPU
else if (Runtime.Is64Bit)
#endif
#if PLATFORM_x64 || PLATFORM_AnyCPU
result = NativeMethods.X64.MagickGeometry_Width_Get(Instance);
#endif
#if PLATFORM_AnyCPU
else
#endif
#if PLATFORM_x86 || PLATFORM_AnyCPU
result = NativeMethods.X86.MagickGeometry_Width_Get(Instance);
#endif
return result;
}
}
public double Height
{
get
{
double result;
#if PLATFORM_AnyCPU
if (Runtime.IsArm64)
#endif
#if PLATFORM_arm64 || PLATFORM_AnyCPU
result = NativeMethods.ARM64.MagickGeometry_Height_Get(Instance);
#endif
#if PLATFORM_AnyCPU
else if (Runtime.Is64Bit)
#endif
#if PLATFORM_x64 || PLATFORM_AnyCPU
result = NativeMethods.X64.MagickGeometry_Height_Get(Instance);
#endif
#if PLATFORM_AnyCPU
else
#endif
#if PLATFORM_x86 || PLATFORM_AnyCPU
result = NativeMethods.X86.MagickGeometry_Height_Get(Instance);
#endif
return result;
}
}
public GeometryFlags Initialize(string value)
{
using var valueNative = UTF8Marshaler.CreateInstance(value);
UIntPtr result;
#if PLATFORM_AnyCPU
if (Runtime.IsArm64)
#endif
#if PLATFORM_arm64 || PLATFORM_AnyCPU
result = NativeMethods.ARM64.MagickGeometry_Initialize(Instance, valueNative.Instance);
#endif
#if PLATFORM_AnyCPU
else if (Runtime.Is64Bit)
#endif
#if PLATFORM_x64 || PLATFORM_AnyCPU
result = NativeMethods.X64.MagickGeometry_Initialize(Instance, valueNative.Instance);
#endif
#if PLATFORM_AnyCPU
else
#endif
#if PLATFORM_x86 || PLATFORM_AnyCPU
result = NativeMethods.X86.MagickGeometry_Initialize(Instance, valueNative.Instance);
#endif
return (GeometryFlags)result;
}
}
internal static MagickGeometry? CreateInstance(IntPtr instance)
{
if (instance == IntPtr.Zero)
return null;
using NativeMagickGeometry nativeInstance = new NativeMagickGeometry(instance);
return new MagickGeometry(nativeInstance);
=> Instance = Create();

public static partial IntPtr Create();

public partial nint X_Get();

public partial nint Y_Get();

public partial nuint Width_Get();

public partial nuint Height_Get();

public partial GeometryFlags Initialize(string value);
}
}
12 changes: 6 additions & 6 deletions src/Magick.NET/Types/MagickGeometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,10 @@ private void InitializeFromPercentage(int x, int y, Percentage percentageWidth,

private void Initialize(NativeMagickGeometry instance)
{
X = (int)instance.X;
Y = (int)instance.Y;
Width = (int)instance.Width;
Height = (int)instance.Height;
X = (int)instance.X_Get();
Y = (int)instance.Y_Get();
Width = (int)instance.Width_Get();
Height = (int)instance.Height_Get();
}

private void Initialize(NativeMagickGeometry instance, GeometryFlags flags)
Expand All @@ -452,7 +452,7 @@ private void InitializeFromAspectRation(NativeMagickGeometry instance, string va
Width = ParseInt(ratio[0]);
Height = ParseInt(ratio[1]);

X = (int)instance.X;
Y = (int)instance.Y;
X = (int)instance.X_Get();
Y = (int)instance.Y_Get();
}
}

0 comments on commit d794c2b

Please sign in to comment.