22 private const string _masterGainKey =
"MasterGain";
23 private const string _redGainKey =
"RedGain";
24 private const string _greenGainKey =
"GreenGain";
25 private const string _blueGainKey =
"BlueGain";
26 internal const float DefaultGain = 1.0f;
28 private readonly Handle _handle;
29 private float _blueGain = DefaultGain;
30 private float _greenGain = DefaultGain;
31 private bool _isEnabled =
true;
32 private float _masterGain = DefaultGain;
33 private float _redGain = DefaultGain;
40 var handle =
new Handle();
41 DllHelper.ExecuteAndMapReturnCodes(() =>
42 CInterface.peak_icv_Preprocessing_Gain_Create(out handle)
58 var range =
new Backend.Types.peak_icv_interval_f();
59 DllHelper.ExecuteAndMapReturnCodes(() =>
60 CInterface.peak_icv_Preprocessing_Gain_GetRange(
64 return new IntervalF(range.minimum, range.maximum);
74 GC.SuppressFinalize(
this);
78 public override string TypeId =>
"Gain";
104 base.Serialize(archive);
141 base.Deserialize(archive);
263 return base.Process(input);
300 SafeHandle IHasSafeHandle.Handle => _handle;
336 Image.Handle inputImageHandle = input._handle;
337 DllHelper.ExecuteAndMapReturnCodes(() =>
338 CInterface.peak_icv_Preprocessing_Gain_ProcessInplace(
339 _handle, inputImageHandle)
345 private void ApplyGain()
347 SetGain(Backend.Types.peak_icv_gain_type.PEAK_ICV_GAIN_TYPE_MASTER, _masterGain);
348 SetGain(Backend.Types.peak_icv_gain_type.PEAK_ICV_GAIN_TYPE_RED, _redGain);
349 SetGain(Backend.Types.peak_icv_gain_type.PEAK_ICV_GAIN_TYPE_GREEN, _greenGain);
350 SetGain(Backend.Types.peak_icv_gain_type.PEAK_ICV_GAIN_TYPE_BLUE, _blueGain);
353 private void SetGain(Backend.Types.peak_icv_gain_type type,
float value)
355 DllHelper.ExecuteAndMapReturnCodes(() =>
356 CInterface.peak_icv_Preprocessing_Gain_SetValue(_handle, type, value)
360 private bool NeedsProcessing()
362 var needsProcessing =
false;
363 DllHelper.ExecuteAndMapReturnCodes(() =>
364 CInterface.peak_icv_Preprocessing_Gain_NeedsProcessing(
365 _handle, out needsProcessing)
368 return needsProcessing;
371 internal sealed class Handle : SafeHandleZeroOrMinusOneIsInvalid
373 internal Handle() : base(true)
377 internal Handle(IntPtr handle) : base(true)
382 protected override bool ReleaseHandle()
384 return CInterface.peak_icv_Preprocessing_Gain_Destroy(handle) == 0;
388 private static class CInterface
390 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
391 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Gain_Create(out Handle handle);
393 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
394 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Gain_Destroy(IntPtr handle);
396 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
397 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Gain_NeedsProcessing(
398 Handle handle, [MarshalAs(UnmanagedType.I1)] out
bool needsProcessing);
400 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
401 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Gain_ProcessInplace(
402 Handle handle,
Image.Handle imageHandle);
404 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
405 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Gain_GetValue(
406 Handle handle, Backend.Types.peak_icv_gain_type type, out
float value);
408 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
409 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Gain_SetValue(
410 Handle handle, Backend.Types.peak_icv_gain_type type,
float value);
412 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
413 internal static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Gain_GetRange(
414 Handle handle, out Backend.Types.peak_icv_interval_f range);