Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Merge remote-tracking branch 'origin/main' into feature/jpeg-xr

KnifeLemon27a99974cfe0
diff --cc src/Filee.Engines/Magick/MagickImageConverter.cs
index 8a6e4ac9,77e1acc8..2623b59a
--- a/src/Filee.Engines/Magick/MagickImageConverter.cs
+++ b/src/Filee.Engines/Magick/MagickImageConverter.cs
@@@ -72,31 -72,23 +72,34 @@@ public sealed class MagickImageConverte
// Animated PNGs are often saved as .png: read them as APNG, so they stay animated as GIF or WebP.
var from = step.From == "png" && Apng.IsAnimated(step.InputPath) ? "apng" : step.From;
using var images = ImageReader.Read(step.InputPath, from, step.Preset);
- cancellationToken.ThrowIfCancellationRequested();
- progress?.Report(0.3);
+ return Write(images, from, step, progress, cancellationToken);
+ }, cancellationToken);
- var animation = ImageEncoder.KeepsAnimation(from, step.To);
- var frames = ImageEncoder.SelectFrames(images, from, step.To);
- // Before the options: frames dropped for speed aren't resized for nothing.
- if (animation && step.Preset.Image.ChangesSpeed)
- frames = AnimationTiming.ChangeSpeed(frames, step.Preset.Image.PlaybackSpeed, step.To);
- foreach (var frame in frames)
- {
- cancellationToken.ThrowIfCancellationRequested();
- ImageEncoder.ApplyOptions(frame, step.Preset.Image, step.To);
- }
- progress?.Report(0.7);
+ /// <summary>
+ /// The rest of a conversion once the picture is read (also for pictures another engine decoded, see
+ /// Wic/WicImageConverter): the frames kept for the target, the preset's options, the files.
+ /// </summary>
+ /// <param name="from">Format the frames were read from (animations and icons keep different frames).</param>
+ internal static IReadOnlyList<string> Write(MagickImageCollection images, string from, ConversionStep step,
+ IProgress<double>? progress, CancellationToken cancellationToken)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+ progress?.Report(0.3);
- var written = ImageEncoder.Write(frames, step.To, step.Output, step.Preset.Image, step.InputPath, animation);
- progress?.Report(1);
- return written;
- }, cancellationToken);
++ var animation = ImageEncoder.KeepsAnimation(from, step.To);
+ var frames = ImageEncoder.SelectFrames(images, from, step.To);
++ // Before the options: frames dropped for speed aren't resized for nothing.
++ if (animation && step.Preset.Image.ChangesSpeed)
++ frames = AnimationTiming.ChangeSpeed(frames, step.Preset.Image.PlaybackSpeed, step.To);
+ foreach (var frame in frames)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+ ImageEncoder.ApplyOptions(frame, step.Preset.Image, step.To);
+ }
+ progress?.Report(0.7);
+
- var written = ImageEncoder.Write(frames, step.To, step.Output, step.Preset.Image, step.InputPath,
- ImageEncoder.KeepsAnimation(from, step.To));
++ var written = ImageEncoder.Write(frames, step.To, step.Output, step.Preset.Image, step.InputPath, animation);
+ progress?.Report(1);
+ return written;
+ }
}