IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
SharpeningModule.cs
Go to the documentation of this file.
1using System.Runtime.InteropServices;
5
7
17{
18 private const string _levelKey = "Level";
19
20 internal const uint DefaultLevel = 0;
21
22 private uint _level = DefaultLevel;
23
25 public override string TypeId => "Sharpening";
26
43 public uint Level
44 {
45 get => _level;
46 set
47 {
48 IntervalU range = LevelRange;
49 if (value < range.Minimum || value > range.Maximum)
50 {
51 throw new IcvOutOfRangeException($"The given level value {value} is out of range!");
52 }
53
54 _level = value;
55 }
56 }
57
62 {
63 get
64 {
65 var levelRange = new Backend.Types.peak_icv_interval_u();
66 DllHelper.ExecuteAndMapReturnCodes(() =>
67 CInterface.peak_icv_ImageFilter_Sharpening_GetRange(out levelRange));
68 return new IntervalU(levelRange.minimum, levelRange.maximum);
69 }
70 }
71
83 public override void Serialize(IArchive archive)
84 {
85 base.Serialize(archive);
86
87 archive.SetInt64(_levelKey, _level);
88 }
89
117 public override void Deserialize(IArchive archive)
118 {
119 base.Deserialize(archive);
120
121 Level = (uint) archive.GetInt64(_levelKey);
122 }
123
144 public override Image Process(Image inputImage)
145 {
146 if (!IsEnabled || Level == 0)
147 {
148 return inputImage;
149 }
150
151 PixelFormat pixelFormat = inputImage.PixelFormat;
152 var info = new PixelFormatInfo(pixelFormat);
153 var isSupportedMonoImage = pixelFormat is PixelFormat.Mono8 or PixelFormat.Mono10 or PixelFormat.Mono12;
154 var isColorImage = info.HasChannel(Channel.Red) && info.HasChannel(Channel.Green) &&
155 info.HasChannel(Channel.Blue);
156 var isSupportedColorImage = isColorImage && pixelFormat != PixelFormat.RGB10p32
157 && pixelFormat != PixelFormat.BGR10p32;
158 if (!isSupportedMonoImage && !isSupportedColorImage)
159 {
160 return inputImage;
161 }
162
163 DllHelper.ExecuteAndMapReturnCodes(() =>
164 CInterface.peak_icv_ImageFilter_Sharpening_ProcessInPlace(inputImage._handle, _level));
165
166 return inputImage;
167 }
168
189 public override object Process(object input)
190 {
191 return base.Process(input);
192 }
193
201 public override void ResetToDefault()
202 {
203 base.ResetToDefault();
204
205 _level = DefaultLevel;
206 }
207
208 private static class CInterface
209 {
210 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
211 internal static extern Backend.Types.peak_icv_status peak_icv_ImageFilter_Sharpening_GetRange(
212 out Backend.Types.peak_icv_interval_u range);
213
214 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
215 internal static extern Backend.Types.peak_icv_status peak_icv_ImageFilter_Sharpening_ProcessInPlace(
216 Image.Handle inputImageHandle, uint level);
217 }
218}
T Maximum
Gets the upper boundary of the interval.
Definition Interval.cs:50
Represents an interval with unsigned integer boundaries.
Definition Interval.cs:137
Provides information and utility functions for pixel formats. The PixelFormatInfo class offers method...
Occurs when a provided value falls outside the allowed valid range.
Definition Exception.cs:128
Base class for all pipeline modules.
Definition ModuleBase.cs:13
virtual bool IsEnabled
Get whether this module is enabled.
Definition ModuleBase.cs:28
Sharpening is an image pipeline module that applies a sharpening filter to enhance image detail.
override void Deserialize(IArchive archive)
Restores the object's state from the provided archive.
override Image Process(Image inputImage)
Processes the input image and returns a sharpened output image.
override void ResetToDefault()
Resets the sharpness level to the default value (0).
override object Process(object input)
Processes the input image and returns a sharpened output image.
override string TypeId
The unique type identifier for this module implementation.This should be a unique string identifying ...
IntervalU LevelRange
Gets the valid range for the sharpness level.
override void Serialize(IArchive archive)
Serializes the object's internal state into the provided archive.
Constructs an Image from an IImageView Instance.
Definition Image.cs:18
PixelFormat PixelFormat
Gets the pixel format from the image.
Definition Image.cs:217
Channel
Represents the various data channels in image or spatial data formats. /// This enumeration defines s...
Definition Channel.cs:13
PixelFormat
Each enumerator represents a specific pixel layout and bit-depth, used for interpreting raw image dat...
Represents a hierarchical, strongly-typed key-value archive.
Definition IArchive.cs:79
long GetInt64(string key)
Retrieves a 64-bit integer value by key.
void SetInt64(string key, long value)
Stores a 64-bit integer value under the specified key.