Skip to content

Commit

Permalink
v0.4.2.2
Browse files Browse the repository at this point in the history
* (Add) Shortcut "ESC" under Islands list view to deselect all items
* (Add) Shortcut "CTRL+A" under Islands list view to select all items
* (Add) Shortcut "*" under Islands list view to invert selection
* (Add) Shortcut "CTRL+F" to go to a layer number
* (Change) Layer image is now a RGB image for better manipulation and draws
* (Change) Layer difference now shows previous and next layers (only pixels not present on current layer) were previous are pink and next are cyan, if a pixel are present in both layers a red pixel will be painted.
* (Fix) Save modified layers on .cbddlp and .cbt corrupts the file to print when Anti-Aliasing is used (> 1)
* (Fix) cbdlp layer encoding
  • Loading branch information
sn4k3 committed Jun 5, 2020
1 parent e5dd60b commit 7788fff
Show file tree
Hide file tree
Showing 13 changed files with 2,408 additions and 136 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 05/06/2020 - v0.4.2.2 - Beta

* (Add) Shortcut "ESC" under Islands list view to deselect all items
* (Add) Shortcut "CTRL+A" under Islands list view to select all items
* (Add) Shortcut "*" under Islands list view to invert selection
* (Add) Shortcut "CTRL+F" to go to a layer number
* (Change) Layer image is now a RGB image for better manipulation and draws
* (Change) Layer difference now shows previous and next layers (only pixels not present on current layer) were previous are pink and next are cyan, if a pixel are present in both layers a red pixel will be painted.
* (Fix) Save modified layers on .cbddlp and .cbt corrupts the file to print when Anti-Aliasing is used (> 1)
* (Fix) cbdlp layer encoding

## 04/06/2020 - v0.4.2.1 - Beta

* (Add) PrusaSlicer Printer "AnyCubic Photon"
Expand Down
118 changes: 88 additions & 30 deletions PrusaSL1Reader/ChituboxFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,39 +713,48 @@ void rleRGB15()

HeaderSettings.LayersDefinitionOffsetAddress = currentOffset;
uint layerDataCurrentOffset = currentOffset + (uint) Helpers.Serializer.SizeOf(new LayerData()) * HeaderSettings.LayerCount * HeaderSettings.AntiAliasLevel;
for (uint layerIndex = 0; layerIndex < LayerCount; layerIndex++)
{
LayerData layerData = new LayerData();
LayerData layerDataHash = null;
var image = this[layerIndex].Image;
rawData = IsCbtFile ? EncodeCbtImage(image, layerIndex) : EncodeCbddlpImage(image);

var byteArr = rawData.ToArray();

if (HeaderSettings.EncryptionKey == 0)
for (byte aaIndex = 0; aaIndex < HeaderSettings.AntiAliasLevel; aaIndex++)
{
for (uint layerIndex = 0; layerIndex < LayerCount; layerIndex++)
{
string hash = Helpers.ComputeSHA1Hash(byteArr);
if (!LayersHash.TryGetValue(hash, out layerDataHash))
{
LayersHash.Add(hash, layerData);
}
}

//layer.DataAddress = CurrentOffset + (uint)Helpers.Serializer.SizeOf(layer);
layerData.DataAddress = layerDataHash?.DataAddress ?? layerDataCurrentOffset;
layerData.DataSize = layerDataHash?.DataSize ?? (uint)byteArr.Length;
layerData.LayerPositionZ = layerIndex * HeaderSettings.LayerHeightMilimeter;
layerData.LayerOffTimeSeconds = layerIndex < HeaderSettings.BottomLayersCount ? PrintParametersSettings.BottomLightOffDelay : PrintParametersSettings.LightOffDelay;
layerData.LayerExposure = layerIndex < HeaderSettings.BottomLayersCount ? HeaderSettings.BottomExposureSeconds : HeaderSettings.LayerExposureSeconds;
LayersDefinitions[layerIndex, 0] = layerData;
LayerData layerData = new LayerData();
LayerData layerDataHash = null;
var image = this[layerIndex].Image;
rawData = IsCbtFile ? EncodeCbtImage(image, layerIndex) : EncodeCbddlpImage(image, aaIndex);

currentOffset += Helpers.SerializeWriteFileStream(outputFile, layerData);
var byteArr = rawData.ToArray();

if (!ReferenceEquals(layerDataHash, null)) continue;
if (HeaderSettings.EncryptionKey == 0)
{
string hash = Helpers.ComputeSHA1Hash(byteArr);
if (!LayersHash.TryGetValue(hash, out layerDataHash))
{
LayersHash.Add(hash, layerData);
}
}

outputFile.Seek(layerDataCurrentOffset, SeekOrigin.Begin);
layerDataCurrentOffset += Helpers.WriteFileStream(outputFile, byteArr);
outputFile.Seek(currentOffset, SeekOrigin.Begin);
//layer.DataAddress = CurrentOffset + (uint)Helpers.Serializer.SizeOf(layer);
layerData.DataAddress = layerDataHash?.DataAddress ?? layerDataCurrentOffset;
layerData.DataSize = layerDataHash?.DataSize ?? (uint) byteArr.Length;
layerData.LayerPositionZ = layerIndex * HeaderSettings.LayerHeightMilimeter;
layerData.LayerOffTimeSeconds = layerIndex < HeaderSettings.BottomLayersCount
? PrintParametersSettings.BottomLightOffDelay
: PrintParametersSettings.LightOffDelay;
layerData.LayerExposure = layerIndex < HeaderSettings.BottomLayersCount
? HeaderSettings.BottomExposureSeconds
: HeaderSettings.LayerExposureSeconds;
LayersDefinitions[layerIndex, aaIndex] = layerData;

currentOffset += Helpers.SerializeWriteFileStream(outputFile, layerData);

if (!ReferenceEquals(layerDataHash, null)) continue;

outputFile.Seek(layerDataCurrentOffset, SeekOrigin.Begin);
layerDataCurrentOffset += Helpers.WriteFileStream(outputFile, byteArr);
outputFile.Seek(currentOffset, SeekOrigin.Begin);
}
}

