Skip to content

Commit

Permalink
Added internal interface to get access to the NativeMagickImage class…
Browse files Browse the repository at this point in the history
… and use that in the Fx method of MagickImageCollection.
  • Loading branch information
dlemstra committed Oct 27, 2024
1 parent 6903d48 commit 1b5518c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
16 changes: 9 additions & 7 deletions src/Magick.NET/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2899,7 +2899,7 @@ public void Fx(string expression, Channels channels)
{
Throw.IfNullOrEmpty(nameof(expression), expression);

_nativeInstance.Instance = NativeMagickImage.Fx(_nativeInstance.Instance, expression, channels);
_nativeInstance.Instance = _nativeInstance.Fx(expression, channels);
}

/// <summary>
Expand Down Expand Up @@ -7047,12 +7047,6 @@ internal static IReadOnlyList<IMagickImage<QuantumType>> CreateList(IntPtr image
return result;
}

internal static IMagickImage<QuantumType> Fx(IMagickImage<QuantumType> image, string expression, Channels channels)
{
var result = NativeMagickImage.Fx(GetInstance(image), expression, channels);
return Create(result, GetSettings(image));
}

internal static IntPtr GetInstance(IMagickImage? image)
{
if (image is null)
Expand All @@ -7064,6 +7058,14 @@ internal static IntPtr GetInstance(IMagickImage? image)
throw new NotSupportedException();
}

internal static INativeMagickImage GetNativeImage(IMagickImage image)
{
if (image is MagickImage magickImage)
return magickImage._nativeInstance;

throw new NotSupportedException();
}

internal static MagickSettings GetSettings(IMagickImage<QuantumType> image)
{
if (image.Settings is MagickSettings settings)
Expand Down
4 changes: 3 additions & 1 deletion src/Magick.NET/MagickImageCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,9 @@ public IMagickImage<QuantumType> Fx(string expression, Channels channels)
Throw.IfNullOrEmpty(nameof(expression), expression);

using var imageAttacher = new TemporaryImageAttacher(_images);
return MagickImage.Fx(_images[0], expression, channels);
var nativeImage = MagickImage.GetNativeImage(_images[0]);
var newInstance = nativeImage.Fx(expression, channels);
return MagickImage.Create(newInstance, MagickImage.GetSettings(_images[0]));
}

/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions src/Magick.NET/Native/INativeMagickImage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
// Licensed under the Apache License, Version 2.0.

using System;

namespace ImageMagick
{
internal interface INativeMagickImage
{
IntPtr Fx(string expression, Channels channels);
}
}
9 changes: 4 additions & 5 deletions src/Magick.NET/Native/MagickImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@ public partial class MagickImage : IDisposable
private delegate long TellStreamDelegate(IntPtr user_data);

[NativeInterop(RaiseWarnings = true, StaticDispose = true)]
private unsafe sealed partial class NativeMagickImage : NativeInstance
private unsafe sealed partial class NativeMagickImage : NativeInstance, INativeMagickImage
{
[Throws]
[Cleanup(Name = nameof(DisposeInstance))]
public static partial NativeMagickImage Create(IMagickSettings<QuantumType>? settings);

[Throws]
[Cleanup(Name = nameof(DisposeInstance))]
public static partial IntPtr Fx(IntPtr image, string expression, Channels channels);

public static partial IntPtr GetNext(IntPtr image);

public partial nuint AnimationDelay_Get();
Expand Down Expand Up @@ -463,6 +459,9 @@ private unsafe sealed partial class NativeMagickImage : NativeInstance
[SetInstance]
public partial void Frame(MagickRectangle geometry);

[Throws]
public partial IntPtr Fx(string expression, Channels channels);

[Throws]
public partial void GammaCorrect(double gamma, Channels channels);

Expand Down

0 comments on commit 1b5518c

Please sign in to comment.