Files
I150/srcs/RobotNet10/RobotApp/Communication/CeresSharp/Native/SafeHandles/InterpolatorHandle.cs
2026-07-03 16:37:12 +07:00

52 lines
1.4 KiB
C#

using System;
using CeresSharp.Native;
namespace CeresSharp.Native.SafeHandles;
/// <summary>
/// Safe handle for Ceres Interpolator (BiCubic or Cubic).
/// </summary>
internal sealed class InterpolatorHandle : BaseSafeHandle
{
private readonly bool _isBicubic;
private InterpolatorHandle() : base()
{
}
private InterpolatorHandle(IntPtr handle, bool ownsHandle, bool isBicubic) : base(handle, ownsHandle)
{
_isBicubic = isBicubic;
}
public static InterpolatorHandle CreateBicubic(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
throw new Exceptions.CeresException(Exceptions.CeresErrorCode.NullPointer, "BiCubic interpolator handle is null");
}
return new InterpolatorHandle(handle, true, true);
}
public static InterpolatorHandle CreateCubic(IntPtr handle)
{
if (handle == IntPtr.Zero)
{
throw new Exceptions.CeresException(Exceptions.CeresErrorCode.NullPointer, "Cubic interpolator handle is null");
}
return new InterpolatorHandle(handle, true, false);
}
protected override void ReleaseNativeHandle(IntPtr handle)
{
if (_isBicubic)
{
CeresNative.ceres_wrapper_free_bicubic_interpolator(handle);
}
else
{
CeresNative.ceres_wrapper_free_cubic_interpolator(handle);
}
}
}