diff options
Diffstat (limited to 'UVtools.Core/FileFormats/FDGFile.cs')
-rw-r--r-- | UVtools.Core/FileFormats/FDGFile.cs | 61 |
1 files changed, 25 insertions, 36 deletions
diff --git a/UVtools.Core/FileFormats/FDGFile.cs b/UVtools.Core/FileFormats/FDGFile.cs index ec1e414..442bc8e 100644 --- a/UVtools.Core/FileFormats/FDGFile.cs +++ b/UVtools.Core/FileFormats/FDGFile.cs @@ -904,7 +904,7 @@ namespace UVtools.Core.FileFormats LayersDefinitions = null; } - protected override void EncodeInternally(string fileFullPath, OperationProgress progress) + protected override void EncodeInternally(OperationProgress progress) { /*if (HeaderSettings.EncryptionKey == 0) { @@ -912,7 +912,7 @@ namespace UVtools.Core.FileFormats HeaderSettings.EncryptionKey = (uint)rnd.Next(short.MaxValue, int.MaxValue); }*/ - using var outputFile = new FileStream(fileFullPath, FileMode.Create, FileAccess.Write); + using var outputFile = new FileStream(FileFullPath, FileMode.Create, FileAccess.Write); outputFile.Seek(Helpers.Serializer.SizeOf(HeaderSettings), SeekOrigin.Begin); for (byte i = 0; i < ThumbnailsCount; i++) @@ -1021,22 +1021,19 @@ namespace UVtools.Core.FileFormats Debug.WriteLine("-End-"); } - protected override void DecodeInternally(string fileFullPath, OperationProgress progress) + protected override void DecodeInternally(OperationProgress progress) { - using var inputFile = new FileStream(fileFullPath, FileMode.Open, FileAccess.Read); + using var inputFile = new FileStream(FileFullPath, FileMode.Open, FileAccess.Read); //HeaderSettings = Helpers.ByteToType<CbddlpFile.Header>(InputFile); //HeaderSettings = Helpers.Serializer.Deserialize<Header>(InputFile.ReadBytes(Helpers.Serializer.SizeOf(typeof(Header)))); HeaderSettings = Helpers.Deserialize<Header>(inputFile); if (HeaderSettings.Magic != MAGIC) { - throw new FileLoadException("Not a valid FDG file!", fileFullPath); + throw new FileLoadException("Not a valid FDG file!", FileFullPath); } HeaderSettings.AntiAliasLevel = 1; - FileFullPath = fileFullPath; - - progress.Reset(OperationProgress.StatusDecodePreviews, ThumbnailsCount); Debug.Write("Header -> "); Debug.WriteLine(HeaderSettings); @@ -1070,7 +1067,7 @@ namespace UVtools.Core.FileFormats HeaderSettings.MachineName = Encoding.ASCII.GetString(buffer); } - LayerManager.Init(HeaderSettings.LayerCount); + LayerManager.Init(HeaderSettings.LayerCount, DecodeType == FileDecodeType.Partial); LayersDefinitions = new LayerDef[HeaderSettings.LayerCount]; progress.Reset(OperationProgress.StatusDecodeLayers, HeaderSettings.LayerCount); @@ -1087,45 +1084,37 @@ namespace UVtools.Core.FileFormats Debug.Write($"LAYER {layerIndex} -> "); Debug.WriteLine(layerDef); - inputFile.SeekDoWorkAndRewind(layerDef.DataAddress, () => + if (DecodeType == FileDecodeType.Full) { - layerDef.EncodedRle = inputFile.ReadBytes(layerDef.DataSize); - }); + inputFile.SeekDoWorkAndRewind(layerDef.DataAddress, + () => { layerDef.EncodedRle = inputFile.ReadBytes(layerDef.DataSize); }); + } } - Parallel.ForEach(batch, CoreSettings.ParallelOptions, layerIndex => + if (DecodeType == FileDecodeType.Full) { - if (progress.Token.IsCancellationRequested) return; - using (var mat = LayersDefinitions[layerIndex].Decode((uint)layerIndex)) + Parallel.ForEach(batch, CoreSettings.ParallelOptions, layerIndex => { - var layer = new Layer((uint)layerIndex, mat, this); - LayersDefinitions[layerIndex].CopyTo(layer); - this[layerIndex] = layer; - } - - progress.LockAndIncrement(); - }); - } - } + if (progress.Token.IsCancellationRequested) return; + if (DecodeType == FileDecodeType.Full) + { + using var mat = LayersDefinitions[layerIndex].Decode((uint)layerIndex); + this[layerIndex] = new Layer((uint)layerIndex, mat, this); + } - public override void SaveAs(string filePath = null, OperationProgress progress = null) - { - if (RequireFullEncode) - { - if (!string.IsNullOrEmpty(filePath)) - { - FileFullPath = filePath; + progress.LockAndIncrement(); + }); } - Encode(FileFullPath, progress); - return; } - if (!string.IsNullOrEmpty(filePath)) + for (uint layerIndex = 0; layerIndex < LayerCount; layerIndex++) { - File.Copy(FileFullPath, filePath, true); - FileFullPath = filePath; + LayersDefinitions[layerIndex].CopyTo(this[layerIndex]); } + } + protected override void PartialSaveInternally(OperationProgress progress) + { using var outputFile = new FileStream(FileFullPath, FileMode.Open, FileAccess.Write); outputFile.Seek(0, SeekOrigin.Begin); Helpers.SerializeWriteFileStream(outputFile, HeaderSettings); |