Skip to content

Commit

Permalink
v0.6.7.0
Browse files Browse the repository at this point in the history
* (Add) Tool: Layer Clone
* (Add) Mutator: Mask
* (Add) Mutator - Pixel Dimming: "Strips" pattern
* (Remove) Bottom progress bar
  • Loading branch information
sn4k3 committed Aug 21, 2020
1 parent 094c331 commit ba5b527
Show file tree
Hide file tree
Showing 25 changed files with 3,849 additions and 27 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Changelog

## ?/08/2020 - v0.6.6.2
## 21/08/2020 - v0.6.7.0

* (Add) Tool: Layer Clone
* (Add) Mutator: Mask
* (Add) Mutator - Pixel Dimming: "Strips" pattern
* (Remove) Bottom progress bar

## 17/08/2020 - v0.6.6.1
Expand Down
3 changes: 2 additions & 1 deletion CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
* Ingo Strohmenger
* Sven Vogt
* Paul Hammerstrom
* Jeremy Lauzon
* Jeremy Lauzon
* Peter Teal
2 changes: 0 additions & 2 deletions UVtools.Core/Extensions/MathExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace UVtools.Core.Extensions
{
Expand Down
6 changes: 3 additions & 3 deletions UVtools.Core/FileFormats/ImageFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public override void Decode(string fileFullPath, OperationProgress progress = nu
{
base.Decode(fileFullPath, progress);

ImageMat = CvInvoke.Imread(fileFullPath, ImreadModes.AnyColor);
ImageMat = CvInvoke.Imread(fileFullPath, ImreadModes.Grayscale);
const byte startDivisor = 2;
for (int i = 0; i < ThumbnailsCount; i++)
{
Expand All @@ -73,10 +73,10 @@ public override void Decode(string fileFullPath, OperationProgress progress = nu
new Size(ImageMat.Width / divisor, ImageMat.Height / divisor));
}

if (ImageMat.NumberOfChannels > 1)
/*if (ImageMat.NumberOfChannels > 1)
{
CvInvoke.CvtColor(ImageMat, ImageMat, ColorConversion.Bgr2Gray);
}
}*/

LayerManager = new LayerManager(1, this);
this[0] = new Layer(0, ImageMat, Path.GetFileName(fileFullPath));
Expand Down
16 changes: 12 additions & 4 deletions UVtools.Core/Layer/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,15 @@ public void MutateSolidify()
}
}

public void MutateMask(Mat mask)
{
using (var mat = LayerMat)
{
CvInvoke.BitwiseAnd(mat, mask, mat);
LayerMat = mat;
}
}

public void MutatePixelDimming(Matrix<byte> evenPattern = null, Matrix<byte> oddPattern = null, ushort borderSize = 5)
{
var anchor = new Point(-1, -1);
Expand Down Expand Up @@ -602,7 +611,7 @@ public void MutatePixelDimming(Matrix<byte> evenPattern = null, Matrix<byte> odd
{
using (Mat mask = dst.CloneBlank())
{
CvInvoke.Erode(dst, erode, kernel, anchor, borderSize, BorderType.Default, default);
CvInvoke.Erode(dst, erode, kernel, anchor, borderSize, BorderType.Reflect101, default);
CvInvoke.Subtract(dst, erode, diff);

if (Index % 2 == 0)
Expand Down Expand Up @@ -643,7 +652,7 @@ public void MutatePixelDimming(Mat evenPatternMask, Mat oddPatternMask = null, u
{
using (Mat diff = new Mat())
{
CvInvoke.Erode(dst, erode, kernel, anchor, borderSize, BorderType.Default, default);
CvInvoke.Erode(dst, erode, kernel, anchor, borderSize, BorderType.Reflect101, default);
CvInvoke.Subtract(dst, erode, diff);
CvInvoke.BitwiseAnd(erode, Index % 2 == 0 ? evenPatternMask : oddPatternMask, dst);
CvInvoke.Add(dst, diff, dst);
Expand Down Expand Up @@ -834,8 +843,6 @@ public void ToolPattern(OperationPattern settings)
}
}



public Layer Clone()
{
return new Layer(Index, CompressedBytes, Filename, ParentLayerManager)
Expand All @@ -849,6 +856,7 @@ public Layer Clone()

#endregion



}
}
73 changes: 73 additions & 0 deletions UVtools.Core/Layer/LayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum Mutate : byte
Flip,
Rotate,
Solidify,
Mask,
PixelDimming,
Erode,
Dilate,
Expand Down Expand Up @@ -188,6 +189,21 @@ public static byte[] DecompressLayer(byte[] input)

#region Methods

/// <summary>
/// Rebuild layer properties based on slice settings
/// </summary>
public void RebuildLayersProperties()
{
var layerHeight = SlicerFile.LayerHeight;
for (uint layerIndex = 0; layerIndex < Count; layerIndex++)
{
var layer = this[layerIndex];
layer.Index = layerIndex;
layer.PositionZ = (float) Math.Round(layerHeight * (layerIndex + 1), 2);
layer.ExposureTime = SlicerFile.GetInitialLayerValueOrNormal(layerIndex, SlicerFile.InitialExposureTime, SlicerFile.LayerExposureTime);
}
}

public Rectangle GetBoundingRectangle(OperationProgress progress = null)
{
if (!_boundingRectangle.IsEmpty) return _boundingRectangle;
Expand Down Expand Up @@ -391,6 +407,24 @@ public void MutateSolidify(uint startLayerIndex, uint endLayerIndex, OperationPr
progress.Token.ThrowIfCancellationRequested();
}

public void MutateMask(uint startLayerIndex, uint endLayerIndex, Mat mask, OperationProgress progress = null)
{
if (ReferenceEquals(progress, null)) progress = new OperationProgress();
progress.Reset("Masking pixels", endLayerIndex - startLayerIndex + 1);

Parallel.For(startLayerIndex, endLayerIndex + 1, layerIndex =>
{
if (progress.Token.IsCancellationRequested) return;
this[layerIndex].MutateMask(mask);
lock (progress.Mutex)
{
progress++;
}
});

progress.Token.ThrowIfCancellationRequested();
}

public void MutatePixelDimming(uint startLayerIndex, uint endLayerIndex, Matrix<byte> evenPattern = null, Matrix<byte> oddPattern = null, ushort borderSize = 5, OperationProgress progress = null)
{
if (ReferenceEquals(progress, null)) progress = new OperationProgress();
Expand Down Expand Up @@ -1331,6 +1365,45 @@ void initImage()
progress.Token.ThrowIfCancellationRequested();
}

public void CloneLayer(uint layerIndexStart, uint layerIndexEnd, uint clones = 1, OperationProgress progress = null)
{

var oldLayers = Layers;

uint totalClones = (layerIndexEnd - layerIndexStart + 1) * clones;
uint newLayerCount = Count + totalClones;
Layers = new Layer[newLayerCount];

progress.Reset("Cloned layers", totalClones);

uint newLayerIndex = 0;
for (uint layerIndex = 0; layerIndex < oldLayers.Length; layerIndex++)
{
Layers[newLayerIndex] = oldLayers[layerIndex];
if (layerIndex >= layerIndexStart && layerIndex <= layerIndexEnd)
{
for (uint i = 0; i < clones; i++)
{
newLayerIndex++;
Layers[newLayerIndex] = oldLayers[layerIndex].Clone();
Layers[newLayerIndex].IsModified = true;

progress++;
}
}

newLayerIndex++;
}

SlicerFile.LayerCount = Count;
BoundingRectangle = Rectangle.Empty;
SlicerFile.RequireFullEncode = true;

RebuildLayersProperties();

progress.Token.ThrowIfCancellationRequested();
}

public void RemoveLayer(uint layerIndex) => RemoveLayer(layerIndex, layerIndex);

public void RemoveLayer(uint layerIndexStart, uint layerIndexEnd)
Expand Down
4 changes: 2 additions & 2 deletions UVtools.Core/UVtools.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<Copyright>Copyright © 2020 PTRTECH</Copyright>
<PackageIcon>UVtools.png</PackageIcon>
<Platforms>AnyCPU;x64</Platforms>
<AssemblyVersion>0.6.6.1</AssemblyVersion>
<FileVersion>0.6.6.1</FileVersion>
<AssemblyVersion>0.6.7.0</AssemblyVersion>
<FileVersion>0.6.7.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
Loading

0 comments on commit ba5b527

Please sign in to comment.