diff options
author | Tiago Conceição <Tiago_caza@hotmail.com> | 2021-08-13 01:19:47 +0300 |
---|---|---|
committer | Tiago Conceição <Tiago_caza@hotmail.com> | 2021-08-13 01:19:47 +0300 |
commit | 80a9adbcd0d80a62eec3f2714ee902af6fb562f1 (patch) | |
tree | 54e5d6b0eb55a963a24ee743fd1c5406349d3c62 /UVtools.Core/Extensions/EmguExtensions.cs | |
parent | b8e05db1133b98ae3c023318b963962834c842eb (diff) |
v2.18.0v2.18.0
- **Command line arguments:**
- (Add) Convert files: UVtools.exe -c \<inputfile\> \<outputfile1/ext1\> [outputfile2/ext2]
- (Add) Extract files: UVtools.exe -e \<inputfile\> [output_folder]
- https://github.com/sn4k3/UVtools#command-line-arguments
- **File formats:**
- (Add) Implement TSMC (Two Stage Motor Control) for the supported formats
- (Add) Implement 'Bottom retract speed' for the supported formats
- (Add) LGS: Support for lgs120 and lg4k (#218)
- (Add) CTB: Special/virtual file extensions .v2.ctb, .v3.ctb, .v4.ctb to force a convertion to the set version (2 to 4). The .ctb is Version 3 by default when creating/converting files
- (Improvement) Better performance for file formats that decode images in sequential pixels groups
- **GCode:**
- (Improvement) Better parsing of the movements / lifts
- (Improvement) Better handling of lifts performed after cure the layer
- (Improvement) More fail-safe checks and sanitize of gcode while parsing
- (Improvement) CTBv3: Enable per layer settings if disabled when fast save without reencode
- (Upgrade) .NET from 5.0.8 to 5.0.9
- (Fix) PrusaSlicer printer: Longer Orange 4k with correct resolution and display size
- (Fix) Odd error when changing properties too fast in multi-thread
Diffstat (limited to 'UVtools.Core/Extensions/EmguExtensions.cs')
-rw-r--r-- | UVtools.Core/Extensions/EmguExtensions.cs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/UVtools.Core/Extensions/EmguExtensions.cs b/UVtools.Core/Extensions/EmguExtensions.cs index d53b283..5968786 100644 --- a/UVtools.Core/Extensions/EmguExtensions.cs +++ b/UVtools.Core/Extensions/EmguExtensions.cs @@ -149,6 +149,11 @@ namespace UVtools.Core.Extensions return mat.GetDataSpan<byte>(); } + public static unsafe Span<byte> GetDataByteSpan(this Mat mat, int length, int offset = 0) + { + return new(IntPtr.Add(mat.DataPointer, offset).ToPointer(), length <= 0 ? mat.GetLength() : length); + } + /// <summary> /// Gets the data span to manipulate or read pixels given a length and offset /// </summary> @@ -217,6 +222,56 @@ namespace UVtools.Core.Extensions } #endregion + #region Memory Fill + + /// <summary> + /// Fill a mat span with a color + /// </summary> + /// <param name="mat">Mat to fill</param> + /// <param name="startPosition">Start position, this reference will increment by the <see cref="length"/></param> + /// <param name="length">Length to fill</param> + /// <param name="color">Color to fill with</param> + /// <param name="colorFillMinThreshold">Ignore and sum <see cref="startPosition"/> to <see cref="length"/> if <see cref="color"/> is less than the threshold value</param> + public static void FillSpan(this Mat mat, ref int startPosition, int length, byte color, byte colorFillMinThreshold = 1) + { + if (length <= 0) return; + if (color < colorFillMinThreshold) // Ignore threshold (mostly if blacks), spare cycles + { + startPosition += length; + return; + } + + mat.GetDataByteSpan(length, startPosition).Fill(color); + startPosition += length; + } + + /// <summary> + /// Fill a mat span with a color + /// </summary> + /// <param name="mat">Mat to fill</param> + /// <param name="x"></param> + /// <param name="y"></param> + /// <param name="length">Length to fill</param> + /// <param name="color">Color to fill with</param> + /// <param name="colorFillMinThreshold">Ignore and sum <see cref="startPosition"/> to <see cref="length"/> if <see cref="color"/> is less than the threshold value</param> + public static void FillSpan(this Mat mat, int x, int y, int length, byte color, byte colorFillMinThreshold = 1) + { + if (length <= 0 || color < colorFillMinThreshold) return; // Ignore threshold (mostly if blacks), spare cycles + mat.GetDataByteSpan(length, mat.GetPixelPos(x, y)).Fill(color); + } + + /// <summary> + /// Fill a mat span with a color + /// </summary> + /// <param name="mat">Mat to fill</param> + /// <param name="position"></param> + /// <param name="length">Length to fill</param> + /// <param name="color">Color to fill with</param> + /// <param name="colorFillMinThreshold">Ignore and sum <see cref="startPosition"/> to <see cref="length"/> if <see cref="color"/> is less than the threshold value</param> + public static void FillSpan(this Mat mat, Point position, int length, byte color, byte colorFillMinThreshold = 1) + => mat.FillSpan(position.X, position.Y, length, color, colorFillMinThreshold); + #endregion + #region Get/Set methods /// <summary> /// Gets the total length of this <see cref="Mat"/></param> |