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.

Rotate and flip: only the turning step gets the rotation

KnifeLemon52c55edbd22d
diff --git a/src/Filee.Core/Conversion/JobQueue.cs b/src/Filee.Core/Conversion/JobQueue.cs
index 8753f790..590f3337 100644
--- a/src/Filee.Core/Conversion/JobQueue.cs
+++ b/src/Filee.Core/Conversion/JobQueue.cs
@@ -375,8 +375,9 @@ public sealed class JobQueue : IAsyncDisposable
await gate.WaitAsync(ct);
try
{
- // Turned once, in step turnAt: the steps after it get the preset without rotation and flip.
- var preset = turnAt >= 0 && s > turnAt ? unturned : job.Preset;
+ // Turned once, in step turnAt: every other step gets the preset without rotation and flip,
+ // also one before it whose engine applies image options but doesn't say it turns.
+ var preset = s == turnAt ? job.Preset : unturned;
var stepInfo = new ConversionStep(input, step.From, step.To, preset, allocator, workDir);
outputs.AddRange(await step.Converter.ConvertAsync(stepInfo, progress, ct));
}
diff --git a/src/Filee.Engines/Models3D/ModelConverter.cs b/src/Filee.Engines/Models3D/ModelConverter.cs
index 2a923e25..7e6ab5cb 100644
--- a/src/Filee.Engines/Models3D/ModelConverter.cs
+++ b/src/Filee.Engines/Models3D/ModelConverter.cs
@@ -13,7 +13,7 @@ using Microsoft.Extensions.Logging.Abstractions;
namespace Filee.Engines.Models3D;
/// <summary>Converts 3D models between GLB, glTF, STL, OBJ, 3MF and PLY, and renders them to pictures.</summary>
-public sealed class ModelConverter(ILogger? logger = null) : IConverter
+public sealed class ModelConverter(ILogger? logger = null) : IConverter, IImageTransformer
{
/// <summary>The 3D formats, each readable and writable.</summary>
public static readonly string[] Formats = ["glb", "gltf", "stl", "obj", "3mf", "ply"];
@@ -26,6 +26,9 @@ public sealed class ModelConverter(ILogger? logger = null) : IConverter
public string Id => "model3d";
public string DisplayName => "3D models (built-in)";
+ /// <summary>The rendered picture goes through the image options, rotation and flip included.</summary>
+ public bool Transforms(string from, string to) => ImageEncoder.Writable.Contains(to);
+
/// <summary>A large mesh takes a few hundred MB while it is converted, so only a few run at once.</summary>
public int MaxParallelism => Math.Clamp(Environment.ProcessorCount / 2, 1, 4);
diff --git a/tests/Filee.Core.Tests/FakeConverter.cs b/tests/Filee.Core.Tests/FakeConverter.cs
index 544de74a..0bdfc339 100644
--- a/tests/Filee.Core.Tests/FakeConverter.cs
+++ b/tests/Filee.Core.Tests/FakeConverter.cs
@@ -61,6 +61,28 @@ internal sealed class FakeTurner(string id, params ConversionEdge[] edges) : ICo
}
}
+/// <summary>An engine that doesn't turn images (no <see cref="IImageTransformer"/>) but records the preset it gets.</summary>
+internal sealed class FakeRecorder(string id, params ConversionEdge[] edges) : IConverter
+{
+ private readonly FakeConverter _writer = new(id, edges);
+
+ public string Id => id;
+ public string DisplayName => id;
+ public IReadOnlyList<ConversionEdge> Edges => edges;
+ public int MaxParallelism => 0;
+
+ public List<(string To, Filee.Core.Presets.ImageRotation Rotation)> Asked { get; } = [];
+
+ public EngineStatus GetStatus() => EngineStatus.Available();
+
+ public Task<IReadOnlyList<string>> ConvertAsync(ConversionStep step, IProgress<double>? progress, CancellationToken cancellationToken)
+ {
+ lock (Asked)
+ Asked.Add((step.To, step.Preset.Image.Rotation));
+ return _writer.ConvertAsync(step, progress, cancellationToken);
+ }
+}
+
internal sealed class FakeMerger : IPdfMerger
{
public List<string> Inputs { get; } = [];
diff --git a/tests/Filee.Core.Tests/JobQueueTests.cs b/tests/Filee.Core.Tests/JobQueueTests.cs
index 12f1e219..4c3d302d 100644
--- a/tests/Filee.Core.Tests/JobQueueTests.cs
+++ b/tests/Filee.Core.Tests/JobQueueTests.cs
@@ -56,6 +56,24 @@ public class JobQueueTests
Assert.Equal(JobState.Completed, plain.State);
}
+ [Fact]
+ public async Task A_step_before_the_turning_one_gets_the_preset_without_rotation()
+ {
+ // STL → PNG (an engine that renders with the image options but doesn't say it turns) → HEIC (one that turns):
+ // only the HEIC step turns, or the picture would be turned twice.
+ using var dir = new TempDir();
+ var model = dir.File("part.stl");
+ var renderer = new FakeRecorder("model3d", new ConversionEdge("stl", "png"));
+ var heic = new FakeTurner("ffmpeg", new ConversionEdge("png", "heic"));
+ await using var queue = new JobQueue(new ConverterCatalog([renderer, heic]));
+
+ var job = await Run(queue, [model], new Preset { TargetFormat = "heic", Image = { Rotation = ImageRotation.Left90 } });
+
+ Assert.Equal(JobState.Completed, job.State);
+ Assert.Equal([("png", ImageRotation.None)], renderer.Asked);
+ Assert.Equal([("heic", ImageRotation.Left90)], heic.Asked);
+ }
+
[Fact]
public async Task Keep_dates_gives_outputs_the_dates_of_their_source()
{
diff --git a/tests/Filee.Engines.Tests/ModelTests.cs b/tests/Filee.Engines.Tests/ModelTests.cs
index 9dd89b9d..48539f1b 100644
--- a/tests/Filee.Engines.Tests/ModelTests.cs
+++ b/tests/Filee.Engines.Tests/ModelTests.cs
@@ -522,6 +522,23 @@ public class ModelTests(EngineFixture fx) : IClassFixture<EngineFixture>
// ───────────────────────── Pictures ─────────────────────────
+ [Fact]
+ public async Task A_rotate_preset_turns_the_rendered_picture_once()
+ {
+ var folder = fx.NewFolder();
+ var source = ModelBuilders.Save(ModelBuilders.Fan(), folder, "fan", "stl");
+ var plain = (await RunAsync(source, "png")).Outputs.Single();
+ var job = await fx.ConvertAsync([source], new Preset { TargetFormat = "png", Image = { Rotation = ImageRotation.Left90 } });
+ Assert.True(job.State == JobState.Completed, string.Join("; ", job.Files.Select(f => $"{f.ErrorKey} {f.ErrorDetail}")));
+
+ using var expected = new MagickImage(plain);
+ expected.Rotate(-90);
+ using var turned = new MagickImage(job.Outputs.Single());
+ using var unturned = new MagickImage(plain);
+ Assert.True(unturned.Compare(expected, ErrorMetric.RootMeanSquared) > 0.01); // the fan looks different turned
+ Assert.True(turned.Compare(expected, ErrorMetric.RootMeanSquared) < 0.01);
+ }
+
[Fact]
public async Task A_model_renders_to_a_shaded_picture_with_a_transparent_background()
{