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.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Merge feat/hide-areas into feat/join-images: Edit pictures (51), Pixelate / blur (52), Merge images (53)
KnifeLemon9255acc22b33
diff --cc src/Filee.Core/Conversion/JobQueue.csindex b8d8ab01,2c4d352b..53e9b84b--- a/src/Filee.Core/Conversion/JobQueue.cs+++ b/src/Filee.Core/Conversion/JobQueue.cs@@@ -410,10 -403,10 +410,10 @@@ public sealed class JobQueue : IAsyncDi}if (slideshow){- parts[i] = source.Id == "png" && !job.Preset.Image.TurnsOrMirrors+ parts[i] = source.Id == "png" && !job.Preset.Image.ReworksPixels? [file.SourcePath]: await RunFileAsync(job, file, i + 1, planner, workDir, finalOutput: false, intermediate: "png",- ceiling: SlidesReadyShare);+ ceiling: PicturesReadyShare);return;}// A video's sound can join an audio file; a picture or a document joins nothing.@@@ -794,10 -721,11 +794,11 @@@// Rotate / flip: only an engine that turns images does it. Without one the file would come out unturned// (a PDF or a video re-encoded "as rotated"); with two in the route (EPS → PNG → JPG) it would turn twice.- var turnAt = runWith.Image.TurnsOrMirrors ? route.FirstTransformStep() : -1;- if (runWith.Image.TurnsOrMirrors && turnAt < 0)- return Fail(file, "error.cannot_turn", $"{source.Id} → {target}");+ // Parts of a picture to hide likewise, once: a route that can't cover them must not write the picture uncovered.- var turnAt = job.Preset.Image.ReworksPixels ? route.FirstTransformStep() : -1;- if (job.Preset.Image.ReworksPixels && turnAt < 0)- return Fail(file, job.Preset.Image.HidesAreas ? "error.cannot_hide" : "error.cannot_turn", $"{source.Id} → {target}");- var unturned = turnAt < 0 ? job.Preset : Unturned(job.Preset);++ var turnAt = runWith.Image.ReworksPixels ? route.FirstTransformStep() : -1;++ if (runWith.Image.ReworksPixels && turnAt < 0)++ return Fail(file, runWith.Image.HidesAreas ? "error.cannot_hide" : "error.cannot_turn", $"{source.Id} → {target}");+ var unturned = turnAt < 0 ? runWith : Unturned(runWith);file.State = FileState.Running;Notify(job);@@@ -840,9 -768,10 +841,10 @@@await gate.WaitAsync(ct);try{- // 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.+ // Turned (and covered) once, in step turnAt: every other step gets the preset without rotation,+ // flip and hidden parts, also one before it whose engine applies image options but doesn't say+ // it turns.- var preset = s == turnAt ? job.Preset : unturned;+ var preset = s == turnAt ? runWith : unturned;// Playback speed changes once, in the step that writes the output: an animation passed from one// engine to another would otherwise change speed in both.if (preset.Image.ChangesSpeed && !(isLast && finalOutput))@@@ -870,7 -799,9 +872,9 @@@}// Under "Save as ZIP" the output is still in the work folder: the source copied over it goes into the ZIP.- var copiedSource = finalOutput && runWith.Output.OnlyIfSmaller && inputs.Count == 1 && CopyIfNotSmaller(file.SourcePath, inputs[0]);+ // Never with hidden parts: the source copied over the result would show them again.- var copiedSource = finalOutput && job.Preset.Output.OnlyIfSmaller && !job.Preset.Image.HidesAreas && inputs.Count == 1++ var copiedSource = finalOutput && runWith.Output.OnlyIfSmaller && !runWith.Image.HidesAreas && inputs.Count == 1+ && CopyIfNotSmaller(file.SourcePath, inputs[0]);if (copiedSource)file.NoticeKey = "notice.pdf_not_smaller";// Watermark, page numbers, password: on every PDF this file became, from whichever engine.diff --cc src/Filee.Core/Presets/BuiltInData.csindex a0d0817d,ef437e67..ffab9bc7--- a/src/Filee.Core/Presets/BuiltInData.cs+++ b/src/Filee.Core/Presets/BuiltInData.cs@@@ -542,11 -555,11 +570,12 @@@ public static class BuiltInDat{Id = "images", NameKey = "profile.images",Extensions = ExtensionsOf(FormatCategory.Image),- PresetIds = ["to-png", "to-jpg", "to-webp", "to-pdf", "trace-svg", "trace-line-art", "to-tiff", "to-bmp", "to-ico", "half-size"],+ PresetIds = ["to-png", "to-jpg", "to-webp", "to-pdf", "trace-svg", "trace-line-art", "to-tiff", "to-bmp", "to-ico", "half-size",+ "tool-image-edit", "tool-hide"],- // Full (ToolbarProfile.MaxSlices): "Extract Live Photo video" stays in the library, on no donut.- BackPresetIds = ["tool-crop", "rotate", "flip", "remove-background", "trim-transparent", "grayscale", "to-avif", "to-gif", "merge-pdf",- "compress-image", "remove-metadata", "zip-all"],+ // Full (ToolbarProfile.MaxSlices): "Extract Live Photo video" stays in the library, on no donut, and "GIF"+ // since "Merge images" took its slot (settings schema 53): a still picture as GIF is the least wanted here.+ BackPresetIds = ["tool-crop", "rotate", "flip", "remove-background", "trim-transparent", "grayscale", "to-avif", "merge-images",+ "merge-pdf", "compress-image", "remove-metadata", "zip-all"],},new(){diff --cc src/Filee.Core/Settings/UserDataStore.csindex f9f0a884,e47cd2ca..a522385d--- a/src/Filee.Core/Settings/UserDataStore.cs+++ b/src/Filee.Core/Settings/UserDataStore.cs@@@ -906,13 -906,21 +906,27 @@@ internal static class SettingsMigration// v50: Dahua DVR recordings (.dav) learn the video donut; custom claims stay put.if (from < 50)changed |= LearnExtensions(profiles, out _, ["dav"]);- // v53: "Merge images" (#645; 51 and 52 are kept for changes that came first, so this may be renumbered), after- // "Merge audio" as in a new library, and on the back of the images donut before "Merge PDF" when the user- // hasn't put it on either face: in a free slot, or in place of "GIF" (which stays in the library) on a- // full face. Present already but saved since by a Filee before 53: that one dropped the option and left a+ // v51: "Edit pictures" (size, format, turn and colour chosen each time, #584), after "Crop" as in a new library,+ // and on the front of the images donut after "Half size" when that is there, the user hasn't put the tool+ // elsewhere on the donut and the face has room.+ // Present already but saved since by a Filee before 45 (2.0): that one dropped the tool's name, which made it+ // a crop, so it is put back. 2.1 keeps the name (the slice is greyed out there, as a tool it doesn't know).+ if (from < 51)+ changed |= AddImageEditTool(presets, profiles);+ // v52: "Pixelate / blur", after "Edit pictures" (else "Crop") as in a new library, and on the images donut after+ // "Half size" (after "Edit pictures" when that follows it) when the front has room, else at the end of the+ // back face when that has room. A front without "Half size" was laid out by the user and is left alone (the+ // tool is in the library); one who put the tool somewhere on the donut keeps it there.+ // Present already but saved since by a Filee before 45 (2.0): that one dropped the tool's name, which made it+ // a crop, so it is put back. 2.1 keeps the name (the slice is greyed out there, as a tool it doesn't know).+ if (from < 52)+ changed |= AddHideTool(presets, profiles);++ // v53: "Merge images" (#645), after "Merge audio" as in a new library, and on the back of the images donut before++ // "Merge PDF" when the user hasn't put it on either face: in a free slot, or in place of "GIF" (which stays in++ // the library) on a full face. Present already but saved since by a Filee before 53: that one dropped the option and left a+ // plain "same format" preset, so it is put back.+ if (from < 53)+ changed |= AddMergeImages(presets, profiles);return changed;}diff --cc tests/Filee.Core.Tests/HideToolTests.csindex 00000000,a545559b..f8384ba4mode 000000,100644..100644--- a/tests/Filee.Core.Tests/HideToolTests.cs+++ b/tests/Filee.Core.Tests/HideToolTests.cs@@@ -1,0 -1,409 +1,408 @@@+ // "Pixelate / blur": where a part lies in pixels, how large the squares or the blur are and which square a pixel is in,+ // the conversion the tool becomes, how it is saved (and read by an older Filee), the job queue covering the parts once+ // and never handing the picture over uncovered, and the tool arriving in libraries from before it (settings schema 52).++ using System.Text.Json;+ using Filee.Core.Conversion;+ using Filee.Core.History;+ using Filee.Core.Presets;+ using Filee.Core.Profiles;+ using Filee.Core.Settings;++ namespace Filee.Core.Tests;++ public class HideToolTests+ {+ private static Preset Tool() => BuiltInData.CreatePresets().Single(p => p.Id == "tool-hide");++ private static HiddenArea Area(double x, double y, double w, double h) => new() { X = x, Y = y, Width = w, Height = h };++ // ───────────────────────── The arithmetic ─────────────────────────++ [Theory]+ [InlineData(1, 1920, 1080, 21.6)] // a desktop screenshot: 2 % of 1080, a little over a line of text+ [InlineData(5, 1920, 1080, 43.2)] // the default: 4 %+ [InlineData(10, 1920, 1080, 70.2)] // 6.5 %+ [InlineData(5, 1080, 2400, 43.2)] // a phone screenshot: its shorter side counts, as tall as a line of its text+ [InlineData(5, 6000, 4000, 160)] // a photo+ [InlineData(1, 120, 80, 8)] // never under 8 px+ [InlineData(0, 1920, 1080, 21.6)] // a hand-edited strength: within 1 … 10+ [InlineData(99, 1920, 1080, 70.2)]+ public void Squares_and_blur_grow_with_the_strength_and_the_pictures_shorter_side(int strength, int width, int height, double expected) =>+ Assert.Equal(expected, HideTool.EffectSize(strength, width, height), 6);++ [Fact]+ public void Even_the_weakest_strength_covers_a_desktop_screenshots_line_of_text()+ {+ // Text on a 1080p screen is about 13 px tall: a square at least that tall leaves no letter to compare.+ Assert.True(HideTool.EffectSize(HideTool.MinStrength, 1920, 1080) >= 13);+ Assert.True(HideTool.EffectSize(HideTool.MinStrength, 3840, 2160) >= 26); // the same screen at 200 %+ }++ [Fact]+ public void A_part_in_pixels_takes_every_pixel_it_touches()+ {+ // 0.1 × 1000 = 100 exactly; 0.1234 × 1000 = 123.4 → from 123; to 0.3234 × 1000 = 323.4 → up to 324.+ Assert.Equal((100, 50, 200, 100), HideTool.PixelBounds(Area(0.1, 0.1, 0.2, 0.2), 1000, 500));+ Assert.Equal((123, 61, 201, 101), HideTool.PixelBounds(Area(0.1234, 0.1234, 0.2, 0.2), 1000, 500));+ // At least one pixel, even for a sliver.+ Assert.Equal((500, 250, 1, 1), HideTool.PixelBounds(Area(0.5, 0.5, 0.0001, 0.0001), 1000, 500));+ }++ [Fact]+ public void A_part_is_kept_inside_the_picture_and_nothing_is_made_of_one_outside_it()+ {+ Assert.Equal((900, 0, 100, 100), HideTool.PixelBounds(Area(0.9, -0.5, 0.5, 0.7), 1000, 500));+ // Drawn from right to left (a negative width): the same part.+ Assert.Equal((100, 50, 200, 100), HideTool.PixelBounds(Area(0.3, 0.3, -0.2, -0.2), 1000, 500));+ Assert.Null(HideTool.PixelBounds(Area(1.2, 0.2, 0.3, 0.3), 1000, 500));+ Assert.Null(HideTool.PixelBounds(Area(0.2, 0.2, 0, 0.3), 1000, 500));+ Assert.Null(HideTool.PixelBounds(Area(double.NaN, 0.2, 0.1, 0.1), 1000, 500));+ Assert.Null(HideTool.PixelBounds(Area(0.2, 0.2, 0.1, 0.1), 0, 500));+ }++ [Theory]+ [InlineData(10)]+ [InlineData(2.5)]+ [InlineData(7.3)]+ [InlineData(43.2)]+ public void Every_pixel_falls_in_exactly_one_square_starting_where_the_square_starts(double cell)+ {+ Assert.Equal(0, HideTool.CellStart(0, cell));+ for (var pixel = 0; pixel < 500; pixel++)+ {+ var square = HideTool.CellOf(pixel, cell);+ Assert.InRange(pixel, HideTool.CellStart(square, cell), HideTool.CellStart(square + 1, cell) - 1);+ }+ // Whole-pixel squares start on their multiples.+ Assert.Equal((0, 10, 20), (HideTool.CellStart(0, 10), HideTool.CellStart(1, 10), HideTool.CellStart(2, 10)));+ Assert.Equal((0, 2, 5), (HideTool.CellStart(0, 2.5), HideTool.CellStart(1, 2.5), HideTool.CellStart(2, 2.5)));+ }++ // ───────────────────────── The tool and its conversion ─────────────────────────++ [Fact]+ public void The_built_in_tool_pixelates_at_the_default_strength_and_names_its_pictures_name_hidden()+ {+ var tool = Tool();+ Assert.True(tool.IsTool);+ Assert.True(tool.IsHideTool);+ Assert.False(tool.IsCropTool || tool.IsClipTool);+ Assert.Equal(("preset.hide", BuiltInData.SameAsSource, "{name}_hidden"), (tool.NameKey, tool.TargetFormat, tool.Output.FileNamePattern));+ Assert.Equal((HideStyle.Pixelate, HideTool.DefaultStrength), (tool.Image.HideStyle, tool.Image.HideStrength));+ Assert.Null(tool.Image.HiddenAreas);+ Assert.False(tool.Image.HidesAreas);+ Assert.False(new Preset { Kind = PresetKind.Tool, Tool = "crop" }.IsHideTool);+ Assert.False(new Preset { Tool = Preset.HideTool }.IsHideTool); // a conversion, not a tool+ }++ [Fact]+ public void The_tool_becomes_a_conversion_with_its_parts_and_never_keeps_the_original_for_being_smaller()+ {+ var tool = Tool();+ tool.Name = "Redact";+ tool.Image.HideStyle = HideStyle.Blur;+ tool.Image.HideStrength = 42; // a hand-edited file+ tool.Output.OnlyIfSmaller = true;++ var conversion = HideTool.ConversionOf(tool, "png", [Area(0.1, 0.1, 0.2, 0.2), Area(0.5, 0.5, -0.1, 0.2), Area(2, 2, 1, 1)]);++ Assert.Equal(PresetKind.Convert, conversion.Kind);+ Assert.Null(conversion.Tool);+ Assert.Equal("png", conversion.TargetFormat);+ Assert.Equal(("tool-hide", "Redact"), (conversion.Id, conversion.Name));+ Assert.Equal(HideStyle.Blur, conversion.Image.HideStyle);+ Assert.Equal(HideTool.MaxStrength, conversion.Image.HideStrength);+ // The part drawn backwards is turned around; the one off the picture is left out.+ Assert.Equal(2, conversion.Image.HiddenAreas!.Count);+ var turned = conversion.Image.HiddenAreas[1];+ Assert.Equal((0.4, 0.5, 0.1, 0.2), (Math.Round(turned.X, 9), Math.Round(turned.Y, 9), Math.Round(turned.Width, 9), Math.Round(turned.Height, 9)));+ Assert.True(conversion.Image.HidesAreas);+ Assert.True(conversion.Image.ReworksPixels);+ Assert.False(conversion.Output.OnlyIfSmaller);+ // The tool itself is untouched, and a copy of the conversion has its own parts.+ Assert.True(tool.IsHideTool);+ Assert.Null(tool.Image.HiddenAreas);+ Assert.True(tool.Output.OnlyIfSmaller);+ var copy = conversion.Clone();+ copy.Image.HiddenAreas![0].X = 0.9;+ Assert.Equal(0.1, conversion.Image.HiddenAreas[0].X);+ }++ [Fact]+ public void The_choice_is_remembered_in_the_tool()+ {+ var tool = Tool();+ HideTool.Remember(tool, HideStyle.Blur, 8);+ Assert.Equal((HideStyle.Blur, 8), (tool.Image.HideStyle, tool.Image.HideStrength));+ HideTool.Remember(tool, HideStyle.Pixelate, -3);+ Assert.Equal((HideStyle.Pixelate, HideTool.MinStrength), (tool.Image.HideStyle, tool.Image.HideStrength));+ }++ [Fact]+ public void A_picture_keeps_its_format_where_it_can_be_written_else_becomes_png()+ {+ var magick = new FakeConverter("magick", new ConversionEdge("jpg", "jpg"), new ConversionEdge("raw", "png"), new ConversionEdge("png", "png"));+ var planner = new ConverterCatalog([magick]).CreatePlanner();++ Assert.Equal(BuiltInData.SameAsSource, HideTool.TargetFor("jpg", planner));+ Assert.Equal(HideTool.FallbackTarget, HideTool.TargetFor("raw", planner)); // a camera RAW is read only+ Assert.Equal(HideTool.FallbackTarget, HideTool.TargetFor("webp", planner)); // no engine here+ Assert.True(HideTool.CanHide("jpg"));+ Assert.False(HideTool.CanHide("pdf"));+ Assert.False(HideTool.CanHide("mp4"));+ }++ // ───────────────────────── Saved, and read by an older Filee ─────────────────────────++ [Fact]+ public void The_choice_is_saved_by_name_and_the_parts_never_reach_a_saved_tool()+ {+ var tool = Tool();+ HideTool.Remember(tool, HideStyle.Blur, 7);+ var json = JsonSerializer.Serialize(new List<Preset> { tool }, FileeJsonContext.Default.ListPreset);+ Assert.Contains("\"tool\": \"hide\"", json);+ Assert.Contains("\"hideStyle\": \"Blur\"", json);+ Assert.Contains("\"hideStrength\": 7", json);+ Assert.DoesNotContain("hiddenAreas", json);++ var read = JsonSerializer.Deserialize(json, FileeJsonContext.Default.ListPreset)!.Single();+ Assert.True(read.IsHideTool);+ Assert.Equal((HideStyle.Blur, 7), (read.Image.HideStyle, read.Image.HideStrength));++ // A conversion keeps its parts.+ var conversion = HideTool.ConversionOf(read, "jpg", [Area(0.1, 0.2, 0.3, 0.4)]);+ var again = JsonSerializer.Deserialize(JsonSerializer.Serialize(new List<Preset> { conversion }, FileeJsonContext.Default.ListPreset),+ FileeJsonContext.Default.ListPreset)!.Single();+ var kept = again.Image.HiddenAreas![0];+ Assert.Equal((0.1, 0.2, 0.3, 0.4), (Math.Round(kept.X, 9), Math.Round(kept.Y, 9), Math.Round(kept.Width, 9), Math.Round(kept.Height, 9)));+ }++ [Fact]+ public void A_style_from_a_newer_Filee_reads_as_pixelate_instead_of_failing_the_whole_file()+ {+ var json = JsonSerializer.Serialize(new List<Preset> { Tool() }, FileeJsonContext.Default.ListPreset)+ .Replace("\"hideStyle\": \"Pixelate\"", "\"hideStyle\": \"Smudge\"", StringComparison.Ordinal);+ Assert.Contains("Smudge", json);+ var read = JsonSerializer.Deserialize(json, FileeJsonContext.Default.ListPreset)!.Single();+ Assert.Equal(HideStyle.Pixelate, read.Image.HideStyle);+ }++ [Fact]+ public void Every_new_option_is_a_field_of_its_own_so_an_older_Filee_reads_the_presets_as_before()+ {+ // 2.1.0 crashes on a value its enums don't know: the tool only adds new fields (which it skips) and a tool name+ // (which it greys out), and leaves every value it knows as it was.+ var tool = Tool();+ HideTool.Remember(tool, HideStyle.Blur, 9);+ using var document = JsonDocument.Parse(JsonSerializer.Serialize(new List<Preset> { tool }, FileeJsonContext.Default.ListPreset));+ var saved = document.RootElement[0];+ Assert.Equal("Tool", saved.GetProperty("kind").GetString());+ var image = saved.GetProperty("image");+ Assert.Equal("None", image.GetProperty("resize").GetString());+ Assert.Equal("None", image.GetProperty("rotation").GetString());+ Assert.Equal("None", image.GetProperty("flip").GetString());+ Assert.Equal("Lzw", image.GetProperty("tiffCompression").GetString());+ }++ [Fact]+ public void A_failed_conversion_with_hidden_parts_offers_no_retry_an_older_Filee_would_run_without_them()+ {+ var conversion = HideTool.ConversionOf(Tool(), BuiltInData.SameAsSource, [Area(0.1, 0.1, 0.2, 0.2)]);+ var job = new ConversionJob(["shot.png"], conversion, "Pixelate / blur");+ job.Files[0].State = FileState.Failed;+ Assert.Null(HistoryEntry.From(job).Preset);++ var plain = new ConversionJob(["shot.png"], new Preset { TargetFormat = "jpg" }, "JPG");+ plain.Files[0].State = FileState.Failed;+ Assert.NotNull(HistoryEntry.From(plain).Preset);+ }++ // ───────────────────────── The job queue ─────────────────────────++ [Fact]+ public async Task The_parts_are_covered_once_by_the_first_engine_that_applies_image_options()+ {+ // EPS → PNG (Ghostscript) → JPG (ImageMagick): covered in the first step, the second gets the picture covered.+ using var dir = new TempDir();+ var art = dir.File("art.eps");+ var reader = new AreaRecorder("ghostscript", transforms: true, new ConversionEdge("eps", "png"));+ var writer = new AreaRecorder("magick", transforms: true, new ConversionEdge("png", "jpg"));+ await using var queue = new JobQueue(new ConverterCatalog([reader, writer]));++ var job = new ConversionJob([art], HideTool.ConversionOf(Tool(), "jpg", [Area(0.1, 0.1, 0.2, 0.2)]), "Test");+ await queue.RunAsync(job);++ Assert.True(job.State == JobState.Completed, string.Join("; ", job.Files.Select(f => $"{f.ErrorKey} {f.ErrorDetail}")));+ Assert.Equal([1], reader.Areas);+ Assert.Equal([0], writer.Areas);+ }++ [Fact]+ public async Task A_route_without_an_engine_that_covers_them_fails_instead_of_writing_the_picture_as_it_is()+ {+ using var dir = new TempDir();+ var picture = dir.File("scan.png");+ var copier = new AreaRecorder("copier", transforms: false, new ConversionEdge("png", "png"));+ await using var queue = new JobQueue(new ConverterCatalog([copier]));++ var job = new ConversionJob([picture], HideTool.ConversionOf(Tool(), BuiltInData.SameAsSource, [Area(0.1, 0.1, 0.2, 0.2)]), "Test");+ await queue.RunAsync(job);++ var file = Assert.Single(job.Files);+ Assert.Equal(FileState.Failed, file.State);+ Assert.Equal("error.cannot_hide", file.ErrorKey);+ Assert.Empty(copier.Areas);+ Assert.Empty(job.Outputs);+ }++ [Fact]+ public async Task Only_if_smaller_never_puts_the_original_back_over_a_covered_picture()+ {+ using var dir = new TempDir();+ var picture = dir.File("shot.png"); // 1 byte: any result is larger+ var magick = new AreaRecorder("magick", transforms: true, new ConversionEdge("png", "png"));+ await using var queue = new JobQueue(new ConverterCatalog([magick]));+ var conversion = HideTool.ConversionOf(Tool(), BuiltInData.SameAsSource, [Area(0.1, 0.1, 0.2, 0.2)]);+ conversion.Output.OnlyIfSmaller = true; // set again after the tool turned it off++ var job = new ConversionJob([picture], conversion, "Test");+ await queue.RunAsync(job);++ var output = Assert.Single(job.Outputs);+ Assert.NotEqual("x", File.ReadAllText(output));+ }++ // ───────────────────────── Settings schema 52 ─────────────────────────++ [Fact]+ public void A_new_library_has_the_tool_after_edit_pictures_in_the_library_and_on_the_images_donut()+ {+ var presets = BuiltInData.CreatePresets();+ Assert.Equal("tool-image-edit", presets[presets.FindIndex(p => p.Id == "tool-hide") - 1].Id);+ var images = BuiltInData.CreateProfiles().Single(p => p.Id == "images");+ Assert.Equal(["half-size", "tool-image-edit", "tool-hide"], images.PresetIds.Skip(images.PresetIds.IndexOf("half-size")));+ Assert.DoesNotContain("tool-hide", images.BackPresetIds!);+ Assert.InRange(images.PresetIds.Count, 1, ToolbarProfile.MaxSlices);+ }++ private static (List<Preset> Presets, List<ToolbarProfile> Profiles, ToolbarProfile Images) Version51()+ {+ var presets = BuiltInData.CreatePresets();+ presets.RemoveAll(p => p.Id == "tool-hide");+ var profiles = BuiltInData.CreateProfiles();+ var images = profiles.Single(p => p.Id == "images");+ images.PresetIds.Remove("tool-hide");+ return (presets, profiles, images);+ }++ [Fact]+ public void Version_51_libraries_get_the_tool_after_edit_pictures_once()+ {+ var (presets, profiles, images) = Version51();++ Assert.True(SettingsMigrations.ApplyToLibrary(51, presets, profiles));++ Assert.Equal(BuiltInData.CreatePresets().Select(p => p.Id), presets.Select(p => p.Id));+ Assert.True(presets.Single(p => p.Id == "tool-hide").IsHideTool);+ Assert.Equal(BuiltInData.CreateProfiles().Single(p => p.Id == "images").PresetIds, images.PresetIds);+ Assert.False(SettingsMigrations.ApplyToLibrary(52, presets, profiles)); // once only- Assert.Equal(52, AppSettings.CurrentSchemaVersion);+ }++ [Fact]+ public void After_edit_pictures_when_that_follows_half_size_else_after_half_size()+ {+ var (presets, profiles, images) = Version51();+ SettingsMigrations.ApplyToLibrary(51, presets, profiles);+ Assert.Equal(["half-size", "tool-image-edit", "tool-hide"], images.PresetIds.Skip(images.PresetIds.IndexOf("half-size")).Take(3));++ // "Edit pictures" moved to the back face by the user: right after "Half size".+ (presets, profiles, images) = Version51();+ images.PresetIds.Remove("tool-image-edit");+ images.BackPresetIds!.Remove("grayscale");+ images.BackPresetIds.Insert(0, "tool-image-edit");+ SettingsMigrations.ApplyToLibrary(51, presets, profiles);+ Assert.Equal(["half-size", "tool-hide"], images.PresetIds.Skip(images.PresetIds.IndexOf("half-size")).Take(2));+ }++ [Fact]+ public void A_full_front_puts_it_on_the_back_and_a_full_donut_or_the_users_own_place_is_left_alone()+ {+ // Front full: at the end of the back face (before "Compress into one archive") when that has room.+ var (presets, profiles, images) = Version51();+ while (images.PresetIds.Count < ToolbarProfile.MaxSlices)+ images.PresetIds.Add("to-gif");+ images.BackPresetIds!.Remove("grayscale");+ SettingsMigrations.ApplyToLibrary(51, presets, profiles);+ Assert.DoesNotContain("tool-hide", images.PresetIds);+ Assert.Equal("tool-hide", images.BackPresetIds[images.BackPresetIds.IndexOf("zip-all") - 1]);++ // Both full: in the library only.+ (presets, profiles, images) = Version51();+ while (images.PresetIds.Count < ToolbarProfile.MaxSlices)+ images.PresetIds.Add("to-gif");+ var front = images.PresetIds.ToList();+ var back = images.BackPresetIds!.ToList();+ Assert.True(SettingsMigrations.ApplyToLibrary(51, presets, profiles));+ Assert.Equal(front, images.PresetIds);+ Assert.Equal(back, images.BackPresetIds);+ Assert.Contains(presets, p => p.Id == "tool-hide");++ // Already on the donut where the user put it (a build of this branch): stays there.+ (presets, profiles, images) = Version51();+ images.BackPresetIds!.Remove("grayscale");+ images.BackPresetIds.Insert(0, "tool-hide");+ presets.Insert(0, Tool());+ SettingsMigrations.ApplyToLibrary(51, presets, profiles);+ Assert.DoesNotContain("tool-hide", images.PresetIds);+ Assert.Equal("tool-hide", images.BackPresetIds[0]);+ }++ [Fact]+ public void Back_from_a_Filee_before_2_1_the_tool_hides_parts_again_and_keeps_the_users_changes()+ {+ // A Filee before 45 (2.0) drops the tool's name: the tool reads as a crop there and is saved so.+ var presets = BuiltInData.CreatePresets();+ var hide = presets.Single(p => p.Id == "tool-hide");+ hide.Tool = null;+ hide.Name = "Redact";+ hide.Output.FileNamePattern = "{name}_safe";+ Assert.True(hide.IsCropTool);++ Assert.True(SettingsMigrations.ApplyToLibrary(51, presets, BuiltInData.CreateProfiles()));++ Assert.True(hide.IsHideTool);+ Assert.Equal(("Redact", "{name}_safe"), (hide.Name, hide.Output.FileNamePattern));+ Assert.Single(presets, p => p.Id == "tool-hide");++ // One that read it as a group.+ hide.Kind = PresetKind.Group;+ hide.TargetFormat = Preset.GroupTarget;+ Assert.True(SettingsMigrations.ApplyToLibrary(51, presets, BuiltInData.CreateProfiles()));+ Assert.True(hide.IsHideTool);+ Assert.Equal(BuiltInData.SameAsSource, hide.TargetFormat);+ }++ /// <summary>An engine that records how many hidden parts each step was given; it may say it applies image options.</summary>+ private sealed class AreaRecorder(string id, bool transforms, params ConversionEdge[] edges) : IConverter, IImageTransformer+ {+ 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<int> Areas { get; } = [];++ public bool Transforms(string from, string to) => transforms;++ public EngineStatus GetStatus() => EngineStatus.Available();++ public Task<IReadOnlyList<string>> ConvertAsync(ConversionStep step, IProgress<double>? progress, CancellationToken cancellationToken)+ {+ lock (Areas)+ Areas.Add(step.Preset.Image.HiddenAreas?.Count ?? 0);+ return _writer.ConvertAsync(step, progress, cancellationToken);+ }+ }+ }