Skip to content

Commit

Permalink
v3.14.1
Browse files Browse the repository at this point in the history
- (Improvement) File formats: When full encoding make sure thumbnails are all set according to file, otherwise clone/create them
- (Fix) Encrypted CTB: Files are getting read/write without thumbnails making invalid files
  • Loading branch information
sn4k3 committed Jun 3, 2023
1 parent e3a3033 commit 32ccf55
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 86 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 03/06/2023 - v3.14.1

- (Improvement) File formats: When full encoding make sure thumbnails are all set according to file, otherwise clone/create them
- (Fix) Encrypted CTB: Files are getting read/write without thumbnails making invalid files

## 31/05/2023 - v3.14.0

- **File formats:**
Expand All @@ -9,9 +14,9 @@
- (Add) Support for Photon Mono M5 (.pm5) and corresponding PrusaSlicer printer
- (Add) Support for Photon Mono M5s (.pm5s) and corresponding PrusaSlicer printer
- (Improvement) Better tables validation and data structures
- (Improvement) Ensure the correct number of thumbnails are created when converting between files with different thumbnail count
- (Add) PRZ file format and corresponding PrusaSlicer printer Phrozen Sonic Mini 8K S (#705)
- (Improvement) When encoding a file with wait time before cure set but file does not support it, attempt to set light-off delay with that extra time if supported
- (Improvement) Ensure the correct number of thumbnails are created when converting between files with different thumbnail count
- (Improvement) Minor code cleanup and improve some types to not nullable
- **PrusaSlicer printers:**
- (Add) Elegoo Mars 4 Max
Expand Down
24 changes: 2 additions & 22 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
- **File formats:**
- **Anycubic:**
- (Add) Support for version 518 of the file format
- (Add) Support for Photon Mono X 6Ks (.px6s) and corresponding PrusaSlicer printer
- (Add) Support for Photon Mono M5 (.pm5) and corresponding PrusaSlicer printer
- (Add) Support for Photon Mono M5s (.pm5s) and corresponding PrusaSlicer printer
- (Improvement) Better tables validation and data structures
- (Improvement) Ensure the correct number of thumbnails are created when converting between files with different thumbnail count
- (Add) PRZ file format and corresponding PrusaSlicer printer Phrozen Sonic Mini 8K S (#705)
- (Improvement) When encoding a file with wait time before cure set but file does not support it, attempt to set light-off delay with that extra time if supported
- (Improvement) Minor code cleanup and improve some types to not nullable
- **PrusaSlicer printers:**
- (Add) Elegoo Mars 4 Max
- (Add) Peopoly Phenom XXL V2
- (Add) Nova3D Bene6
- (Improvement) Suggestion - Wait time before cure: Create the empty layer only to file formats that we know who require it
- (Improvement) Disable suggestions for image file formats
- (Improvement) After file load, if version is outside the supported range for the printer and format it will prompt to change for the latest supported version
- (Improvement) Pixel size information on status bar: If pixel width is not equal to pixel height, show both
- (Fix) Tool - Timelapse: The informative number of additional lifts not respecting the selected layer range and get calculated for whole model height
- (Fix) Tool - Change resolution: Allow image file types to run this tool without error (#716)
- (Fix) Menu - Open recent file: Filenames with underscore (_) are not shown correctly
- (Improvement) File formats: When full encoding make sure thumbnails are all set according to file, otherwise clone/create them
- (Fix) Encrypted CTB: Files are getting read/write without thumbnails making invalid files

31 changes: 14 additions & 17 deletions UVtools.Core/FileFormats/CTBEncryptedFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,28 +1119,25 @@ protected override void DecodeInternally(OperationProgress progress)

progress.Reset(OperationProgress.StatusDecodePreviews, ThumbnailsCount);

if (HaveThumbnails)
for (byte i = 0; i < ThumbnailsCount; i++)
{
for (byte i = 0; i < ThumbnailsCount; i++)
{
uint offsetAddress = i == 0
? Settings.LargePreviewOffset
: Settings.SmallPreviewOffset;
if (offsetAddress == 0) continue;
uint offsetAddress = i == 0
? Settings.LargePreviewOffset
: Settings.SmallPreviewOffset;
if (offsetAddress == 0) continue;

inputFile.Seek(offsetAddress, SeekOrigin.Begin);
Previews[i] = Helpers.Deserialize<Preview>(inputFile);
inputFile.Seek(offsetAddress, SeekOrigin.Begin);
Previews[i] = Helpers.Deserialize<Preview>(inputFile);

Debug.Write($"Preview {i} -> ");
Debug.WriteLine(Previews[i]);
Debug.Write($"Preview {i} -> ");
Debug.WriteLine(Previews[i]);

inputFile.Seek(Previews[i].ImageOffset, SeekOrigin.Begin);
byte[] rawImageData = new byte[Previews[i].ImageLength];
inputFile.Read(rawImageData, 0, (int) Previews[i].ImageLength);
inputFile.Seek(Previews[i].ImageOffset, SeekOrigin.Begin);
byte[] rawImageData = new byte[Previews[i].ImageLength];
inputFile.Read(rawImageData, 0, (int) Previews[i].ImageLength);

Thumbnails[i] = Previews[i].Decode(rawImageData);
progress++;
}
Thumbnails[i] = Previews[i].Decode(rawImageData);
progress++;
}

/* Read the settings and disclaimer */
Expand Down
37 changes: 26 additions & 11 deletions UVtools.Core/FileFormats/FileFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,14 +1243,14 @@ public virtual uint Version
public virtual Size[] ThumbnailsOriginalSize => Array.Empty<Size>();

/// <summary>
/// Gets if this file have any valid thumbnail
/// Gets the thumbnails count present in this file format
/// </summary>
public bool HaveThumbnails => Thumbnails.Any(thumbnail => thumbnail is not null);
public byte ThumbnailsCount => (byte)ThumbnailsOriginalSize.Length;

/// <summary>
/// Gets the thumbnails count present in this file format
/// Gets if this file have any valid thumbnail
/// </summary>
public byte ThumbnailsCount => (byte)ThumbnailsOriginalSize.Length;
public bool HaveThumbnails => Thumbnails.Any(thumbnail => thumbnail is not null && !thumbnail.IsEmpty);

/// <summary>
/// Gets the number of created thumbnails
Expand Down Expand Up @@ -3430,11 +3430,14 @@ public bool SetThumbnails(Mat?[] images, bool generateImagesIfEmpty = false)

images = images.Where(mat => mat is not null && !mat.IsEmpty).ToArray();

int count = 0;

if (images.Length == 0)
{
if (!generateImagesIfEmpty) return false;
using var mat = FirstLayer?.BrgMat;
if (mat is null || mat.IsEmpty)
count = Thumbnails.Length;
using var matRoi = FirstLayer?.LayerMatModelBoundingRectangle;
if (matRoi is null || matRoi.SourceMat.IsEmpty)
{
using var genMat = EmguExtensions.InitMat(new Size(200, 100), 3);
CvInvoke.PutText(genMat, About.Software, new Point(40, 60), FontFace.HersheyDuplex, 1, EmguExtensions.WhiteColor, 2);
Expand All @@ -3451,7 +3454,8 @@ public bool SetThumbnails(Mat?[] images, bool generateImagesIfEmpty = false)
{
Thumbnails[i]?.Dispose();
Thumbnails[i] = new Mat();
CvInvoke.Resize(mat, Thumbnails[i], ThumbnailsOriginalSize[i]);
CvInvoke.CvtColor(matRoi.RoiMat, Thumbnails[i], ColorConversion.Gray2Bgr);
CvInvoke.Resize(Thumbnails[i], Thumbnails[i], ThumbnailsOriginalSize[i]);
}
}
}
Expand All @@ -3468,9 +3472,13 @@ public bool SetThumbnails(Mat?[] images, bool generateImagesIfEmpty = false)
{
CvInvoke.Resize(Thumbnails[i], Thumbnails[i], ThumbnailsOriginalSize[i]);
}

count++;
}
}

if (count == 0) return false;

RaisePropertyChanged(nameof(Thumbnails));
RequireFullEncode = true;
return true;
Expand Down Expand Up @@ -3607,16 +3615,21 @@ public void Encode(string? fileFullPath, OperationProgress? progress = null)
}
}

