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.

feat(hide): black box per area in Pixelate / blur

lightscape-jmc842d5a07ed4
diff --git a/src/Filee.App/Assets/i18n/ar.json b/src/Filee.App/Assets/i18n/ar.json
index 1e05f9b0..068459d8 100644
--- a/src/Filee.App/Assets/i18n/ar.json
+++ b/src/Filee.App/Assets/i18n/ar.json
@@ -277,6 +277,8 @@
"hide.pixelate_hint": "التغطية بمربعات بمتوسط الألوان (P)",
"hide.blur": "تمويه",
"hide.blur_hint": "التغطية بتمويه قوي (B)",
+ "hide.box": "مربع أسود",
+ "hide.box_hint": "تغطية بمربع أسود معتم (X)",
"hide.strength": "الشدة",
"hide.strength_value": "الشدة {0} من 10 (− / +)",
"hide.remove": "إزالة الإطار",
diff --git a/src/Filee.App/Assets/i18n/de.json b/src/Filee.App/Assets/i18n/de.json
index 09f5fa47..76b2510e 100644
--- a/src/Filee.App/Assets/i18n/de.json
+++ b/src/Filee.App/Assets/i18n/de.json
@@ -277,6 +277,8 @@
"hide.pixelate_hint": "Mit Quadraten in der Durchschnittsfarbe abdecken (P)",
"hide.blur": "Weichzeichnen",
"hide.blur_hint": "Mit starker Unschärfe abdecken (B)",
+ "hide.box": "Schwarzer Balken",
+ "hide.box_hint": "Mit einem schwarzen Balken abdecken (X)",
"hide.strength": "Stärke",
"hide.strength_value": "Stärke {0} von 10 (− / +)",
"hide.remove": "Rahmen entfernen",
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index 6cf11509..ed024c31 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -286,6 +286,8 @@
"hide.pixelate_hint": "Cover with squares of the average colour (P)",
"hide.blur": "Blur",
"hide.blur_hint": "Cover with a strong blur (B)",
+ "hide.box": "Black box",
+ "hide.box_hint": "Cover with a solid black box (X)",
"hide.strength": "Strength",
"hide.strength_value": "Strength {0} of 10 (− / +)",
"hide.remove": "Remove frame",
diff --git a/src/Filee.App/Assets/i18n/es.json b/src/Filee.App/Assets/i18n/es.json
index 8252484b..21184cf9 100644
--- a/src/Filee.App/Assets/i18n/es.json
+++ b/src/Filee.App/Assets/i18n/es.json
@@ -277,6 +277,8 @@
"hide.pixelate_hint": "Cubrir con cuadros del color medio (P)",
"hide.blur": "Difuminar",
"hide.blur_hint": "Cubrir con un desenfoque fuerte (B)",
+ "hide.box": "Bloque negro",
+ "hide.box_hint": "Cubrir con un bloque negro opaco (X)",
"hide.strength": "Intensidad",
"hide.strength_value": "Intensidad {0} de 10 (− / +)",
"hide.remove": "Quitar marco",
diff --git a/src/Filee.App/Assets/i18n/fr.json b/src/Filee.App/Assets/i18n/fr.json
index 83e7c574..f99ef663 100644
--- a/src/Filee.App/Assets/i18n/fr.json
+++ b/src/Filee.App/Assets/i18n/fr.json
@@ -286,6 +286,8 @@
"hide.pixelate_hint": "Couvrir de carrés de la couleur moyenne (P)",
"hide.blur": "Flouter",
"hide.blur_hint": "Couvrir d'un flou intense (B)",
+ "hide.box": "Bloc noir",
+ "hide.box_hint": "Couvrir d'un bloc noir opaque (X)",
"hide.strength": "Intensité",
"hide.strength_value": "Intensité {0} sur 10 (− / +)",
"hide.remove": "Supprimer le cadre",
diff --git a/src/Filee.App/Assets/i18n/hi.json b/src/Filee.App/Assets/i18n/hi.json
index 584c33fa..ad105fad 100644
--- a/src/Filee.App/Assets/i18n/hi.json
+++ b/src/Filee.App/Assets/i18n/hi.json
@@ -277,6 +277,8 @@
"hide.pixelate_hint": "औसत रंग के वर्गों से ढकें (P)",
"hide.blur": "धुंधला",
"hide.blur_hint": "गहरे धुंधलेपन से ढकें (B)",
+ "hide.box": "काला बॉक्स",
+ "hide.box_hint": "ठोस काले बॉक्स से ढकें (X)",
"hide.strength": "तीव्रता",
"hide.strength_value": "तीव्रता {0} / 10 (− / +)",
"hide.remove": "फ़्रेम हटाएँ",
diff --git a/src/Filee.App/Assets/i18n/id.json b/src/Filee.App/Assets/i18n/id.json
index 9d32cc1e..7cf59099 100644
--- a/src/Filee.App/Assets/i18n/id.json
+++ b/src/Filee.App/Assets/i18n/id.json
@@ -277,6 +277,8 @@
"hide.pixelate_hint": "Tutupi dengan kotak-kotak warna rata-rata (P)",
"hide.blur": "Buramkan",
"hide.blur_hint": "Tutupi dengan keburaman kuat (B)",
+ "hide.box": "Kotak hitam",
+ "hide.box_hint": "Tutupi dengan kotak hitam pekat (X)",
"hide.strength": "Kekuatan",
"hide.strength_value": "Kekuatan {0} dari 10 (− / +)",
"hide.remove": "Hapus bingkai",
diff --git a/src/Filee.App/Assets/i18n/it.json b/src/Filee.App/Assets/i18n/it.json
index 0000b0ad..ff5916c3 100644
--- a/src/Filee.App/Assets/i18n/it.json
+++ b/src/Filee.App/Assets/i18n/it.json
@@ -277,6 +277,8 @@
"hide.pixelate_hint": "Copri con quadratini del colore medio (P)",
"hide.blur": "Sfoca",
"hide.blur_hint": "Copri con una forte sfocatura (B)",
+"hide.box": "Riquadro nero",
+"hide.box_hint": "Copri con un riquadro nero pieno (X)",
"hide.strength": "Intensità",
"hide.strength_value": "Intensità {0} di 10 (− / +)",
"hide.remove": "Rimuovi riquadro",
diff --git a/src/Filee.App/Assets/i18n/ja.json b/src/Filee.App/Assets/i18n/ja.json
index 9efb19e0..79366e77 100644
--- a/src/Filee.App/Assets/i18n/ja.json
+++ b/src/Filee.App/Assets/i18n/ja.json
@@ -277,6 +277,8 @@
"hide.pixelate_hint": "平均色のブロックで隠す (P)",
"hide.blur": "ぼかし",
"hide.blur_hint": "強いぼかしで隠す (B)",
+ "hide.box": "黒塗り",
+ "hide.box_hint": "黒い四角で完全に隠す (X)",
"hide.strength": "強さ",
"hide.strength_value": "強さ {0} / 10(− / +)",
"hide.remove": "枠を削除",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index b4718d90..edb320ef 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -286,6 +286,8 @@
"hide.pixelate_hint": "평균 색 네모로 가리기 (P)",
"hide.blur": "흐림",
"hide.blur_hint": "강하게 흐려서 가리기 (B)",
+ "hide.box": "검은 상자",
+ "hide.box_hint": "검은 상자로 완전히 가리기 (X)",
"hide.strength": "세기",
"hide.strength_value": "세기 {0} / 10 (− / +)",
"hide.remove": "틀 지우기",
diff --git a/src/Filee.App/Assets/i18n/ne.json b/src/Filee.App/Assets/i18n/ne.json
index 8ba9fa48..65fcaa11 100644
--- a/src/Filee.App/Assets/i18n/ne.json
+++ b/src/Filee.App/Assets/i18n/ne.json
@@ -277,6 +277,8 @@
"hide.pixelate_hint": "औसत रङका वर्गहरूले ढाक्नुहोस् (P)",
"hide.blur": "धमिलो",
"hide.blur_hint": "गाढा धमिलोपनले ढाक्नुहोस् (B)",
+ "hide.box": "कालो बाकस",
+ "hide.box_hint": "ठोस कालो बाकसले छोप्नुहोस् (X)",
"hide.strength": "तीव्रता",
"hide.strength_value": "तीव्रता {0} / 10 (− / +)",
"hide.remove": "फ्रेम हटाउनुहोस्",
diff --git a/src/Filee.App/Assets/i18n/pl.json b/src/Filee.App/Assets/i18n/pl.json
index 6690c78e..9e5ac7a3 100644
--- a/src/Filee.App/Assets/i18n/pl.json
+++ b/src/Filee.App/Assets/i18n/pl.json
@@ -286,6 +286,8 @@
"hide.pixelate_hint": "Zakryj kwadratami w średnim kolorze (P)",
"hide.blur": "Rozmycie",
"hide.blur_hint": "Zakryj mocnym rozmyciem (B)",
+ "hide.box": "Czarny prostokąt",
+ "hide.box_hint": "Zakryj czarnym prostokątem (X)",
"hide.strength": "Siła",
"hide.strength_value": "Siła {0} z 10 (− / +)",
"hide.remove": "Usuń ramkę",
diff --git a/src/Filee.App/Assets/i18n/pt-BR.json b/src/Filee.App/Assets/i18n/pt-BR.json
index 41ec4e0c..92a5658b 100644
--- a/src/Filee.App/Assets/i18n/pt-BR.json
+++ b/src/Filee.App/Assets/i18n/pt-BR.json
@@ -287,6 +287,8 @@
"hide.pixelate_hint": "Cobrir com quadrados da cor média (P)",
"hide.blur": "Desfocar",
"hide.blur_hint": "Cobrir com um desfoque forte (B)",
+ "hide.box": "Tarja preta",
+ "hide.box_hint": "Cobrir com uma tarja preta opaca (X)",
"hide.strength": "Intensidade",
"hide.strength_value": "Intensidade {0} de 10 (− / +)",
"hide.remove": "Remover moldura",
diff --git a/src/Filee.App/Assets/i18n/pt-PT.json b/src/Filee.App/Assets/i18n/pt-PT.json
index dc7da8b8..25fa4a6a 100644
--- a/src/Filee.App/Assets/i18n/pt-PT.json
+++ b/src/Filee.App/Assets/i18n/pt-PT.json
@@ -286,6 +286,8 @@
"hide.pixelate_hint": "Cobrir com quadrados da cor média (P)",
"hide.blur": "Desfocar",
"hide.blur_hint": "Cobrir com uma desfocagem forte (B)",
+ "hide.box": "Tarja preta",
+ "hide.box_hint": "Cobrir com uma tarja preta opaca (X)",
"hide.strength": "Intensidade",
"hide.strength_value": "Intensidade {0} de 10 (− / +)",
"hide.remove": "Remover moldura",
diff --git a/src/Filee.App/Assets/i18n/ru.json b/src/Filee.App/Assets/i18n/ru.json
index 12f0f347..68f92caa 100644
--- a/src/Filee.App/Assets/i18n/ru.json
+++ b/src/Filee.App/Assets/i18n/ru.json
@@ -286,6 +286,8 @@
"hide.pixelate_hint": "Закрыть квадратами среднего цвета (P)",
"hide.blur": "Размытие",
"hide.blur_hint": "Закрыть сильным размытием (B)",
+ "hide.box": "Чёрный блок",
+ "hide.box_hint": "Закрыть сплошным чёрным блоком (X)",
"hide.strength": "Сила",
"hide.strength_value": "Сила {0} из 10 (− / +)",
"hide.remove": "Удалить рамку",
diff --git a/src/Filee.App/Assets/i18n/th.json b/src/Filee.App/Assets/i18n/th.json
index 012a66d7..0b786fb9 100644
--- a/src/Filee.App/Assets/i18n/th.json
+++ b/src/Filee.App/Assets/i18n/th.json
@@ -277,6 +277,8 @@
"hide.pixelate_hint": "ปิดด้วยช่องสี่เหลี่ยมสีเฉลี่ย (P)",
"hide.blur": "เบลอ",
"hide.blur_hint": "ปิดด้วยการเบลออย่างแรง (B)",
+ "hide.box": "กล่องดำ",
+ "hide.box_hint": "ปิดด้วยกล่องสีดำทึบ (X)",
"hide.strength": "ความแรง",
"hide.strength_value": "ความแรง {0} / 10 (− / +)",
"hide.remove": "ลบกรอบ",
diff --git a/src/Filee.App/Assets/i18n/tr.json b/src/Filee.App/Assets/i18n/tr.json
index b72f1b0d..3851e059 100644
--- a/src/Filee.App/Assets/i18n/tr.json
+++ b/src/Filee.App/Assets/i18n/tr.json
@@ -277,6 +277,8 @@
"hide.pixelate_hint": "Ortalama renkteki karelerle kapat (P)",
"hide.blur": "Bulanıklaştır",
"hide.blur_hint": "Güçlü bir bulanıklıkla kapat (B)",
+ "hide.box": "Siyah kutu",
+ "hide.box_hint": "Düz siyah bir kutuyla kapat (X)",
"hide.strength": "Güç",
"hide.strength_value": "Güç {0} / 10 (− / +)",
"hide.remove": "Çerçeveyi sil",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index e2bfb41c..85a345a3 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -286,6 +286,8 @@
"hide.pixelate_hint": "用平均色方块遮盖 (P)",
"hide.blur": "模糊",
"hide.blur_hint": "用强模糊遮盖 (B)",
+ "hide.box": "黑框",
+ "hide.box_hint": "用纯黑方块完全遮住 (X)",
"hide.strength": "强度",
"hide.strength_value": "强度 {0} / 10(− / +)",
"hide.remove": "删除选框",
diff --git a/src/Filee.App/Assets/i18n/zh-TW.json b/src/Filee.App/Assets/i18n/zh-TW.json
index bcccbe0a..cabf6ec2 100644
--- a/src/Filee.App/Assets/i18n/zh-TW.json
+++ b/src/Filee.App/Assets/i18n/zh-TW.json
@@ -286,6 +286,8 @@
"hide.pixelate_hint": "以平均色方塊遮蓋 (P)",
"hide.blur": "模糊",
"hide.blur_hint": "以強烈模糊遮蓋 (B)",
+ "hide.box": "黑框",
+ "hide.box_hint": "用純黑方塊完全遮住 (X)",
"hide.strength": "強度",
"hide.strength_value": "強度 {0} / 10(− / +)",
"hide.remove": "刪除選框",
diff --git a/src/Filee.App/Controls/HideAreaSet.cs b/src/Filee.App/Controls/HideAreaSet.cs
index eea6b497..4733c74b 100644
--- a/src/Filee.App/Controls/HideAreaSet.cs
+++ b/src/Filee.App/Controls/HideAreaSet.cs
@@ -1,8 +1,10 @@
// The parts of a picture the "Pixelate / blur" window hides, without a window: the frames (in parts of the picture),
-// the one selected, and undo / redo of adding, moving, sizing and removing them. The canvas draws and drags them, the
+// how each is covered (pixelate, blur or black box), the one selected, and undo / redo of adding, moving, sizing,
+// restyling and removing them. The canvas draws and drags them, the
// keys move and remove them, the window's view model turns them into the conversion.
using Avalonia;
+using Filee.Core.Presets;
namespace Filee.App.Controls;
@@ -15,17 +17,24 @@ public sealed class HideAreaSet
private const int MaxUndo = 100;
private readonly List<Rect> _areas = [];
+ private readonly List<HideStyle> _styles = [];
private readonly List<Snapshot> _undo = [];
private readonly List<Snapshot> _redo = [];
/// <summary>The state when a drag began (<see cref="Begin"/>): one undo step however far it went.</summary>
private Snapshot? _gesture;
- private readonly record struct Snapshot(Rect[] Areas, int Selected);
+ private readonly record struct Snapshot(Rect[] Areas, HideStyle[] Styles, int Selected);
/// <summary>The frames, in parts of the picture (0 to 1), in the order they were drawn (the last on top).</summary>
public IReadOnlyList<Rect> Areas => _areas;
+ /// <summary>How each frame is covered, in the order of <see cref="Areas"/>.</summary>
+ public IReadOnlyList<HideStyle> Styles => _styles;
+
+ /// <summary>How a frame drawn next is covered: the style picked last.</summary>
+ public HideStyle DefaultStyle { get; set; }
+
/// <summary>The selected frame, -1 for none.</summary>
public int Selected { get; private set; } = -1;
@@ -46,18 +55,22 @@ public sealed class HideAreaSet
if (_gesture is not { } before)
return;
_gesture = null;
- if (!before.Areas.SequenceEqual(_areas))
+ if (!before.Areas.SequenceEqual(_areas) || !before.Styles.SequenceEqual(_styles))
Push(before);
Changed?.Invoke();
}
- /// <summary>Adds a frame and selects it; false when there are <see cref="MaxAreas"/> already.</summary>
- public bool Add(Rect area)
+ /// <summary>
+ /// Adds a frame, covered as <paramref name="style"/> (else <see cref="DefaultStyle"/>), and selects it; false when
+ /// there are <see cref="MaxAreas"/> already.
+ /// </summary>
+ public bool Add(Rect area, HideStyle? style = null)
{
if (_areas.Count >= MaxAreas)
return false;
Record();
_areas.Add(Fit(area));
+ _styles.Add(style ?? DefaultStyle);
Selected = _areas.Count - 1;
Changed?.Invoke();
return true;
@@ -76,6 +89,16 @@ public sealed class HideAreaSet
Changed?.Invoke();
}
+ /// <summary>Covers frame <paramref name="index"/> as <paramref name="style"/> (one undo step).</summary>
+ public void SetStyle(int index, HideStyle style)
+ {
+ if (index < 0 || index >= _styles.Count || _styles[index] == style)
+ return;
+ Record();
+ _styles[index] = style;
+ Changed?.Invoke();
+ }
+
public void Select(int index)
{
index = index >= 0 && index < _areas.Count ? index : -1;
@@ -104,6 +127,7 @@ public sealed class HideAreaSet
return false;
Record();
_areas.RemoveAt(Selected);
+ _styles.RemoveAt(Selected);
Selected = _areas.Count == 0 ? -1 : Math.Max(0, Selected - 1);
Changed?.Invoke();
return true;
@@ -116,6 +140,7 @@ public sealed class HideAreaSet
return;
Record();
_areas.Clear();
+ _styles.Clear();
Selected = -1;
Changed?.Invoke();
}
@@ -129,14 +154,19 @@ public sealed class HideAreaSet
}
/// <summary>
- /// Starts over with <paramref name="areas"/> (a new picture: the last one's frames carry on), none selected and
- /// nothing to undo.
+ /// Starts over with <paramref name="areas"/> (a new picture: the last one's frames carry on, with their styles), none
+ /// selected and nothing to undo.
/// </summary>
- public void Reset(IEnumerable<Rect> areas)
+ public void Reset(IEnumerable<(Rect Area, HideStyle Style)> areas)
{
_gesture = null;
_areas.Clear();
- _areas.AddRange(areas.Select(Fit).Take(MaxAreas));
+ _styles.Clear();
+ foreach (var (area, style) in areas.Take(MaxAreas))
+ {
+ _areas.Add(Fit(area));
+ _styles.Add(style);
+ }
_undo.Clear();
_redo.Clear();
Selected = -1;
@@ -172,6 +202,8 @@ public sealed class HideAreaSet
to.Add(Take());
_areas.Clear();
_areas.AddRange(snapshot.Areas);
+ _styles.Clear();
+ _styles.AddRange(snapshot.Styles);
Selected = Math.Min(snapshot.Selected, _areas.Count - 1);
Changed?.Invoke();
}
@@ -191,7 +223,7 @@ public sealed class HideAreaSet
_redo.Clear();
}
- private Snapshot Take() => new([.. _areas], Selected);
+ private Snapshot Take() => new([.. _areas], [.. _styles], Selected);
/// <summary>The frame inside the picture.</summary>
private static Rect Fit(Rect area)
diff --git a/src/Filee.App/Controls/HideCanvas.cs b/src/Filee.App/Controls/HideCanvas.cs
index 89a69418..064e3664 100644
--- a/src/Filee.App/Controls/HideCanvas.cs
+++ b/src/Filee.App/Controls/HideCanvas.cs
@@ -14,6 +14,7 @@ using Avalonia.Input;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Styling;
+using Filee.Core.Presets;
using static Filee.App.Controls.CropCanvas;
namespace Filee.App.Controls;
@@ -23,10 +24,14 @@ public sealed class HideCanvas : Control
public static readonly StyledProperty<Bitmap?> SourceImageProperty =
AvaloniaProperty.Register<HideCanvas, Bitmap?>(nameof(SourceImage));
- /// <summary>The whole preview pixelated or blurred as chosen: what the frames show.</summary>
+ /// <summary>The whole preview pixelated: what a pixelate frame shows.</summary>
public static readonly StyledProperty<Bitmap?> CoverImageProperty =
AvaloniaProperty.Register<HideCanvas, Bitmap?>(nameof(CoverImage));
+ /// <summary>The whole preview blurred: what a blur frame shows.</summary>
+ public static readonly StyledProperty<Bitmap?> BlurCoverImageProperty =
+ AvaloniaProperty.Register<HideCanvas, Bitmap?>(nameof(BlurCoverImage));
+
public static readonly StyledProperty<HideAreaSet?> AreasProperty =
AvaloniaProperty.Register<HideCanvas, HideAreaSet?>(nameof(Areas));
@@ -56,6 +61,7 @@ public sealed class HideCanvas : Control
public Bitmap? SourceImage { get => GetValue(SourceImageProperty); set => SetValue(SourceImageProperty, value); }
public Bitmap? CoverImage { get => GetValue(CoverImageProperty); set => SetValue(CoverImageProperty, value); }
+ public Bitmap? BlurCoverImage { get => GetValue(BlurCoverImageProperty); set => SetValue(BlurCoverImageProperty, value); }
public HideAreaSet? Areas { get => GetValue(AreasProperty); set => SetValue(AreasProperty, value); }
public Thickness ImagePadding { get => GetValue(ImagePaddingProperty); set => SetValue(ImagePaddingProperty, value); }
public PixelSize PixelSize { get => GetValue(PixelSizeProperty); set => SetValue(PixelSizeProperty, value); }
@@ -121,7 +127,7 @@ public sealed class HideCanvas : Control
static HideCanvas()
{
- AffectsRender<HideCanvas>(SourceImageProperty, CoverImageProperty, ImagePaddingProperty, AccentBrushProperty,
+ AffectsRender<HideCanvas>(SourceImageProperty, CoverImageProperty, BlurCoverImageProperty, ImagePaddingProperty, AccentBrushProperty,
StageBrushProperty, ChipBackgroundProperty, ChipForegroundProperty, PixelSizeProperty);
FocusableProperty.OverrideDefaultValue<HideCanvas>(false);
}
@@ -256,17 +262,26 @@ public sealed class HideCanvas : Control
if (Areas is not { } areas)
return;
- // Inside every frame the covered picture: crisp squares for pixelate (the copy has them at the preview's size).
- var cover = CoverImage ?? _soft;
+ // Inside every frame the covered picture as its style says: crisp squares for pixelate (the copy has them at the
+ // preview's size), the blurred copy for blur, solid black for a box.
for (var i = 0; i < areas.Count; i++)
{
var frame = ToScreen(areas.Areas[i], picture);
- if (cover is null || frame.Width <= 0 || frame.Height <= 0)
+ if (frame.Width <= 0 || frame.Height <= 0)
+ continue;
+ var style = areas.Styles[i];
+ if (style == HideStyle.Box)
+ {
+ context.DrawRectangle(Brushes.Black, null, frame);
+ continue;
+ }
+ var made = style == HideStyle.Blur ? BlurCoverImage : CoverImage;
+ if ((made ?? _soft) is not { } cover)
continue;
using (context.PushClip(frame))
using (context.PushRenderOptions(new RenderOptions
{
- BitmapInterpolationMode = CoverImage is null ? BitmapInterpolationMode.HighQuality : BitmapInterpolationMode.MediumQuality,
+ BitmapInterpolationMode = made is null ? BitmapInterpolationMode.HighQuality : BitmapInterpolationMode.MediumQuality,
}))
context.DrawImage(cover, new Rect(cover.Size), picture);
}
diff --git a/src/Filee.App/ViewModels/HideWindowViewModel.cs b/src/Filee.App/ViewModels/HideWindowViewModel.cs
index 25e6cd24..8e32663e 100644
--- a/src/Filee.App/ViewModels/HideWindowViewModel.cs
+++ b/src/Filee.App/ViewModels/HideWindowViewModel.cs
@@ -1,6 +1,6 @@
// State of the "Pixelate / blur" window: one picture at a time, as in the crop overlay, with frames drawn over the parts
-// to hide, each showing them already pixelated or blurred; the choice of the two and how strongly (kept in the tool for
-// the next time); and the conversion that writes the picture with those parts covered, which runs in the toast like
+// to hide, each showing them already pixelated, blurred or blacked out (each frame its own style); the last style picked
+// and how strongly (kept in the tool for the next time); and the conversion that writes the picture with those parts covered, which runs in the toast like
// any other. The frames carry on to the next picture of a batch (screenshots of one app put names in the same place).
using System.Collections.ObjectModel;
@@ -34,15 +34,22 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
private int _coverShown;
private bool _closed;
- /// <summary>The frames of the last picture saved, for the next one.</summary>
- private List<Rect> _carried = [];
+ /// <summary>The frames of the last picture saved, with their styles, for the next one.</summary>
+ private List<(Rect, HideStyle)> _carried = [];
+
+ /// <summary>The styles the covers were last asked for, so a frame moved or added in one of them asks for nothing.</summary>
+ private string _coverStyles = "";
[ObservableProperty] private int _currentIndex;
[ObservableProperty] private string _currentFileName = "";
[ObservableProperty] private string _counterText = "";
[ObservableProperty] private bool _hasMultipleFiles;
[ObservableProperty] private Bitmap? _previewImage;
+ /// <summary>The preview pixelated all over: what a pixelate frame shows inside it.</summary>
[ObservableProperty] private Bitmap? _coverImage;
+
+ /// <summary>The preview blurred all over: what a blur frame shows inside it.</summary>
+ [ObservableProperty] private Bitmap? _blurCoverImage;
[ObservableProperty] private string _saveText = "";
[ObservableProperty]
@@ -58,8 +65,9 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
[NotifyCanExecuteChangedFor(nameof(SaveCommand))]
private bool _isBusy;
+ /// <summary>The style the buttons show: the selected frame's, else the one a new frame gets.</summary>
[ObservableProperty]
- [NotifyPropertyChangedFor(nameof(IsPixelate), nameof(IsBlur))]
+ [NotifyPropertyChangedFor(nameof(IsPixelate), nameof(IsBlur), nameof(IsBox), nameof(CanChangeStrength))]
private HideStyle _style;
[ObservableProperty]
@@ -139,6 +147,19 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
}
}
+ public bool IsBox
+ {
+ get => Style == HideStyle.Box;
+ set
+ {
+ if (value)
+ Style = HideStyle.Box;
+ }
+ }
+
+ /// <summary>A black box has no strength: the slider is greyed while it is the style shown.</summary>
+ public bool CanChangeStrength => Style != HideStyle.Box;
+
/// <summary>"Strength: 5", for the slider's tooltip and screen readers.</summary>
public string StrengthText => _loc.Format("hide.strength_value", Strength);
@@ -162,6 +183,7 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
_export = export;
_log = log;
_style = tool.Image.HideStyle;
+ Areas.DefaultStyle = _style;
_strength = HideTool.ClampStrength(tool.Image.HideStrength);
_hasMultipleFiles = files.Count > 1;
for (var i = 0; i < files.Count; i++)
@@ -171,7 +193,7 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
_ = LoadFileAsync(0);
}
- partial void OnStyleChanged(HideStyle value) => RefreshCover();
+ partial void OnStyleChanged(HideStyle value) => RefreshCoverIfStylesChanged();
partial void OnStrengthChanged(int value)
{
@@ -195,6 +217,19 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
OnPropertyChanged(nameof(CanSave));
OnPropertyChanged(nameof(ShowEmptyHint));
SaveCommand.NotifyCanExecuteChanged();
+ // Selecting a frame shows its style; with none selected, the style a new frame gets.
+ Style = Areas.Selected >= 0 ? Areas.Styles[Areas.Selected] : Areas.DefaultStyle;
+ RefreshCoverIfStylesChanged();
+ }
+
+ /// <summary>The styles that need a cover: those of the frames and the one shown (a frame is drawn in it next).</summary>
+ private List<HideStyle> CoverStyles() =>
+ [.. Areas.Styles.Append(Style).Where(s => s != HideStyle.Box).Distinct().Order()];
+
+ private void RefreshCoverIfStylesChanged()
+ {
+ if (string.Join(",", CoverStyles()) != _coverStyles)
+ RefreshCover();
}
/// <summary>Opens picture <paramref name="index"/>; past the last one, the end.</summary>
@@ -257,19 +292,21 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
}
/// <summary>
- /// Covers the preview again as chosen, off the window's thread: the frames show the picture as it is until then
- /// (softly blurred). Only the newest result is kept, so dragging the strength never queues up work.
+ /// Covers the preview again for each style in use (pixelate, blur; a black box needs none), off the window's thread:
+ /// the frames show the picture as it is until then (softly blurred). Only the newest result is kept, so dragging the
+ /// strength never queues up work.
/// </summary>
private void RefreshCover()
{
if (_preview is not { } preview || _closed)
return;
var version = ++_coverVersion;
- var style = Style;
- var size = HideService.PreviewEffectSize(style, Strength, OriginalWidth, OriginalHeight, (int)preview.Width);
+ var styles = CoverStyles();
+ _coverStyles = string.Join(",", styles);
+ var sizes = styles.Select(style => (style, HideService.PreviewEffectSize(style, Strength, OriginalWidth, OriginalHeight, (int)preview.Width))).ToList();
_ = Task.Run(() =>
{
- Bitmap? cover = null;
+ var covers = new Dictionary<HideStyle, Bitmap>();
try
{
lock (preview)
@@ -277,31 +314,39 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
// A newer choice, or another picture (this one disposed): nothing to do.
if (version != Volatile.Read(ref _coverVersion) || !ReferenceEquals(preview, Volatile.Read(ref _preview)))
return;
- cover = HideService.Cover(preview, style, size);
+ foreach (var (style, size) in sizes)
+ covers[style] = HideService.Cover(preview, style, size);
}
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
_log?.LogDebug(ex, "Could not cover the preview");
+ foreach (var made in covers.Values)
+ made.Dispose();
return;
}
Avalonia.Threading.Dispatcher.UIThread.Post(() =>
{
if (version != _coverVersion || _closed || !ReferenceEquals(preview, _preview))
{
- cover.Dispose();
+ foreach (var made in covers.Values)
+ made.Dispose();
return;
}
- var old = CoverImage;
- CoverImage = cover;
+ var oldPixelate = CoverImage;
+ var oldBlur = BlurCoverImage;
+ CoverImage = covers.GetValueOrDefault(HideStyle.Pixelate);
+ BlurCoverImage = covers.GetValueOrDefault(HideStyle.Blur);
_coverShown = version;
- old?.Dispose();
+ oldPixelate?.Dispose();
+ oldBlur?.Dispose();
});
});
}
- /// <summary>Waits for the covered preview of the current choice (tests capture it).</summary>
- internal bool IsCoverCurrent => CoverImage is not null && _coverShown == _coverVersion;
+ /// <summary>Waits for the covered previews of the current choice (tests capture them).</summary>
+ internal bool IsCoverCurrent => _coverShown == _coverVersion
+ && CoverStyles().All(style => (style == HideStyle.Blur ? BlurCoverImage : CoverImage) is not null);
private void ReplacePreview(MagickImage? preview)
{
@@ -313,8 +358,12 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
old.Dispose();
}
var cover = CoverImage;
+ var blur = BlurCoverImage;
CoverImage = null;
+ BlurCoverImage = null;
+ _coverStyles = "";
cover?.Dispose();
+ blur?.Dispose();
}
// ───────────────────────── Commands ─────────────────────────
@@ -329,7 +378,7 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
if (!CanSave || _closed || CurrentIndex >= _files.Count)
return;
var path = _files[CurrentIndex];
- var areas = Areas.Areas.Select(a => new HiddenArea { X = a.X, Y = a.Y, Width = a.Width, Height = a.Height }).ToList();
+ var areas = Areas.Areas.Select((a, i) => new HiddenArea { X = a.X, Y = a.Y, Width = a.Width, Height = a.Height, Style = Areas.Styles[i] }).ToList();
Remember();
try
{
@@ -342,10 +391,12 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
AddProblem(path, "error.conversion_failed");
Queue[CurrentIndex].State = CropItemState.Failed;
}
- _carried = [.. Areas.Areas];
+ _carried = Carried();
await LoadFileAsync(CurrentIndex + 1);
}
+ private List<(Rect, HideStyle)> Carried() => [.. Areas.Areas.Zip(Areas.Styles)];
+
/// <summary>Leaves this picture as it is and opens the next one.</summary>
[RelayCommand]
public async Task SkipAsync()
@@ -354,7 +405,7 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
return;
Queue[CurrentIndex].State = CropItemState.Skipped;
// The frames stay for the next picture, as drawn.
- _carried = [.. Areas.Areas];
+ _carried = Carried();
await LoadFileAsync(CurrentIndex + 1);
}
@@ -366,11 +417,18 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
CloseRequested?.Invoke();
}
+ /// <summary>
+ /// Covers the selected frame as <paramref name="style"/> (one undo step); either way, frames drawn next get it too.
+ /// </summary>
[RelayCommand]
public void SetStyle(HideStyle style)
{
- if (IsEditing)
- Style = style;
+ if (!IsEditing)
+ return;
+ Areas.DefaultStyle = style;
+ if (Areas.Selected >= 0)
+ Areas.SetStyle(Areas.Selected, style);
+ Style = style;
}
/// <summary>Removes every frame (R); Ctrl+Z brings them back.</summary>
@@ -411,14 +469,15 @@ public sealed partial class HideWindowViewModel : ObservableObject, IDisposable
// ───────────────────────── Files, messages and the end ─────────────────────────
- /// <summary>Keeps pixelate or blur and the strength in the tool, as saved and as given to this window.</summary>
+ /// <summary>Keeps the style picked last and the strength in the tool, as saved and as given to this window.</summary>
private void Remember()
{
- HideTool.Remember(_tool, Style, Strength);
+ var style = Areas.DefaultStyle;
+ HideTool.Remember(_tool, style, Strength);
if (_store.FindPreset(_tool.Id) is not { IsHideTool: true } saved
- || (saved.Image.HideStyle == Style && saved.Image.HideStrength == Strength))
+ || (saved.Image.HideStyle == style && saved.Image.HideStrength == Strength))
return;
- HideTool.Remember(saved, Style, Strength);
+ HideTool.Remember(saved, style, Strength);
try
{
_store.SaveLibrary();
diff --git a/src/Filee.App/Views/HideWindow.axaml b/src/Filee.App/Views/HideWindow.axaml
index bc5430a2..d85a1309 100644
--- a/src/Filee.App/Views/HideWindow.axaml
+++ b/src/Filee.App/Views/HideWindow.axaml
@@ -1,7 +1,7 @@
<!-- "Pixelate / blur": the crop overlay's frameless soft-rounded stage, with the picture large on the dimmed theme
- backdrop and frames over the parts to hide, already pixelated or blurred. Floating on it: the file chip (top left),
+ backdrop and frames over the parts to hide, already pixelated, blurred or blacked out. Floating on it: the file chip (top left),
the strip of files (top, several files), size and close (top right), "Drag over what you want to hide" on a picture
- without frames, and the toolbar pill at the bottom with Pixelate / Blur, the strength, undo, remove, clear, Skip and
+ without frames, and the toolbar pill at the bottom with Pixelate / Blur / Black box, the strength, undo, remove, clear, Skip and
"Hide & save" / "Hide & next". After the last file with problems, the crop overlay's summary card. -->
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -20,6 +20,7 @@
CanResize="True">
<Window.Resources>
+ <StreamGeometry x:Key="Hide.Box">M3,3H21V21H3V3Z</StreamGeometry>
<StreamGeometry x:Key="Hide.Blur">M12,2.6C12.3,2.6 12.55,2.73 12.74,2.96C14.9,5.6 19,10.4 19,14.2A7,7 0 0,1 5,14.2C5,10.4 9.1,5.6 11.26,2.96A0.95,0.95 0 0,1 12,2.6Z</StreamGeometry>
<StreamGeometry x:Key="Hide.Redo">M11.5,8C14.15,8 16.55,9 18.4,10.6L22,7V16H13L16.62,12.38C15.23,11.22 13.46,10.5 11.5,10.5C7.96,10.5 4.95,12.81 3.9,16L1.53,15.22C2.92,11.03 6.85,8 11.5,8Z</StreamGeometry>
<StreamGeometry x:Key="Hide.Maximize">M4 7a3 3 0 0 1 3-3h10a3 3 0 0 1 3 3v10a3 3 0 0 1-3 3H7a3 3 0 0 1-3-3z M7 6.2a.8.8 0 0 0-.8.8v10c0 .44.36.8.8.8h10a.8.8 0 0 0 .8-.8V7a.8.8 0 0 0-.8-.8z</StreamGeometry>
@@ -164,7 +165,7 @@
</Style>
<!-- A narrow window (or long names, or wide fonts): the toolbar gives up names in two steps (HideWindow.FitToolbar),
- first those of Clear all and Skip and the keycaps, then those of Pixelate and Blur; the tooltips keep them -->
+ first those of Clear all and Skip and the keycaps, then those of Pixelate, Blur and Black box; the tooltips keep them -->
<Style Selector="Window.tight TextBlock.minor, Window.tight Border.minor, Window.compact TextBlock.major">
<Setter Property="IsVisible" Value="False" />
</Style>
@@ -193,6 +194,7 @@
<c:HideCanvas x:Name="Canvas"
SourceImage="{Binding PreviewImage}"
CoverImage="{Binding CoverImage}"
+ BlurCoverImage="{Binding BlurCoverImage}"
Areas="{Binding Areas}"
PixelSize="{Binding PixelSize}"
ImagePadding="36,70,36,118"
@@ -297,7 +299,7 @@
<StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="16,0,16,12" Spacing="7" IsVisible="{Binding IsEditing}">
<Border x:Name="Toolbar" Classes="float" Padding="5">
<StackPanel x:Name="ToolbarContent" Orientation="Horizontal" Spacing="3">
- <!-- Pixelate or blur: the one in use tinted -->
+ <!-- Pixelate, blur or black box: the one shown (the selected frame's, else the next frame's) tinted -->
<Button x:Name="PixelateButton" Classes="tool" Classes.open="{Binding IsPixelate}" Padding="10,8,12,8"
Command="{Binding SetStyleCommand}" CommandParameter="{x:Static p:HideStyle.Pixelate}"
ToolTip.Tip="{DynamicResource hide.pixelate_hint}" AutomationProperties.Name="{DynamicResource hide.pixelate}">
@@ -314,10 +316,18 @@
<TextBlock Classes="major" Text="{DynamicResource hide.blur}" FontSize="13" VerticalAlignment="Center" />
</StackPanel>
</Button>
+ <Button x:Name="BoxButton" Classes="tool" Classes.open="{Binding IsBox}" Padding="10,8,12,8"
+ Command="{Binding SetStyleCommand}" CommandParameter="{x:Static p:HideStyle.Box}"
+ ToolTip.Tip="{DynamicResource hide.box_hint}" AutomationProperties.Name="{DynamicResource hide.box}">
+ <StackPanel Orientation="Horizontal" Spacing="7">
+ <PathIcon Width="12" Height="12" Data="{StaticResource Hide.Box}" Foreground="{DynamicResource AccentBrush}" />
+ <TextBlock Classes="major" Text="{DynamicResource hide.box}" FontSize="13" VerticalAlignment="Center" />
+ </StackPanel>
+ </Button>
<!-- How strongly: small squares to large, a light blur to a heavy one -->
<StackPanel Orientation="Horizontal" Spacing="7" Margin="8,0,6,0" VerticalAlignment="Center"
- ToolTip.Tip="{Binding StrengthText}">
+ ToolTip.Tip="{Binding StrengthText}" IsEnabled="{Binding CanChangeStrength}">
<Ellipse Width="5" Height="5" Fill="{DynamicResource TextSecondaryBrush}" VerticalAlignment="Center" />
<Slider x:Name="StrengthSlider" Minimum="{Binding MinStrength}" Maximum="{Binding MaxStrength}"
TickFrequency="1" IsSnapToTickEnabled="True" SmallChange="1" LargeChange="2"
diff --git a/src/Filee.App/Views/HideWindow.axaml.cs b/src/Filee.App/Views/HideWindow.axaml.cs
index b625c7d3..7fbb6c1f 100644
--- a/src/Filee.App/Views/HideWindow.axaml.cs
+++ b/src/Filee.App/Views/HideWindow.axaml.cs
@@ -225,6 +225,10 @@ public partial class HideWindow : Window
vm.SetStyle(HideStyle.Blur);
e.Handled = true;
break;
+ case Key.X when plain && editing:
+ vm.SetStyle(HideStyle.Box);
+ e.Handled = true;
+ break;
case Key.OemPlus or Key.Add when (plain || e.KeyModifiers == KeyModifiers.Shift) && editing:
vm.StepStrength(1);
e.Handled = true;
diff --git a/src/Filee.Core/Presets/HideTool.cs b/src/Filee.Core/Presets/HideTool.cs
index 2a275090..1c4e65c2 100644
--- a/src/Filee.Core/Presets/HideTool.cs
+++ b/src/Filee.Core/Presets/HideTool.cs
@@ -1,7 +1,7 @@
// "Pixelate / blur" runs as an ordinary conversion once its window has the parts of a picture to hide: the tool preset
// becomes a conversion into the picture's own format with those parts (ImageOptions.HiddenAreas), so the job queue, the
-// toast, cancelling and the output rules work as for any other file. How they are covered (pixelate or blur, and how
-// strongly) is kept in the tool, so the window opens with the last choice. The arithmetic shared by the window's
+// toast, cancelling and the output rules work as for any other file. Each part is pixelated, blurred or blacked out
+// (HiddenArea.Style); the last style picked and how strongly are kept in the tool, so the window opens with them. The arithmetic shared by the window's
// preview and the image engine is here too: where a part lies in pixels, how large the squares or the blur are, and
// which square a pixel falls in.
@@ -93,7 +93,9 @@ public static class HideTool
var right = Math.Clamp(Math.Max(area.X, area.X + area.Width), 0, 1);
var top = Math.Clamp(Math.Min(area.Y, area.Y + area.Height), 0, 1);
var bottom = Math.Clamp(Math.Max(area.Y, area.Y + area.Height), 0, 1);
- return right > left && bottom > top ? new HiddenArea { X = left, Y = top, Width = right - left, Height = bottom - top } : null;
+ return right > left && bottom > top
+ ? new HiddenArea { X = left, Y = top, Width = right - left, Height = bottom - top, Style = area.Style }
+ : null;
}
/// <summary>
diff --git a/src/Filee.Core/Presets/Preset.cs b/src/Filee.Core/Presets/Preset.cs
index 7e6f7111..967848d0 100644
--- a/src/Filee.Core/Presets/Preset.cs
+++ b/src/Filee.Core/Presets/Preset.cs
@@ -402,6 +402,11 @@ public enum HideStyle
Pixelate,
/// <summary>A strong blur.</summary>
Blur,
+ /// <summary>
+ /// Solid, opaque black: nothing of what was there is left. A Filee from before it reads it as
+ /// <see cref="Pixelate"/>.
+ /// </summary>
+ Box,
}
/// <summary>
@@ -415,6 +420,10 @@ public sealed class HiddenArea
public double Width { get; set; }
public double Height { get; set; }
+ /// <summary>How this part is covered; null for the preset's <see cref="ImageOptions.HideStyle"/>.</summary>
+ [JsonConverter(typeof(LenientEnumJsonConverter<HideStyle>))]
+ public HideStyle? Style { get; set; }
+
public HiddenArea Clone() => (HiddenArea)MemberwiseClone();
}
@@ -616,8 +625,8 @@ public sealed class ImageOptions
public List<int> IcoSizes { get; set; } = [256, 128, 64, 48, 32, 16];
/// <summary>
- /// "Pixelate / blur": how <see cref="HiddenAreas"/> are covered. Kept in the tool, so its window opens with the last
- /// one. A field of its own (not a value added to another option), read leniently: an older Filee skips it.
+ /// "Pixelate / blur": how <see cref="HiddenAreas"/> without a <see cref="HiddenArea.Style"/> of their own are covered.
+ /// Kept in the tool as the last style picked, so its window opens with it. A field of its own (not a value added to another option), read leniently: an older Filee skips it.
/// </summary>
[JsonConverter(typeof(LenientEnumJsonConverter<HideStyle>))]
public HideStyle HideStyle { get; set; }
diff --git a/src/Filee.Engines/Magick/AreaHider.cs b/src/Filee.Engines/Magick/AreaHider.cs
index fb6aab06..00e172cd 100644
--- a/src/Filee.Engines/Magick/AreaHider.cs
+++ b/src/Filee.Engines/Magick/AreaHider.cs
@@ -1,5 +1,5 @@
-// "Pixelate / blur": covers parts of a picture (ImageOptions.HiddenAreas) so what was there can't be read back. Each
-// part is changed on its own; the rest of the picture keeps its pixels. Also used on the window's preview, so what the
+// "Pixelate / blur": covers parts of a picture (ImageOptions.HiddenAreas) so what was there can't be read back, each
+// pixelated, blurred or blacked out as its style says. Each part is changed on its own; the rest of the picture keeps its pixels. Also used on the window's preview, so what the
// user sees while drawing the parts is what the file gets.
using Filee.Core.Presets;
@@ -7,7 +7,7 @@ using ImageMagick;
namespace Filee.Engines.Magick;
-/// <summary>Pixelates or blurs parts of a picture for good.</summary>
+/// <summary>Pixelates, blurs or blacks out parts of a picture for good.</summary>
public static class AreaHider
{
/// <summary>
@@ -24,10 +24,18 @@ public static class AreaHider
{
if (HideTool.PixelBounds(area, width, height) is not { } bounds)
continue;
- if (options.HideStyle == HideStyle.Blur)
- Blur(image, bounds, size);
- else
- Pixelate(image, bounds, Math.Round(size));
+ switch (area.Style ?? options.HideStyle)
+ {
+ case HideStyle.Blur:
+ Blur(image, bounds, size);
+ break;
+ case HideStyle.Box:
+ Box(image, bounds);
+ break;
+ default:
+ Pixelate(image, bounds, Math.Round(size));
+ break;
+ }
}
DropPreviews(image);
}
@@ -129,6 +137,21 @@ public static class AreaHider
image.Composite(squares, left, top, CompositeOperator.Copy);
}
+ /// <summary>
+ /// <paramref name="bounds"/> filled with opaque black: every pixel of the part is replaced, transparency included, so
+ /// nothing of it is left to recover.
+ /// </summary>
+ public static void Box(IMagickImage<byte> image, (int X, int Y, int Width, int Height) bounds)
+ {
+ var (x, y, w, h) = bounds;
+ if (w <= 0 || h <= 0)
+ return;
+ using var black = new MagickImage(MagickColors.Black, (uint)w, (uint)h);
+ if (image.HasAlpha)
+ black.Alpha(AlphaOption.Opaque);
+ image.Composite(black, x, y, CompositeOperator.Copy);
+ }
+
/// <summary>
/// <paramref name="bounds"/> blurred with a Gaussian of <paramref name="sigma"/> pixels, after its pixels are
/// averaged into squares of about a third of it.
diff --git a/tests/Filee.App.Tests/HideWindowTests.cs b/tests/Filee.App.Tests/HideWindowTests.cs
index 5cc3dcce..a6fae899 100644
--- a/tests/Filee.App.Tests/HideWindowTests.cs
+++ b/tests/Filee.App.Tests/HideWindowTests.cs
@@ -61,12 +61,30 @@ public class HideWindowTests
Assert.True(vm.CanSave);
Save(window, $"hide-pixelate-{suffix}.png");
- vm.SetStyle(HideStyle.Blur);
+ // Each frame has its own style: every one blurred here.
+ for (var i = 0; i < Frames.Length; i++)
+ {
+ vm.Areas.Select(i);
+ vm.SetStyle(HideStyle.Blur);
+ }
vm.Strength = 7;
vm.Areas.Select(2);
WaitForCover(vm);
Settle(window);
Save(window, $"hide-blur-{suffix}.png");
+
+ // The phone number blacked out, the name and the face pixelated.
+ vm.Areas.Select(0);
+ vm.SetStyle(HideStyle.Pixelate);
+ vm.Areas.Select(2);
+ vm.SetStyle(HideStyle.Pixelate);
+ vm.Areas.Select(1);
+ vm.SetStyle(HideStyle.Box);
+ vm.Strength = 5;
+ WaitForCover(vm);
+ Settle(window);
+ Assert.False(vm.CanChangeStrength);
+ Save(window, $"hide-box-{suffix}.png");
});
}
@@ -263,6 +281,53 @@ public class HideWindowTests
});
}
+ [AvaloniaFact]
+ public void Each_frame_keeps_its_own_style_undoably_and_the_conversion_gets_them()
+ {
+ WithWindow("en", "light", ["chat.png", "chat.png"], (window, vm, _, exported) =>
+ {
+ vm.Areas.Add(Frames[0]);
+ vm.Areas.Add(Frames[1]);
+ // Frame 1 selected: X blacks out only it; the slider is greyed while a box is shown.
+ Press(window, Key.X);
+ Assert.Equal([HideStyle.Pixelate, HideStyle.Box], vm.Areas.Styles);
+ Assert.True(vm.IsBox);
+ Assert.False(vm.CanChangeStrength);
+
+ // Selecting the other frame shows its style; a frame drawn next gets the style picked last.
+ vm.Areas.Select(0);
+ Assert.True(vm.IsPixelate);
+ Assert.True(vm.CanChangeStrength);
+ vm.Areas.Select(-1);
+ Assert.True(vm.IsBox);
+ vm.Areas.Add(Frames[2]);
+ Assert.Equal(HideStyle.Box, vm.Areas.Styles[2]);
+
+ // A style change is one undo step.
+ vm.Areas.Select(2);
+ vm.SetStyle(HideStyle.Blur);
+ Assert.Equal(HideStyle.Blur, vm.Areas.Styles[2]);
+ vm.Undo();
+ Assert.Equal(HideStyle.Box, vm.Areas.Styles[2]);
+ vm.Redo();
+ WaitForCover(vm);
+ Assert.NotNull(vm.CoverImage);
+ Assert.NotNull(vm.BlurCoverImage);
+
+ vm.SaveCommand.Execute(null);
+ WaitFor(() => exported.Count == 1 && !vm.IsBusy);
+ var areas = exported[0].Conversion.Image.HiddenAreas!;
+ Assert.Equal([HideStyle.Pixelate, HideStyle.Box, HideStyle.Blur], areas.Select(a => a.Style));
+ // The next picture of the batch starts with the same frames and styles.
+ Assert.Equal([HideStyle.Pixelate, HideStyle.Box, HideStyle.Blur], vm.Areas.Styles);
+ // The style picked last is the one remembered.
+ Assert.Equal(HideStyle.Blur, AppHost.Get<UserDataStore>().FindPreset("tool-hide")!.Image.HideStyle);
+ });
+ var store = AppHost.Get<UserDataStore>();
+ HideTool.Remember(store.FindPreset("tool-hide")!, HideStyle.Pixelate, HideTool.DefaultStrength);
+ store.SaveLibrary();
+ }
+
[AvaloniaFact]
public void Escape_closes_without_saving_and_the_choice_is_remembered_in_the_tool()
{
diff --git a/tests/Filee.Core.Tests/HideToolTests.cs b/tests/Filee.Core.Tests/HideToolTests.cs
index f8384ba4..45987026 100644
--- a/tests/Filee.Core.Tests/HideToolTests.cs
+++ b/tests/Filee.Core.Tests/HideToolTests.cs
@@ -178,6 +178,26 @@ public class HideToolTests
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 Each_part_keeps_its_own_style_through_the_conversion_and_saving()
+ {
+ var tool = Tool();
+ HideTool.Remember(tool, HideStyle.Box, 5);
+ var boxed = Area(0.1, 0.2, 0.3, 0.4);
+ boxed.Style = HideStyle.Box;
+ var blurred = Area(0.5, 0.5, 0.6, 0.6); // runs off the picture: clamped, its style kept
+ blurred.Style = HideStyle.Blur;
+
+ var conversion = HideTool.ConversionOf(tool, "png", [boxed, blurred, Area(0, 0, 0.1, 0.1)]);
+ var json = JsonSerializer.Serialize(new List<Preset> { conversion }, FileeJsonContext.Default.ListPreset);
+ var read = JsonSerializer.Deserialize(json, FileeJsonContext.Default.ListPreset)!.Single();
+
+ Assert.Equal([HideStyle.Box, HideStyle.Blur, null], read.Image.HiddenAreas!.Select(a => a.Style));
+ Assert.Equal(0.5, read.Image.HiddenAreas![1].Width, 9);
+ Assert.Equal(HideStyle.Box, read.Image.HideStyle);
+ Assert.Contains("\"style\": \"Box\"", json);
+ }
+
[Fact]
public void A_style_from_a_newer_Filee_reads_as_pixelate_instead_of_failing_the_whole_file()
{
diff --git a/tests/Filee.Engines.Tests/HideAreasTests.cs b/tests/Filee.Engines.Tests/HideAreasTests.cs
index c2f1f265..a10874b4 100644
--- a/tests/Filee.Engines.Tests/HideAreasTests.cs
+++ b/tests/Filee.Engines.Tests/HideAreasTests.cs
@@ -1,5 +1,5 @@
-// "Pixelate / blur" through the real image engine: the parts become squares of their average colour or a blur that
-// leaves none of their detail, the rest of the picture keeps every pixel, the parts land on the picture as it is seen
+// "Pixelate / blur" through the real image engine: the parts become squares of their average colour, a blur that
+// leaves none of their detail or opaque black boxes, each part as its own style says, the rest of the picture keeps every pixel, the parts land on the picture as it is seen
// (EXIF orientation), the format stays, and the previews a file carries of the uncovered picture go.
using Filee.Core.Conversion;
@@ -84,6 +84,39 @@ public class HideAreasTests(EngineFixture fx) : IClassFixture<EngineFixture>
}
}
+ [Fact]
+ public async Task A_black_box_is_opaque_black_and_each_part_takes_its_own_style()
+ {
+ var folder = fx.NewFolder();
+ var path = Path.Combine(folder, "noise.png");
+ using (var source = Noise(400, 200))
+ {
+ // Half transparent everywhere: a box must not let any of what was there show through.
+ source.Alpha(AlphaOption.Set);
+ source.Evaluate(Channels.Alpha, EvaluateOperator.Set, Quantum.Max / 2);
+ source.Write(path, MagickFormat.Png);
+ }
+ var box = Area(0.1, 0.1, 0.3, 0.5); // 40, 20, 120 × 100
+ box.Style = HideStyle.Box;
+ var pixelated = Area(0.6, 0.1, 0.3, 0.5); // no style of its own: the preset's
+
+ var output = await RunAsync(path, Hide(HideStyle.Pixelate, 5, box, pixelated));
+
+ using var before = new MagickImage(path);
+ using var after = new MagickImage(output);
+ var a = before.GetPixels().ToByteArray(PixelMapping.RGBA)!;
+ var b = after.GetPixels().ToByteArray(PixelMapping.RGBA)!;
+ int Index(int x, int y) => (y * 400 + x) * 4;
+ for (var y = 20; y < 120; y++)
+ for (var x = 40; x < 160; x++)
+ Assert.Equal((0, 0, 0, 255), (b[Index(x, y)], b[Index(x, y) + 1], b[Index(x, y) + 2], b[Index(x, y) + 3]));
+ // Just outside the box, as it was; the other part pixelated (two neighbours in one square alike, unlike before).
+ Assert.Equal(a[Index(39, 50)], b[Index(39, 50)]);
+ Assert.Equal(a[Index(160, 50)], b[Index(160, 50)]);
+ Assert.Equal(b[Index(250, 50)], b[Index(251, 50)]);
+ Assert.NotEqual((0, 0, 0), (b[Index(250, 50)], b[Index(250, 50) + 1], b[Index(250, 50) + 2]));
+ }
+
[Fact]
public async Task Blur_leaves_none_of_the_parts_detail_and_keeps_everything_else()
{