IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
MonoConversionModule.cs
Go to the documentation of this file.
4
6
17public class MonoConversionModule : ModuleBase, IDisposable
18{
19 private readonly ImageConverterCInterface.Handle _handle;
20
25 {
26 var handle = new ImageConverterCInterface.Handle();
27 DllHelper.ExecuteAndMapReturnCodes(() =>
28 ImageConverterCInterface.CInterface.peak_icv_Preprocessing_ImageConverter_Create(out handle));
29 _handle = handle;
30 }
31
33 public override string TypeId => "MonoConversion";
34
38 public void Dispose()
39 {
40 _handle.Dispose();
41 GC.SuppressFinalize(this);
42 }
43
47 public override void ResetToDefault()
48 {
49 }
50
64 public override Image Process(Image inputImage)
65 {
66 if (!IsEnabled)
67 {
68 return inputImage;
69 }
70
71 PixelFormat inputFormat = inputImage.PixelFormat;
72 PixelFormat outputFormat = GetOutputFormat(inputFormat);
73
74 if (inputFormat == outputFormat)
75 {
76 return inputImage;
77 }
78
79 var outputImageHandle = new Image.Handle();
80
81 DllHelper.ExecuteAndMapReturnCodes(() =>
82 ImageConverterCInterface.CInterface.peak_icv_Preprocessing_ImageConverter_Convert(_handle,
83 inputImage._handle,
84 outputFormat, out outputImageHandle));
85
86 return new Image(outputImageHandle);
87 }
88
105 public void ReleaseBuffers()
106 {
107 DllHelper.ExecuteAndMapReturnCodes(() =>
108 ImageConverterCInterface.CInterface.peak_icv_Preprocessing_ImageConverter_ReleaseBuffers(_handle));
109 }
110
111 private PixelFormat GetOutputFormat(PixelFormat inputFormat)
112 {
113 var info = new PixelFormatInfo(inputFormat);
114
115 if (info.IsSingleChannel && info.HasIntensityChannel)
116 {
117 return inputFormat;
118 }
119
120 var bitDepth = info.StorageBitsPerChannel;
121
122 return bitDepth switch
123 {
124 <= 8 => PixelFormat.Mono8,
125 <= 10 => PixelFormat.Mono10,
126 <= 12 => PixelFormat.Mono12,
127 _ => PixelFormat.Mono16
128 };
129 }
130}
Provides information and utility functions for pixel formats. The PixelFormatInfo class offers method...
Base class for all pipeline modules.
Definition ModuleBase.cs:13
virtual bool IsEnabled
Get whether this module is enabled.
Definition ModuleBase.cs:28
Mono conversion is an image pipeline module that converts images to a monochrome format.
MonoConversionModule()
Creates an instance of class MonoConversionModule.
override Image Process(Image inputImage)
Converts the input image to the configured output pixel format.
override void ResetToDefault()
Calling this method has no effect.
void Dispose()
Releases all resources used by this class.
override string TypeId
The unique type identifier for this module implementation.This should be a unique string identifying ...
Constructs an Image from an IImageView Instance.
Definition Image.cs:18
PixelFormat PixelFormat
Gets the pixel format from the image.
Definition Image.cs:217
PixelFormat
Each enumerator represents a specific pixel layout and bit-depth, used for interpreting raw image dat...