1using System.Runtime.InteropServices;
19 internal const bool DefaultMirrorLeftRight =
false;
20 internal const bool DefaultMirrorUpDown =
false;
22 internal const bool DefaultIsMirrorEnabled =
true;
23 internal const bool DefaultIsRotationEnabled =
true;
25 private const string _leftRightKey =
"LeftRight";
26 private const string _upDownKey =
"UpDown";
27 private const string _mirrorKey =
"Mirror";
28 private const string _angleKey =
"Angle";
29 private const string _rotationKey =
"Rotation";
32 public override string TypeId =>
"TransformationModule";
37 get => IsMirrorEnabled || IsRotationEnabled;
40 IsMirrorEnabled = value;
41 IsRotationEnabled = value;
60 internal bool IsMirrorEnabled {
get;
set; } = DefaultIsMirrorEnabled;
61 internal bool IsRotationEnabled {
get;
set; } = DefaultIsRotationEnabled;
98 if (!mirrorNeedsProcessing && !rotationNeedsProcessing)
103 var parameters =
new Backend.Types.peak_icv_preprocessing_transformation_parameters(
106 CInterface.RotationAngleToCType(IsRotationEnabled
111 DllHelper.ExecuteAndMapReturnCodes(() =>
112 CInterface.peak_icv_Preprocessing_Transformation_GetOutputPixelFormat(inputImage.
PixelFormat,
113 parameters, out outputFormat));
115 var transpose = IsRotationEnabled && (
RotationAngle == Rotation.Degree90Clockwise ||
119 var outputImage =
new Image(outputFormat, outputSize);
120 DllHelper.ExecuteAndMapReturnCodes(() =>
121 CInterface.peak_icv_Preprocessing_Transformation_Process(inputImage._handle, parameters,
122 outputImage._handle));
159 return base.Process(input);
178 mirrorArchive.
SetBool(EnabledKey, IsMirrorEnabled);
181 archive.
SetArchive(_mirrorKey, mirrorArchive);
184 rotationArchive.
SetBool(EnabledKey, IsRotationEnabled);
186 archive.
SetArchive(_rotationKey, rotationArchive);
215 var version = archive.
GetInt64(VersionKey);
216 ValidateVersion(version,
TypeId);
219 IsRotationEnabled = rotationArchive.
GetBool(EnabledKey);
221 var angle = (int) rotationArchive.
GetInt64(_angleKey);
222 if (!Enum.IsDefined(typeof(
Rotation), angle))
230 IsMirrorEnabled = mirrorArchive.
GetBool(EnabledKey);
265 private static class CInterface
267 public static Backend.Types.peak_icv_preprocessing_transformation_rotation_angle RotationAngleToCType(
270 return rotation
switch
272 Rotation.None => Backend.Types.peak_icv_preprocessing_transformation_rotation_angle
273 .PEAK_ICV_PREPROCESSING_TRANSFORMATION_ROTATION_NONE,
274 Rotation.Degree90Counterclockwise => Backend.Types
275 .peak_icv_preprocessing_transformation_rotation_angle
276 .PEAK_ICV_PREPROCESSING_TRANSFORMATION_ROTATION_90_DEGREE_COUNTERCLOCKWISE,
277 Rotation.Degree180 => Backend.Types.peak_icv_preprocessing_transformation_rotation_angle
278 .PEAK_ICV_PREPROCESSING_TRANSFORMATION_ROTATION_180_DEGREE,
279 Rotation.Degree90Clockwise => Backend.Types.peak_icv_preprocessing_transformation_rotation_angle
280 .PEAK_ICV_PREPROCESSING_TRANSFORMATION_ROTATION_90_DEGREE_CLOCKWISE,
285 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
286 public static extern Backend.Types.peak_icv_status
287 peak_icv_Preprocessing_Transformation_GetOutputPixelFormat(
289 Backend.Types.peak_icv_preprocessing_transformation_parameters parameters,
292 [DllImport(Global.LibraryName, CallingConvention = Global.CallingConvention)]
293 public static extern Backend.Types.peak_icv_status peak_icv_Preprocessing_Transformation_Process(
294 Image.Handle inputImageHandle, Backend.Types.peak_icv_preprocessing_transformation_parameters parameters,
295 Image.Handle outputImageHandle);
Represents a size with integer width and height values.
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
Base class for all pipeline modules.
int Version
The module version.
Constructs an Image from an IImageView Instance.
PixelFormat PixelFormat
Gets the pixel format from the image.
Size Size
Gets the image size in pixels from the image.
PixelFormat
Each enumerator represents a specific pixel layout and bit-depth, used for interpreting raw image dat...
Rotation
Angle parameter for the rotation algorithm.
Represents a hierarchical, strongly-typed key-value archive.
IArchive GetArchive(string key)
Retrieves a nested archive by key.
IArchive CreateArchive()
Creates a new, empty archive instance of the same concrete type.
void SetBool(string key, bool value)
Stores a boolean value under the specified key.
long GetInt64(string key)
Retrieves a 64-bit integer value by key.
void SetArchive(string key, IArchive value)
Stores a nested archive under the specified key.
void SetInt64(string key, long value)
Stores a 64-bit integer value under the specified key.
bool GetBool(string key)
Retrieves a boolean value by key.