Skip to content

Commit

Permalink
v0.3.3
Browse files Browse the repository at this point in the history
* (Add) PHZ file format
* (Add) "Phrozen Sonic Mini" printer
* (Add) Convert Chitubox files to PHZ files and otherwise
* (Add) Convert Chitubox and PHZ files to ZCodex
* (Add) Elapsed seconds to convertion and extract dialog
* (Improvement) "Convert To" menu now only show available formats to convert to, if none menu is disabled
* (Fixed) Enforce cbt encryption
* (Fixed) Not implemented convertions stay processing forever
  • Loading branch information
sn4k3 committed May 19, 2020
1 parent e756162 commit d91986f
Show file tree
Hide file tree
Showing 14 changed files with 1,591 additions and 73 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## ? - v0.3.3 - Beta

* (Add) PHZ file format
* (Add) "Phrozen Sonic Mini" printer
* (Add) Convert Chitubox files to PHZ files and otherwise
* (Add) Convert Chitubox and PHZ files to ZCodex
* (Add) Elapsed seconds to convertion and extract dialog
* (Improvement) "Convert To" menu now only show available formats to convert to, if none menu is disabled
* (Fixed) Enforce cbt encryption
* (Fixed) Not implemented convertions stay processing forever


## 11/05/2020 - v0.3.2 - Beta

* (Add) Show layer differences where daker pixels were also present on previous layer and the white pixels the difference between previous and current layer.
Expand Down
162 changes: 152 additions & 10 deletions PrusaSL1Reader/ChituboxFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using BinarySerialization;
using PrusaSL1Reader.Extensions;
Expand All @@ -29,7 +30,7 @@ public class ChituboxFile : FileFormat
private const ushort REPEATRGB15MASK = 0x20;

private const byte RLE8EncodingLimit = 125;
private const ushort RLE16EncodingLimit = 0x1000;
private const ushort RLE16EncodingLimit = 0xFFF;
#endregion

#region Sub Classes
Expand Down Expand Up @@ -438,10 +439,7 @@ public byte Next()
public List<byte> Read(List<byte> input)
{
List<byte> data = new List<byte>(input.Count);
for (int i = 0; i < input.Count; i++)
{
data[i] = (byte)(input[i] ^ Next());
}
data.AddRange(input.Select(t => (byte) (t ^ Next())));

return data;
}
Expand Down Expand Up @@ -482,6 +480,12 @@ public byte[] Read(byte[] input)
new FileExtension("photon", "Photon Files"),
};

public override Type[] ConvertToFormats { get; } =
{
typeof(PHZFile),
typeof(ZCodexFile),
};