OnBeforeEncode(false);
BeforeEncode();
// Make sure thumbnails are all set, otherwise clone/create them
SetThumbnails(Thumbnails, true);

// Make sure thumbnails are in right size
for (var i = 0; i < Thumbnails.Length; i++)
{
if (Thumbnails[i] is null || Thumbnails[i]!.IsEmpty) continue;
if(Thumbnails[i]!.Size == ThumbnailsOriginalSize[i]) continue;
CvInvoke.Resize(Thumbnails[i], Thumbnails[i], new Size(ThumbnailsOriginalSize[i].Width, ThumbnailsOriginalSize[i].Height));
CvInvoke.Resize(Thumbnails[i], Thumbnails[i], ThumbnailsOriginalSize[i]);
}

OnBeforeEncode(false);
BeforeEncode();

bool success;
try
{
EncodeInternally(progress);
Expand All @@ -3627,7 +3640,7 @@ public void Encode(string? fileFullPath, OperationProgress? progress = null)
IsModified = false;
RequireFullEncode = false;

OnAfterEncode(false);
success = true;
}
catch (Exception)
{
Expand All @@ -3636,6 +3649,8 @@ public void Encode(string? fileFullPath, OperationProgress? progress = null)
if (File.Exists(tempFile)) File.Delete(tempFile);
throw;
}

if (success) OnAfterEncode(false);
}

public void Encode(OperationProgress progress) => Encode(null, progress);
Expand Down
Loading

0 comments on commit 32ccf55

Please sign in to comment.