IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
Hdr.cs
Go to the documentation of this file.
1using System.Runtime.InteropServices;
5using Microsoft.Win32.SafeHandles;
6
8
25public enum HdrAlgorithm
26{
35 Debevec = 0
36}
37
92public class Hdr : IDisposable, IHasSafeHandle
93{
94 private readonly Handle _handle;
95 private bool _disposed;
96
105 public Hdr()
106 {
107 _handle = new Handle();
108 }
109
119 {
120 get
121 {
122 ThrowIfDisposed();
123 var algorithm = 0;
124 DllHelper.ExecuteAndMapReturnCodes(() => CInterface.peak_icv_HDR_GetAlgorithm(_handle, out algorithm));
125 return (HdrAlgorithm) algorithm;
126 }
127 }
128
132 public void Dispose()
133 {
134 Dispose(true);
135 GC.SuppressFinalize(this);
136 }
137
138 SafeHandle IHasSafeHandle.Handle => _handle;
139
143 ~Hdr()
144 {
145 Dispose(false);
146 }
147
195 public void EstimateResponseCurve(IEnumerable<Image> images)
196 {
197 ThrowIfDisposed();
198
199 if (images == null)
200 {
201 throw new ArgumentNullException(nameof(images));
202 }
203
204 Image[] imageArray = images.ToArray();
205 if (imageArray.Length == 0)
206 {
207 throw new ArgumentException("The image collection must not be empty.", nameof(images));
208 }
209
210 IntPtr[] imageHandles = imageArray.Select(img => img._handle.DangerousGetHandle()).ToArray();
211
212 DllHelper.ExecuteAndMapReturnCodes(() => CInterface.peak_icv_HDR_EstimateResponseCurve(
213 _handle,
214 imageHandles,
215 (nuint) imageHandles.Length));
216 }
217
262 public Image Process(IEnumerable<Image> images)
263 {
264 ThrowIfDisposed();
265
266 if (images == null)
267 {
268 throw new IcvNullPointerException("The given image enumerable is null.");
269 }
270
271 Image[] imageArray = images.ToArray();
272 if (imageArray.Length == 0)
273 {
274 throw new IcvNullPointerException("The given image enumerable is empty.");
275 }
276
277 Image refImage = imageArray.First();
278 PixelFormat outputPixelFormat = new();
279
280 IntPtr[] imageHandles = imageArray.Select(img => img._handle.DangerousGetHandle()).ToArray();
281
282 DllHelper.ExecuteAndMapReturnCodes(() => CInterface.peak_icv_HDR_Process_GetOutputPixelFormat(
283 _handle,
284 refImage.PixelFormat,
285 out outputPixelFormat));
286
287 Image outputImage = new(
288 outputPixelFormat,
289 refImage.Size);
290
291 DllHelper.ExecuteAndMapReturnCodes(() => CInterface.peak_icv_HDR_Process(
292 _handle,
293 imageHandles,
294 (nuint) imageHandles.Length,
295 outputImage._handle));
296
297 return outputImage;
298 }
299
303 protected virtual void Dispose(bool disposing)
304 {
305 if (_disposed)
306 {
307 return;
308 }
309
310 if (disposing)
311 {
312 _handle.Dispose();
313 }
314
315 _disposed = true;
316 }
317
318 private void ThrowIfDisposed()
319 {
320 if (_disposed)
321 {
322 throw new IcvNotPossibleException("The class is already disposed.");
323 }
324 }
325
326 internal sealed class Handle : SafeHandleZeroOrMinusOneIsInvalid
327 {
328 internal Handle() : base(true)
329 {
330 DllHelper.ExecuteAndMapReturnCodes(() => CInterface.peak_icv_HDR_Create(out handle));
331 }
332
333 protected override bool ReleaseHandle()
334 {
335 return CInterface.peak_icv_HDR_Destroy(handle) == 0;
336 }
337 }
338
339 private static class CInterface
340 {
341 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
342 public static extern Backend.Types.peak_icv_status peak_icv_HDR_Create(
343 out IntPtr hdr_handle);
344
345 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
346 public static extern Backend.Types.peak_icv_status peak_icv_HDR_Destroy(
347 IntPtr hdr_handle);
348
349 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
350 public static extern Backend.Types.peak_icv_status peak_icv_HDR_GetAlgorithm(
351 Handle hdr_handle,
352 out int algorithm);
353
354 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
355 public static extern Backend.Types.peak_icv_status peak_icv_HDR_EstimateResponseCurve(
356 Handle hdr_handle,
357 [In] IntPtr[] image_handles,
358 nuint image_count);
359
360 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
361 public static extern Backend.Types.peak_icv_status peak_icv_HDR_Process_GetOutputPixelFormat(
362 Handle hdr_handle,
363 PixelFormat input_pixel_format,
364 out PixelFormat output_pixel_format);
365
366 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
367 public static extern Backend.Types.peak_icv_status peak_icv_HDR_Process(
368 Handle hdr_handle,
369 [In] IntPtr[] image_handles,
370 nuint image_count,
371 Image.Handle output_image_handle);
372 }
373}
Performs High Dynamic Range (HDR) image reconstruction.
Definition Hdr.cs:93
void EstimateResponseCurve(IEnumerable< Image > images)
Estimates the Camera Response Curve (CRC) from a set of input images.
Definition Hdr.cs:195
void Dispose()
Releases all resources.
Definition Hdr.cs:132
Image Process(IEnumerable< Image > images)
Generates an HDR image from the specified input images.
Definition Hdr.cs:262
HdrAlgorithm Algorithm
Returns the HDR algorithm used by this object.
Definition Hdr.cs:119
Hdr()
Constructs an HDR processing object.
Definition Hdr.cs:105
Occurs when an operation cannot be performed due to logical constraints (e.g., camera calibration wit...
Definition Exception.cs:102
Occurs when attempting to access an object or value via an uninitialized or null pointer.
Definition Exception.cs:115
Constructs an Image from an IImageView Instance.
Definition Image.cs:18
PixelFormat PixelFormat
Gets the pixel format from the image.
Definition Image.cs:217
Size Size
Gets the image size in pixels from the image.
Definition Image.cs:223
PixelFormat
Each enumerator represents a specific pixel layout and bit-depth, used for interpreting raw image dat...
HdrAlgorithm
Specifies the HDR reconstruction algorithm.
Definition Hdr.cs:26
@ Debevec
Debevec HDR reconstruction algorithm.