outputFile.Seek(0, SeekOrigin.Begin);
Expand All @@ -764,11 +773,60 @@ void rleRGB15()
}
}

private List<byte> EncodeCbddlpImage(Image<L8> image)
private List<byte> EncodeCbddlpImage(Image<L8> image, byte aalevel)
{
List<byte> rawData = new List<byte>();

byte color;
bool obit = false;
int rep = 0;

void AddRep()
{
if (rep <= 0) return;

byte by = (byte) rep;

if (obit)
{
by |= 0x80;
//bitsOn += uint(rep)
}

rawData.Add(by);
}

for (int y = 0; y < image.Height; y++)
{
Span<L8> pixelRowSpan = image.GetPixelRowSpan(y);
for (int x = 0; x < image.Width; x++)
{
//ngrey:= uint16(r | g | b)

var nbit = (pixelRowSpan[x].PackedValue & (1 << (int)(8 - HeaderSettings.AntiAliasLevel + aalevel))) != 0;

if (nbit == obit)
{
rep++;

if (rep == RLE8EncodingLimit)
{
AddRep();
rep = 0;
}
}
else
{
AddRep();
obit = nbit;
rep = 1;
}
}
}

// Collect stragglers
AddRep();

/*byte color;
byte black = 0;
byte white = 1;
Expand Down Expand Up @@ -796,7 +854,7 @@ private List<byte> EncodeCbddlpImage(Image<L8> image)
nrOfColor = 1;
}
}
}
}*/

return rawData;
}
Expand Down
2 changes: 1 addition & 1 deletion PrusaSL1Reader/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace PrusaSL1Reader
public static class Helpers
{
public static PngEncoder PngEncoder { get; } = new PngEncoder();
public static BmpEncoder BmpEncoder { get; } = new BmpEncoder();
public static BmpEncoder BmpEncoder { get; } = new BmpEncoder{SupportTransparency = true, BitsPerPixel = BmpBitsPerPixel.Pixel32};
/// <summary>
/// Gets the <see cref="BinarySerializer"/> instance
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions PrusaSL1Reader/LayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public Image<L8> Image
}
}

/// <summary>
/// Gets a new RGBA image instance
/// </summary>
public Image<Rgba32> ImageRbga32 => Image.CloneAs<Rgba32>();

#endregion

#region Constructor
Expand Down
6 changes: 3 additions & 3 deletions PrusaSL1Reader/PrusaSL1Reader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<PackageProjectUrl>https://github.com/sn4k3/PrusaSL1Viewer</PackageProjectUrl>
<PackageIcon></PackageIcon>
<RepositoryUrl>https://github.com/sn4k3/PrusaSL1Viewer</RepositoryUrl>
<AssemblyVersion>0.4.2.1</AssemblyVersion>
<FileVersion>0.4.2.1</FileVersion>
<Version>0.4.2.1</Version>
<AssemblyVersion>0.4.2.2</AssemblyVersion>
<FileVersion>0.4.2.2</FileVersion>
<Version>0.4.2.2</Version>
<Description>Open, view, edit, extract and convert DLP/SLA files generated from Slicers</Description>
</PropertyGroup>

Expand Down
24 changes: 13 additions & 11 deletions PrusaSL1Viewer/FrmInputBox.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions PrusaSL1Viewer/FrmInputBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ public FrmInputBox()

}

public FrmInputBox(FileFormat.PrintParameterModifier modifier, decimal currentValue) : this(modifier.Name,
modifier.Description, currentValue, modifier.ValueUnit, modifier.Minimum, modifier.Maximum)
public FrmInputBox(FileFormat.PrintParameterModifier modifier, decimal currentValue, byte decimals = 2) : this(modifier.Name,
modifier.Description, currentValue, modifier.ValueUnit, modifier.Minimum, modifier.Maximum, decimals)
{ }
public FrmInputBox(string title, string description, decimal currentValue, string valueUnit = null, decimal minValue = 0, decimal maxValue = 100) : this()
public FrmInputBox(string title, string description, decimal currentValue, string valueUnit = null, decimal minValue = 0, decimal maxValue = 100, byte decimals = 2, string valueLabel = "Value") : this()
{
Text = title;
lbCurrentValue.Text = $"Current {valueLabel}";
lbNewValue.Text = $"New {valueLabel}";
Description = description;
ValueUint = valueUnit ?? string.Empty;
CurrentValue = currentValue;
numNewValue.Minimum = minValue;
numNewValue.Maximum = maxValue;
numNewValue.DecimalPlaces = decimals;
NewValue = currentValue;
}
#endregion
Expand Down
Loading

0 comments on commit 7788fff

Please sign in to comment.