Skip to content

Commit 1b5518c

Browse files
committed
Added internal interface to get access to the NativeMagickImage class and use that in the Fx method of MagickImageCollection.
1 parent 6903d48 commit 1b5518c

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

src/Magick.NET/MagickImage.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,7 +2899,7 @@ public void Fx(string expression, Channels channels)
28992899
{
29002900
Throw.IfNullOrEmpty(nameof(expression), expression);
29012901

2902-
_nativeInstance.Instance = NativeMagickImage.Fx(_nativeInstance.Instance, expression, channels);
2902+
_nativeInstance.Instance = _nativeInstance.Fx(expression, channels);
29032903
}
29042904

29052905
/// <summary>
@@ -7047,12 +7047,6 @@ internal static IReadOnlyList<IMagickImage<QuantumType>> CreateList(IntPtr image
70477047
return result;
70487048
}
70497049

7050-
internal static IMagickImage<QuantumType> Fx(IMagickImage<QuantumType> image, string expression, Channels channels)
7051-
{
7052-
var result = NativeMagickImage.Fx(GetInstance(image), expression, channels);
7053-
return Create(result, GetSettings(image));
7054-
}
7055-
70567050
internal static IntPtr GetInstance(IMagickImage? image)
70577051
{
70587052
if (image is null)
@@ -7064,6 +7058,14 @@ internal static IntPtr GetInstance(IMagickImage? image)
70647058
throw new NotSupportedException();
70657059
}
70667060

7061+
internal static INativeMagickImage GetNativeImage(IMagickImage image)
7062+
{
7063+
if (image is MagickImage magickImage)
7064+
return magickImage._nativeInstance;
7065+
7066+
throw new NotSupportedException();
7067+
}
7068+
70677069
internal static MagickSettings GetSettings(IMagickImage<QuantumType> image)
70687070
{
70697071
if (image.Settings is MagickSettings settings)

src/Magick.NET/MagickImageCollection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ public IMagickImage<QuantumType> Fx(string expression, Channels channels)
572572
Throw.IfNullOrEmpty(nameof(expression), expression);
573573

574574
using var imageAttacher = new TemporaryImageAttacher(_images);
575-
return MagickImage.Fx(_images[0], expression, channels);
575+
var nativeImage = MagickImage.GetNativeImage(_images[0]);
576+
var newInstance = nativeImage.Fx(expression, channels);
577+
return MagickImage.Create(newInstance, MagickImage.GetSettings(_images[0]));
576578
}
577579

578580
/// <summary>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System;
5+
6+
namespace ImageMagick
7+
{
8+
internal interface INativeMagickImage
9+
{
10+
IntPtr Fx(string expression, Channels channels);
11+
}
12+
}

src/Magick.NET/Native/MagickImage.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,12 @@ public partial class MagickImage : IDisposable
3535
private delegate long TellStreamDelegate(IntPtr user_data);
3636

3737
[NativeInterop(RaiseWarnings = true, StaticDispose = true)]
38-
private unsafe sealed partial class NativeMagickImage : NativeInstance
38+
private unsafe sealed partial class NativeMagickImage : NativeInstance, INativeMagickImage
3939
{
4040
[Throws]
4141
[Cleanup(Name = nameof(DisposeInstance))]
4242
public static partial NativeMagickImage Create(IMagickSettings<QuantumType>? settings);
4343

44-
[Throws]
45-
[Cleanup(Name = nameof(DisposeInstance))]
46-
public static partial IntPtr Fx(IntPtr image, string expression, Channels channels);
47-
4844
public static partial IntPtr GetNext(IntPtr image);
4945

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

462+
[Throws]
463+
public partial IntPtr Fx(string expression, Channels channels);
464+
466465
[Throws]
467466
public partial void GammaCorrect(double gamma, Channels channels);
468467

0 commit comments

Comments
 (0)