21 private const string _xKey =
"X";
22 private const string _yKey =
"Y";
23 private const string _hotpixelListKey =
"HotpixelList";
25 private readonly Handle _handle;
32 var handle =
new Handle();
33 DllHelper.ExecuteAndMapReturnCodes(() =>
34 CInterface.peak_icv_Preprocessing_HotpixelCorrection_Create(out handle));
39 public override string TypeId =>
"HotpixelCorrection";
48 nuint hotpixelCount = 0;
50 DllHelper.ExecuteAndMapReturnCodes(() =>
51 CInterface.peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(
52 _handle, out hotpixelCount));
54 var hotpixelList =
new Backend.Types.peak_icv_point[hotpixelCount];
55 DllHelper.ExecuteAndMapReturnCodes(() =>
56 CInterface.peak_icv_Preprocessing_HotpixelCorrection_GetList(
57 _handle, hotpixelList, hotpixelCount));
59 return hotpixelList.Select(point =>
new Point(point.x, point.y));
63 Backend.Types.peak_icv_point[] hotpixelList =
64 value.Select(point =>
new Backend.Types.peak_icv_point(point.X, point.Y)).ToArray();
65 DllHelper.ExecuteAndMapReturnCodes(() =>
66 CInterface.peak_icv_Preprocessing_HotpixelCorrection_SetList(
67 _handle, hotpixelList, (nuint) hotpixelList.Count()));
82 var interval =
new Backend.Types.peak_icv_interval_u();
83 DllHelper.ExecuteAndMapReturnCodes(() =>
84 CInterface.peak_icv_Preprocessing_HotpixelCorrection_GetSensitivityRange(
85 _handle, out interval));
86 return new IntervalU(interval.minimum, interval.maximum);
96 GC.SuppressFinalize(
this);
99 SafeHandle IHasSafeHandle.Handle => _handle;
135 DllHelper.ExecuteAndMapReturnCodes(() =>
136 CInterface.peak_icv_Preprocessing_HotpixelCorrection_ProcessInplace(
137 _handle, inputImage._handle));
141 bool NeedsProcessing()
143 nuint hotpixelCount = 0;
144 DllHelper.ExecuteAndMapReturnCodes(() =>
145 CInterface.peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(
146 _handle, out hotpixelCount));
148 return hotpixelCount != 0;
181 return base.Process(input);
197 base.Serialize(archive);
200 var archivesList =
new List<IArchive>(hotpixelList.Length);
201 foreach (
Point pixel
in hotpixelList)
206 archivesList.Add(pixelArchive);
209 archive.SetArchiveArray(_hotpixelListKey, archivesList);
241 base.Deserialize(archive);
243 IReadOnlyList<IArchive> archives = archive.
GetArchiveArray(_hotpixelListKey);
244 var hotpixelList =
new List<Point>(archives.Count);
245 foreach (
IArchive? pixelArchive
in archives)
247 var x = pixelArchive.
GetInt64(_xKey);
248 var y = pixelArchive.
GetInt64(_yKey);
249 hotpixelList.Add(
new Point((
int) x, (
int) y));
294 public void Detect(
Image image, uint sensitivity = 3,
float gainFactor = 1.0F)
296 DllHelper.ExecuteAndMapReturnCodes(() =>
297 CInterface.peak_icv_Preprocessing_HotpixelCorrection_Detect(
298 _handle, image._handle, sensitivity, gainFactor));
310 DllHelper.ExecuteAndMapReturnCodes(() =>
311 CInterface.peak_icv_Preprocessing_HotpixelCorrection_ResetList(
315 internal sealed class Handle : SafeHandleZeroOrMinusOneIsInvalid
317 internal Handle() : base(true)
321 protected override bool ReleaseHandle()
323 return CInterface.peak_icv_Preprocessing_HotpixelCorrection_Destroy(handle) == 0;
327 private static class CInterface
329 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
330 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_HotpixelCorrection_Create(
333 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
334 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_HotpixelCorrection_Destroy(
337 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
338 internal static extern Backend.Types.peak_icv_status
339 peak_icv_Preprocessing_HotpixelCorrection_ProcessInplace(
340 Handle handle,
Image.Handle imageHandle);
342 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
343 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_HotpixelCorrection_ResetList(
346 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
347 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_HotpixelCorrection_SetList(
348 Handle handle, Backend.Types.peak_icv_point[] list, nuint count);
350 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
351 internal static extern Backend.Types.peak_icv_status
352 peak_icv_Preprocessing_HotpixelCorrection_GetList_GetCount(
353 Handle handle, out nuint count);
355 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
356 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_HotpixelCorrection_GetList(
357 Handle handle, [Out] Backend.Types.peak_icv_point[] list, nuint count);
359 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
360 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_HotpixelCorrection_Detect(
361 Handle handle,
Image.Handle imageHandle, uint sensitivity,
float gainFactor);
363 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
364 internal static extern Backend.Types.peak_icv_status
365 peak_icv_Preprocessing_HotpixelCorrection_GetSensitivityRange(
366 Handle handle, out Backend.Types.peak_icv_interval_u range);