From 95020ce2f103b781d65318059adc6768e16e4a6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Concei=C3=A7=C3=A3o?= Date: Tue, 17 Aug 2021 20:17:08 +0100 Subject: v2.19.0 - **File formats:** - Add and remove some image types that can be open - (Add) `CanProcess` method to know if a file can be read under a format and to allow diferent formats with same extension - (Fix) `LiftHeightTotal` and `RetractHeight` was rounding to no decimals and returning wrong values - (Improvement) Round all float setters on `Layer` class - (Improvement) Decode/encode RAM usage and performance by processing in batch groups - **Pixel Dimming:** (#262) - (Add) Option "Lightening pixels" to add brightness/lightening instead of dimming/subtract pixels - (Fix) "Dim walls only" would reset body brightness by increase pixel brightness two times it value - **Pixel Arithmetic:** - (Change) Transpose "Pixel Dimming" to "Pixel Arithmetic" - (Improvement) New options and manipulations - **(Fix) Exposure time finder:** - Generate top staircase based on selected measure (px or mm) - Zebra bars when used in mm measures, it was using X density instead Y to calculate the thickness - Move 'Unit of measure' to 'Object configuration' - Custom text with wrong Y position when using out of portion resolutions/LCDs - **CTBv4:** - (Fix) More Unknown fields discovered and implemented - (Fix) Reserved table is 384 bytes instead of 420 - (Fix) When full encoding it was forcing to change to version 3. This also affected convertions. (#263) - (Fix) `BottomRetractHeight2` was being set to `BottomRetractSpeed2` - (Fix) `RetractHeight2` was being set to `RetracSpeed2` - (Fix) The PrintParametersV4 table address - (Fix) Generates invalid files to open with Chitubox and printers (#263) - (Fix) Better progress report - **(Add) PrusaSlicer printer notes variables:** - BottomLiftHeight2 - BottomLiftSpeed2 - LiftHeight2 - LiftSpeed2 - BottomRetractSpeed - BottomRetractSpeed2 - BottomRetractHeight2 - BottomRetractSpeed2 - RetractHeight2 - RetractSpeed2 - **UI:** - (Add) File - Open current file folder (Ctrl+Shift+L): Locate and open the folder that contain the current loaded file - (Improvement) Hide some virtual extensions from file open dialog filters - (Improvement) UI: Refresh active thumbnail when changed - (Change) Icon for File - Open and Open in a new file - (Change) Rename File - Extract to: Extract file contents - (Upgrade) AvaloniaUI from 0.10.6 to 0.10.7 - (Fix) PW0, PWM, PWMX, PWMO, PWMS: Unable to decode some files with AntiAliasing (#143) --- UVtools.Core/FileFormats/CXDLPFile.cs | 164 ++++++++++++++-------------------- 1 file changed, 69 insertions(+), 95 deletions(-) (limited to 'UVtools.Core/FileFormats/CXDLPFile.cs') diff --git a/UVtools.Core/FileFormats/CXDLPFile.cs b/UVtools.Core/FileFormats/CXDLPFile.cs index a81ad75..fb0f1bb 100644 --- a/UVtools.Core/FileFormats/CXDLPFile.cs +++ b/UVtools.Core/FileFormats/CXDLPFile.cs @@ -36,7 +36,7 @@ namespace UVtools.Core.FileFormats #region Header public sealed class Header { - private string _printerModel = "CL-89"; + //private string _printerModel = "CL-89"; /// /// Gets the size of the header @@ -447,12 +447,6 @@ namespace UVtools.Core.FileFormats } } - public override byte AntiAliasing - { - get => 8; - set {} - } - public override float LayerHeight { get => float.Parse(Encoding.ASCII.GetString(SlicerInfoSettings.LayerHeightBytes.Where(b => b != 0).ToArray())); @@ -608,33 +602,24 @@ namespace UVtools.Core.FileFormats Helpers.SerializeWriteFileStream(outputFile, HeaderSettings); - byte[][] previews = new byte[ThumbnailsOriginalSize.Length][]; - for (int i = 0; i < ThumbnailsOriginalSize.Length; i++) - { - previews[i] = new byte[ThumbnailsOriginalSize[i].Area() * 2]; - } + var previews = new byte[ThumbnailsOriginalSize.Length][]; + // Previews Parallel.For(0, previews.Length, previewIndex => { if (progress.Token.IsCancellationRequested) return; - if (Thumbnails[previewIndex] is null) return; - var span = Thumbnails[previewIndex].GetDataByteSpan(); - int index = 0; - for (int i = 0; i < span.Length; i += 3) + var encodeLength = ThumbnailsOriginalSize[previewIndex].Area() * 2; + if (Thumbnails[previewIndex] is null) { - byte b = span[i]; - byte g = span[i + 1]; - byte r = span[i + 2]; - - ushort rgb15 = (ushort)(((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3) << 0)); - - previews[previewIndex][index++] = (byte)(rgb15 >> 8); - previews[previewIndex][index++] = (byte)(rgb15 & 0xff); + previews[previewIndex] = new byte[encodeLength]; + return; } - if (index != previews[previewIndex].Length) + previews[previewIndex] = EncodeImage(DATATYPE_RGB565_BE, Thumbnails[previewIndex]); + + if (encodeLength != previews[previewIndex].Length) { - throw new FileLoadException($"Preview encode incomplete encode, expected: {previews[previewIndex].Length}, encoded: {index}"); + throw new FileLoadException($"Preview encode incomplete encode, expected: {previews[previewIndex].Length}, encoded: {encodeLength}"); } }); @@ -642,7 +627,7 @@ namespace UVtools.Core.FileFormats { Helpers.SerializeWriteFileStream(outputFile, previews[i]); outputFile.WriteBytes(pageBreak); - //Helpers.SerializeWriteFileStream(outputFile, pageBreak); + previews[i] = null; } Helpers.SerializeWriteFileStream(outputFile, SlicerInfoSettings); @@ -662,10 +647,8 @@ namespace UVtools.Core.FileFormats //Helpers.SerializeWriteFileStream(outputFile, pageBreak); outputFile.WriteBytes(pageBreak); - var range = Enumerable.Range(0, (int) LayerCount); - var layerBytes = new List[LayerCount]; - foreach (var batch in range.Batch(Environment.ProcessorCount * 10)) + foreach (var batch in BatchLayersIndexes()) { progress.Token.ThrowIfCancellationRequested(); @@ -673,48 +656,52 @@ namespace UVtools.Core.FileFormats { if (progress.Token.IsCancellationRequested) return; var layer = this[layerIndex]; - using var mat = layer.LayerMat; - var span = mat.GetDataByteSpan(); + using (var mat = layer.LayerMat) + { + var span = mat.GetDataByteSpan(); - layerBytes[layerIndex] = new(); + layerBytes[layerIndex] = new(); - uint lineCount = 0; + uint lineCount = 0; - for (int x = layer.BoundingRectangle.X; x < layer.BoundingRectangle.Right; x++) - { - int y = layer.BoundingRectangle.Y; - int startY = -1; - byte lastColor = 0; - for (; y < layer.BoundingRectangle.Bottom; y++) + for (int x = layer.BoundingRectangle.X; x < layer.BoundingRectangle.Right; x++) { - int pos = mat.GetPixelPos(x, y); - byte color = span[pos]; + int y = layer.BoundingRectangle.Y; + int startY = -1; + byte lastColor = 0; + for (; y < layer.BoundingRectangle.Bottom; y++) + { + int pos = mat.GetPixelPos(x, y); + byte color = span[pos]; + + if (lastColor == color && color != 0) continue; - if (lastColor == color && color != 0) continue; + if (startY >= 0) + { + layerBytes[layerIndex].AddRange(LayerLine.GetBytes((ushort)startY, (ushort)(y - 1), + (ushort)x, lastColor)); + lineCount++; + } + + startY = color == 0 ? -1 : y; + + lastColor = color; + } if (startY >= 0) { - layerBytes[layerIndex].AddRange(LayerLine.GetBytes((ushort)startY, (ushort)(y - 1), (ushort)x, lastColor)); + layerBytes[layerIndex].AddRange(LayerLine.GetBytes((ushort)startY, (ushort)(y - 1), + (ushort)x, lastColor)); lineCount++; } - - startY = color == 0 ? -1 : y; - - lastColor = color; } - if (startY >= 0) - { - layerBytes[layerIndex].AddRange(LayerLine.GetBytes((ushort)startY, (ushort)(y - 1), (ushort)x, lastColor)); - lineCount++; - } + layerBytes[layerIndex].InsertRange(0, LayerDef.GetHeaderBytes( + (uint)Math.Round(layer.BoundingRectangleMillimeters.Area() * 1000), + lineCount)); + layerBytes[layerIndex].AddRange(pageBreak); } - layerBytes[layerIndex].InsertRange(0, LayerDef.GetHeaderBytes( - (uint)Math.Round(layer.BoundingRectangleMillimeters.Area()*1000), - lineCount)); - layerBytes[layerIndex].AddRange(pageBreak); - progress.LockAndIncrement(); }); @@ -842,23 +829,8 @@ namespace UVtools.Core.FileFormats Parallel.For(0, previews.Length, previewIndex => { - var mat = new Mat(ThumbnailsOriginalSize[previewIndex], DepthType.Cv8U, 3); - var span = mat.GetDataByteSpan(); - - int spanIndex = 0; - for (int i = 0; i < previews[previewIndex].Length; i += 2) - { - ushort rgb15 = (ushort)((ushort)(previews[previewIndex][i + 0] << 8) | previews[previewIndex][i + 1]); - byte r = (byte)((rgb15 >> 11) << 3); - byte g = (byte)((rgb15 >> 5) << 2); - byte b = (byte)((rgb15 >> 0) << 3); - - span[spanIndex++] = b; - span[spanIndex++] = g; - span[spanIndex++] = r; - } - - Thumbnails[previewIndex] = mat; + Thumbnails[previewIndex] = DecodeImage(DATATYPE_RGB565_BE, previews[previewIndex], ThumbnailsOriginalSize[previewIndex]); + previews[previewIndex] = null; }); @@ -877,10 +849,9 @@ namespace UVtools.Core.FileFormats }*/ //inputFile.Seek(2, SeekOrigin.Current); - var range = Enumerable.Range(0, (int)LayerCount); var linesBytes = new byte[LayerCount][]; - foreach (var batch in range.Batch(Environment.ProcessorCount * 10)) + foreach (var batch in BatchLayersIndexes()) { progress.Token.ThrowIfCancellationRequested(); @@ -899,29 +870,32 @@ namespace UVtools.Core.FileFormats Parallel.ForEach(batch, layerIndex => { if (progress.Token.IsCancellationRequested) return; - using var mat = EmguExtensions.InitMat(Resolution); - - for (int i = 0; i < linesBytes[layerIndex].Length; i++) + using (var mat = EmguExtensions.InitMat(Resolution)) { - LayerLine line = new() + + for (int i = 0; i < linesBytes[layerIndex].Length; i++) { - Coordinates = + LayerLine line = new() { - [0] = linesBytes[layerIndex][i++], - [1] = linesBytes[layerIndex][i++], - [2] = linesBytes[layerIndex][i++], - [3] = linesBytes[layerIndex][i++], - [4] = linesBytes[layerIndex][i++] - }, - Gray = linesBytes[layerIndex][i] - }; - - CvInvoke.Line(mat, new Point(line.StartX, line.StartY), new Point(line.StartX, line.EndY), new MCvScalar(line.Gray)); - } + Coordinates = + { + [0] = linesBytes[layerIndex][i++], + [1] = linesBytes[layerIndex][i++], + [2] = linesBytes[layerIndex][i++], + [3] = linesBytes[layerIndex][i++], + [4] = linesBytes[layerIndex][i++] + }, + Gray = linesBytes[layerIndex][i] + }; + + CvInvoke.Line(mat, new Point(line.StartX, line.StartY), new Point(line.StartX, line.EndY), + new MCvScalar(line.Gray)); + } - linesBytes[layerIndex] = null; + linesBytes[layerIndex] = null; - this[layerIndex] = new Layer((uint)layerIndex, mat, this); + this[layerIndex] = new Layer((uint)layerIndex, mat, this); + } progress.LockAndIncrement(); }); -- cgit v1.2.3