IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
ToneMapping.cs
Go to the documentation of this file.
1using System.Runtime.InteropServices;
5using Microsoft.Win32.SafeHandles;
6
8
25{
35 Reinhard = 0
36}
37
80public class ToneMapping : IDisposable, IHasSafeHandle
81{
82 private readonly Handle _handle;
83 private bool _disposed;
84
93 public ToneMapping()
94 {
95 _handle = new Handle();
96 }
97
107 {
108 get
109 {
110 ThrowIfDisposed();
111 var algorithm = 0;
112 DllHelper.ExecuteAndMapReturnCodes(() =>
113 CInterface.peak_icv_ToneMapping_GetAlgorithm(_handle, out algorithm));
114 return (ToneMappingAlgorithm) algorithm;
115 }
116 }
117
121 public void Dispose()
122 {
123 Dispose(true);
124 GC.SuppressFinalize(this);
125 }
126
127 SafeHandle IHasSafeHandle.Handle => _handle;
128
133 {
134 Dispose(false);
135 }
136
160 public Image Process(Image image)
161 {
162 ThrowIfDisposed();
163
164 if (image == null)
165 {
166 throw new IcvNullPointerException("The input image cannot be null.");
167 }
168
169 PixelFormat outputPixelFormat = new();
170
171 DllHelper.ExecuteAndMapReturnCodes(() => CInterface.peak_icv_ToneMapping_Process_GetOutputPixelFormat(
172 _handle,
173 image.PixelFormat,
174 out outputPixelFormat));
175
176 Image outputImage = new(
177 outputPixelFormat,
178 image.Size);
179
180 DllHelper.ExecuteAndMapReturnCodes(() => CInterface.peak_icv_ToneMapping_Process(
181 _handle,
182 image._handle,
183 outputImage._handle));
184
185 return outputImage;
186 }
187
191 protected virtual void Dispose(bool disposing)
192 {
193 if (_disposed)
194 {
195 return;
196 }
197
198 if (disposing)
199 {
200 _handle.Dispose();
201 }
202
203 _disposed = true;
204 }
205
206 private void ThrowIfDisposed()
207 {
208 if (_disposed)
209 {
210 throw new IcvNotPossibleException("The class is already disposed.");
211 }
212 }
213
214 internal sealed class Handle : SafeHandleZeroOrMinusOneIsInvalid
215 {
216 internal Handle() : base(true)
217 {
218 DllHelper.ExecuteAndMapReturnCodes(() => CInterface.peak_icv_ToneMapping_Create(out handle));
219 }
220
221 protected override bool ReleaseHandle()
222 {
223 return CInterface.peak_icv_ToneMapping_Destroy(handle) == 0;
224 }
225 }
226
227 private static class CInterface
228 {
229 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
230 public static extern Backend.Types.peak_icv_status peak_icv_ToneMapping_Create(
231 out IntPtr handle);
232
233 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
234 public static extern Backend.Types.peak_icv_status peak_icv_ToneMapping_Destroy(
235 IntPtr handle);
236
237 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
238 public static extern Backend.Types.peak_icv_status peak_icv_ToneMapping_GetAlgorithm(
239 Handle handle,
240 out int algorithm);
241
242 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
243 public static extern Backend.Types.peak_icv_status peak_icv_ToneMapping_SetAlgorithm(
244 Handle handle,
245 int algorithm);
246
247 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
248 public static extern Backend.Types.peak_icv_status peak_icv_ToneMapping_Process_GetOutputPixelFormat(
249 Handle handle,
250 PixelFormat input_pixel_format,
251 out PixelFormat output_pixel_format);
252
253 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
254 public static extern Backend.Types.peak_icv_status peak_icv_ToneMapping_Process(
255 Handle handle,
256 Image.Handle input_image_handle,
257 Image.Handle output_image_handle);
258 }
259}
Performs tone mapping on HDR images.
ToneMappingAlgorithm Algorithm
The tone mapping algorithm used by this object.
Image Process(Image image)
Applies tone mapping to an HDR image.
void Dispose()
Releases all resources associated with the tone mapping object.
ToneMapping()
Constructs a tone mapping object.
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...
ToneMappingAlgorithm
Specifies the tone mapping algorithm.