public override PrintParameterModifier[] PrintParameterModifiers { get; } =
{
PrintParameterModifier.InitialLayerCount,
Expand Down Expand Up @@ -564,11 +568,19 @@ public override void Encode(string fileFullPath)
HeaderSettings.Magic = fileFullPath.EndsWith(".ctb") ? MAGIC_CBT : MAGIC_CBDDLP;
HeaderSettings.PrintParametersSize = (uint)Helpers.Serializer.SizeOf(PrintParametersSettings);


if (IsCbtFile)
{
PrintParametersSettings.Padding4 = 0x1234;
SlicerInfoSettings.EncryptionMode = 0xf;
//SlicerInfoSettings.EncryptionMode = 0xf;
SlicerInfoSettings.EncryptionMode = 7;
SlicerInfoSettings.Unknown1 = 0x200;

if (HeaderSettings.EncryptionKey == 0)
{
Random rnd = new Random();
HeaderSettings.EncryptionKey = (uint)rnd.Next(short.MaxValue, int.MaxValue);
}
}

uint currentOffset = (uint)Helpers.Serializer.SizeOf(HeaderSettings);
Expand Down Expand Up @@ -854,10 +866,7 @@ void AddRep()
for (int x = 0; x < image.Width; x++)
{
var grey7 = (byte)(pixelRowSpan[x].PackedValue >> 1);
if (pixelRowSpan[x].PackedValue > 0)
{

}
if (grey7 == color)
{
stride++;
Expand Down Expand Up @@ -1389,7 +1398,140 @@ public override void SaveAs(string filePath = null)

public override bool Convert(Type to, string fileFullPath)
{
throw new NotImplementedException();
if (to == typeof(PHZFile))
{
PHZFile file = new PHZFile
{
Layers = Layers
};


file.HeaderSettings.Version = 2;
file.HeaderSettings.BedSizeX = HeaderSettings.BedSizeX;
file.HeaderSettings.BedSizeY = HeaderSettings.BedSizeY;
file.HeaderSettings.BedSizeZ = HeaderSettings.BedSizeZ;
file.HeaderSettings.OverallHeightMilimeter = TotalHeight;
file.HeaderSettings.BottomExposureSeconds = InitialExposureTime;
file.HeaderSettings.BottomLayersCount = InitialLayerCount;
file.HeaderSettings.BottomLightPWM = HeaderSettings.BottomLightPWM;
file.HeaderSettings.LayerCount = LayerCount;
file.HeaderSettings.LayerExposureSeconds = LayerExposureTime;
file.HeaderSettings.LayerHeightMilimeter = LayerHeight;
file.HeaderSettings.LayerOffTime = HeaderSettings.LayerOffTime;
file.HeaderSettings.LightPWM = HeaderSettings.LightPWM;
file.HeaderSettings.PrintTime = HeaderSettings.PrintTime;
file.HeaderSettings.ProjectorType = HeaderSettings.ProjectorType;
file.HeaderSettings.ResolutionX = ResolutionX;
file.HeaderSettings.ResolutionY = ResolutionY;

file.HeaderSettings.BottomLayerCount = InitialLayerCount;
file.HeaderSettings.BottomLiftHeight = PrintParametersSettings.BottomLiftHeight;
file.HeaderSettings.BottomLiftSpeed = PrintParametersSettings.BottomLiftSpeed;
file.HeaderSettings.BottomLightOffDelay = PrintParametersSettings.BottomLightOffDelay;
file.HeaderSettings.CostDollars = MaterialCost;
file.HeaderSettings.LiftHeight = PrintParametersSettings.LiftHeight;
file.HeaderSettings.LiftingSpeed = PrintParametersSettings.LiftingSpeed;
file.HeaderSettings.LayerOffTime = HeaderSettings.LayerOffTime;
file.HeaderSettings.RetractSpeed = PrintParametersSettings.RetractSpeed;
file.HeaderSettings.VolumeMl = UsedMaterial;
file.HeaderSettings.WeightG = PrintParametersSettings.WeightG;

file.HeaderSettings.MachineName = MachineName;
file.HeaderSettings.MachineNameSize = (uint) MachineName.Length;

file.SetThumbnails(Thumbnails);
file.Encode(fileFullPath);

return true;
}

if (to == typeof(ZCodexFile))
{
TimeSpan ts = new TimeSpan(0, 0, (int)PrintTime);
ZCodexFile file = new ZCodexFile
{
ResinMetadataSettings = new ZCodexFile.ResinMetadata
{
MaterialId = 2,
Material = MaterialName,
AdditionalSupportLayerTime = 0,
BottomLayersNumber = InitialLayerCount,
BottomLayersTime = (uint)(InitialExposureTime * 1000),
LayerTime = (uint)(LayerExposureTime * 1000),
DisableSettingsChanges = false,
LayerThickness = LayerHeight,
PrintTime = (uint)PrintTime,
TotalLayersCount = LayerCount,
TotalMaterialVolumeUsed = UsedMaterial,
TotalMaterialWeightUsed = UsedMaterial,
},
UserSettings = new ZCodexFile.UserSettingsdata
{
Printer = MachineName,
BottomLayersCount = InitialLayerCount,
PrintTime = $"{ts.Hours}h {ts.Minutes}m",
LayerExposureTime = (uint)(LayerExposureTime * 1000),
BottomLayerExposureTime = (uint)(InitialExposureTime * 1000),
MaterialId = 2,
LayerThickness = $"{LayerHeight} mm",
AntiAliasing = 0,
CrossSupportEnabled = 1,
ExposureOffTime = (uint) HeaderSettings.LayerOffTime,
HollowEnabled = 0,
HollowThickness = 0,
InfillDensity = 0,
IsAdvanced = 0,
MaterialType = MaterialName,
MaterialVolume = UsedMaterial,
MaxLayer = LayerCount - 1,
ModelLiftEnabled = 0,
ModelLiftHeight = 0,
RaftEnabled = 0,
RaftHeight = 0,
RaftOffset = 0,
SupportAdditionalExposureEnabled = 0,
SupportAdditionalExposureTime = 0,
XCorrection = 0,
YCorrection = 0,
ZLiftDistance = PrintParametersSettings.LiftHeight,
ZLiftFeedRate = PrintParametersSettings.LiftingSpeed,
ZLiftRetractRate = PrintParametersSettings.RetractSpeed,
},
ZCodeMetadataSettings = new ZCodexFile.ZCodeMetadata
{
PrintTime = (uint)PrintTime,
PrinterName = MachineName,
Materials = new List<ZCodexFile.ZCodeMetadata.MaterialsData>
{
new ZCodexFile.ZCodeMetadata.MaterialsData
{
Name = MaterialName,
ExtruderType = "MAIN",
Id = 0,
Usage = 0,
Temperature = 0
}
},
},
Layers = Layers
};

float usedMaterial = UsedMaterial / LayerCount;
for (uint layerIndex = 0; layerIndex < LayerCount; layerIndex++)
{
file.ResinMetadataSettings.Layers.Add(new ZCodexFile.ResinMetadata.LayerData
{
Layer = layerIndex,
UsedMaterialVolume = usedMaterial
});
}

file.SetThumbnails(Thumbnails);
file.Encode(fileFullPath);
return true;
}

return false;
}
#endregion
}
Expand Down
18 changes: 13 additions & 5 deletions PrusaSL1Reader/FileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@
* of this license document, but changing it is not allowed.
*/
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using PrusaSL1Reader.Extensions;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using Size = System.Drawing.Size;
Expand Down Expand Up @@ -133,6 +128,7 @@ public override string ToString()
{
new SL1File(), // Prusa SL1
new ChituboxFile(), // cbddlp, cbt, photon
new PHZFile(), // phz
new ZCodexFile(), // zcodex
};

Expand Down Expand Up @@ -172,13 +168,25 @@ public static FileFormat FindByExtension(string extension, bool isFilePath = fal
{
return (from fileFormat in AvaliableFormats where fileFormat.IsExtensionValid(extension, isFilePath) select createNewInstance ? (FileFormat) Activator.CreateInstance(fileFormat.GetType()) : fileFormat).FirstOrDefault();
}

/// <summary>
/// Find <see cref="FileFormat"/> by an type
/// </summary>
/// <param name="type">Type to find</param>
/// <param name="createNewInstance">True to create a new instance of found file format, otherwise will return a pre created one which should be used for read-only purpose</param>
/// <returns><see cref="FileFormat"/> object or null if not found</returns>
public static FileFormat FindByType(Type type, bool createNewInstance = false)
{
return (from t in AvaliableFormats where type == t.GetType() select createNewInstance ? (FileFormat) Activator.CreateInstance(type) : t).FirstOrDefault();
}
#endregion

#region Properties

public abstract FileFormatType FileType { get; }

public abstract FileExtension[] FileExtensions { get; }
public abstract Type[] ConvertToFormats { get; }

public abstract PrintParameterModifier[] PrintParameterModifiers { get; }

Expand Down
5 changes: 5 additions & 0 deletions PrusaSL1Reader/IFileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public interface IFileFormat
/// </summary>
FileExtension[] FileExtensions { get; }

/// <summary>
/// Gets the implemented file formats able to convert to
/// </summary>
Type[] ConvertToFormats { get; }

/// <summary>
/// Gets the available <see cref="FileFormat.PrintParameterModifier"/>
/// </summary>
Expand Down
Loading

0 comments on commit d91986f

Please sign in to comment.