68 private const string _modeKey =
"Mode";
69 private const string _xKey =
"X";
70 private const string _yKey =
"Y";
71 private const string _defaultModeKey =
"DefaultMode";
73 internal const uint DefaultX = 1;
74 internal const uint DefaultY = 1;
76 private readonly Handle _handle;
87 var handle =
new Handle();
88 DllHelper.ExecuteAndMapReturnCodes(() =>
89 CInterface.peak_icv_Preprocessing_Downsampling_Create(out handle,
90 new Backend.Types.peak_common_point_u(1, 1),
91 (Backend.Types.peak_icv_downsampling_mode) _defaultMode));
101 _defaultMode = defaultMode;
104 var handle =
new Handle();
105 DllHelper.ExecuteAndMapReturnCodes(() =>
106 CInterface.peak_icv_Preprocessing_Downsampling_Create(out handle,
107 new Backend.Types.peak_common_point_u(1, 1),
108 (Backend.Types.peak_icv_downsampling_mode) _defaultMode));
129 DllHelper.ExecuteAndMapReturnCodes(() =>
130 CInterface.peak_icv_Preprocessing_Downsampling_SetFactor(_handle,
131 new Backend.Types.peak_common_point_u(value,
Y)));
144 DllHelper.ExecuteAndMapReturnCodes(() =>
145 CInterface.peak_icv_Preprocessing_Downsampling_SetFactor(_handle,
146 new Backend.Types.peak_common_point_u(
X, value)));
157 var range =
new Backend.Types.peak_icv_interval_u();
158 DllHelper.ExecuteAndMapReturnCodes(() =>
159 CInterface.peak_icv_Preprocessing_Downsampling_GetRange(_handle,
161 return new IntervalU(range.minimum, range.maximum);
172 Backend.Types.peak_icv_downsampling_mode mode = Backend.Types.peak_icv_downsampling_mode
173 .PEAK_ICV_BINNING_AVERAGE;
174 DllHelper.ExecuteAndMapReturnCodes(() =>
175 CInterface.peak_icv_Preprocessing_Downsampling_GetMode(_handle,
187 DllHelper.ExecuteAndMapReturnCodes(() =>
188 CInterface.peak_icv_Preprocessing_Downsampling_SetMode(_handle,
189 (Backend.Types.peak_icv_downsampling_mode) value));
197 var factor =
new Backend.Types.peak_common_point_u();
198 DllHelper.ExecuteAndMapReturnCodes(() =>
199 CInterface.peak_icv_Preprocessing_Downsampling_GetFactor(_handle,
201 return new PointU(factor.x, factor.y);
205 DllHelper.ExecuteAndMapReturnCodes(() =>
206 CInterface.peak_icv_Preprocessing_Downsampling_SetFactor(_handle,
207 new Backend.Types.peak_common_point_u(value.X, value.Y)));
217 GC.SuppressFinalize(
this);
220 SafeHandle IHasSafeHandle.Handle => _handle;
259 var outputImageSize =
new Backend.Types.peak_common_size();
260 DllHelper.ExecuteAndMapReturnCodes(() =>
261 CInterface.peak_icv_Preprocessing_Downsampling_GetOutputImageSize(_handle,
262 inputImage._handle, out outputImageSize));
264 var outputImage =
new Image(inputImage.
PixelFormat,
new Size(outputImageSize.width, outputImageSize.height));
266 DllHelper.ExecuteAndMapReturnCodes(() =>
267 CInterface.peak_icv_Preprocessing_Downsampling_Process(_handle,
268 inputImage._handle, outputImage._handle));
272 bool NeedsProcessing()
274 var shouldProcess =
false;
275 DllHelper.ExecuteAndMapReturnCodes(() =>
276 CInterface.peak_icv_Preprocessing_Downsampling_NeedsProcessing(_handle, out shouldProcess));
277 return shouldProcess;
313 return base.Process(input);
329 base.Serialize(archive);
336 archive.
SetString(_defaultModeKey, _defaultMode.ToString());
368 base.Deserialize(archive);
370 var x = (uint) archive.
GetInt64(_xKey);
371 var y = (uint) archive.
GetInt64(_yKey);
372 Factor =
new PointU(x, y);
374 var modeStr = archive.
GetString(_modeKey);
375 var defaultModeStr = archive.
GetString(_defaultModeKey);
385 $
"The given default downsampling mode \"{defaultModeStr}\" is unknown!");
389 _defaultMode = defaultMode;
417 base.ResetToDefault();
424 internal sealed class Handle : SafeHandleZeroOrMinusOneIsInvalid
426 public Handle() : base(true)
430 protected override bool ReleaseHandle()
432 return CInterface.peak_icv_Preprocessing_Downsampling_Destroy(handle) ==
433 Backend.Types.peak_icv_status.PEAK_ICV_STATUS_SUCCESS;
437 private static class CInterface
439 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
440 public static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Downsampling_Create(
441 out Handle handle, Backend.Types.peak_common_point_u factor,
442 Backend.Types.peak_icv_downsampling_mode mode);
444 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
445 public static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Downsampling_Destroy(
448 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
449 public static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Downsampling_SetFactor(
450 Handle handle, Backend.Types.peak_common_point_u factor);
452 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
453 public static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Downsampling_GetFactor(
454 Handle handle, out Backend.Types.peak_common_point_u factor);
456 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
457 public static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Downsampling_GetRange(
458 Handle handle, out Backend.Types.peak_icv_interval_u range);
460 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
461 public static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Downsampling_SetMode(
462 Handle handle, Backend.Types.peak_icv_downsampling_mode mode);
464 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
465 public static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Downsampling_GetMode(
466 Handle handle, out Backend.Types.peak_icv_downsampling_mode mode);
468 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
469 public static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Downsampling_GetOutputImageSize(
470 Handle handle,
Image.Handle imageHandle, out Backend.Types.peak_common_size outputImageSize);
472 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
473 public static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Downsampling_NeedsProcessing(
474 Handle handle, [MarshalAs(UnmanagedType.I1)] out
bool needsProcessing);
476 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
477 public static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Downsampling_Process(
478 Handle handle,
Image.Handle inputImageHandle,
Image.Handle outputImageHandle);