Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 7 additions & 28 deletions src/CoreImage/CIContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,18 @@
using CoreGraphics;
using CoreFoundation;
using ObjCRuntime;
#if !MONOMAC
using Metal;
#endif
#if HAS_OPENGLES
using OpenGLES;
#endif

#nullable enable

namespace CoreImage {
#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
public class CIContextOptions : DictionaryContainer {

public CIContextOptions ()
Expand Down Expand Up @@ -105,15 +101,13 @@ public int? CIImageFormat {
}
}

#if NET
/// <summary>Gets or sets whether to request low priority from the GPU.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
#endif
public bool? PriorityRequestLow {
get {
return GetBoolValue (CIContext.PriorityRequestLow);
Expand All @@ -136,15 +130,13 @@ public bool? HighQualityDownsample {
}
}

#if NET
/// <summary>If <see langword="true" />, the output should premultiply pixel values by their alpha values.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
public bool? OutputPremultiplied {
get {
return GetBoolValue (CIContext.OutputPremultiplied);
Expand All @@ -154,15 +146,13 @@ public bool? OutputPremultiplied {
}
}

#if NET
/// <summary>If not <see langword="null" />, <see langword="true" /> indicates that intermediate images should be cached.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
#endif
public bool? CacheIntermediates {
get {
return GetBoolValue (CIContext.CacheIntermediates);
Expand All @@ -172,15 +162,10 @@ public bool? CacheIntermediates {
}
}

#if NET
[SupportedOSPlatform ("ios13.0")]
[SupportedOSPlatform ("tvos13.0")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("maccatalyst")]
#else
[iOS (13, 0)]
[TV (13, 0)]
#endif
public bool? AllowLowPower {
get {
return GetBoolValue (CIContext.AllowLowPower);
Expand All @@ -190,15 +175,10 @@ public bool? AllowLowPower {
}
}

#if NET
[SupportedOSPlatform ("ios14.0")]
[SupportedOSPlatform ("tvos14.0")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("maccatalyst")]
#else
[iOS (14, 0)]
[TV (14, 0)]
#endif
public string? Name {
get {
return GetStringValue (CIContext.Name);
Expand All @@ -210,13 +190,10 @@ public string? Name {
}

public partial class CIContext {

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
public CIContext (CIContextOptions options) :
this (options?.Dictionary)
{
Expand All @@ -233,13 +210,20 @@ public static CIContext FromContext (CGContext ctx)
}

#if HAS_OPENGLES
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("tvos")]
[UnsupportedOSPlatform ("maccatalyst")]
[UnsupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("ios12.0")]
[ObsoletedOSPlatform ("tvos12.0")]
public static CIContext FromContext (EAGLContext eaglContext, CIContextOptions? options)
{
if (options is null)
return FromContext (eaglContext);

return FromContext (eaglContext, options.Dictionary);
}
#endif

public static CIContext FromMetalDevice (IMTLDevice device, CIContextOptions? options)
{
Expand All @@ -248,16 +232,11 @@ public static CIContext FromMetalDevice (IMTLDevice device, CIContextOptions? op

return FromMetalDevice (device, options.Dictionary);
}
#endif

#if MONOMAC
#if NET
[UnsupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[ObsoletedOSPlatform ("macos10.11")]
#else
[Deprecated (PlatformName.MacOSX, 10, 11)]
#endif
public CGLayer? CreateCGLayer (CGSize size)
{
return CreateCGLayer (size, null);
Expand Down
2 changes: 0 additions & 2 deletions src/CoreImage/CIDetectorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ public partial class CIDetectorOptions {
/// <remarks>To be added.</remarks>
public float? MinFeatureSize { get; set; }

#if NET
/// <summary>To be added.</summary>
/// <value>To be added.</value>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("tvos")]
#endif
public int? MaxFeatureCount { get; set; }

/// <summary>Gets or sets whether faces are tracked between frames.</summary>
Expand Down
52 changes: 22 additions & 30 deletions src/CoreImage/CIFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,10 @@

namespace CoreImage {
public partial class CIFilter {

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
protected CIFilter () : base ()
{
}
Expand Down Expand Up @@ -482,6 +479,8 @@ internal static CIFilter FromName (string? filterName, IntPtr handle)
case "CIMinimumComponent":
return new CIMinimumComponent (handle);
case "CIPersonSegmentation":
if (!SystemVersion.IsAtLeastXcode13)
throw new PlatformNotSupportedException (string.Format ("The filter '{0}' is not supported on the current version of this platform.", filterName));
return new CIPersonSegmentation (handle);
case "CIPerspectiveTile":
return new CIPerspectiveTile (handle);
Expand Down Expand Up @@ -536,14 +535,24 @@ internal static CIFilter FromName (string? filterName, IntPtr handle)
case "CIConvolution9Vertical":
return new CIConvolution9Vertical (handle);
case "CIConvolutionRGB3X3":
if (!SystemVersion.IsAtLeastXcode13)
throw new PlatformNotSupportedException (string.Format ("The filter '{0}' is not supported on the current version of this platform.", filterName));
return new CIConvolutionRGB3X3 (handle);
case "CIConvolutionRGB5X5":
if (!SystemVersion.IsAtLeastXcode13)
throw new PlatformNotSupportedException (string.Format ("The filter '{0}' is not supported on the current version of this platform.", filterName));
return new CIConvolutionRGB5X5 (handle);
case "CIConvolutionRGB7X7":
if (!SystemVersion.IsAtLeastXcode13)
throw new PlatformNotSupportedException (string.Format ("The filter '{0}' is not supported on the current version of this platform.", filterName));
return new CIConvolutionRGB7X7 (handle);
case "CIConvolutionRGB9Horizontal":
if (!SystemVersion.IsAtLeastXcode13)
throw new PlatformNotSupportedException (string.Format ("The filter '{0}' is not supported on the current version of this platform.", filterName));
return new CIConvolutionRGB9Horizontal (handle);
case "CIConvolutionRGB9Vertical":
if (!SystemVersion.IsAtLeastXcode13)
throw new PlatformNotSupportedException (string.Format ("The filter '{0}' is not supported on the current version of this platform.", filterName));
return new CIConvolutionRGB9Vertical (handle);
case "CILinearToSRGBToneCurve":
return new CILinearToSRGBToneCurve (handle);
Expand Down Expand Up @@ -592,6 +601,8 @@ internal static CIFilter FromName (string? filterName, IntPtr handle)
case "CILinearDodgeBlendMode":
return new CILinearDodgeBlendMode (handle);
case "CILinearLightBlendMode":
if (!SystemVersion.IsAtLeastXcode13)
throw new PlatformNotSupportedException (string.Format ("The filter '{0}' is not supported on the current version of this platform.", filterName));
return new CILinearLightBlendMode (handle);
case "CIPerspectiveCorrection":
return new CIPerspectiveCorrection (handle);
Expand All @@ -600,6 +611,8 @@ internal static CIFilter FromName (string? filterName, IntPtr handle)
case "CISubtractBlendMode":
return new CISubtractBlendMode (handle);
case "CIVividLightBlendMode":
if (!SystemVersion.IsAtLeastXcode13)
throw new PlatformNotSupportedException (string.Format ("The filter '{0}' is not supported on the current version of this platform.", filterName));
return new CIVividLightBlendMode (handle);
case "CIAccordionFoldTransition":
return new CIAccordionFoldTransition (handle);
Expand Down Expand Up @@ -722,41 +735,20 @@ internal static CIFilter FromName (string? filterName, IntPtr handle)
case "CIBlendWithRedMask":
return new CIBlendWithRedMask (handle);
case "CIMaximumScaleTransform":
if (!SystemVersion.IsAtLeastXcode16)
throw new PlatformNotSupportedException (string.Format ("The filter '{0}' is not supported on the current version of this platform.", filterName));
return new CIMaximumScaleTransform (handle);
case "CIToneMapHeadroom":
if (!SystemVersion.IsAtLeastXcode16)
throw new PlatformNotSupportedException (string.Format ("The filter '{0}' is not supported on the current version of this platform.", filterName));
return new CIToneMapHeadroom (handle);
case "CIAreaBoundsRed":
if (!SystemVersion.IsAtLeastXcode16)
throw new PlatformNotSupportedException (string.Format ("The filter '{0}' is not supported on the current version of this platform.", filterName));
return new CIAreaBoundsRed (handle);
default:
throw new NotImplementedException (String.Format ("Unknown filter type returned: `{0}', returning a default CIFilter", filterName));
}
}

#if !NET
// not every CIFilter supports inputImage, i.e.
// NSUnknownKeyException [<CICheckerboardGenerator 0x1648cb20> valueForUndefinedKey:]: this class is not key value coding-compliant for the key inputImage.
// and those will crash (on devices) if the property is called - and that includes displaying it in the debugger
[Obsolete ("Use 'InputImage' instead. If not available then the filter does not support it.")]
public CIImage? Image {
get {
return SupportsInputImage ? ValueForKey (CIFilterInputKey.Image) as CIImage : null;
}
set {
if (!SupportsInputImage)
ObjCRuntime.ThrowHelper.ThrowArgumentException ("inputImage is not supported by this filter");
SetValueForKey (value, CIFilterInputKey.Image.GetHandle ());
}
}

bool? supportsInputImage;

bool SupportsInputImage {
get {
if (!supportsInputImage.HasValue)
supportsInputImage = Array.IndexOf (InputKeys, "inputImage") >= 0;
return supportsInputImage.Value;
}
}
#endif
}
}
11 changes: 1 addition & 10 deletions src/CoreImage/CIImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,13 @@
using CoreVideo;
#endif

#if !NET
using NativeHandle = System.IntPtr;
#endif

#nullable enable

namespace CoreImage {
#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
public class CIAutoAdjustmentFilterOptions {

// The default value is true.
Expand Down Expand Up @@ -75,23 +69,20 @@ public class CIAutoAdjustmentFilterOptions {
/// <remarks>Some adjustments depend on image orientation to work, providing this hint helps the auto correction software pick the best results.</remarks>
public CIImageOrientation? ImageOrientation;

#if NET
/// <summary>Whether or not to automatically crop the image.</summary>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
public bool? AutoAdjustCrop;
#if NET

/// <summary>Gets or sets the automatic adjustment level.</summary>
/// <remarks>To be added.</remarks>
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
public bool? AutoAdjustLevel;

internal NSDictionary? ToDictionary ()
Expand Down
2 changes: 0 additions & 2 deletions src/CoreImage/CIImageInitializationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ public CGColorSpace? ColorSpace {
}


#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
// Keeping 'CIImageInitializationOptionsWithMetadata' to avoid breaking change
public class CIImageInitializationOptionsWithMetadata : CIImageInitializationOptions {
#if !COREBUILD
Expand Down
6 changes: 0 additions & 6 deletions src/CoreImage/CISampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ public enum CIFilterMode {
Linear,
}

#if NET
[SupportedOSPlatform ("ios")]
[SupportedOSPlatform ("maccatalyst")]
[SupportedOSPlatform ("macos")]
[SupportedOSPlatform ("tvos")]
#endif
public class CISamplerOptions {
public CISamplerOptions () { }

Expand All @@ -84,11 +82,7 @@ internal NSDictionary ToDictionary ()

if (AffineMatrix.HasValue) {
var a = AffineMatrix.Value;
#if NET
using (var array = NSArray.FromObjects (a.A, a.B, a.C, a.D, a.Tx, a.Ty))
#else
using (var array = NSArray.FromObjects (a.xx, a.yx, a.xy, a.yy, a.x0, a.y0))
#endif
ret.SetObject (array, CISampler.AffineMatrix);
}
if (WrapMode.HasValue) {
Expand Down
Loading