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
feat(images): pixelate or blur parts of a picture before sharing it
KnifeLemonbf6f9aad7fb1
diff --git a/src/Filee.App/Assets/i18n/ar.json b/src/Filee.App/Assets/i18n/ar.jsonindex 8738fcda..f1631f3b 100644--- a/src/Filee.App/Assets/i18n/ar.json+++ b/src/Filee.App/Assets/i18n/ar.json@@ -251,6 +251,23 @@"crop.state_done": "تم الاقتصاص","crop.state_skipped": "تم التخطي","crop.state_failed": "فشل",+ "preset.hide": "بكسلة / تمويه",+ "preset.hide.donut": "بكسلة",+ "error.cannot_hide": "البكسلة والتمويه متاحان للصور فقط",+ "hide.save": "إخفاء وحفظ",+ "hide.save_next": "إخفاء والتالي",+ "hide.pixelate": "بكسلة",+ "hide.pixelate_hint": "التغطية بمربعات بمتوسط الألوان (P)",+ "hide.blur": "تمويه",+ "hide.blur_hint": "التغطية بتمويه قوي (B)",+ "hide.strength": "الشدة",+ "hide.strength_value": "الشدة {0} من 10 (− / +)",+ "hide.remove": "إزالة الإطار",+ "hide.remove_hint": "إزالة الإطار المحدد (Del)",+ "hide.clear": "إزالة الكل",+ "hide.empty_hint": "اسحب فوق ما تريد إخفاءه",+ "hide.hint_keys": "يختار Tab إطارًا وتحرّكه مفاتيح الأسهم، ومع Shift تكون الخطوة أكبر بعشر مرات · Del يزيله · Ctrl+Z للتراجع · Esc للإغلاق",+ "hide.state_done": "تم","preset.clip": "قص مقطع","clip.start": "البداية","clip.end": "النهاية",diff --git a/src/Filee.App/Assets/i18n/de.json b/src/Filee.App/Assets/i18n/de.jsonindex 154a2512..9c5050f0 100644--- a/src/Filee.App/Assets/i18n/de.json+++ b/src/Filee.App/Assets/i18n/de.json@@ -251,6 +251,23 @@"crop.state_done": "Zugeschnitten","crop.state_skipped": "Übersprungen","crop.state_failed": "Fehlgeschlagen",+ "preset.hide": "Verpixeln / Weichzeichnen",+ "preset.hide.donut": "Verpixeln",+ "error.cannot_hide": "Verpixeln und Weichzeichnen ist nur bei Bildern möglich",+ "hide.save": "Verbergen & Speichern",+ "hide.save_next": "Verbergen & Weiter",+ "hide.pixelate": "Verpixeln",+ "hide.pixelate_hint": "Mit Quadraten in der Durchschnittsfarbe abdecken (P)",+ "hide.blur": "Weichzeichnen",+ "hide.blur_hint": "Mit starker Unschärfe abdecken (B)",+ "hide.strength": "Stärke",+ "hide.strength_value": "Stärke {0} von 10 (− / +)",+ "hide.remove": "Rahmen entfernen",+ "hide.remove_hint": "Ausgewählten Rahmen entfernen (Entf)",+ "hide.clear": "Alle entfernen",+ "hide.empty_hint": "Ziehe über das, was verborgen werden soll",+ "hide.hint_keys": "Tab wählt einen Rahmen, Pfeiltasten verschieben ihn, Umschalt × 10 · Entf entfernt ihn · Strg+Z macht rückgängig · Esc schließt",+ "hide.state_done": "Fertig","preset.clip": "Clip schneiden","clip.start": "Beginn","clip.end": "Ende",diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.jsonindex 4cd5e0eb..9220cdbc 100644--- a/src/Filee.App/Assets/i18n/en.json+++ b/src/Filee.App/Assets/i18n/en.json@@ -260,6 +260,23 @@"crop.state_done": "Cropped","crop.state_skipped": "Skipped","crop.state_failed": "Failed",+ "preset.hide": "Pixelate / blur",+ "preset.hide.donut": "Pixelate",+ "error.cannot_hide": "Only pictures can be pixelated or blurred",+ "hide.save": "Hide & Save",+ "hide.save_next": "Hide & Next",+ "hide.pixelate": "Pixelate",+ "hide.pixelate_hint": "Cover with squares of the average colour (P)",+ "hide.blur": "Blur",+ "hide.blur_hint": "Cover with a strong blur (B)",+ "hide.strength": "Strength",+ "hide.strength_value": "Strength {0} of 10 (− / +)",+ "hide.remove": "Remove frame",+ "hide.remove_hint": "Remove the selected frame (Del)",+ "hide.clear": "Clear all",+ "hide.empty_hint": "Drag over what you want to hide",+ "hide.hint_keys": "Tab picks a frame, arrow keys move it, Shift × 10 · Del removes it · Ctrl+Z undoes · Esc closes",+ "hide.state_done": "Done","preset.clip": "Cut a clip","clip.start": "Start","clip.end": "End",diff --git a/src/Filee.App/Assets/i18n/es.json b/src/Filee.App/Assets/i18n/es.jsonindex 02dab483..d6e636a5 100644--- a/src/Filee.App/Assets/i18n/es.json+++ b/src/Filee.App/Assets/i18n/es.json@@ -251,6 +251,23 @@"crop.state_done": "Recortado","crop.state_skipped": "Omitido","crop.state_failed": "Error",+ "preset.hide": "Pixelar / difuminar",+ "preset.hide.donut": "Pixelar",+ "error.cannot_hide": "Solo se pueden pixelar o difuminar imágenes",+ "hide.save": "Ocultar y guardar",+ "hide.save_next": "Ocultar y seguir",+ "hide.pixelate": "Pixelar",+ "hide.pixelate_hint": "Cubrir con cuadros del color medio (P)",+ "hide.blur": "Difuminar",+ "hide.blur_hint": "Cubrir con un desenfoque fuerte (B)",+ "hide.strength": "Intensidad",+ "hide.strength_value": "Intensidad {0} de 10 (− / +)",+ "hide.remove": "Quitar marco",+ "hide.remove_hint": "Quitar el marco seleccionado (Supr)",+ "hide.clear": "Quitar todos",+ "hide.empty_hint": "Arrastra sobre lo que quieras ocultar",+ "hide.hint_keys": "Tab elige un marco, las flechas lo mueven, Mayús × 10 · Supr lo quita · Ctrl+Z deshace · Esc cierra",+ "hide.state_done": "Hecho","preset.clip": "Cortar un clip","clip.start": "Inicio","clip.end": "Fin",diff --git a/src/Filee.App/Assets/i18n/fr.json b/src/Filee.App/Assets/i18n/fr.jsonindex 36e31d0f..5bf94e50 100644--- a/src/Filee.App/Assets/i18n/fr.json+++ b/src/Filee.App/Assets/i18n/fr.json@@ -260,6 +260,23 @@"crop.state_done": "Recadré","crop.state_skipped": "Ignoré","crop.state_failed": "Échec",+ "preset.hide": "Pixeliser / flouter",+ "preset.hide.donut": "Pixeliser",+ "error.cannot_hide": "Seules les images peuvent être pixelisées ou floutées",+ "hide.save": "Masquer et enregistrer",+ "hide.save_next": "Masquer et suivant",+ "hide.pixelate": "Pixeliser",+ "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.strength": "Intensité",+ "hide.strength_value": "Intensité {0} sur 10 (− / +)",+ "hide.remove": "Supprimer le cadre",+ "hide.remove_hint": "Supprimer le cadre sélectionné (Suppr)",+ "hide.clear": "Tout effacer",+ "hide.empty_hint": "Faites glisser sur ce que vous voulez masquer",+ "hide.hint_keys": "Tab choisit un cadre, les flèches le déplacent, Maj × 10 · Suppr le supprime · Ctrl+Z annule · Échap ferme",+ "hide.state_done": "Terminé","preset.clip": "Couper un extrait","clip.start": "Début","clip.end": "Fin",diff --git a/src/Filee.App/Assets/i18n/hi.json b/src/Filee.App/Assets/i18n/hi.jsonindex 11dad241..6d1c00a3 100644--- a/src/Filee.App/Assets/i18n/hi.json+++ b/src/Filee.App/Assets/i18n/hi.json@@ -251,6 +251,23 @@"crop.state_done": "क्रॉप हो गया","crop.state_skipped": "छोड़ा गया","crop.state_failed": "विफल",+ "preset.hide": "पिक्सलेट / धुंधला",+ "preset.hide.donut": "पिक्सलेट",+ "error.cannot_hide": "पिक्सलेट और धुंधला केवल इमेज पर काम करता है",+ "hide.save": "छिपाकर सहेजें",+ "hide.save_next": "छिपाकर अगला",+ "hide.pixelate": "पिक्सलेट",+ "hide.pixelate_hint": "औसत रंग के वर्गों से ढकें (P)",+ "hide.blur": "धुंधला",+ "hide.blur_hint": "गहरे धुंधलेपन से ढकें (B)",+ "hide.strength": "तीव्रता",+ "hide.strength_value": "तीव्रता {0} / 10 (− / +)",+ "hide.remove": "फ़्रेम हटाएँ",+ "hide.remove_hint": "चुना गया फ़्रेम हटाएँ (Del)",+ "hide.clear": "सभी हटाएँ",+ "hide.empty_hint": "जो छिपाना है उस पर खींचें",+ "hide.hint_keys": "Tab से फ़्रेम चुनें, ऐरो कुंजियों से खिसकाएँ, Shift से 10 गुना · Del से हटाएँ · Ctrl+Z से पूर्ववत करें · Esc से बंद करें",+ "hide.state_done": "हो गया","preset.clip": "क्लिप काटें","clip.start": "शुरुआत","clip.end": "अंत",diff --git a/src/Filee.App/Assets/i18n/ja.json b/src/Filee.App/Assets/i18n/ja.jsonindex 5298e5df..c53dc15a 100644--- a/src/Filee.App/Assets/i18n/ja.json+++ b/src/Filee.App/Assets/i18n/ja.json@@ -251,6 +251,23 @@"crop.state_done": "トリミング済み","crop.state_skipped": "スキップ","crop.state_failed": "失敗",+ "preset.hide": "モザイク・ぼかし",+ "preset.hide.donut": "モザイク",+ "error.cannot_hide": "モザイクとぼかしは画像でのみ使えます",+ "hide.save": "隠して保存",+ "hide.save_next": "隠して次へ",+ "hide.pixelate": "モザイク",+ "hide.pixelate_hint": "平均色のブロックで隠す (P)",+ "hide.blur": "ぼかし",+ "hide.blur_hint": "強いぼかしで隠す (B)",+ "hide.strength": "強さ",+ "hide.strength_value": "強さ {0} / 10(− / +)",+ "hide.remove": "枠を削除",+ "hide.remove_hint": "選択した枠を削除(Del)",+ "hide.clear": "すべて消去",+ "hide.empty_hint": "隠したい部分をドラッグしてください",+ "hide.hint_keys": "Tab で枠を選択、矢印キーで移動、Shift で 10 倍 · Del で削除 · Ctrl+Z で元に戻す · Esc で閉じる",+ "hide.state_done": "完了","preset.clip": "クリップを切り出す","clip.start": "開始","clip.end": "終了",diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.jsonindex bb6eb21d..4559cb0c 100644--- a/src/Filee.App/Assets/i18n/ko.json+++ b/src/Filee.App/Assets/i18n/ko.json@@ -260,6 +260,23 @@"crop.state_done": "자르기 완료","crop.state_skipped": "건너뜀","crop.state_failed": "실패",+ "preset.hide": "모자이크·흐림",+ "preset.hide.donut": "모자이크",+ "error.cannot_hide": "모자이크와 흐림은 이미지에만 할 수 있어요",+ "hide.save": "가리고 저장",+ "hide.save_next": "가리고 다음으로",+ "hide.pixelate": "모자이크",+ "hide.pixelate_hint": "평균 색 네모로 가리기 (P)",+ "hide.blur": "흐림",+ "hide.blur_hint": "강하게 흐려서 가리기 (B)",+ "hide.strength": "세기",+ "hide.strength_value": "세기 {0} / 10 (− / +)",+ "hide.remove": "틀 지우기",+ "hide.remove_hint": "선택한 틀 지우기 (Del)",+ "hide.clear": "모두 지우기",+ "hide.empty_hint": "가릴 부분을 드래그하세요",+ "hide.hint_keys": "Tab으로 틀 선택, 화살표 키로 이동, Shift는 10배 · Del로 지우기 · Ctrl+Z로 실행 취소 · Esc로 닫기",+ "hide.state_done": "완료","preset.clip": "클립 자르기","clip.start": "시작","clip.end": "끝",diff --git a/src/Filee.App/Assets/i18n/ne.json b/src/Filee.App/Assets/i18n/ne.jsonindex 0716ee27..3ede86f2 100644--- a/src/Filee.App/Assets/i18n/ne.json+++ b/src/Filee.App/Assets/i18n/ne.json@@ -251,6 +251,23 @@"crop.state_done": "क्रप गरियो","crop.state_skipped": "छोडियो","crop.state_failed": "असफल भयो",+ "preset.hide": "पिक्सलेट / धमिलो",+ "preset.hide.donut": "पिक्सलेट",+ "error.cannot_hide": "पिक्सलेट र धमिलो पार्ने कार्य केवल छविहरूमा मात्र काम गर्छ",+ "hide.save": "लुकाएर सुरक्षित गर्नुहोस्",+ "hide.save_next": "लुकाएर अर्कोमा जानुहोस्",+ "hide.pixelate": "पिक्सलेट",+ "hide.pixelate_hint": "औसत रङका वर्गहरूले ढाक्नुहोस् (P)",+ "hide.blur": "धमिलो",+ "hide.blur_hint": "गाढा धमिलोपनले ढाक्नुहोस् (B)",+ "hide.strength": "तीव्रता",+ "hide.strength_value": "तीव्रता {0} / 10 (− / +)",+ "hide.remove": "फ्रेम हटाउनुहोस्",+ "hide.remove_hint": "चयन गरिएको फ्रेम हटाउनुहोस् (Del)",+ "hide.clear": "सबै हटाउनुहोस्",+ "hide.empty_hint": "लुकाउन चाहेको भागमाथि ड्र्याग गर्नुहोस्",+ "hide.hint_keys": "Tab ले फ्रेम छान्छ, एरो कीहरूले सार्छन्, Shift थिच्दा १० गुणा · Del ले हटाउँछ · Ctrl+Z ले पूर्वावस्थामा फर्काउँछ · Esc ले बन्द गर्छ",+ "hide.state_done": "सम्पन्न","preset.clip": "क्लिप काट्नुहोस्","clip.start": "सुरु","clip.end": "अन्त्य",diff --git a/src/Filee.App/Assets/i18n/pl.json b/src/Filee.App/Assets/i18n/pl.jsonindex 7ea3d913..7d816cdc 100644--- a/src/Filee.App/Assets/i18n/pl.json+++ b/src/Filee.App/Assets/i18n/pl.json@@ -260,6 +260,23 @@"crop.state_done": "Wykadrowany","crop.state_skipped": "Pominięty","crop.state_failed": "Błąd",+ "preset.hide": "Pikselizacja / rozmycie",+ "preset.hide.donut": "Mozaika",+ "error.cannot_hide": "Pikselizować i rozmywać można tylko obrazy",+ "hide.save": "Ukryj i zapisz",+ "hide.save_next": "Ukryj i dalej",+ "hide.pixelate": "Pikselizacja",+ "hide.pixelate_hint": "Zakryj kwadratami w średnim kolorze (P)",+ "hide.blur": "Rozmycie",+ "hide.blur_hint": "Zakryj mocnym rozmyciem (B)",+ "hide.strength": "Siła",+ "hide.strength_value": "Siła {0} z 10 (− / +)",+ "hide.remove": "Usuń ramkę",+ "hide.remove_hint": "Usuń zaznaczoną ramkę (Del)",+ "hide.clear": "Usuń wszystkie",+ "hide.empty_hint": "Przeciągnij po tym, co chcesz ukryć",+ "hide.hint_keys": "Tab wybiera ramkę, strzałki ją przesuwają, Shift × 10 · Del ją usuwa · Ctrl+Z cofa · Esc zamyka",+ "hide.state_done": "Gotowe","preset.clip": "Wytnij klip","clip.start": "Początek","clip.end": "Koniec",diff --git a/src/Filee.App/Assets/i18n/pt-BR.json b/src/Filee.App/Assets/i18n/pt-BR.jsonindex 140aa954..795657c3 100644--- a/src/Filee.App/Assets/i18n/pt-BR.json+++ b/src/Filee.App/Assets/i18n/pt-BR.json@@ -261,6 +261,23 @@"crop.state_done": "Recortado","crop.state_skipped": "Pulado","crop.state_failed": "Falhou",+ "preset.hide": "Pixelizar / desfocar",+ "preset.hide.donut": "Pixelizar",+ "error.cannot_hide": "Só é possível pixelizar ou desfocar imagens",+ "hide.save": "Ocultar e salvar",+ "hide.save_next": "Ocultar e avançar",+ "hide.pixelate": "Pixelizar",+ "hide.pixelate_hint": "Cobrir com quadrados da cor média (P)",+ "hide.blur": "Desfocar",+ "hide.blur_hint": "Cobrir com um desfoque forte (B)",+ "hide.strength": "Intensidade",+ "hide.strength_value": "Intensidade {0} de 10 (− / +)",+ "hide.remove": "Remover moldura",+ "hide.remove_hint": "Remover a moldura selecionada (Del)",+ "hide.clear": "Remover todas",+ "hide.empty_hint": "Arraste sobre o que você quer ocultar",+ "hide.hint_keys": "Tab escolhe uma moldura, as setas a movem, Shift × 10 · Del a remove · Ctrl+Z desfaz · Esc fecha",+ "hide.state_done": "Concluído","clip.start": "Início","clip.end": "Fim","clip.length": "Duração",diff --git a/src/Filee.App/Assets/i18n/pt-PT.json b/src/Filee.App/Assets/i18n/pt-PT.jsonindex 05327916..6c8a6f9d 100644--- a/src/Filee.App/Assets/i18n/pt-PT.json+++ b/src/Filee.App/Assets/i18n/pt-PT.json@@ -260,6 +260,23 @@"crop.state_done": "Recortado","crop.state_skipped": "Ignorado","crop.state_failed": "Falhou",+ "preset.hide": "Pixelizar / desfocar",+ "preset.hide.donut": "Pixelizar",+ "error.cannot_hide": "Só é possível pixelizar ou desfocar imagens",+ "hide.save": "Ocultar e guardar",+ "hide.save_next": "Ocultar e avançar",+ "hide.pixelate": "Pixelizar",+ "hide.pixelate_hint": "Cobrir com quadrados da cor média (P)",+ "hide.blur": "Desfocar",+ "hide.blur_hint": "Cobrir com uma desfocagem forte (B)",+ "hide.strength": "Intensidade",+ "hide.strength_value": "Intensidade {0} de 10 (− / +)",+ "hide.remove": "Remover moldura",+ "hide.remove_hint": "Remover a moldura selecionada (Del)",+ "hide.clear": "Remover todas",+ "hide.empty_hint": "Arraste sobre o que pretende ocultar",+ "hide.hint_keys": "Tab escolhe uma moldura, as teclas de direção movem-na, Shift × 10 · Del remove-a · Ctrl+Z anula · Esc fecha",+ "hide.state_done": "Concluído","preset.clip": "Cortar um excerto","clip.start": "Início","clip.end": "Fim",diff --git a/src/Filee.App/Assets/i18n/ru.json b/src/Filee.App/Assets/i18n/ru.jsonindex c6b23149..7be0da3f 100644--- a/src/Filee.App/Assets/i18n/ru.json+++ b/src/Filee.App/Assets/i18n/ru.json@@ -260,6 +260,23 @@"crop.state_done": "Обрезан","crop.state_skipped": "Пропущен","crop.state_failed": "Ошибка",+ "preset.hide": "Пикселизация / размытие",+ "preset.hide.donut": "Мозаика",+ "error.cannot_hide": "Пикселизировать и размывать можно только изображения",+ "hide.save": "Скрыть и сохранить",+ "hide.save_next": "Скрыть и дальше",+ "hide.pixelate": "Пикселизация",+ "hide.pixelate_hint": "Закрыть квадратами среднего цвета (P)",+ "hide.blur": "Размытие",+ "hide.blur_hint": "Закрыть сильным размытием (B)",+ "hide.strength": "Сила",+ "hide.strength_value": "Сила {0} из 10 (− / +)",+ "hide.remove": "Удалить рамку",+ "hide.remove_hint": "Удалить выбранную рамку (Del)",+ "hide.clear": "Удалить все",+ "hide.empty_hint": "Выделите мышью то, что нужно скрыть",+ "hide.hint_keys": "Tab — выбрать рамку · стрелки — двигать, Shift × 10 · Del — удалить · Ctrl+Z — отменить · Esc — закрыть",+ "hide.state_done": "Готово","preset.clip": "Вырезать клип","clip.start": "Начало","clip.end": "Конец",diff --git a/src/Filee.App/Assets/i18n/th.json b/src/Filee.App/Assets/i18n/th.jsonindex bd33fbba..c2d901e7 100644--- a/src/Filee.App/Assets/i18n/th.json+++ b/src/Filee.App/Assets/i18n/th.json@@ -251,6 +251,23 @@"crop.state_done": "ครอบตัดแล้ว","crop.state_skipped": "ข้ามแล้ว","crop.state_failed": "ล้มเหลว",+ "preset.hide": "โมเสก / เบลอ",+ "preset.hide.donut": "โมเสก",+ "error.cannot_hide": "ใส่โมเสกหรือเบลอได้เฉพาะไฟล์รูปภาพเท่านั้น",+ "hide.save": "ซ่อนและบันทึก",+ "hide.save_next": "ซ่อนและต่อไป",+ "hide.pixelate": "โมเสก",+ "hide.pixelate_hint": "ปิดด้วยช่องสี่เหลี่ยมสีเฉลี่ย (P)",+ "hide.blur": "เบลอ",+ "hide.blur_hint": "ปิดด้วยการเบลออย่างแรง (B)",+ "hide.strength": "ความแรง",+ "hide.strength_value": "ความแรง {0} / 10 (− / +)",+ "hide.remove": "ลบกรอบ",+ "hide.remove_hint": "ลบกรอบที่เลือก (Del)",+ "hide.clear": "ลบทั้งหมด",+ "hide.empty_hint": "ลากคลุมส่วนที่ต้องการซ่อน",+ "hide.hint_keys": "Tab เพื่อเลือกกรอบ, ปุ่มลูกศรเพื่อเลื่อน, Shift × 10 · Del เพื่อลบ · Ctrl+Z เพื่อเลิกทำ · Esc เพื่อปิด",+ "hide.state_done": "เสร็จแล้ว","preset.clip": "ตัดคลิป","clip.start": "เริ่ม","clip.end": "สิ้นสุด",diff --git a/src/Filee.App/Assets/i18n/tr.json b/src/Filee.App/Assets/i18n/tr.jsonindex 0a0ddf6c..73f14542 100644--- a/src/Filee.App/Assets/i18n/tr.json+++ b/src/Filee.App/Assets/i18n/tr.json@@ -251,6 +251,23 @@"crop.state_done": "Kırpıldı","crop.state_skipped": "Atlandı","crop.state_failed": "Başarısız",+ "preset.hide": "Pikselleştir / bulanıklaştır",+ "preset.hide.donut": "Mozaik",+ "error.cannot_hide": "Yalnızca görseller pikselleştirilebilir veya bulanıklaştırılabilir",+ "hide.save": "Gizle ve kaydet",+ "hide.save_next": "Gizle ve ilerle",+ "hide.pixelate": "Pikselleştir",+ "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.strength": "Güç",+ "hide.strength_value": "Güç {0} / 10 (− / +)",+ "hide.remove": "Çerçeveyi sil",+ "hide.remove_hint": "Seçili çerçeveyi sil (Del)",+ "hide.clear": "Tümünü sil",+ "hide.empty_hint": "Gizlemek istediğiniz yerin üzerine sürükleyin",+ "hide.hint_keys": "Tab çerçeve seçer, ok tuşları taşır, Shift × 10 · Del siler · Ctrl+Z geri alır · Esc kapatır",+ "hide.state_done": "Tamamlandı","preset.clip": "Klip kes","clip.start": "Başlangıç","clip.end": "Bitiş",diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.jsonindex 7f250fbd..72ba92d0 100644--- a/src/Filee.App/Assets/i18n/zh-CN.json+++ b/src/Filee.App/Assets/i18n/zh-CN.json@@ -260,6 +260,23 @@"crop.state_done": "已裁剪","crop.state_skipped": "已跳过","crop.state_failed": "失败",+ "preset.hide": "马赛克/模糊",+ "preset.hide.donut": "马赛克",+ "error.cannot_hide": "只能对图片打马赛克或模糊",+ "hide.save": "遮盖并保存",+ "hide.save_next": "遮盖并下一张",+ "hide.pixelate": "马赛克",+ "hide.pixelate_hint": "用平均色方块遮盖 (P)",+ "hide.blur": "模糊",+ "hide.blur_hint": "用强模糊遮盖 (B)",+ "hide.strength": "强度",+ "hide.strength_value": "强度 {0} / 10(− / +)",+ "hide.remove": "删除选框",+ "hide.remove_hint": "删除所选选框(Del)",+ "hide.clear": "全部清除",+ "hide.empty_hint": "拖动框选要隐藏的部分",+ "hide.hint_keys": "Tab 选择选框,方向键移动,Shift 为 10 倍 · Del 删除 · Ctrl+Z 撤销 · Esc 关闭",+ "hide.state_done": "完成","preset.clip": "剪切片段","clip.start": "开始","clip.end": "结束",diff --git a/src/Filee.App/Assets/i18n/zh-TW.json b/src/Filee.App/Assets/i18n/zh-TW.jsonindex 2d8f1978..76a52b46 100644--- a/src/Filee.App/Assets/i18n/zh-TW.json+++ b/src/Filee.App/Assets/i18n/zh-TW.json@@ -260,6 +260,23 @@"crop.state_done": "已裁剪","crop.state_skipped": "已跳過","crop.state_failed": "失敗",+ "preset.hide": "馬賽克/模糊",+ "preset.hide.donut": "馬賽克",+ "error.cannot_hide": "只能對圖片加上馬賽克或模糊",+ "hide.save": "遮蓋並儲存",+ "hide.save_next": "遮蓋並下一張",+ "hide.pixelate": "馬賽克",+ "hide.pixelate_hint": "以平均色方塊遮蓋 (P)",+ "hide.blur": "模糊",+ "hide.blur_hint": "以強烈模糊遮蓋 (B)",+ "hide.strength": "強度",+ "hide.strength_value": "強度 {0} / 10(− / +)",+ "hide.remove": "刪除選框",+ "hide.remove_hint": "刪除所選選框(Del)",+ "hide.clear": "全部清除",+ "hide.empty_hint": "拖曳框選要隱藏的部分",+ "hide.hint_keys": "Tab 選擇選框,方向鍵移動,Shift 為 10 倍 · Del 刪除 · Ctrl+Z 復原 · Esc 關閉",+ "hide.state_done": "完成","preset.clip": "剪輯片段","clip.start": "開始","clip.end": "結束",diff --git a/src/Filee.App/Controls/CropCanvas.cs b/src/Filee.App/Controls/CropCanvas.csindex 9b7cfad6..3b0f358b 100644--- a/src/Filee.App/Controls/CropCanvas.cs+++ b/src/Filee.App/Controls/CropCanvas.cs@@ -140,13 +140,13 @@ public sealed class CropCanvas : Controlprivate static readonly Cursor TopRightCursor = new(StandardCursorType.TopRightCorner);private static readonly Cursor CrossCursor = new(StandardCursorType.Cross);- private static readonly IPen FrameShadowPen = new Pen(new SolidColorBrush(Color.FromArgb(70, 0, 0, 0)), 4);+ internal static readonly IPen FrameShadowPen = new Pen(new SolidColorBrush(Color.FromArgb(70, 0, 0, 0)), 4);private static readonly IPen GridPen = new Pen(new SolidColorBrush(Color.FromArgb(170, 255, 255, 255)), 1);private static readonly IPen GridShadowPen = new Pen(new SolidColorBrush(Color.FromArgb(60, 0, 0, 0)), 1);private static readonly IPen HandleRingPen = new Pen(Brushes.White, 2.5);private static readonly IBrush HandleShadowBrush = new SolidColorBrush(Color.FromArgb(60, 0, 0, 0));- private static readonly BoxShadows PictureShadow = BoxShadows.Parse("0 10 30 0 #38000000");- private static readonly BoxShadows ChipShadow = BoxShadows.Parse("0 2 8 0 #26000000");+ internal static readonly BoxShadows PictureShadow = BoxShadows.Parse("0 10 30 0 #38000000");+ internal static readonly BoxShadows ChipShadow = BoxShadows.Parse("0 2 8 0 #26000000");private static double SafeClamp(double val, double min, double max) =>min > max ? Math.Clamp(val, max, min) : Math.Clamp(val, min, max);@@ -420,16 +420,18 @@ public sealed class CropCanvas : Controlprivate bool IsDark => ActualThemeVariant == ThemeVariant.Dark;- /// <summary>The backdrop: the page colour dimmed, with two soft glows of the accent colour.</summary>- private void DrawStage(DrawingContext context, Rect bounds)+ private void DrawStage(DrawingContext context, Rect bounds) => DrawStage(context, bounds, StageBrush, AccentBrush, IsDark);++ /// <summary>The backdrop: the page colour dimmed, with two soft glows of the accent colour (also the hide window's).</summary>+ internal static void DrawStage(DrawingContext context, Rect bounds, IBrush? stageBrush, IBrush? accentBrush, bool dark){- if (StageBrush is { } stage)+ if (stageBrush is { } stage)context.FillRectangle(stage, bounds);- context.FillRectangle(new SolidColorBrush(Colors.Black, IsDark ? 0.28 : 0.06), bounds);+ context.FillRectangle(new SolidColorBrush(Colors.Black, dark ? 0.28 : 0.06), bounds);- if (AccentBrush is ISolidColorBrush { Color: var accent })+ if (accentBrush is ISolidColorBrush { Color: var accent }){- var strength = IsDark ? 0.16 : 0.22;+ var strength = dark ? 0.16 : 0.22;Glow(context, accent, new Point(bounds.Width * 0.12, bounds.Height * 0.10), bounds.Width * 0.45, strength);Glow(context, accent, new Point(bounds.Width * 0.92, bounds.Height * 0.95), bounds.Width * 0.38, strength * 0.7);}@@ -499,18 +501,23 @@ public sealed class CropCanvas : Controlif ((horizontal ? crop.Width : crop.Height) < 90)continue;var grow = handle == _poppedHandle ? pop : 0;- var length = 22 + 8 * grow;- const double thickness = 7;- var c = HandlePoint(crop, handle);- var rect = horizontal- ? new Rect(c.X - length / 2, c.Y - thickness / 2, length, thickness)- : new Rect(c.X - thickness / 2, c.Y - length / 2, thickness, length);- context.DrawRectangle(HandleShadowBrush, null, new RoundedRect(rect.Translate(new Vector(0, 1)).Inflate(1.5), thickness));- context.DrawRectangle(accent, HandleRingPen, new RoundedRect(rect, thickness / 2));+ DrawPill(context, accent, HandlePoint(crop, handle), horizontal, 22 + 8 * grow);}}- private static void DrawDot(DrawingContext context, IBrush accent, Point center, double radius)+ /// <summary>A handle on the middle of an edge: a pill in the accent colour with a white ring.</summary>+ internal static void DrawPill(DrawingContext context, IBrush accent, Point c, bool horizontal, double length)+ {+ const double thickness = 7;+ var rect = horizontal+ ? new Rect(c.X - length / 2, c.Y - thickness / 2, length, thickness)+ : new Rect(c.X - thickness / 2, c.Y - length / 2, thickness, length);+ context.DrawRectangle(HandleShadowBrush, null, new RoundedRect(rect.Translate(new Vector(0, 1)).Inflate(1.5), thickness));+ context.DrawRectangle(accent, HandleRingPen, new RoundedRect(rect, thickness / 2));+ }++ /// <summary>A corner handle: a dot in the accent colour with a white ring.</summary>+ internal static void DrawDot(DrawingContext context, IBrush accent, Point center, double radius){context.DrawEllipse(HandleShadowBrush, null, center + new Vector(0, 1), radius + 2, radius + 2);context.DrawEllipse(accent, HandleRingPen, center, radius, radius);@@ -562,12 +569,12 @@ public sealed class CropCanvas : Control/// </summary>internal static Func<long> Clock { get; set; } = Stopwatch.GetTimestamp;- private static long Now() => Clock();+ internal static long Now() => Clock();- private static double EaseOutCubic(double t) => 1 - Math.Pow(1 - Math.Clamp(t, 0, 1), 3);+ internal static double EaseOutCubic(double t) => 1 - Math.Pow(1 - Math.Clamp(t, 0, 1), 3);/// <summary>Overshoots a little before settling: the "squishy" grow of a handle.</summary>- private static double EaseOutBack(double t)+ internal static double EaseOutBack(double t){t = Math.Clamp(t, 0, 1);const double s = 1.9;@@ -624,7 +631,7 @@ public sealed class CropCanvas : Control}/// <summary>A value easing from <see cref="From"/> to <see cref="To"/> over a time, read against the clock.</summary>- private readonly record struct Tween(double From, double To, long Start, double Seconds)+ internal readonly record struct Tween(double From, double To, long Start, double Seconds){public static Tween Done(double value) => new(value, value, 0, 0);diff --git a/src/Filee.App/Controls/HideAreaSet.cs b/src/Filee.App/Controls/HideAreaSet.csnew file mode 100644index 00000000..eea6b497--- /dev/null+++ b/src/Filee.App/Controls/HideAreaSet.cs@@ -0,0 +1,205 @@+// 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+// keys move and remove them, the window's view model turns them into the conversion.++using Avalonia;++namespace Filee.App.Controls;++public sealed class HideAreaSet+{+ /// <summary>Most parts one picture takes: more are a slip of the hand, not something to hide.</summary>+ public const int MaxAreas = 100;++ /// <summary>Undo steps kept.</summary>+ private const int MaxUndo = 100;++ private readonly List<Rect> _areas = [];+ 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);++ /// <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>The selected frame, -1 for none.</summary>+ public int Selected { get; private set; } = -1;++ public Rect? SelectedArea => Selected >= 0 ? _areas[Selected] : null;+ public int Count => _areas.Count;+ public bool CanUndo => _undo.Count > 0;+ public bool CanRedo => _redo.Count > 0;++ /// <summary>Something changed: the frames, the selection or what can be undone.</summary>+ public event Action? Changed;++ /// <summary>A drag starts: what it does until <see cref="End"/> is undone in one step.</summary>+ public void Begin() => _gesture ??= Take();++ /// <summary>The drag ends: one undo step when it changed the frames.</summary>+ public void End()+ {+ if (_gesture is not { } before)+ return;+ _gesture = null;+ if (!before.Areas.SequenceEqual(_areas))+ 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)+ {+ if (_areas.Count >= MaxAreas)+ return false;+ Record();+ _areas.Add(Fit(area));+ Selected = _areas.Count - 1;+ Changed?.Invoke();+ return true;+ }++ /// <summary>Moves or sizes frame <paramref name="index"/> (a drag; see <see cref="Begin"/>).</summary>+ public void Set(int index, Rect area)+ {+ if (index < 0 || index >= _areas.Count)+ return;+ var fitted = Fit(area);+ if (_areas[index] == fitted)+ return;+ Record();+ _areas[index] = fitted;+ Changed?.Invoke();+ }++ public void Select(int index)+ {+ index = index >= 0 && index < _areas.Count ? index : -1;+ if (index == Selected)+ return;+ Selected = index;+ Changed?.Invoke();+ }++ /// <summary>+ /// The next (or previous) frame in the order they were drawn, round and round: from none, the first (or the last).+ /// </summary>+ public void SelectNext(int step)+ {+ if (_areas.Count == 0)+ return;+ Select(Selected < 0+ ? (step >= 0 ? 0 : _areas.Count - 1)+ : ((Selected + step) % _areas.Count + _areas.Count) % _areas.Count);+ }++ /// <summary>Removes the selected frame; the one drawn before it is selected next. False when none is selected.</summary>+ public bool RemoveSelected()+ {+ if (Selected < 0)+ return false;+ Record();+ _areas.RemoveAt(Selected);+ Selected = _areas.Count == 0 ? -1 : Math.Max(0, Selected - 1);+ Changed?.Invoke();+ return true;+ }++ /// <summary>Removes every frame (undoable).</summary>+ public void Clear()+ {+ if (_areas.Count == 0)+ return;+ Record();+ _areas.Clear();+ Selected = -1;+ Changed?.Invoke();+ }++ /// <summary>Moves the selected frame by whole pixels of a <paramref name="width"/> × <paramref name="height"/> picture.</summary>+ public void Nudge(int dx, int dy, int width, int height)+ {+ if (Selected < 0)+ return;+ Set(Selected, CropMath.Nudge(_areas[Selected], dx, dy, width, height));+ }++ /// <summary>+ /// Starts over with <paramref name="areas"/> (a new picture: the last one's frames carry on), none selected and+ /// nothing to undo.+ /// </summary>+ public void Reset(IEnumerable<Rect> areas)+ {+ _gesture = null;+ _areas.Clear();+ _areas.AddRange(areas.Select(Fit).Take(MaxAreas));+ _undo.Clear();+ _redo.Clear();+ Selected = -1;+ Changed?.Invoke();+ }++ public void Undo() => Step(_undo, _redo);++ public void Redo() => Step(_redo, _undo);++ /// <summary>+ /// The frame on top under <paramref name="point"/> (in parts of the picture), -1 for none; the selected one first, so+ /// a frame drawn over it later doesn't take it away while it is being worked on.+ /// </summary>+ public int HitTest(Point point)+ {+ if (Selected >= 0 && _areas[Selected].Contains(point))+ return Selected;+ for (var i = _areas.Count - 1; i >= 0; i--)+ {+ if (_areas[i].Contains(point))+ return i;+ }+ return -1;+ }++ private void Step(List<Snapshot> from, List<Snapshot> to)+ {+ if (from.Count == 0 || _gesture is not null)+ return;+ var snapshot = from[^1];+ from.RemoveAt(from.Count - 1);+ to.Add(Take());+ _areas.Clear();+ _areas.AddRange(snapshot.Areas);+ Selected = Math.Min(snapshot.Selected, _areas.Count - 1);+ Changed?.Invoke();+ }++ /// <summary>An undo step for a change made now, unless a drag records one for itself.</summary>+ private void Record()+ {+ if (_gesture is null)+ Push(Take());+ }++ private void Push(Snapshot snapshot)+ {+ _undo.Add(snapshot);+ if (_undo.Count > MaxUndo)+ _undo.RemoveAt(0);+ _redo.Clear();+ }++ private Snapshot Take() => new([.. _areas], Selected);++ /// <summary>The frame inside the picture.</summary>+ private static Rect Fit(Rect area)+ {+ var left = Math.Clamp(Math.Min(area.Left, area.Right), 0, 1);+ var top = Math.Clamp(Math.Min(area.Top, area.Bottom), 0, 1);+ var right = Math.Clamp(Math.Max(area.Left, area.Right), left, 1);+ var bottom = Math.Clamp(Math.Max(area.Top, area.Bottom), top, 1);+ return new Rect(left, top, right - left, bottom - top);+ }+}diff --git a/src/Filee.App/Controls/HideCanvas.cs b/src/Filee.App/Controls/HideCanvas.csnew file mode 100644index 00000000..89a69418--- /dev/null+++ b/src/Filee.App/Controls/HideCanvas.cs@@ -0,0 +1,644 @@+// The "Pixelate / blur" window's stage, drawn as the crop overlay's: the picture on the dimmed backdrop with soft accent+// glows, and over it the frames of the parts to hide, each already showing the picture pixelated or blurred inside it+// (a copy of the whole preview covered once per choice, drawn clipped to the frames, so drawing and dragging cost+// nothing). The selected frame has the crop frame's accent outline, round corner handles and edge pills, and a size chip;+// the others a thinner, lighter accent outline that turns full under the pointer. Dragging on the picture draws a new+// frame, dragging a frame moves it (snapping to the picture's centre lines), its handles size it, the wheel grows or+// shrinks it.++using System.Globalization;+using Avalonia;+using Avalonia.Controls;+using Avalonia.Controls.Documents;+using Avalonia.Input;+using Avalonia.Media;+using Avalonia.Media.Imaging;+using Avalonia.Styling;+using static Filee.App.Controls.CropCanvas;++namespace Filee.App.Controls;++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>+ public static readonly StyledProperty<Bitmap?> CoverImageProperty =+ AvaloniaProperty.Register<HideCanvas, Bitmap?>(nameof(CoverImage));++ public static readonly StyledProperty<HideAreaSet?> AreasProperty =+ AvaloniaProperty.Register<HideCanvas, HideAreaSet?>(nameof(Areas));++ /// <summary>Room kept free around the picture for the floating chips and the toolbar.</summary>+ public static readonly StyledProperty<Thickness> ImagePaddingProperty =+ AvaloniaProperty.Register<HideCanvas, Thickness>(nameof(ImagePadding));++ /// <summary>The picture's size in pixels: the size chip, and arrow keys move frames by whole pixels of it.</summary>+ public static readonly StyledProperty<PixelSize> PixelSizeProperty =+ AvaloniaProperty.Register<HideCanvas, PixelSize>(nameof(PixelSize));++ public static readonly StyledProperty<IBrush?> AccentBrushProperty =+ AvaloniaProperty.Register<HideCanvas, IBrush?>(nameof(AccentBrush), Brushes.MediumPurple);++ public static readonly StyledProperty<IBrush?> StageBrushProperty =+ AvaloniaProperty.Register<HideCanvas, IBrush?>(nameof(StageBrush));++ public static readonly StyledProperty<IBrush?> ChipBackgroundProperty =+ AvaloniaProperty.Register<HideCanvas, IBrush?>(nameof(ChipBackground), Brushes.White);++ public static readonly StyledProperty<IBrush?> ChipForegroundProperty =+ AvaloniaProperty.Register<HideCanvas, IBrush?>(nameof(ChipForeground), Brushes.Black);++ /// <summary>False with reduced motion: every change shows at once.</summary>+ public static readonly StyledProperty<bool> PlayAnimationsProperty =+ AvaloniaProperty.Register<HideCanvas, bool>(nameof(PlayAnimations), true);++ public Bitmap? SourceImage { get => GetValue(SourceImageProperty); set => SetValue(SourceImageProperty, value); }+ public Bitmap? CoverImage { get => GetValue(CoverImageProperty); set => SetValue(CoverImageProperty, 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); }+ public IBrush? AccentBrush { get => GetValue(AccentBrushProperty); set => SetValue(AccentBrushProperty, value); }+ public IBrush? StageBrush { get => GetValue(StageBrushProperty); set => SetValue(StageBrushProperty, value); }+ public IBrush? ChipBackground { get => GetValue(ChipBackgroundProperty); set => SetValue(ChipBackgroundProperty, value); }+ public IBrush? ChipForeground { get => GetValue(ChipForegroundProperty); set => SetValue(ChipForegroundProperty, value); }+ public bool PlayAnimations { get => GetValue(PlayAnimationsProperty); set => SetValue(PlayAnimationsProperty, value); }++ /// <summary>The smallest frame a drag makes or a handle leaves, in screen pixels.</summary>+ private const double MinSizePx = 6;++ /// <summary>How far the pointer has to move before a press on the picture becomes a new frame (else it is a click).</summary>+ private const double DragThreshold = 4;++ private enum Drag+ {+ None,+ Pending,+ New,+ Body,+ TopLeft,+ Top,+ TopRight,+ Right,+ BottomRight,+ Bottom,+ BottomLeft,+ Left,+ }++ private Drag _drag = Drag.None;+ private int _dragIndex = -1;+ private Point _dragStartPoint;+ private Rect _dragStartFrame; // on screen+ private bool _snappedX, _snappedY;+ private int _hoverIndex = -1;+ private Drag _hoverHandle = Drag.None;++ // ───── Motion (the crop overlay's) ─────++ private const double AppearSeconds = 0.42; // a new picture+ private const double HandleSeconds = 0.26;+ private Tween _appear = Tween.Done(1);+ private Tween _handlePop = Tween.Done(0);+ private Drag _poppedHandle = Drag.None;+ private bool _looping;++ private Bitmap? _soft; // a tiny copy: the frames' fill until the covered copy is ready+ private FormattedText? _chipText;+ private string? _chipTextFor;+ private IBrush? _chipTextBrush;++ private static readonly Cursor ArrowCursor = new(StandardCursorType.Arrow);+ private static readonly Cursor SizeAllCursor = new(StandardCursorType.SizeAll);+ private static readonly Cursor SizeNorthSouthCursor = new(StandardCursorType.SizeNorthSouth);+ private static readonly Cursor SizeWestEastCursor = new(StandardCursorType.SizeWestEast);+ private static readonly Cursor TopLeftCursor = new(StandardCursorType.TopLeftCorner);+ private static readonly Cursor TopRightCursor = new(StandardCursorType.TopRightCorner);+ private static readonly Cursor CrossCursor = new(StandardCursorType.Cross);++++ static HideCanvas()+ {+ AffectsRender<HideCanvas>(SourceImageProperty, CoverImageProperty, ImagePaddingProperty, AccentBrushProperty,+ StageBrushProperty, ChipBackgroundProperty, ChipForegroundProperty, PixelSizeProperty);+ FocusableProperty.OverrideDefaultValue<HideCanvas>(false);+ }++ // The picture is never mirrored, also in a right-to-left UI.+ public HideCanvas() => FlowDirection = FlowDirection.LeftToRight;++ /// <summary>The picture's place: as large as fits inside <see cref="ImagePadding"/>, centred.</summary>+ public Rect CalculateImageBounds()+ {+ if (SourceImage is null || Bounds.Width <= 0 || Bounds.Height <= 0)+ return default;+ var area = new Rect(Bounds.Size).Deflate(ImagePadding);+ if (area.Width <= 0 || area.Height <= 0)+ area = new Rect(Bounds.Size);+ var size = SourceImage.Size;+ var scale = Math.Min(area.Width / size.Width, area.Height / size.Height);+ var w = size.Width * scale;+ var h = size.Height * scale;+ return new Rect(area.X + (area.Width - w) / 2, area.Y + (area.Height - h) / 2, w, h);+ }++ /// <summary>A frame (in parts of the picture) on screen.</summary>+ public static Rect ToScreen(Rect area, Rect picture) => new(+ picture.X + area.X * picture.Width, picture.Y + area.Y * picture.Height,+ area.Width * picture.Width, area.Height * picture.Height);++ private static Rect ToPicture(Rect screen, Rect picture) => new(+ (screen.X - picture.X) / picture.Width, (screen.Y - picture.Y) / picture.Height,+ screen.Width / picture.Width, screen.Height / picture.Height);++ /// <summary>Ends every running animation (tests capture the settled picture).</summary>+ internal void FinishAnimations()+ {+ _appear = Tween.Done(1);+ _handlePop = Tween.Done(_handlePop.To);+ InvalidateVisual();+ }++ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)+ {+ if (change.Property == AreasProperty)+ {+ if (change.GetOldValue<HideAreaSet?>() is { } old)+ old.Changed -= OnAreasChanged;+ if (change.GetNewValue<HideAreaSet?>() is { } areas)+ areas.Changed += OnAreasChanged;+ InvalidateVisual();+ }+ else if (change.Property == SourceImageProperty)+ {+ _soft?.Dispose();+ _soft = Soften(change.GetNewValue<Bitmap?>());+ CancelDrag();+ if (change.GetNewValue<Bitmap?>() is not null && PlayAnimations)+ {+ _appear = Tween.Begin(0, 1, AppearSeconds);+ StartLoop();+ }+ else+ {+ _appear = Tween.Done(1);+ }+ }+ else if (change.Property == PlayAnimationsProperty && !change.GetNewValue<bool>())+ {+ FinishAnimations();+ }+ base.OnPropertyChanged(change);+ }++ private void OnAreasChanged() => InvalidateVisual();++ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)+ {+ base.OnAttachedToVisualTree(e);+ _soft ??= Soften(SourceImage);+ }++ protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)+ {+ base.OnDetachedFromVisualTree(e);+ _soft?.Dispose();+ _soft = null;+ }++ /// <summary>A copy at most 24 px across: drawn as large as the picture it is a soft blur, at no cost per frame.</summary>+ private static Bitmap? Soften(Bitmap? source)+ {+ if (source is null)+ return null;+ try+ {+ var size = source.PixelSize;+ var scale = Math.Min(1, 24.0 / Math.Max(size.Width, size.Height));+ var target = new PixelSize(Math.Max(1, (int)Math.Round(size.Width * scale)), Math.Max(1, (int)Math.Round(size.Height * scale)));+ return source.CreateScaledBitmap(target, BitmapInterpolationMode.HighQuality);+ }+ catch (Exception ex) when (ex is not OutOfMemoryException)+ {+ return null;+ }+ }++ // ───────────────────────── Drawing ─────────────────────────++ private bool IsDark => ActualThemeVariant == ThemeVariant.Dark;++ public override void Render(DrawingContext context)+ {+ base.Render(context);+ var now = CropCanvas.Now();+ var bounds = new Rect(Bounds.Size);+ CropCanvas.DrawStage(context, bounds, StageBrush, AccentBrush, IsDark);++ var picture = CalculateImageBounds();+ if (SourceImage is null || picture.Width <= 0 || picture.Height <= 0)+ return;++ // A new picture settles in: a little smaller and transparent at first.+ var appear = EaseOutCubic(_appear.Value(now));+ var scale = 0.965 + 0.035 * appear;+ var center = picture.Center;+ using var appearing = context.PushTransform(+ Matrix.CreateTranslation(-center.X, -center.Y) * Matrix.CreateScale(scale, scale) * Matrix.CreateTranslation(center.X, center.Y));+ using var fading = context.PushOpacity(appear);++ context.DrawRectangle(StageBrush ?? Brushes.Gray, null, new RoundedRect(picture), PictureShadow);+ using (context.PushRenderOptions(new RenderOptions { BitmapInterpolationMode = BitmapInterpolationMode.HighQuality }))+ context.DrawImage(SourceImage, new Rect(SourceImage.Size), picture);++ 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;+ 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)+ continue;+ using (context.PushClip(frame))+ using (context.PushRenderOptions(new RenderOptions+ {+ BitmapInterpolationMode = CoverImage is null ? BitmapInterpolationMode.HighQuality : BitmapInterpolationMode.MediumQuality,+ }))+ context.DrawImage(cover, new Rect(cover.Size), picture);+ }++ var accent = AccentBrush ?? Brushes.MediumPurple;+ for (var i = 0; i < areas.Count; i++)+ {+ if (i == areas.Selected)+ continue;+ var frame = Snap(ToScreen(areas.Areas[i], picture));+ if (i == _hoverIndex && _drag == Drag.None)+ {+ context.DrawRectangle(null, FrameShadowPen, frame);+ context.DrawRectangle(null, new Pen(accent, 2), frame);+ }+ else+ {+ using (context.PushOpacity(0.75))+ context.DrawRectangle(null, new Pen(accent, 1.5), frame);+ }+ }++ DrawCentreGuides(context, picture, accent);+ if (areas.SelectedArea is { } selected)+ {+ var frame = ToScreen(selected, picture);+ DrawSelected(context, frame, accent, now);+ DrawSizeChip(context, frame, selected, picture, bounds);+ }+ }++ /// <summary>A frame on whole screen pixels, so its outline stays sharp.</summary>+ private static Rect Snap(Rect frame) =>+ new(Math.Round(frame.X), Math.Round(frame.Y), Math.Max(1, Math.Round(frame.Width)), Math.Max(1, Math.Round(frame.Height)));++ private void DrawSelected(DrawingContext context, Rect frame, IBrush accent, long now)+ {+ context.DrawRectangle(null, FrameShadowPen, frame);+ context.DrawRectangle(null, new Pen(accent, 2), frame);++ var pop = EaseOutBack(_handlePop.Value(now));+ // Smaller dots on a small frame, so they don't cover it.+ var dot = Math.Clamp(Math.Min(frame.Width, frame.Height) / 4, 3.5, 6.5);+ foreach (var handle in new[] { Drag.TopLeft, Drag.TopRight, Drag.BottomRight, Drag.BottomLeft })+ {+ var grow = handle == _poppedHandle ? pop : 0;+ DrawDot(context, accent, HandlePoint(frame, handle), dot + 2.5 * grow);+ }+ foreach (var handle in new[] { Drag.Top, Drag.Right, Drag.Bottom, Drag.Left })+ {+ var horizontal = handle is Drag.Top or Drag.Bottom;+ if ((horizontal ? frame.Width : frame.Height) < 90)+ continue;+ var grow = handle == _poppedHandle ? pop : 0;+ DrawPill(context, accent, HandlePoint(frame, handle), horizontal, 22 + 8 * grow);+ }+ }++ private void DrawCentreGuides(DrawingContext context, Rect picture, IBrush accent)+ {+ if (_drag != Drag.Body || !(_snappedX || _snappedY))+ return;+ var pen = new Pen(accent, 1, DashStyle.Dash);+ var x = Math.Round(picture.Center.X) + 0.5;+ var y = Math.Round(picture.Center.Y) + 0.5;+ if (_snappedX)+ context.DrawLine(pen, new Point(x, picture.Top), new Point(x, picture.Bottom));+ if (_snappedY)+ context.DrawLine(pen, new Point(picture.Left, y), new Point(picture.Right, y));+ }++ /// <summary>How far below the picture the size chip may go (the toolbar starts further down).</summary>+ private const double ChipReach = 40;++ private void DrawSizeChip(DrawingContext context, Rect frame, Rect area, Rect picture, Rect bounds)+ {+ var pixels = PixelSize;+ if (pixels.Width <= 0 || pixels.Height <= 0)+ return;+ var size = CropMath.PixelSize(area, pixels.Width, pixels.Height);+ var text = $"{size.Width} × {size.Height} px";+ var foreground = ChipForeground ?? Brushes.Black;+ if (_chipText is null || _chipTextFor != text || !ReferenceEquals(_chipTextBrush, foreground))+ {+ var typeface = new Typeface(GetValue(TextElement.FontFamilyProperty), FontStyle.Normal, FontWeight.SemiBold);+ _chipText = new FormattedText(text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeface, 11.5, foreground);+ _chipTextFor = text;+ _chipTextBrush = foreground;+ }+ var chip = new Size(Math.Ceiling(_chipText.Width) + 20, Math.Ceiling(_chipText.Height) + 8);+ var room = new Rect(picture.Left, picture.Top, picture.Width, picture.Height + ChipReach).Intersect(bounds.Deflate(6));+ var origin = CropMath.SizeChipOrigin(frame, chip, room);+ context.DrawRectangle(ChipBackground, null, new RoundedRect(new Rect(origin, chip), chip.Height / 2), ChipShadow);+ context.DrawText(_chipText, new Point(origin.X + 10, origin.Y + 4));+ }++ private static Point HandlePoint(Rect frame, Drag handle) => handle switch+ {+ Drag.TopLeft => frame.TopLeft,+ Drag.TopRight => frame.TopRight,+ Drag.BottomRight => frame.BottomRight,+ Drag.BottomLeft => frame.BottomLeft,+ Drag.Top => new Point(frame.Center.X, frame.Top),+ Drag.Bottom => new Point(frame.Center.X, frame.Bottom),+ Drag.Left => new Point(frame.Left, frame.Center.Y),+ Drag.Right => new Point(frame.Right, frame.Center.Y),+ _ => frame.Center,+ };++ // ───────────────────────── Motion ─────────────────────────++ private void PopHandle(Drag handle)+ {+ if (handle is Drag.None or Drag.Pending or Drag.New or Drag.Body)+ handle = Drag.None;+ if (handle == _poppedHandle)+ return;+ _poppedHandle = handle;+ _handlePop = handle == Drag.None || !PlayAnimations+ ? Tween.Done(handle == Drag.None ? 0 : 1)+ : Tween.Begin(0, 1, HandleSeconds);+ StartLoop();+ }++ private void StartLoop()+ {+ InvalidateVisual();+ if (_looping || TopLevel.GetTopLevel(this) is not { } top)+ return;+ _looping = true;+ top.RequestAnimationFrame(OnFrame);+ }++ private void OnFrame(TimeSpan _)+ {+ InvalidateVisual();+ var now = CropCanvas.Now();+ if ((_appear.IsRunning(now) || _handlePop.IsRunning(now)) && TopLevel.GetTopLevel(this) is { } top)+ {+ top.RequestAnimationFrame(OnFrame);+ return;+ }+ _looping = false;+ }++ // ───────────────────────── Pointer ─────────────────────────++ /// <summary>What a press at <paramref name="point"/> would drag, and which frame.</summary>+ private (Drag Drag, int Index) HitTest(Point point, Rect picture)+ {+ if (Areas is not { } areas || picture.Width <= 0 || picture.Height <= 0)+ return (Drag.None, -1);+ if (areas.SelectedArea is { } selected)+ {+ var frame = ToScreen(selected, picture);+ // A small frame keeps room in its middle for moving it.+ var tolerance = Math.Clamp(Math.Min(frame.Width, frame.Height) / 3, 5, 14);+ foreach (var corner in new[] { Drag.TopLeft, Drag.TopRight, Drag.BottomLeft, Drag.BottomRight })+ {+ if (Distance(point, HandlePoint(frame, corner)) <= tolerance)+ return (corner, areas.Selected);+ }+ var alongX = point.X >= frame.Left && point.X <= frame.Right;+ var alongY = point.Y >= frame.Top && point.Y <= frame.Bottom;+ if (alongX && Math.Abs(point.Y - frame.Top) <= tolerance) return (Drag.Top, areas.Selected);+ if (alongX && Math.Abs(point.Y - frame.Bottom) <= tolerance) return (Drag.Bottom, areas.Selected);+ if (alongY && Math.Abs(point.X - frame.Left) <= tolerance) return (Drag.Left, areas.Selected);+ if (alongY && Math.Abs(point.X - frame.Right) <= tolerance) return (Drag.Right, areas.Selected);+ }+ var index = areas.HitTest(ToPicture(new Rect(point, new Size(0, 0)), picture).TopLeft);+ if (index >= 0)+ return (Drag.Body, index);+ return picture.Contains(point) ? (Drag.Pending, -1) : (Drag.None, -1);+ }++ private static double Distance(Point a, Point b) => Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2));++ private static Cursor CursorFor(Drag drag) => drag switch+ {+ Drag.TopLeft or Drag.BottomRight => TopLeftCursor,+ Drag.TopRight or Drag.BottomLeft => TopRightCursor,+ Drag.Top or Drag.Bottom => SizeNorthSouthCursor,+ Drag.Left or Drag.Right => SizeWestEastCursor,+ Drag.Body => SizeAllCursor,+ Drag.Pending or Drag.New => CrossCursor,+ _ => ArrowCursor,+ };++ protected override void OnPointerExited(PointerEventArgs e)+ {+ base.OnPointerExited(e);+ if (_drag != Drag.None)+ return;+ _hoverHandle = Drag.None;+ _hoverIndex = -1;+ PopHandle(Drag.None);+ }++ protected override void OnPointerPressed(PointerPressedEventArgs e)+ {+ base.OnPointerPressed(e);+ var picture = CalculateImageBounds();+ if (Areas is not { } areas || !e.GetCurrentPoint(this).Properties.IsLeftButtonPressed || picture.Width <= 0)+ return;+ var point = e.GetPosition(this);+ var (drag, index) = HitTest(point, picture);+ if (drag == Drag.None)+ return;++ _drag = drag;+ _dragIndex = index;+ _dragStartPoint = point;+ _snappedX = _snappedY = false;+ if (index >= 0)+ {+ areas.Select(index);+ _dragStartFrame = ToScreen(areas.Areas[index], picture);+ areas.Begin();+ }+ e.Pointer.Capture(this);+ e.Handled = true;+ PopHandle(drag);+ }++ protected override void OnPointerMoved(PointerEventArgs e)+ {+ base.OnPointerMoved(e);+ var picture = CalculateImageBounds();+ if (Areas is not { } areas || picture.Width <= 0 || picture.Height <= 0)+ return;+ var point = e.GetPosition(this);++ if (_drag == Drag.None)+ {+ var (hover, index) = HitTest(point, picture);+ Cursor = CursorFor(hover);+ if (index != _hoverIndex)+ {+ _hoverIndex = index;+ InvalidateVisual();+ }+ _hoverHandle = hover;+ PopHandle(hover);+ return;+ }++ var start = Clamp(_dragStartPoint, picture);+ var at = Clamp(point, picture);+ switch (_drag)+ {+ case Drag.Pending:+ if (Distance(point, _dragStartPoint) < DragThreshold)+ return;+ areas.Begin();+ if (!areas.Add(ToPicture(FrameBetween(start, at, picture), picture)))+ {+ areas.End();+ _drag = Drag.None;+ return;+ }+ _drag = Drag.New;+ _dragIndex = areas.Selected;+ break;+ case Drag.New:+ areas.Set(_dragIndex, ToPicture(FrameBetween(start, at, picture), picture));+ break;+ case Drag.Body:+ {+ var x = SafeClamp(_dragStartFrame.X + point.X - _dragStartPoint.X, picture.Left, picture.Right - _dragStartFrame.Width);+ var y = SafeClamp(_dragStartFrame.Y + point.Y - _dragStartPoint.Y, picture.Top, picture.Bottom - _dragStartFrame.Height);+ (x, _snappedX) = CropMath.SnapToCentre(x, _dragStartFrame.Width, picture.Left, picture.Right);+ (y, _snappedY) = CropMath.SnapToCentre(y, _dragStartFrame.Height, picture.Top, picture.Bottom);+ var moved = new Rect(x, y, _dragStartFrame.Width, _dragStartFrame.Height);+ // Kept at its size in parts of the picture: rounding on the way to the screen and back must not resize it.+ var old = areas.Areas[_dragIndex];+ var next = ToPicture(moved, picture);+ areas.Set(_dragIndex, new Rect(next.X, next.Y, old.Width, old.Height));+ break;+ }+ default:+ areas.Set(_dragIndex, ToPicture(Resize(_drag, _dragStartFrame, point - _dragStartPoint, picture), picture));+ break;+ }+ }++ protected override void OnPointerReleased(PointerReleasedEventArgs e)+ {+ base.OnPointerReleased(e);+ if (_drag == Drag.None)+ return;+ // A click on the picture beside every frame: nothing selected.+ if (_drag == Drag.Pending)+ Areas?.Select(-1);+ EndDrag();+ e.Pointer.Capture(null);+ e.Handled = true;+ PopHandle(_hoverHandle);+ }++ protected override void OnPointerCaptureLost(PointerCaptureLostEventArgs e)+ {+ base.OnPointerCaptureLost(e);+ if (_drag != Drag.None)+ {+ EndDrag();+ PopHandle(Drag.None);+ }+ }++ private void EndDrag()+ {+ var wasDragging = _drag is not (Drag.None or Drag.Pending);+ _drag = Drag.None;+ _dragIndex = -1;+ _snappedX = _snappedY = false;+ if (wasDragging)+ Areas?.End();+ InvalidateVisual();+ }++ private void CancelDrag()+ {+ if (_drag != Drag.None)+ EndDrag();+ _hoverIndex = -1;+ }++ /// <summary>The wheel grows or shrinks the selected frame about its centre.</summary>+ protected override void OnPointerWheelChanged(PointerWheelEventArgs e)+ {+ base.OnPointerWheelChanged(e);+ var picture = CalculateImageBounds();+ if (Areas is not { SelectedArea: { } selected } areas || picture.Width <= 0 || Math.Abs(e.Delta.Y) < 0.001 || _drag != Drag.None)+ return;+ var frame = ToScreen(selected, picture);+ var factor = e.Delta.Y > 0 ? 1.05 : 0.95;+ var w = SafeClamp(frame.Width * factor, MinSizePx, picture.Width);+ var h = SafeClamp(frame.Height * factor, MinSizePx, picture.Height);+ var x = SafeClamp(frame.Center.X - w / 2, picture.Left, picture.Right - w);+ var y = SafeClamp(frame.Center.Y - h / 2, picture.Top, picture.Bottom - h);+ areas.Set(areas.Selected, ToPicture(new Rect(x, y, w, h), picture));+ e.Handled = true;+ }++ private static Point Clamp(Point point, Rect picture) =>+ new(Math.Clamp(point.X, picture.Left, picture.Right), Math.Clamp(point.Y, picture.Top, picture.Bottom));++ private static double SafeClamp(double value, double min, double max) =>+ min > max ? Math.Clamp(value, max, min) : Math.Clamp(value, min, max);++ /// <summary>The frame between where a drag began and the pointer, at least <see cref="MinSizePx"/>, on the picture.</summary>+ private static Rect FrameBetween(Point a, Point b, Rect picture)+ {+ var w = Math.Max(MinSizePx, Math.Abs(b.X - a.X));+ var h = Math.Max(MinSizePx, Math.Abs(b.Y - a.Y));+ var x = SafeClamp(b.X < a.X ? a.X - w : a.X, picture.Left, picture.Right - w);+ var y = SafeClamp(b.Y < a.Y ? a.Y - h : a.Y, picture.Top, picture.Bottom - h);+ return new Rect(x, y, w, h);+ }++ /// <summary>A frame sized by one of its handles, its other sides staying put, within the picture.</summary>+ private static Rect Resize(Drag handle, Rect start, Vector delta, Rect picture)+ {+ double left = start.Left, top = start.Top, right = start.Right, bottom = start.Bottom;+ if (handle is Drag.TopLeft or Drag.Left or Drag.BottomLeft)+ left = SafeClamp(start.Left + delta.X, picture.Left, right - MinSizePx);+ if (handle is Drag.TopRight or Drag.Right or Drag.BottomRight)+ right = SafeClamp(start.Right + delta.X, left + MinSizePx, picture.Right);+ if (handle is Drag.TopLeft or Drag.Top or Drag.TopRight)+ top = SafeClamp(start.Top + delta.Y, picture.Top, bottom - MinSizePx);+ if (handle is Drag.BottomLeft or Drag.Bottom or Drag.BottomRight)+ bottom = SafeClamp(start.Bottom + delta.Y, top + MinSizePx, picture.Bottom);+ return new Rect(left, top, right - left, bottom - top);+ }+}diff --git a/src/Filee.App/Services/HideService.cs b/src/Filee.App/Services/HideService.csnew file mode 100644index 00000000..022c0735--- /dev/null+++ b/src/Filee.App/Services/HideService.cs@@ -0,0 +1,93 @@+// Pictures for the "Pixelate / blur" window: the preview, read as the image engine reads the file (so the frames land on+// the picture the conversion covers), and copies of it pixelated or blurred as chosen, which the frames show.++using System.Runtime.InteropServices;+using Avalonia;+using Avalonia.Media.Imaging;+using Avalonia.Platform;+using Filee.Core.Formats;+using Filee.Core.Presets;+using Filee.Engines.Magick;+using ImageMagick;++namespace Filee.App.Services;++public static class HideService+{+ /// <summary>Longest side of the preview: huge pictures are shown smaller, for a fluid window.</summary>+ public const int MaxPreviewSide = 2560;++ /// <summary>True when the window can open a <paramref name="formatId"/> file: a picture the image engine reads.</summary>+ public static bool CanOpen(string formatId) =>+ HideTool.CanHide(formatId) && ImageEncoder.Sources.Contains(formatId);++ /// <summary>+ /// Reads <paramref name="path"/> as the conversion will (the composite of a PSD, the largest size of an icon, turned+ /// as its EXIF orientation says) and makes a preview of it at most <see cref="MaxPreviewSide"/> across. The size is+ /// the picture's own. Animations and multi-page files are refused: the frames drawn on the first page would hide+ /// nothing on the others.+ /// </summary>+ public static Task<(MagickImage Preview, int Width, int Height)> LoadPreviewAsync(string path, Preset tool) =>+ Task.Run(() =>+ {+ var format = FormatRegistry.Detect(path)?.Id ?? throw new NotSupportedException("Unknown picture format.");+ if (format == "png" && Apng.IsAnimated(path))+ throw new NotSupportedException("Animated PNG files can't have parts hidden.");+ using var images = ImageReader.Read(path, format, tool);+ var frames = ImageEncoder.SelectFrames(images, format, format);+ if (frames.Count != 1)+ throw new NotSupportedException("Animated or multi-page pictures can't have parts hidden.");+ var preview = (MagickImage)frames[0].Clone();+ try+ {+ preview.AutoOrient();+ var (width, height) = ((int)preview.Width, (int)preview.Height);+ if (preview.Width > MaxPreviewSide || preview.Height > MaxPreviewSide)+ preview.Resize(new MagickGeometry(MaxPreviewSide, MaxPreviewSide) { Greater = true });+ preview.ResetPage();+ return (preview, width, height);+ }+ catch+ {+ preview.Dispose();+ throw;+ }+ });++ /// <summary>+ /// The size of the squares (or the blur) on the preview, for a picture of <paramref name="width"/> × <paramref name="height"/>+ /// shown at <paramref name="previewWidth"/> pixels across: the conversion's, scaled. A square is a whole number of+ /// the picture's pixels, as the conversion makes it.+ /// </summary>+ public static double PreviewEffectSize(HideStyle style, int strength, int width, int height, int previewWidth)+ {+ var size = HideTool.EffectSize(strength, width, height);+ if (style == HideStyle.Pixelate)+ size = Math.Round(size);+ return size * previewWidth / Math.Max(1, width);+ }++ /// <summary>A copy of <paramref name="preview"/> covered all over: what a frame shows inside it.</summary>+ public static Bitmap Cover(MagickImage preview, HideStyle style, double size)+ {+ using var copy = preview.Clone();+ AreaHider.Cover(copy, style, size);+ return ToBitmap(copy);+ }++ /// <summary>The picture as a bitmap the window draws.</summary>+ public static Bitmap ToBitmap(IMagickImage<byte> image)+ {+ var pixels = image.ToByteArray(MagickFormat.Bgra);+ var handle = GCHandle.Alloc(pixels, GCHandleType.Pinned);+ try+ {+ return new Bitmap(PixelFormat.Bgra8888, AlphaFormat.Unpremul, handle.AddrOfPinnedObject(),+ new PixelSize((int)image.Width, (int)image.Height), new Vector(96, 96), (int)image.Width * 4);+ }+ finally+ {+ handle.Free();+ }+ }+}diff --git a/src/Filee.App/Services/PresetAvailability.cs b/src/Filee.App/Services/PresetAvailability.csindex b4ee3947..6184fcb5 100644--- a/src/Filee.App/Services/PresetAvailability.cs+++ b/src/Filee.App/Services/PresetAvailability.cs@@ -119,6 +119,12 @@ public sealed class PresetAvailability: new(PresetUse.Unusable, _loc["error.no_route"]);}+ // Any picture among the files: the others are left out when the window opens.+ if (preset.IsHideTool)+ return formats.Any(f => HideService.CanOpen(f.Id))+ ? new(PresetUse.Usable, null)+ : new(PresetUse.Unusable, _loc["error.images_only"]);+if (preset.IsTool){if (preset.Id == "tool-sheet-studio")diff --git a/src/Filee.App/Services/WindowService.cs b/src/Filee.App/Services/WindowService.csindex c6c23879..98dec687 100644--- a/src/Filee.App/Services/WindowService.cs+++ b/src/Filee.App/Services/WindowService.cs@@ -36,8 +36,10 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services, Memprivate CropOverlayWindow? _cropOverlay;private ClipWindow? _clipWindow;+ private HideWindow? _hideWindow;internal ClipWindow? ClipWindow => _clipWindow;+ internal HideWindow? HideWindow => _hideWindow;private readonly HashSet<SpreadsheetPrintStudioWindow> _spreadsheetStudios = [];internal IReadOnlyCollection<SpreadsheetPrintStudioWindow> SpreadsheetStudios => _spreadsheetStudios;@@ -121,13 +123,15 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services, Mempublic MainWindow? Main => _main;/// <summary>- /// Opens the window of a tool preset (crop, cut a clip, the spreadsheet print studio: one per workbook, the PDF page- /// editor) on the files. A tool this version doesn't know opens nothing.+ /// Opens the window of a tool preset (crop, cut a clip, pixelate / blur, the spreadsheet print studio: one per+ /// workbook, the PDF page editor) on the files. A tool this version doesn't know opens nothing./// </summary>public void ShowTool(IReadOnlyList<string> files, Preset preset, PixelPoint? near = null){if (preset.IsClipTool)ShowClipWindow(files, preset, near);+ else if (preset.IsHideTool)+ ShowHideWindow(files, preset, near);// Before the crop: the print studio and the PDF page tools have no Tool of their own, which reads as a crop// ("Crop PDF" is one and opens the crop overlay).else if (preset.Id == "tool-sheet-studio")@@ -173,6 +177,38 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services, Memwin.Activate();}+ /// <summary>+ /// Opens the "Pixelate / blur" window on the pictures among the files. Each picture is written by an ordinary+ /// conversion, shown in the toast.+ /// </summary>+ public void ShowHideWindow(IReadOnlyList<string> files, Preset preset, PixelPoint? near = null)+ {+ var pictures = files.Where(f => FormatRegistry.Detect(f) is { } format && HideService.CanOpen(format.Id)).ToList();+ if (pictures.Count == 0)+ return;+ _hideWindow?.Close();+ var store = services.GetRequiredService<UserDataStore>();+ var catalog = services.GetRequiredService<ConverterCatalog>();+ var conversions = services.GetRequiredService<ConversionService>();+ var log = services.GetService<ILogger<HideWindowViewModel>>();+ var planner = catalog.CreatePlanner();+ var vm = new HideWindowViewModel(pictures, preset, loc, store,+ path => HideTool.TargetFor(FormatRegistry.Detect(path)?.Id ?? "", planner),+ (path, conversion) => conversions.Start([path], conversion), log);+ var win = new HideWindow { DataContext = vm };+ PrepareWindow(win);+ win.PositionOnScreen(near);+ win.Closed += (_, _) =>+ {+ if (_hideWindow == win)+ _hideWindow = null;+ trimmer.Request();+ };+ _hideWindow = win;+ win.Show();+ win.Activate();+ }+/// <summary>Opens the interactive crop overlay for the files.</summary>public void ShowCropOverlay(IReadOnlyList<string> files, Preset preset, PixelPoint? near = null){diff --git a/src/Filee.App/Styles/Icons.axaml b/src/Filee.App/Styles/Icons.axamlindex c8c0588b..ac9152fe 100644--- a/src/Filee.App/Styles/Icons.axaml+++ b/src/Filee.App/Styles/Icons.axaml@@ -36,6 +36,8 @@<StreamGeometry x:Key="Icon.Undo">M12.5,8C9.85,8 7.45,9 5.6,10.6L2,7V16H11L7.38,12.38C8.77,11.22 10.54,10.5 12.5,10.5C16.04,10.5 19.05,12.81 20.1,16L22.47,15.22C21.08,11.03 17.15,8 12.5,8Z</StreamGeometry><StreamGeometry x:Key="Icon.Record">M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7Z</StreamGeometry><StreamGeometry x:Key="Icon.Crop">M7,17V1H5V5H1V7H5V17A2,2 0 0,0 7,19H17V23H19V19H23V17M17,15H19V7C19,5.89 18.1,5 17,5H9V7H17V15Z</StreamGeometry>+ <!-- "Pixelate / blur": squares of a mosaic. -->+ <StreamGeometry x:Key="Icon.Pixelate">M3,3H9V9H3Z M15,3H21V9H15Z M9,9H15V15H9Z M3,15H9V21H3Z M15,15H21V21H15Z</StreamGeometry><StreamGeometry x:Key="Icon.Cut">M9.64,7.64C9.87,7.14 10,6.59 10,6A4,4 0 0,0 6,2A4,4 0 0,0 2,6A4,4 0 0,0 6,10C6.59,10 7.14,9.87 7.64,9.64L10,12L7.64,14.36C7.14,14.13 6.59,14 6,14A4,4 0 0,0 2,18A4,4 0 0,0 6,22A4,4 0 0,0 10,18C10,17.41 9.87,16.86 9.64,16.36L12,14L19,21H22V20L9.64,7.64M6,8A2,2 0 0,1 4,6A2,2 0 0,1 6,4A2,2 0 0,1 8,6A2,2 0 0,1 6,8M6,20A2,2 0 0,1 4,18A2,2 0 0,1 6,16A2,2 0 0,1 8,18A2,2 0 0,1 6,20M19,3L13,9L15,11L22,4V3H19Z</StreamGeometry><StreamGeometry x:Key="Icon.File">M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20Z</StreamGeometry><StreamGeometry x:Key="Icon.OpenWith">M14,3V5H17.59L7.76,14.83L9.17,16.24L19,6.41V10H21V3M19,19H5V5H12V3H5C3.89,3 3,3.9 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V12H19V19Z</StreamGeometry>diff --git a/src/Filee.App/ViewModels/CropOverlayViewModel.cs b/src/Filee.App/ViewModels/CropOverlayViewModel.csindex 20a0c8c6..8a9ef5ed 100644--- a/src/Filee.App/ViewModels/CropOverlayViewModel.cs+++ b/src/Filee.App/ViewModels/CropOverlayViewModel.cs@@ -520,8 +520,12 @@ public enum CropItemStateFailed,}-/// <summary>One file of the crop overlay's strip: a small thumbnail once it has been opened, and how it went.</summary>-public sealed partial class CropQueueItem(ILocalizer loc, string name, int index) : ObservableObject, IDisposable+/// <summary>+/// One file of the strip of the crop overlay (and of the "Pixelate / blur" window): a small thumbnail once it has been+/// opened, and how it went. <paramref name="doneKey"/> names a file that is done.+/// </summary>+public sealed partial class CropQueueItem(ILocalizer loc, string name, int index, string doneKey = "crop.state_done")+ : ObservableObject, IDisposable{/// <summary>Longest side of a thumbnail in the strip (at twice its size on screen, for high-DPI displays).</summary>private const int ThumbnailSide = 72;@@ -553,7 +557,7 @@ public sealed partial class CropQueueItem(ILocalizer loc, string name, int indexpublic string StateText => loc[State switch{CropItemState.Current => "crop.state_current",- CropItemState.Done => "crop.state_done",+ CropItemState.Done => doneKey,CropItemState.Skipped => "crop.state_skipped",CropItemState.Failed => "crop.state_failed",_ => "crop.state_waiting",diff --git a/src/Filee.App/ViewModels/HideWindowViewModel.cs b/src/Filee.App/ViewModels/HideWindowViewModel.csnew file mode 100644index 00000000..25e6cd24--- /dev/null+++ b/src/Filee.App/ViewModels/HideWindowViewModel.cs@@ -0,0 +1,495 @@+// 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+// 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;+using System.IO;+using Avalonia;+using Avalonia.Media.Imaging;+using CommunityToolkit.Mvvm.ComponentModel;+using CommunityToolkit.Mvvm.Input;+using Filee.App.Controls;+using Filee.App.Services;+using Filee.Core.Localization;+using Filee.Core.Presets;+using Filee.Core.Settings;+using ImageMagick;+using Microsoft.Extensions.Logging;++namespace Filee.App.ViewModels;++public sealed partial class HideWindowViewModel : ObservableObject, IDisposable+{+ private readonly IReadOnlyList<string> _files;+ private readonly Preset _tool;+ private readonly ILocalizer _loc;+ private readonly UserDataStore _store;+ private readonly Func<string, string> _targetFor;+ private readonly Action<string, Preset> _export;+ private readonly ILogger? _log;++ private MagickImage? _preview;+ private int _coverVersion;+ private int _coverShown;+ private bool _closed;++ /// <summary>The frames of the last picture saved, for the next one.</summary>+ private List<Rect> _carried = [];++ [ObservableProperty] private int _currentIndex;+ [ObservableProperty] private string _currentFileName = "";+ [ObservableProperty] private string _counterText = "";+ [ObservableProperty] private bool _hasMultipleFiles;+ [ObservableProperty] private Bitmap? _previewImage;+ [ObservableProperty] private Bitmap? _coverImage;+ [ObservableProperty] private string _saveText = "";++ [ObservableProperty]+ [NotifyPropertyChangedFor(nameof(PixelSize))]+ private int _originalWidth;++ [ObservableProperty]+ [NotifyPropertyChangedFor(nameof(PixelSize))]+ private int _originalHeight;++ [ObservableProperty]+ [NotifyPropertyChangedFor(nameof(CanSave), nameof(ShowEmptyHint))]+ [NotifyCanExecuteChangedFor(nameof(SaveCommand))]+ private bool _isBusy;++ [ObservableProperty]+ [NotifyPropertyChangedFor(nameof(IsPixelate), nameof(IsBlur))]+ private HideStyle _style;++ [ObservableProperty]+ [NotifyPropertyChangedFor(nameof(StrengthText))]+ private int _strength;++ [ObservableProperty]+ [NotifyPropertyChangedFor(nameof(HasStatusNotice))]+ private string _statusNotice = "";++ /// <summary>+ /// All files are done and some could not be opened: the window stays open on <see cref="Summary"/> and+ /// <see cref="Problems"/> until the user closes it.+ /// </summary>+ [ObservableProperty]+ [NotifyPropertyChangedFor(nameof(IsEditing), nameof(CanSave), nameof(ShowEmptyHint))]+ [NotifyCanExecuteChangedFor(nameof(SaveCommand))]+ private bool _isFinished;++ [ObservableProperty] private string _summary = "";++ [ObservableProperty]+ [NotifyPropertyChangedFor(nameof(HasDone))]+ private int _doneCount;++ [ObservableProperty]+ [NotifyPropertyChangedFor(nameof(HasSkipped))]+ private int _skippedCount;++ [ObservableProperty]+ [NotifyPropertyChangedFor(nameof(HasFailed))]+ private int _failedCount;++ /// <summary>The parts of the current picture to hide.</summary>+ public HideAreaSet Areas { get; } = new();++ /// <summary>"file: reason" for each file that could not be opened.</summary>+ public ObservableCollection<string> Problems { get; } = [];++ /// <summary>Every file of the run with how it went, for the strip of thumbnails.</summary>+ public ObservableCollection<CropQueueItem> Queue { get; } = [];++ public PixelSize PixelSize => new(OriginalWidth, OriginalHeight);+ public bool IsEditing => !IsFinished;+ public bool HasStatusNotice => !string.IsNullOrWhiteSpace(StatusNotice);+ public bool HasDone => DoneCount > 0;+ public bool HasSkipped => SkippedCount > 0;+ public bool HasFailed => FailedCount > 0;+ public bool HasAreas => Areas.Count > 0;+ public bool HasSelection => Areas.Selected >= 0;+ public bool CanUndo => Areas.CanUndo;+ public bool CanRedo => Areas.CanRedo;++ /// <summary>Saving needs a part to hide: without one the copy would only be the picture again.</summary>+ public bool CanSave => IsEditing && !IsBusy && HasAreas;++ /// <summary>"Drag over what you want to hide", on a picture without frames.</summary>+ public bool ShowEmptyHint => IsEditing && !IsBusy && !HasAreas && PreviewImage is not null;++ public bool IsPixelate+ {+ get => Style == HideStyle.Pixelate;+ set+ {+ if (value)+ Style = HideStyle.Pixelate;+ }+ }++ public bool IsBlur+ {+ get => Style == HideStyle.Blur;+ set+ {+ if (value)+ Style = HideStyle.Blur;+ }+ }++ /// <summary>"Strength: 5", for the slider's tooltip and screen readers.</summary>+ public string StrengthText => _loc.Format("hide.strength_value", Strength);++ public int MinStrength => HideTool.MinStrength;+ public int MaxStrength => HideTool.MaxStrength;++ public event Action? CloseRequested;++ /// <param name="files">The pictures, one after the other (other files are left out by the caller).</param>+ /// <param name="tool">The "Pixelate / blur" tool: the last choice, its name and output rule.</param>+ /// <param name="targetFor">The format a picture at a path is written in (<see cref="HideTool.TargetFor"/>).</param>+ /// <param name="export">Starts the conversion that writes a picture (the file, the conversion's preset).</param>+ public HideWindowViewModel(IReadOnlyList<string> files, Preset tool, ILocalizer loc, UserDataStore store,+ Func<string, string> targetFor, Action<string, Preset> export, ILogger? log = null)+ {+ _files = files;+ _tool = tool;+ _loc = loc;+ _store = store;+ _targetFor = targetFor;+ _export = export;+ _log = log;+ _style = tool.Image.HideStyle;+ _strength = HideTool.ClampStrength(tool.Image.HideStrength);+ _hasMultipleFiles = files.Count > 1;+ for (var i = 0; i < files.Count; i++)+ Queue.Add(new CropQueueItem(loc, Path.GetFileName(files[i]), i, "hide.state_done"));+ Areas.Changed += OnAreasChanged;+ loc.LanguageChanged += OnLanguageChanged;+ _ = LoadFileAsync(0);+ }++ partial void OnStyleChanged(HideStyle value) => RefreshCover();++ partial void OnStrengthChanged(int value)+ {+ var clamped = HideTool.ClampStrength(value);+ if (clamped != value)+ {+ Strength = clamped;+ return;+ }+ RefreshCover();+ }++ partial void OnPreviewImageChanged(Bitmap? value) => OnPropertyChanged(nameof(ShowEmptyHint));++ private void OnAreasChanged()+ {+ OnPropertyChanged(nameof(HasAreas));+ OnPropertyChanged(nameof(HasSelection));+ OnPropertyChanged(nameof(CanUndo));+ OnPropertyChanged(nameof(CanRedo));+ OnPropertyChanged(nameof(CanSave));+ OnPropertyChanged(nameof(ShowEmptyHint));+ SaveCommand.NotifyCanExecuteChanged();+ }++ /// <summary>Opens picture <paramref name="index"/>; past the last one, the end.</summary>+ public async Task LoadFileAsync(int index)+ {+ if (_closed)+ return;+ if (index < 0 || index >= _files.Count)+ {+ Finish();+ return;+ }++ IsBusy = true;+ CurrentIndex = index;+ var path = _files[index];+ CurrentFileName = Path.GetFileName(path);+ CounterText = _loc.Format("crop.page_counter", index + 1, _files.Count);+ SaveText = _loc[index < _files.Count - 1 ? "hide.save_next" : "hide.save"];+ Queue[index].State = CropItemState.Current;++ try+ {+ var (preview, width, height) = await HideService.LoadPreviewAsync(path, _tool);+ var bitmap = await Task.Run(() => HideService.ToBitmap(preview));+ if (_closed)+ {+ preview.Dispose();+ bitmap.Dispose();+ return;+ }+ ReplacePreview(preview);+ var old = PreviewImage;+ OriginalWidth = width;+ OriginalHeight = height;+ PreviewImage = bitmap;+ old?.Dispose();+ Queue[index].SetThumbnail(bitmap);+ Areas.Reset(_carried);+ RefreshCover();+ }+ catch (Exception ex) when (ex is not OutOfMemoryException)+ {+ _log?.LogInformation(ex, "Could not open {File} for hiding parts", path);+ if (_closed)+ return;+ // The animated / multi-page check throws NotSupportedException: its English message stays in the log.+ var unsupported = ex is NotSupportedException;+ AddProblem(path, unsupported ? "error.unsupported_source" : "error.conversion_failed");+ Queue[index].State = CropItemState.Failed;+ IsBusy = false;+ await LoadFileAsync(index + 1);+ return;+ }+ finally+ {+ if (!_closed && CurrentIndex == index)+ IsBusy = false;+ }+ }++ /// <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.+ /// </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);+ _ = Task.Run(() =>+ {+ Bitmap? cover = null;+ try+ {+ lock (preview)+ {+ // 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);+ }+ }+ catch (Exception ex) when (ex is not OutOfMemoryException)+ {+ _log?.LogDebug(ex, "Could not cover the preview");+ return;+ }+ Avalonia.Threading.Dispatcher.UIThread.Post(() =>+ {+ if (version != _coverVersion || _closed || !ReferenceEquals(preview, _preview))+ {+ cover.Dispose();+ return;+ }+ var old = CoverImage;+ CoverImage = cover;+ _coverShown = version;+ old?.Dispose();+ });+ });+ }++ /// <summary>Waits for the covered preview of the current choice (tests capture it).</summary>+ internal bool IsCoverCurrent => CoverImage is not null && _coverShown == _coverVersion;++ private void ReplacePreview(MagickImage? preview)+ {+ var old = _preview;+ _preview = preview;+ if (old is not null)+ {+ lock (old)+ old.Dispose();+ }+ var cover = CoverImage;+ CoverImage = null;+ cover?.Dispose();+ }++ // ───────────────────────── Commands ─────────────────────────++ /// <summary>+ /// Starts the conversion that writes the picture with its parts covered (its progress shows in the toast), keeps the+ /// choice in the tool, then opens the next picture or closes.+ /// </summary>+ [RelayCommand(CanExecute = nameof(CanSave))]+ public async Task SaveAsync()+ {+ 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();+ Remember();+ try+ {+ _export(path, HideTool.ConversionOf(_tool, _targetFor(path), areas));+ Queue[CurrentIndex].State = CropItemState.Done;+ }+ catch (Exception ex) when (ex is not OutOfMemoryException)+ {+ _log?.LogError(ex, "Could not start hiding parts of {File}", path);+ AddProblem(path, "error.conversion_failed");+ Queue[CurrentIndex].State = CropItemState.Failed;+ }+ _carried = [.. Areas.Areas];+ await LoadFileAsync(CurrentIndex + 1);+ }++ /// <summary>Leaves this picture as it is and opens the next one.</summary>+ [RelayCommand]+ public async Task SkipAsync()+ {+ if (IsBusy || IsFinished || _closed)+ return;+ Queue[CurrentIndex].State = CropItemState.Skipped;+ // The frames stay for the next picture, as drawn.+ _carried = [.. Areas.Areas];+ await LoadFileAsync(CurrentIndex + 1);+ }++ /// <summary>Close (Esc). Pictures already started go on in the toast.</summary>+ [RelayCommand]+ public void Cancel()+ {+ Shutdown();+ CloseRequested?.Invoke();+ }++ [RelayCommand]+ public void SetStyle(HideStyle style)+ {+ if (IsEditing)+ Style = style;+ }++ /// <summary>Removes every frame (R); Ctrl+Z brings them back.</summary>+ [RelayCommand]+ public void Clear()+ {+ if (IsEditing && !IsBusy)+ Areas.Clear();+ }++ [RelayCommand]+ public void RemoveSelected()+ {+ if (IsEditing && !IsBusy)+ Areas.RemoveSelected();+ }++ [RelayCommand]+ public void Undo()+ {+ if (IsEditing && !IsBusy)+ Areas.Undo();+ }++ [RelayCommand]+ public void Redo()+ {+ if (IsEditing && !IsBusy)+ Areas.Redo();+ }++ /// <summary>A step stronger or weaker (+ / −).</summary>+ public void StepStrength(int step)+ {+ if (IsEditing)+ Strength = HideTool.ClampStrength(Strength + step);+ }++ // ───────────────────────── 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>+ private void Remember()+ {+ HideTool.Remember(_tool, Style, Strength);+ if (_store.FindPreset(_tool.Id) is not { IsHideTool: true } saved+ || (saved.Image.HideStyle == Style && saved.Image.HideStrength == Strength))+ return;+ HideTool.Remember(saved, Style, Strength);+ try+ {+ _store.SaveLibrary();+ }+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)+ {+ _log?.LogWarning(ex, "Could not remember how parts are hidden");+ }+ }++ private void AddProblem(string path, string key)+ {+ var line = $"{Path.GetFileName(path)}: {_loc[key]}";+ Problems.Add(line);+ StatusNotice = line;+ }++ /// <summary>Closes after the last picture, or stays open on the summary when a picture could not be opened.</summary>+ private void Finish()+ {+ if (Problems.Count == 0)+ {+ Cancel();+ return;+ }+ Summary = _loc.Format("toast.done_errors", Problems.Count, Queue.Count);+ DoneCount = Queue.Count(q => q.State == CropItemState.Done);+ SkippedCount = Queue.Count(q => q.State == CropItemState.Skipped);+ FailedCount = Queue.Count(q => q.State == CropItemState.Failed);+ StatusNotice = "";+ HasMultipleFiles = false;+ IsBusy = false;+ Areas.Reset([]);+ ReplacePreview(null);+ var old = PreviewImage;+ PreviewImage = null;+ old?.Dispose();+ IsFinished = true;+ }++ private void Shutdown()+ {+ if (_closed)+ return;+ // A choice made without saving is kept too: the window opens with it next time.+ if (IsEditing && PreviewImage is not null)+ Remember();+ _closed = true;+ }++ private void OnLanguageChanged(object? sender, EventArgs e)+ {+ if (!IsFinished && CurrentIndex < _files.Count)+ {+ CounterText = _loc.Format("crop.page_counter", CurrentIndex + 1, _files.Count);+ SaveText = _loc[CurrentIndex < _files.Count - 1 ? "hide.save_next" : "hide.save"];+ }+ OnPropertyChanged(nameof(StrengthText));+ foreach (var item in Queue)+ item.RefreshTexts();+ }++ public void Dispose()+ {+ Shutdown();+ _loc.LanguageChanged -= OnLanguageChanged;+ Areas.Changed -= OnAreasChanged;+ ReplacePreview(null);+ PreviewImage?.Dispose();+ PreviewImage = null;+ foreach (var item in Queue)+ item.Dispose();+ }+}diff --git a/src/Filee.App/Views/HideWindow.axaml b/src/Filee.App/Views/HideWindow.axamlnew file mode 100644index 00000000..f46641ed--- /dev/null+++ b/src/Filee.App/Views/HideWindow.axaml@@ -0,0 +1,430 @@+<!-- "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),+ 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+ "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"+ xmlns:vm="using:Filee.App.ViewModels"+ xmlns:c="using:Filee.App.Controls"+ xmlns:p="using:Filee.Core.Presets"+ x:Class="Filee.App.Views.HideWindow"+ x:DataType="vm:HideWindowViewModel"+ Title="{DynamicResource preset.hide}"+ Icon="avares://Filee/Assets/Icons/filee.ico"+ Width="1040" Height="720" MinWidth="680" MinHeight="500"+ WindowDecorations="None"+ Background="Transparent"+ TransparencyLevelHint="Transparent"+ Topmost="True"+ CanResize="True">++ <Window.Resources>+ <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>+ <StreamGeometry x:Key="Hide.Grip">M18 10a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3z M18 16a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3z M12 16a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3z</StreamGeometry>+ </Window.Resources>++ <Window.Styles>+ <!-- The frame of the window; none when maximized -->+ <Style Selector="Border#Shell">+ <Setter Property="Margin" Value="12" />+ <Setter Property="CornerRadius" Value="{DynamicResource SoftRadiusLarge}" />+ </Style>+ <Style Selector="Window.maximized Border#Shell">+ <Setter Property="Margin" Value="0" />+ <Setter Property="CornerRadius" Value="0" />+ <Setter Property="BorderThickness" Value="0" />+ </Style>++ <!-- Floating pieces on the stage -->+ <Style Selector="Border.float">+ <Setter Property="Background" Value="{DynamicResource SurfaceBrush}" />+ <Setter Property="BorderBrush" Value="{DynamicResource SubtleBorderBrush}" />+ <Setter Property="BorderThickness" Value="1" />+ <Setter Property="CornerRadius" Value="999" />+ <Setter Property="BoxShadow" Value="{DynamicResource CardShadow}" />+ </Style>++ <!-- Toolbar buttons: quiet, round, a soft tint on hover; the style in use tinted -->+ <Style Selector="Button.tool">+ <Setter Property="Background" Value="Transparent" />+ <Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />+ <Setter Property="BorderThickness" Value="0" />+ <Setter Property="CornerRadius" Value="999" />+ <Setter Property="Padding" Value="12,8" />+ <Setter Property="VerticalAlignment" Value="Center" />+ <Setter Property="Cursor" Value="Hand" />+ </Style>+ <Style Selector="Button.tool:pointerover /template/ ContentPresenter#PART_ContentPresenter">+ <Setter Property="Background" Value="{DynamicResource AccentFaintBrush}" />+ <Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />+ </Style>+ <Style Selector="Button.tool.open /template/ ContentPresenter#PART_ContentPresenter">+ <Setter Property="Background" Value="{DynamicResource AccentSoftBrush}" />+ </Style>+ <Style Selector="Button.tool:disabled /template/ ContentPresenter#PART_ContentPresenter">+ <Setter Property="Background" Value="Transparent" />+ </Style>+ <Style Selector="Button.tool:disabled">+ <Setter Property="Opacity" Value="0.45" />+ </Style>+ <Style Selector="Button.round">+ <Setter Property="Padding" Value="9" />+ <Setter Property="Width" Value="34" />+ <Setter Property="Height" Value="34" />+ </Style>+ <Style Selector="Button.primary">+ <Setter Property="CornerRadius" Value="999" />+ <Setter Property="Padding" Value="16,8" />+ <Setter Property="FontWeight" Value="SemiBold" />+ <Setter Property="VerticalAlignment" Value="Center" />+ </Style>+ <Style Selector="Border.divider">+ <Setter Property="Width" Value="1" />+ <Setter Property="Height" Value="22" />+ <Setter Property="Margin" Value="3,0" />+ <Setter Property="Background" Value="{DynamicResource SubtleBorderBrush}" />+ <Setter Property="VerticalAlignment" Value="Center" />+ </Style>++ <!-- Keycaps: the shortcut beside a button's name -->+ <Style Selector="Border.key">+ <Setter Property="Background" Value="{DynamicResource SurfaceAltBrush}" />+ <Setter Property="CornerRadius" Value="5" />+ <Setter Property="Padding" Value="5,0" />+ <Setter Property="MinWidth" Value="18" />+ <Setter Property="Height" Value="18" />+ <Setter Property="VerticalAlignment" Value="Center" />+ </Style>+ <Style Selector="Border.key > TextBlock">+ <Setter Property="FontSize" Value="10.5" />+ <Setter Property="Foreground" Value="{DynamicResource TextSecondaryBrush}" />+ <Setter Property="HorizontalAlignment" Value="Center" />+ <Setter Property="VerticalAlignment" Value="Center" />+ </Style>+ <Style Selector="Border.key.onaccent">+ <Setter Property="Background" Value="#2EFFFFFF" />+ </Style>+ <Style Selector="Border.key.onaccent > TextBlock">+ <Setter Property="Foreground" Value="{DynamicResource OnAccentBrush}" />+ </Style>++ <!-- The strip of files -->+ <Style Selector="Border.tile">+ <Setter Property="Width" Value="38" />+ <Setter Property="Height" Value="28" />+ <Setter Property="Margin" Value="3,0" />+ <Setter Property="CornerRadius" Value="7" />+ <Setter Property="ClipToBounds" Value="True" />+ <Setter Property="Background" Value="{DynamicResource SurfaceAltBrush}" />+ <Setter Property="BorderBrush" Value="{DynamicResource SubtleBorderBrush}" />+ <Setter Property="BorderThickness" Value="1" />+ <Setter Property="RenderTransform" Value="scale(0.86)" />+ <Setter Property="Opacity" Value="0.9" />+ <Setter Property="Transitions">+ <Transitions>+ <TransformOperationsTransition Property="RenderTransform" Duration="0:0:0.32" Easing="{StaticResource SoftEase}" />+ <DoubleTransition Property="Opacity" Duration="0:0:0.2" />+ </Transitions>+ </Setter>+ </Style>+ <Style Selector="Border.tile.current">+ <Setter Property="RenderTransform" Value="scale(1.08)" />+ <Setter Property="BorderBrush" Value="{DynamicResource AccentBrush}" />+ <Setter Property="BorderThickness" Value="2" />+ <Setter Property="Opacity" Value="1" />+ </Style>+ <Style Selector="Border.tile.skipped, Border.tile.failed">+ <Setter Property="Opacity" Value="0.55" />+ </Style>+ <Style Selector="Border.badge-dot">+ <Setter Property="Width" Value="13" />+ <Setter Property="Height" Value="13" />+ <Setter Property="CornerRadius" Value="999" />+ <Setter Property="HorizontalAlignment" Value="Right" />+ <Setter Property="VerticalAlignment" Value="Bottom" />+ <Setter Property="Margin" Value="0,0,1,1" />+ <Setter Property="BorderBrush" Value="{DynamicResource SurfaceBrush}" />+ <Setter Property="BorderThickness" Value="1.5" />+ </Style>++ <!-- "Drag over what you want to hide": fades in on a picture without frames -->+ <Style Selector="Border#EmptyHint">+ <Setter Property="Opacity" Value="0" />+ <Setter Property="Transitions">+ <Transitions>+ <DoubleTransition Property="Opacity" Duration="0:0:0.22" />+ </Transitions>+ </Setter>+ </Style>+ <Style Selector="Border#EmptyHint.shown">+ <Setter Property="Opacity" Value="1" />+ </Style>++ <!-- A narrow window (or long names): the toolbar's buttons show their icons only, their names in the tooltips -->+ <Style Selector="Window.compact TextBlock.named, Window.compact Border.named">+ <Setter Property="IsVisible" Value="False" />+ </Style>+ <Style Selector="Window.compact Button.tool:not(.round)">+ <Setter Property="Padding" Value="10,8" />+ </Style>+ <Style Selector="Slider#StrengthSlider">+ <Setter Property="Width" Value="96" />+ </Style>+ <Style Selector="Window.compact Slider#StrengthSlider">+ <Setter Property="Width" Value="72" />+ </Style>++ <!-- Reduced motion: everything here appears at once -->+ <Style Selector="Window.reduced-motion Border.tile, Window.reduced-motion Border#EmptyHint">+ <Setter Property="Transitions" Value="{x:Null}" />+ </Style>+ </Window.Styles>++ <Border x:Name="Shell" ClipToBounds="True"+ Background="{DynamicResource PageBrush}"+ BorderBrush="{DynamicResource SubtleBorderBrush}" BorderThickness="1"+ BoxShadow="{DynamicResource CardShadow}">+ <Grid x:Name="Stage">+ <!-- The picture, the frames and the backdrop -->+ <c:HideCanvas x:Name="Canvas"+ SourceImage="{Binding PreviewImage}"+ CoverImage="{Binding CoverImage}"+ Areas="{Binding Areas}"+ PixelSize="{Binding PixelSize}"+ ImagePadding="36,70,36,118"+ AccentBrush="{DynamicResource AccentBrush}"+ StageBrush="{DynamicResource PageBrush}"+ ChipBackground="{DynamicResource SurfaceBrush}"+ ChipForeground="{DynamicResource TextPrimaryBrush}" />++ <!-- A picture without frames: what to do, in the middle of the picture (it never takes a click) -->+ <Border x:Name="EmptyHint" Classes="float" Classes.shown="{Binding ShowEmptyHint}" IsHitTestVisible="False"+ HorizontalAlignment="Center" VerticalAlignment="Center" Margin="36,70,36,118" Padding="8,7,16,7" MaxWidth="460">+ <StackPanel Orientation="Horizontal" Spacing="10">+ <Border Width="28" Height="28" CornerRadius="999" Background="{DynamicResource AccentSoftBrush}" VerticalAlignment="Center">+ <PathIcon Width="13" Height="13" Data="{StaticResource Icon.Pixelate}" Foreground="{DynamicResource AccentBrush}" />+ </Border>+ <TextBlock Text="{DynamicResource hide.empty_hint}" FontSize="13" FontWeight="SemiBold" VerticalAlignment="Center"+ TextWrapping="Wrap" MaxWidth="400" Foreground="{DynamicResource TextPrimaryBrush}" />+ </StackPanel>+ </Border>++ <!-- Top: the file, the strip of files, size and close -->+ <Grid ColumnDefinitions="Auto,*,Auto" VerticalAlignment="Top" Margin="14,14,14,0">+ <StackPanel Spacing="8" HorizontalAlignment="Left">+ <Border Classes="float" Padding="5,5,12,5" IsVisible="{Binding IsEditing}" HorizontalAlignment="Left">+ <StackPanel Orientation="Horizontal" Spacing="9">+ <Border Width="26" Height="26" CornerRadius="999" Background="{DynamicResource AccentSoftBrush}">+ <PathIcon Width="12" Height="12" Data="{StaticResource Icon.Pixelate}" Foreground="{DynamicResource AccentBrush}" />+ </Border>+ <TextBlock Text="{Binding CurrentFileName}" FontSize="13" FontWeight="SemiBold" VerticalAlignment="Center"+ TextTrimming="CharacterEllipsis" MaxWidth="260" Foreground="{DynamicResource TextPrimaryBrush}" />+ <Border IsVisible="{Binding HasMultipleFiles}" Background="{DynamicResource SurfaceAltBrush}" CornerRadius="999"+ Padding="8,2" VerticalAlignment="Center">+ <TextBlock Text="{Binding CounterText}" FontSize="11.5" Foreground="{DynamicResource TextSecondaryBrush}" />+ </Border>+ </StackPanel>+ </Border>++ <!-- The last file that could not be opened -->+ <Border Classes="float" Padding="10,6,12,6" IsVisible="{Binding HasStatusNotice}" HorizontalAlignment="Left"+ CornerRadius="{DynamicResource SoftRadius}" MaxWidth="420">+ <StackPanel Orientation="Horizontal" Spacing="8">+ <PathIcon Width="13" Height="13" Data="{StaticResource Icon.Alert}" Foreground="{DynamicResource WarningBrush}" VerticalAlignment="Center" />+ <TextBlock Text="{Binding StatusNotice}" FontSize="12" TextTrimming="CharacterEllipsis" VerticalAlignment="Center"+ Foreground="{DynamicResource TextSecondaryBrush}" MaxWidth="380" />+ </StackPanel>+ </Border>+ </StackPanel>++ <!-- Several files: a thumbnail each, the current one lifted, done / skipped / failed marked -->+ <Border Grid.Column="1" Classes="float" Padding="6" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="16,0"+ IsVisible="{Binding HasMultipleFiles}">+ <ScrollViewer x:Name="StripScroller" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Disabled" MaxWidth="440">+ <ItemsControl x:Name="Strip" ItemsSource="{Binding Queue}">+ <ItemsControl.ItemsPanel>+ <ItemsPanelTemplate>+ <StackPanel Orientation="Horizontal" />+ </ItemsPanelTemplate>+ </ItemsControl.ItemsPanel>+ <ItemsControl.ItemTemplate>+ <DataTemplate x:DataType="vm:CropQueueItem">+ <Panel ToolTip.Tip="{Binding AccessibleName}" AutomationProperties.Name="{Binding AccessibleName}">+ <Border Classes="tile" Classes.current="{Binding IsCurrent}" Classes.skipped="{Binding IsSkipped}"+ Classes.failed="{Binding IsFailed}">+ <Panel>+ <TextBlock Text="{Binding Number}" FontSize="10.5" HorizontalAlignment="Center" VerticalAlignment="Center"+ Foreground="{DynamicResource TextSecondaryBrush}" IsVisible="{Binding !HasThumbnail}" />+ <Image Source="{Binding Thumbnail}" Stretch="UniformToFill" />+ </Panel>+ </Border>+ <Border Classes="badge-dot" Background="{DynamicResource AccentBrush}" IsVisible="{Binding IsDone}">+ <PathIcon Width="7" Height="7" Data="{StaticResource Icon.Check}" Foreground="{DynamicResource OnAccentBrush}" />+ </Border>+ <Border Classes="badge-dot" Background="{DynamicResource TextSecondaryBrush}" IsVisible="{Binding IsSkipped}">+ <Border Width="6" Height="1.5" Background="{DynamicResource SurfaceBrush}" />+ </Border>+ <Border Classes="badge-dot" Background="{DynamicResource DangerBrush}" IsVisible="{Binding IsFailed}">+ <TextBlock Text="!" FontSize="9" FontWeight="Bold" Foreground="{DynamicResource SurfaceBrush}"+ HorizontalAlignment="Center" VerticalAlignment="Center" />+ </Border>+ </Panel>+ </DataTemplate>+ </ItemsControl.ItemTemplate>+ </ItemsControl>+ </ScrollViewer>+ </Border>++ <Border Grid.Column="2" Classes="float" Padding="3" VerticalAlignment="Top">+ <StackPanel Orientation="Horizontal" Spacing="2">+ <Button x:Name="MaximizeButton" Classes="tool round" Click="OnMaximize"+ ToolTip.Tip="{DynamicResource crop.maximize}" AutomationProperties.Name="{DynamicResource crop.maximize}">+ <PathIcon Width="13" Height="13" Data="{StaticResource Hide.Maximize}" Foreground="{DynamicResource TextSecondaryBrush}" />+ </Button>+ <Button Classes="tool round" Command="{Binding CancelCommand}"+ ToolTip.Tip="{DynamicResource crop.close_hint}" AutomationProperties.Name="{DynamicResource common.close}">+ <PathIcon Width="11" Height="11" Data="{StaticResource Icon.Close}" Foreground="{DynamicResource TextSecondaryBrush}" />+ </Button>+ </StackPanel>+ </Border>+ </Grid>++ <!-- Bottom: the toolbar pill and the keys -->+ <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 -->+ <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}">+ <StackPanel Orientation="Horizontal" Spacing="7">+ <PathIcon Width="13" Height="13" Data="{StaticResource Icon.Pixelate}" Foreground="{DynamicResource AccentBrush}" />+ <TextBlock Classes="named" Text="{DynamicResource hide.pixelate}" FontSize="13" VerticalAlignment="Center" />+ </StackPanel>+ </Button>+ <Button x:Name="BlurButton" Classes="tool" Classes.open="{Binding IsBlur}" Padding="10,8,12,8"+ Command="{Binding SetStyleCommand}" CommandParameter="{x:Static p:HideStyle.Blur}"+ ToolTip.Tip="{DynamicResource hide.blur_hint}" AutomationProperties.Name="{DynamicResource hide.blur}">+ <StackPanel Orientation="Horizontal" Spacing="7">+ <PathIcon Width="13" Height="13" Data="{StaticResource Hide.Blur}" Foreground="{DynamicResource AccentBrush}" />+ <TextBlock Classes="named" Text="{DynamicResource hide.blur}" 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}">+ <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"+ Value="{Binding Strength}" VerticalAlignment="Center"+ AutomationProperties.Name="{DynamicResource hide.strength}" />+ <Ellipse Width="11" Height="11" Fill="{DynamicResource TextSecondaryBrush}" VerticalAlignment="Center" />+ </StackPanel>++ <Border Classes="divider" />++ <Button Classes="tool round" Command="{Binding UndoCommand}" IsEnabled="{Binding CanUndo}"+ ToolTip.Tip="{DynamicResource clip.undo}" AutomationProperties.Name="{DynamicResource clip.undo}">+ <PathIcon Width="14" Height="14" Data="{StaticResource Icon.Undo}" Foreground="{DynamicResource TextSecondaryBrush}" />+ </Button>+ <Button Classes="tool round" Command="{Binding RedoCommand}" IsEnabled="{Binding CanRedo}"+ ToolTip.Tip="{DynamicResource clip.redo}" AutomationProperties.Name="{DynamicResource clip.redo}">+ <PathIcon Width="14" Height="14" Data="{StaticResource Hide.Redo}" Foreground="{DynamicResource TextSecondaryBrush}" />+ </Button>+ <Button x:Name="RemoveButton" Classes="tool round" Command="{Binding RemoveSelectedCommand}" IsEnabled="{Binding HasSelection}"+ ToolTip.Tip="{DynamicResource hide.remove_hint}" AutomationProperties.Name="{DynamicResource hide.remove}">+ <PathIcon Width="13" Height="13" Data="{StaticResource Icon.Delete}" Foreground="{DynamicResource TextSecondaryBrush}" />+ </Button>+ <Button Classes="tool" Command="{Binding ClearCommand}" IsEnabled="{Binding HasAreas}"+ ToolTip.Tip="{DynamicResource hide.clear}" AutomationProperties.Name="{DynamicResource hide.clear}">+ <StackPanel Orientation="Horizontal" Spacing="7">+ <PathIcon Width="13" Height="13" Data="{StaticResource Icon.Refresh}" Foreground="{DynamicResource TextSecondaryBrush}" />+ <TextBlock Classes="named" Text="{DynamicResource hide.clear}" FontSize="13" VerticalAlignment="Center" />+ <Border Classes="key named"><TextBlock Text="R" /></Border>+ </StackPanel>+ </Button>+ <Button Classes="tool" Command="{Binding SkipCommand}" IsVisible="{Binding HasMultipleFiles}"+ ToolTip.Tip="{DynamicResource crop.skip}" AutomationProperties.Name="{DynamicResource crop.skip}">+ <StackPanel Orientation="Horizontal" Spacing="5">+ <TextBlock Classes="named" Text="{DynamicResource crop.skip}" FontSize="13" VerticalAlignment="Center" />+ <PathIcon Width="11" Height="11" Data="{StaticResource Icon.ChevronRight}" Foreground="{DynamicResource TextSecondaryBrush}" />+ </StackPanel>+ </Button>++ <Button x:Name="PrimaryButton" Classes="accent primary" Margin="4,0,0,0" Command="{Binding SaveCommand}"+ AutomationProperties.Name="{Binding SaveText}">+ <StackPanel Orientation="Horizontal" Spacing="9">+ <TextBlock Text="{Binding SaveText}" FontSize="13" VerticalAlignment="Center" />+ <Border Classes="key onaccent named"><TextBlock Text="Enter" /></Border>+ </StackPanel>+ </Button>+ </StackPanel>+ </Border>+ <TextBlock Text="{DynamicResource hide.hint_keys}" FontSize="11" HorizontalAlignment="Center" TextAlignment="Center"+ TextWrapping="Wrap" MaxWidth="760" Opacity="0.8" Foreground="{DynamicResource TextSecondaryBrush}" />+ </StackPanel>++ <!-- Drag the bottom-right corner to resize -->+ <Border x:Name="ResizeGrip" Width="22" Height="22" Background="Transparent" HorizontalAlignment="Right" VerticalAlignment="Bottom"+ Margin="0,0,4,4" Cursor="BottomRightCorner">+ <PathIcon Width="14" Height="14" Data="{StaticResource Hide.Grip}" Foreground="{DynamicResource TextSecondaryBrush}" Opacity="0.6" />+ </Border>++ <!-- After the last file, when files could not be opened -->+ <Border Classes="card" IsVisible="{Binding IsFinished}" HorizontalAlignment="Center" VerticalAlignment="Center"+ MaxWidth="540" Margin="24" Padding="26,24">+ <StackPanel Spacing="14">+ <c:CropSummaryRing Width="112" Height="112" HorizontalAlignment="Center"+ Done="{Binding DoneCount}" Skipped="{Binding SkippedCount}" Failed="{Binding FailedCount}"+ AccentBrush="{DynamicResource AccentBrush}" MutedBrush="{DynamicResource TextSecondaryBrush}"+ DangerBrush="{DynamicResource DangerBrush}" HubBrush="{DynamicResource SurfaceBrush}"+ Foreground="{DynamicResource TextPrimaryBrush}" />+ <TextBlock Text="{Binding Summary}" FontWeight="SemiBold" FontSize="16" TextAlignment="Center" TextWrapping="Wrap"+ Foreground="{DynamicResource TextPrimaryBrush}" />+ <WrapPanel HorizontalAlignment="Center">+ <StackPanel Orientation="Horizontal" Spacing="6" Margin="8,2" IsVisible="{Binding HasDone}">+ <Ellipse Width="9" Height="9" Fill="{DynamicResource AccentBrush}" VerticalAlignment="Center" />+ <TextBlock FontSize="12.5" Foreground="{DynamicResource TextSecondaryBrush}">+ <Run Text="{DynamicResource hide.state_done}" /><Run Text=" " /><Run Text="{Binding DoneCount}" FontWeight="SemiBold" />+ </TextBlock>+ </StackPanel>+ <StackPanel Orientation="Horizontal" Spacing="6" Margin="8,2" IsVisible="{Binding HasSkipped}">+ <Ellipse Width="9" Height="9" Fill="{DynamicResource TextSecondaryBrush}" VerticalAlignment="Center" />+ <TextBlock FontSize="12.5" Foreground="{DynamicResource TextSecondaryBrush}">+ <Run Text="{DynamicResource crop.state_skipped}" /><Run Text=" " /><Run Text="{Binding SkippedCount}" FontWeight="SemiBold" />+ </TextBlock>+ </StackPanel>+ <StackPanel Orientation="Horizontal" Spacing="6" Margin="8,2" IsVisible="{Binding HasFailed}">+ <Ellipse Width="9" Height="9" Fill="{DynamicResource DangerBrush}" VerticalAlignment="Center" />+ <TextBlock FontSize="12.5" Foreground="{DynamicResource TextSecondaryBrush}">+ <Run Text="{DynamicResource crop.state_failed}" /><Run Text=" " /><Run Text="{Binding FailedCount}" FontWeight="SemiBold" />+ </TextBlock>+ </StackPanel>+ </WrapPanel>+ <Border Background="{DynamicResource SurfaceAltBrush}" CornerRadius="{DynamicResource SoftRadiusSmall}" Padding="14,10">+ <ScrollViewer MaxHeight="220">+ <ItemsControl ItemsSource="{Binding Problems}">+ <ItemsControl.ItemTemplate>+ <DataTemplate x:DataType="x:String">+ <TextBlock Text="{Binding}" FontSize="12" Margin="0,2" TextWrapping="Wrap" Foreground="{DynamicResource TextSecondaryBrush}" />+ </DataTemplate>+ </ItemsControl.ItemTemplate>+ </ItemsControl>+ </ScrollViewer>+ </Border>+ <Button x:Name="CloseButton" Classes="accent primary" HorizontalAlignment="Center" MinWidth="120"+ HorizontalContentAlignment="Center" Content="{DynamicResource common.close}" Command="{Binding CancelCommand}" />+ </StackPanel>+ </Border>++ <!-- Loading a picture -->+ <Border Classes="float" IsVisible="{Binding IsBusy}" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="18,14">+ <ProgressBar Classes="soft" IsIndeterminate="True" Width="96" />+ </Border>+ </Grid>+ </Border>+</Window>diff --git a/src/Filee.App/Views/HideWindow.axaml.cs b/src/Filee.App/Views/HideWindow.axaml.csnew file mode 100644index 00000000..c3eda35d--- /dev/null+++ b/src/Filee.App/Views/HideWindow.axaml.cs@@ -0,0 +1,264 @@+using System.ComponentModel;+using Avalonia;+using Avalonia.Controls;+using Avalonia.Input;+using Avalonia.Interactivity;+using Avalonia.Threading;+using Filee.App.Controls;+using Filee.App.Services;+using Filee.App.ViewModels;+using Filee.Core.Presets;++namespace Filee.App.Views;++/// <summary>+/// The "Pixelate / blur" window: placement, keys (Enter saves, Esc closes, Delete removes the selected frame, Tab and+/// Shift+Tab go from frame to frame, the arrow keys move it (Shift × 10), R clears every frame, P pixelates, B blurs,+/// + and − change the strength, Ctrl+Z / Ctrl+Y undo and redo) and moving, sizing and maximizing the frameless window,+/// as the crop overlay's.+/// </summary>+public partial class HideWindow : Window+{+ private HideWindowViewModel? _vm;++ /// <summary>The focus came from the keyboard (Tab, arrows), not from a click.</summary>+ private bool _focusByKeyboard;++ public HideWindow()+ {+ InitializeComponent();+ Motion.Track(this);+ Canvas.PlayAnimations = Motion.Enabled;+ Motion.Changed += OnMotionChanged;+ DataContextChanged += OnDataContextChanged;+ AddHandler(GotFocusEvent, (_, e) => _focusByKeyboard = e.NavigationMethod is NavigationMethod.Tab or NavigationMethod.Directional,+ RoutingStrategies.Bubble, handledEventsToo: true);+ AddHandler(KeyDownEvent, OnKeyDownFirst, RoutingStrategies.Tunnel);+ // Enter is the window's own (save), so a button that was clicked can't be pressed by it later; nor by its key-up.+ AddHandler(KeyUpEvent, (_, e) =>+ {+ if (e.Key is Key.Enter or Key.Space && !ControlTakes(e))+ e.Handled = true;+ }, RoutingStrategies.Tunnel);+ ResizeGrip.PointerPressed += OnGripPressed;+ Stage.SizeChanged += (_, _) => FitToolbar();+ Closed += (_, _) => Motion.Changed -= OnMotionChanged;+ }++ /// <summary>The toolbar's width with its buttons' names, measured when it last had to give them up.</summary>+ private double _namedWidth;++ /// <summary>+ /// Shows the toolbar's buttons with their icons only (<c>compact</c>) when their names don't fit the window, and with+ /// the names again once there is room.+ /// </summary>+ private void FitToolbar()+ {+ var available = Stage.Bounds.Width - 32; // the pill's margin+ if (available <= 0)+ return;+ if (!Classes.Contains("compact"))+ {+ ToolbarContent.Measure(Size.Infinity);+ var wanted = ToolbarContent.DesiredSize.Width + Toolbar.Padding.Left + Toolbar.Padding.Right + 2;+ if (wanted > available)+ {+ _namedWidth = wanted;+ Classes.Set("compact", true);+ }+ }+ else if (available >= _namedWidth)+ {+ Classes.Set("compact", false);+ }+ }++ /// <summary>The names changed (language, "Hide & Next" → "Hide & Save", Skip shown): measured again with them.</summary>+ private void RefitToolbar()+ {+ Classes.Set("compact", false);+ Dispatcher.UIThread.Post(FitToolbar, DispatcherPriority.Render);+ }++ internal HideCanvas HideCanvas => Canvas;++ /// <summary>+ /// Opens near <paramref name="near"/> (the screen of the donut), else on the primary screen, centred in its working+ /// area and no larger than most of it.+ /// </summary>+ public void PositionOnScreen(PixelPoint? near = null)+ {+ var screen = (near.HasValue ? Screens.ScreenFromPoint(near.Value) : null)+ ?? Screens.ScreenFromPoint(Screens.Primary?.Bounds.Center ?? default)+ ?? Screens.Primary;+ if (screen is null)+ return;+ var scaling = screen.Scaling;+ var area = screen.WorkingArea;+ Width = Math.Max(MinWidth, Math.Min(Width, area.Width / scaling * 0.94));+ Height = Math.Max(MinHeight, Math.Min(Height, area.Height / scaling * 0.92));+ var x = area.X + Math.Max(0, (area.Width - (int)(Width * scaling)) / 2);+ var y = area.Y + Math.Max(0, (area.Height - (int)(Height * scaling)) / 2);+ Position = new PixelPoint(x, y);+ }++ /// <summary>Settles every animation and transition (tests capture the end state).</summary>+ internal void SettleForCapture()+ {+ Classes.Set("reduced-motion", true);+ Canvas.PlayAnimations = false;+ Canvas.FinishAnimations();+ }++ private void OnDataContextChanged(object? sender, EventArgs e)+ {+ if (DataContext is HideWindowViewModel vm && !ReferenceEquals(vm, _vm))+ {+ _vm = vm;+ vm.CloseRequested += Close;+ vm.PropertyChanged += OnViewModelChanged;+ Closed += (_, _) => vm.Dispose();+ }+ }++ private void OnViewModelChanged(object? sender, PropertyChangedEventArgs e)+ {+ if (_vm is null)+ return;+ if (e.PropertyName == nameof(HideWindowViewModel.CurrentIndex))+ Dispatcher.UIThread.Post(() => Strip.ContainerFromIndex(_vm.CurrentIndex)?.BringIntoView(), DispatcherPriority.Background);+ else if (e.PropertyName is nameof(HideWindowViewModel.SaveText) or nameof(HideWindowViewModel.HasMultipleFiles))+ RefitToolbar();+ }++ private void OnMotionChanged(object? sender, EventArgs e) => Canvas.PlayAnimations = Motion.Enabled;++ // ───────────────────────── Keys ─────────────────────────++ /// <summary>+ /// The control that has the focus, reached with the keyboard, takes <paramref name="e"/>'s key as it would anywhere+ /// else: Space and Enter press a button, the arrows move the strength slider.+ /// </summary>+ private bool ControlTakes(KeyEventArgs e)+ {+ if (!_focusByKeyboard || e.KeyModifiers != KeyModifiers.None)+ return false;+ return FocusManager?.GetFocusedElement() switch+ {+ Button => e.Key is Key.Space or Key.Enter,+ Slider => e.Key is Key.Left or Key.Right or Key.Up or Key.Down or Key.Home or Key.End or Key.PageUp or Key.PageDown,+ _ => false,+ };+ }++ /// <summary>Before any focused control: the window's keys, unless a control reached with the keyboard takes it.</summary>+ private void OnKeyDownFirst(object? sender, KeyEventArgs e)+ {+ if (_vm is not { } vm || ControlTakes(e))+ return;+ var plain = e.KeyModifiers == KeyModifiers.None;+ var command = e.KeyModifiers == KeyModifiers.Control || e.KeyModifiers == KeyModifiers.Meta;+ var commandShift = e.KeyModifiers == (KeyModifiers.Control | KeyModifiers.Shift) || e.KeyModifiers == (KeyModifiers.Meta | KeyModifiers.Shift);+ var editing = vm.IsEditing && !vm.IsBusy;+ switch (e.Key)+ {+ case Key.Escape:+ vm.Cancel();+ e.Handled = true;+ break;+ case Key.Enter:+ if (vm.IsFinished)+ vm.Cancel();+ else+ _ = vm.SaveAsync();+ e.Handled = true;+ break;+ case Key.Delete or Key.Back when plain && editing:+ vm.RemoveSelected();+ e.Handled = true;+ break;+ // Tab goes from frame to frame while there are frames; without, it moves the focus as usual.+ case Key.Tab when editing && vm.HasAreas && (plain || e.KeyModifiers == KeyModifiers.Shift):+ vm.Areas.SelectNext(e.KeyModifiers == KeyModifiers.Shift ? -1 : 1);+ e.Handled = true;+ break;+ case Key.Z when command && editing:+ vm.Undo();+ e.Handled = true;+ break;+ case Key.Y when command && editing:+ case Key.Z when commandShift && editing:+ vm.Redo();+ e.Handled = true;+ break;+ case Key.R when plain && editing:+ vm.Clear();+ e.Handled = true;+ break;+ case Key.P when plain && editing:+ vm.SetStyle(HideStyle.Pixelate);+ e.Handled = true;+ break;+ case Key.B when plain && editing:+ vm.SetStyle(HideStyle.Blur);+ e.Handled = true;+ break;+ case Key.OemPlus or Key.Add when (plain || e.KeyModifiers == KeyModifiers.Shift) && editing:+ vm.StepStrength(1);+ e.Handled = true;+ break;+ case Key.OemMinus or Key.Subtract when plain && editing:+ vm.StepStrength(-1);+ e.Handled = true;+ break;+ // The picture is never mirrored, also in right-to-left languages: Left is always left.+ case Key.Left or Key.Right or Key.Up or Key.Down when editing && vm.HasSelection+ && (e.KeyModifiers & ~KeyModifiers.Shift) == KeyModifiers.None:+ var step = e.KeyModifiers.HasFlag(KeyModifiers.Shift) ? 10 : 1;+ vm.Areas.Nudge(e.Key switch { Key.Left => -step, Key.Right => step, _ => 0 },+ e.Key switch { Key.Up => -step, Key.Down => step, _ => 0 }, vm.OriginalWidth, vm.OriginalHeight);+ e.Handled = true;+ break;+ }+ }++ // ───────────────────────── Moving and sizing the window ─────────────────────────++ /// <summary>The stage beside the picture moves the window; a double click maximizes it.</summary>+ protected override void OnPointerPressed(PointerPressedEventArgs e)+ {+ base.OnPointerPressed(e);+ if (e.Handled || !e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)+ return;+ if (e.ClickCount == 2)+ ToggleMaximized();+ else if (WindowState == WindowState.Normal)+ BeginMoveDrag(e);+ }++ private void OnGripPressed(object? sender, PointerPressedEventArgs e)+ {+ if (WindowState == WindowState.Normal && e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)+ BeginResizeDrag(WindowEdge.SouthEast, e);+ e.Handled = true;+ }++ private void OnMaximize(object? sender, RoutedEventArgs e) => ToggleMaximized();++ private void ToggleMaximized() =>+ WindowState = WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;++ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)+ {+ base.OnPropertyChanged(change);+ if (change.Property == WindowStateProperty)+ {+ var maximized = WindowState == WindowState.Maximized;+ Classes.Set("maximized", maximized);+ ResizeGrip.IsVisible = !maximized;+ var key = maximized ? "crop.restore" : "crop.maximize";+ MaximizeButton.Bind(ToolTip.TipProperty, MaximizeButton.GetResourceObservable(key));+ MaximizeButton.Bind(Avalonia.Automation.AutomationProperties.NameProperty, MaximizeButton.GetResourceObservable(key));+ }+ }+}diff --git a/src/Filee.Core/Conversion/JobQueue.cs b/src/Filee.Core/Conversion/JobQueue.csindex f826f669..2c4d352b 100644--- a/src/Filee.Core/Conversion/JobQueue.cs+++ b/src/Filee.Core/Conversion/JobQueue.cs@@ -265,8 +265,8 @@ public sealed class JobQueue : IAsyncDisposable// one whose text is recognized first.if (FormatRegistry.Detect(file.SourcePath)?.Id == "pdf" && !IsEmptyFile(file.SourcePath) && !job.Preset.RecognizesTextOf("pdf")){- // Already a PDF, merged as it is: its pages can't be turned (only images going into it can).- if (job.Preset.Image.TurnsOrMirrors)+ // Already a PDF, merged as it is: its pages can't be turned or covered (only images going into it can).+ if (job.Preset.Image.ReworksPixels)FailUnturned(job, file, "pdf → pdf");elseparts[i] = file.SourcePath;@@ -323,8 +323,8 @@ public sealed class JobQueue : IAsyncDisposablevar file = job.Files[i];if (Stopped(file))return;- // A TIFF joins as it is, unless it is to be turned: then it goes through the engine like the rest.- parts[i] = FormatRegistry.Detect(file.SourcePath)?.Id == "tiff" && !job.Preset.Image.TurnsOrMirrors+ // A TIFF joins as it is, unless it is to be turned or covered: then it goes through the engine like the rest.+ parts[i] = FormatRegistry.Detect(file.SourcePath)?.Id == "tiff" && !job.Preset.Image.ReworksPixels&& !IsEmptyFile(file.SourcePath)? [file.SourcePath]: await RunFileAsync(job, file, i + 1, planner, workDir, finalOutput: false, intermediate: "tiff");@@ -403,7 +403,7 @@ public sealed class JobQueue : IAsyncDisposable}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);@@ -500,11 +500,11 @@ public sealed class JobQueue : IAsyncDisposableNotify(job);}- /// <summary>A file that would be used as it is although the preset turns or mirrors it.</summary>+ /// <summary>A file that would be used as it is although the preset turns, mirrors or covers parts of it.</summary>private void FailUnturned(ConversionJob job, FileResult file, string detail){file.State = FileState.Failed;- file.ErrorKey = "error.cannot_turn";+ file.ErrorKey = job.Preset.Image.HidesAreas ? "error.cannot_hide" : "error.cannot_turn";file.ErrorDetail = detail;file.Progress = 1;Notify(job);@@ -721,9 +721,10 @@ public sealed class JobQueue : IAsyncDisposable// 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 = job.Preset.Image.TurnsOrMirrors ? route.FirstTransformStep() : -1;- if (job.Preset.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);file.State = FileState.Running;@@ -767,8 +768,9 @@ public sealed class JobQueue : IAsyncDisposableawait 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;// 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.@@ -797,7 +799,9 @@ public sealed class JobQueue : IAsyncDisposable}// Under "Save as ZIP" the output is still in the work folder: the source copied over it goes into the ZIP.- var copiedSource = finalOutput && job.Preset.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+ && 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.@@ -856,6 +860,7 @@ public sealed class JobQueue : IAsyncDisposablevar copy = preset.Clone();copy.Image.Rotation = ImageRotation.None;copy.Image.Flip = ImageFlip.None;+ copy.Image.HiddenAreas = null;return copy;}diff --git a/src/Filee.Core/History/HistoryEntry.cs b/src/Filee.Core/History/HistoryEntry.csindex 5a606c2e..9efa654a 100644--- a/src/Filee.Core/History/HistoryEntry.cs+++ b/src/Filee.Core/History/HistoryEntry.cs@@ -61,7 +61,8 @@ public sealed class HistoryEntryOutputs = [.. job.Outputs],Failures = failures,// history.json isn't the place for a PDF password: a retry takes it from the preset again.- Preset = failures.Count > 0 ? job.Preset.Clone().WithoutPassword(mark: true) : null,+ // No Retry for parts of a picture to hide: a Filee from before them would write the picture as it is.+ Preset = failures.Count > 0 && !job.Preset.Image.HidesAreas ? job.Preset.Clone().WithoutPassword(mark: true) : null,Undoable = UndoableOutputs(job),OriginalsInTrash = job.Files.Any(f => f.OriginalInTrash),};diff --git a/src/Filee.Core/Presets/BuiltInData.cs b/src/Filee.Core/Presets/BuiltInData.csindex ce888074..6bb3f5ca 100644--- a/src/Filee.Core/Presets/BuiltInData.cs+++ b/src/Filee.Core/Presets/BuiltInData.cs@@ -49,6 +49,7 @@ public static class BuiltInDataId = "tool-crop", NameKey = "preset.crop", TargetFormat = SameAsSource,Kind = PresetKind.Tool, Output = { FileNamePattern = "{name}_cropped" },},+ .. HidePresets(),new(){Id = "tool-sheet-studio", NameKey = "preset.sheet_studio", TargetFormat = "pdf",@@ -193,6 +194,19 @@ public static class BuiltInData},];+ /// <summary>+ /// "Pixelate / blur" (added in settings schema 52): parts of a picture (names, faces, numbers) covered before it is+ /// shared. On the front of the images donut after "Half size".+ /// </summary>+ public static List<Preset> HidePresets() =>+ [+ new()+ {+ Id = "tool-hide", NameKey = "preset.hide", TargetFormat = SameAsSource,+ Kind = PresetKind.Tool, Tool = Preset.HideTool, Output = { FileNamePattern = "{name}_hidden" },+ },+ ];+/// <summary>/// "Trim transparent borders" (issue #332, added in settings schema 33): a copy cropped to the visible pixels, in the/// same format. On the images donut's back face after "Remove background".@@ -527,7 +541,8 @@ public static class BuiltInData{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-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"],diff --git a/src/Filee.Core/Presets/HideTool.cs b/src/Filee.Core/Presets/HideTool.csnew file mode 100644index 00000000..2a275090--- /dev/null+++ b/src/Filee.Core/Presets/HideTool.cs@@ -0,0 +1,122 @@+// "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+// 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.++using Filee.Core.Conversion;+using Filee.Core.Formats;++namespace Filee.Core.Presets;++/// <summary>Turns the "Pixelate / blur" tool into the conversion that writes a picture with parts of it covered.</summary>+public static class HideTool+{+ /// <summary>Where a picture goes when its own format can't be written (a camera RAW, a DICOM …).</summary>+ public const string FallbackTarget = "png";++ /// <summary>The range of <see cref="ImageOptions.HideStrength"/>.</summary>+ public const int MinStrength = 1, MaxStrength = 10, DefaultStrength = 5;++ /// <summary>The smallest square (or blur) in pixels, whatever the picture's size.</summary>+ public const double MinEffectPixels = 8;++ /// <summary>+ /// Parts smaller than this (in parts of the picture's side) are a click, not a drag: none is added for them.+ /// </summary>+ public const double MinAreaSide = 0.004;++ /// <summary>True when a <paramref name="sourceFormat"/> file is a picture the tool can open.</summary>+ public static bool CanHide(string sourceFormat) =>+ FormatRegistry.FindById(sourceFormat)?.Category == FormatCategory.Image;++ /// <summary>+ /// The format a <paramref name="sourceFormat"/> picture is written in: its own when it can be written from itself,+ /// else <see cref="FallbackTarget"/>.+ /// </summary>+ public static string TargetFor(string sourceFormat, RoutePlanner planner) =>+ FormatRegistry.FindById(sourceFormat) is { Writable: true } && planner.Plan(sourceFormat, sourceFormat) is not null+ ? BuiltInData.SameAsSource+ : FallbackTarget;++ /// <summary>+ /// The conversion that writes a picture as <paramref name="targetFormat"/> with <paramref name="areas"/> covered as+ /// the tool says, with the tool's name and output rule. The tool itself is left as it is.+ /// </summary>+ public static Preset ConversionOf(Preset tool, string targetFormat, IEnumerable<HiddenArea> areas)+ {+ var preset = tool.Clone();+ preset.Kind = PresetKind.Convert;+ preset.Tool = null;+ preset.SubPresetIds = [];+ preset.TargetFormat = targetFormat;+ preset.Image.HiddenAreas = [.. areas.Select(Clamp).OfType<HiddenArea>()];+ preset.Image.HideStrength = ClampStrength(preset.Image.HideStrength);+ // "Only if smaller" would keep the original, every part of it in view, when the covered copy came out larger.+ preset.Output.OnlyIfSmaller = false;+ return preset;+ }++ /// <summary>Keeps the window's choice in <paramref name="tool"/> for the next time.</summary>+ public static void Remember(Preset tool, HideStyle style, int strength)+ {+ tool.Image.HideStyle = style;+ tool.Image.HideStrength = ClampStrength(strength);+ }++ /// <summary><paramref name="strength"/> within <see cref="MinStrength"/> … <see cref="MaxStrength"/>.</summary>+ public static int ClampStrength(int strength) => Math.Clamp(strength, MinStrength, MaxStrength);++ /// <summary>+ /// The side of a square (pixelate) or the blur's sigma, in pixels of a <paramref name="width"/> × <paramref name="height"/>+ /// picture: 2 % of its shorter side at the lowest strength to 6.5 % at the highest, never under+ /// <see cref="MinEffectPixels"/>.+ /// </summary>+ /// <remarks>+ /// Tied to the picture rather than to the part being hidden: a screenshot's line of text is about 1.2 % of a desktop+ /// screen's shorter side and 4 % of a phone's, so at the default strength (4 %) a square is as tall as a line of+ /// text or taller. Squares much smaller than the letters leave them guessable: text in a known font can be drawn,+ /// pixelated the same way and compared square by square until it matches.+ /// </remarks>+ public static double EffectSize(int strength, int width, int height) =>+ Math.Max(MinEffectPixels, Math.Min(Math.Max(1, width), Math.Max(1, height)) * (0.015 + 0.005 * ClampStrength(strength)));++ /// <summary>+ /// <paramref name="area"/> within the picture, or null when nothing of it is left (or it is not a number).+ /// </summary>+ public static HiddenArea? Clamp(HiddenArea area)+ {+ if (!double.IsFinite(area.X) || !double.IsFinite(area.Y) || !double.IsFinite(area.Width) || !double.IsFinite(area.Height))+ return null;+ var left = Math.Clamp(Math.Min(area.X, area.X + area.Width), 0, 1);+ 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;+ }++ /// <summary>+ /// <paramref name="area"/> in whole pixels of a <paramref name="width"/> × <paramref name="height"/> picture, rounded+ /// outwards (a pixel the part touches is covered), at least one pixel; null when nothing of it is on the picture.+ /// </summary>+ public static (int X, int Y, int Width, int Height)? PixelBounds(HiddenArea area, int width, int height)+ {+ if (width <= 0 || height <= 0 || Clamp(area) is not { } inside)+ return null;+ var left = Math.Clamp((int)Math.Floor(inside.X * width + 1e-9), 0, width - 1);+ var top = Math.Clamp((int)Math.Floor(inside.Y * height + 1e-9), 0, height - 1);+ var right = Math.Clamp((int)Math.Ceiling((inside.X + inside.Width) * width - 1e-9), left + 1, width);+ var bottom = Math.Clamp((int)Math.Ceiling((inside.Y + inside.Height) * height - 1e-9), top + 1, height);+ return (left, top, right - left, bottom - top);+ }++ /// <summary>+ /// The square a pixel column (or row) falls in, on a grid of <paramref name="cell"/>-pixel squares from the picture's+ /// top-left corner: by the pixel's centre, so a cell of 2.5 pixels takes pixels 0–1, 2–4, 5–6 …+ /// </summary>+ public static int CellOf(int pixel, double cell) => (int)Math.Floor((pixel + 0.5) / cell);++ /// <summary>The first pixel column (or row) of square <paramref name="index"/> (see <see cref="CellOf"/>).</summary>+ public static int CellStart(int index, double cell) => (int)Math.Ceiling(index * cell - 0.5);+}diff --git a/src/Filee.Core/Presets/Preset.cs b/src/Filee.Core/Presets/Preset.csindex a795927f..0d6306cd 100644--- a/src/Filee.Core/Presets/Preset.cs+++ b/src/Filee.Core/Presets/Preset.cs@@ -194,10 +194,15 @@ public sealed class Preset/// <summary><see cref="Tool"/> of "Cut a clip": a part of a video, chosen on a timeline.</summary>public const string ClipTool = "clip";+ /// <summary>+ /// <see cref="Tool"/> of "Pixelate / blur": parts of a picture covered before it is shared (names, faces, numbers).+ /// </summary>+ public const string HideTool = "hide";+/// <summary>/// <see cref="PresetKind.Tool"/>: which window it opens, <see cref="CropTool"/> (or null, as saved before there were- /// other tools) or <see cref="ClipTool"/>. A tool this version doesn't know (from a newer Filee) opens nothing.- /// Ignored for other kinds.+ /// other tools), <see cref="ClipTool"/> or <see cref="HideTool"/>. A tool this version doesn't know (from a newer+ /// Filee) opens nothing. Ignored for other kinds./// </summary>public string? Tool { get; set; }@@ -209,6 +214,10 @@ public sealed class Preset[JsonIgnore]public bool IsClipTool => IsTool && Tool == ClipTool;+ /// <summary>True for "Pixelate / blur".</summary>+ [JsonIgnore]+ public bool IsHideTool => IsTool && Tool == HideTool;+/// <summary>/// True if converting a <paramref name="sourceFormat"/> file cuts a clip of it (<see cref="MediaOptions.Clip"/>,/// set by the clip window on the conversion it starts): the file is a video. Other files convert as usual.@@ -305,6 +314,29 @@ public enum FitsTiffModeStretched,}+/// <summary>How "Pixelate / blur" covers the parts of a picture it hides (<see cref="ImageOptions.HideStyle"/>).</summary>+public enum HideStyle+{+ /// <summary>Squares of the average colour of what is under them.</summary>+ Pixelate,+ /// <summary>A strong blur.</summary>+ Blur,+}++/// <summary>+/// A part of a picture to hide, in parts of the picture as it is seen (EXIF orientation applied): 0 to 1 from its left+/// and top edges.+/// </summary>+public sealed class HiddenArea+{+ public double X { get; set; }+ public double Y { get; set; }+ public double Width { get; set; }+ public double Height { get; set; }++ public HiddenArea Clone() => (HiddenArea)MemberwiseClone();+}+/// <summary>Raster image encoding options.</summary>public sealed class ImageOptions{@@ -331,6 +363,13 @@ public sealed class ImageOptions[JsonIgnore]public bool TurnsOrMirrors => Rotation != ImageRotation.None || Flip != ImageFlip.None;+ /// <summary>+ /// Turns, mirrors or covers parts of the image (<see cref="HidesAreas"/>): done once, in the first step of a route whose+ /// engine applies image options (<see cref="Conversion.IImageTransformer"/>); a file is never passed on as it is.+ /// </summary>+ [JsonIgnore]+ public bool ReworksPixels => TurnsOrMirrors || HidesAreas;+/// <summary>Whether the preset edits picture content, size, or playback speed.</summary>[JsonIgnore]public bool EditsPicture => Resize != ResizeMode.None || Grayscale || TrimTransparent || RemoveBackground || MaxCompression || ChangesSpeed;@@ -422,6 +461,30 @@ public sealed class ImageOptions/// <summary>Icon sizes embedded in an ICO file.</summary>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.+ /// </summary>+ [JsonConverter(typeof(LenientEnumJsonConverter<HideStyle>))]+ public HideStyle HideStyle { get; set; }++ /// <summary>+ /// How large the squares or how wide the blur over <see cref="HiddenAreas"/> is, <see cref="HideTool.MinStrength"/>+ /// to <see cref="HideTool.MaxStrength"/> (see <see cref="HideTool.EffectSize"/>). Kept in the tool, as+ /// <see cref="HideStyle"/>.+ /// </summary>+ public int HideStrength { get; set; } = HideTool.DefaultStrength;++ /// <summary>+ /// The parts of the picture "Pixelate / blur" covers. Set by its window on the conversion it starts, never on a+ /// saved preset.+ /// </summary>+ public List<HiddenArea>? HiddenAreas { get; set; }++ /// <summary>The picture gets parts of it covered (<see cref="HiddenAreas"/>).</summary>+ [JsonIgnore]+ public bool HidesAreas => HiddenAreas is { Count: > 0 };+/// <summary>The playback speeds the preset editor offers (<see cref="AnimationSpeed"/>).</summary>public static readonly double[] AnimationSpeeds = [0.25, 0.5, 0.75, 1, 1.5, 2, 4];@@ -446,6 +509,7 @@ public sealed class ImageOptions{var copy = (ImageOptions)MemberwiseClone();copy.IcoSizes = [.. IcoSizes];+ copy.HiddenAreas = HiddenAreas?.Select(area => area.Clone()).ToList();return copy;}}diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.csindex 731f3263..f38249a0 100644--- a/src/Filee.Core/Settings/AppSettings.cs+++ b/src/Filee.Core/Settings/AppSettings.cs@@ -123,7 +123,7 @@ public sealed class DonutSettingspublic sealed class AppSettings{/// <summary>Current schema version. Increase when the format changes and add a migration.</summary>- public const int CurrentSchemaVersion = 50;+ public const int CurrentSchemaVersion = 52;public int SchemaVersion { get; set; } = CurrentSchemaVersion;diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.csindex 6a2f68c2..cb89f91d 100644--- a/src/Filee.Core/Settings/UserDataStore.cs+++ b/src/Filee.Core/Settings/UserDataStore.cs@@ -906,6 +906,14 @@ internal static class SettingsMigrations// v50: Dahua DVR recordings (.dav) learn the video donut; custom claims stay put.if (from < 50)changed |= LearnExtensions(profiles, out _, ["dav"]);+ // v52 (51 is kept for "Edit pictures"): "Pixelate / blur", after "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);return changed;}@@ -1032,6 +1040,52 @@ internal static class SettingsMigrationsreturn changed;}+ private static bool AddHideTool(List<Preset> presets, List<ToolbarProfile> profiles)+ {+ var changed = false;+ var hide = BuiltInData.HidePresets().Single();+ if (presets.FirstOrDefault(p => p.Id == hide.Id) is { } existing)+ {+ if (!existing.IsHideTool)+ {+ existing.Kind = PresetKind.Tool;+ existing.Tool = Preset.HideTool;+ existing.SubPresetIds = [];+ if (existing.TargetFormat == Preset.GroupTarget)+ existing.TargetFormat = hide.TargetFormat;+ changed = true;+ }+ }+ else+ {+ var at = presets.FindIndex(p => p.Id == "tool-crop");+ presets.Insert(at < 0 ? presets.Count : at + 1, hide);+ changed = true;+ }+ if (profiles.FirstOrDefault(p => p.Id == "images") is not { } images+ || images.PresetIds.Contains(hide.Id) || images.BackPresetIds?.Contains(hide.Id) == true)+ return changed;+ var front = images.PresetIds;+ // Next to the other everyday edits: "Half size", and "Edit pictures" when it follows it. A front without "Half+ // size" was laid out by the user and stays so, with the back face.+ var after = front.IndexOf("half-size");+ if (after < 0)+ return changed;+ if (after + 1 < front.Count && front[after + 1] == "tool-image-edit")+ after++;+ if (front.Count < ToolbarProfile.MaxSlices)+ {+ front.Insert(after + 1, hide.Id);+ return true;+ }+ if (images.BackPresetIds is { } back && back.Count < ToolbarProfile.MaxSlices)+ {+ InsertBefore(back, hide.Id, "zip-all");+ return true;+ }+ return changed;+ }+private static bool AddGeo(List<Preset> presets, List<ToolbarProfile> profiles){var changed = false;diff --git a/src/Filee.Engines/Magick/AreaHider.cs b/src/Filee.Engines/Magick/AreaHider.csnew file mode 100644index 00000000..fb6aab06--- /dev/null+++ b/src/Filee.Engines/Magick/AreaHider.cs@@ -0,0 +1,195 @@+// "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+// user sees while drawing the parts is what the file gets.++using Filee.Core.Presets;+using ImageMagick;++namespace Filee.Engines.Magick;++/// <summary>Pixelates or blurs parts of a picture for good.</summary>+public static class AreaHider+{+ /// <summary>+ /// Covers <see cref="ImageOptions.HiddenAreas"/> of <paramref name="image"/> (upright, as the parts were drawn) as+ /// <paramref name="options"/> say. Nothing happens without parts.+ /// </summary>+ public static void Apply(IMagickImage<byte> image, ImageOptions options)+ {+ if (!options.HidesAreas)+ return;+ int width = (int)image.Width, height = (int)image.Height;+ var size = HideTool.EffectSize(options.HideStrength, width, height);+ foreach (var area in options.HiddenAreas!)+ {+ 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));+ }+ DropPreviews(image);+ }++ /// <summary>+ /// The whole of <paramref name="image"/> covered with an effect <paramref name="size"/> pixels large (a square's side+ /// or the blur's sigma): the window's preview, of which it shows the parts inside the frames.+ /// </summary>+ public static void Cover(IMagickImage<byte> image, HideStyle style, double size)+ {+ var bounds = (0, 0, (int)image.Width, (int)image.Height);+ if (style == HideStyle.Blur)+ Blur(image, bounds, size);+ else+ Pixelate(image, bounds, size);+ }++ /// <summary>+ /// Every pixel of <paramref name="bounds"/> becomes the average colour of its square on a grid of+ /// <paramref name="cell"/>-pixel squares laid from the picture's top-left corner (<see cref="HideTool.CellOf"/>).+ /// </summary>+ /// <remarks>+ /// Averaging is many-to-one: a square's worth of pixels becomes one colour, and what made it up is gone. Squares on+ /// the edge of a part are averaged over all of their pixels, those beside the part too (which stay in view anyway):+ /// the grid stays the same wherever a part is moved, and two parts that meet look like one. How large a square has+ /// to be to make text unreadable is <see cref="HideTool.EffectSize"/>'s concern.+ /// </remarks>+ public static void Pixelate(IMagickImage<byte> image, (int X, int Y, int Width, int Height) bounds, double cell)+ {+ cell = Math.Max(1, cell);+ int width = (int)image.Width, height = (int)image.Height;+ var (x, y, w, h) = bounds;+ if (w <= 0 || h <= 0)+ return;+ // The squares the part touches, whole: their pixels beside the part count towards their colour.+ int firstColumn = HideTool.CellOf(x, cell), lastColumn = HideTool.CellOf(x + w - 1, cell);+ int firstRow = HideTool.CellOf(y, cell), lastRow = HideTool.CellOf(y + h - 1, cell);+ var left = Math.Max(0, HideTool.CellStart(firstColumn, cell));+ var right = Math.Min(width, HideTool.CellStart(lastColumn + 1, cell));+ var top = Math.Max(0, HideTool.CellStart(firstRow, cell));+ var bottom = Math.Min(height, HideTool.CellStart(lastRow + 1, cell));+ int regionWidth = right - left, regionHeight = bottom - top;+ // RGB(A) whatever the picture holds: the squares are written back as a picture of their own (see below).+ var mapping = image.HasAlpha ? PixelMapping.RGBA : PixelMapping.RGB;+ var channels = image.HasAlpha ? 4 : 3;+ int columns = lastColumn - firstColumn + 1, rows = lastRow - firstRow + 1;++ byte[] data;+ using (var pixels = image.GetPixels())+ data = pixels.ToByteArray(left, top, (uint)regionWidth, (uint)regionHeight, mapping)+ ?? throw new InvalidOperationException("The picture's pixels could not be read.");++ var columnOf = new int[regionWidth];+ for (var i = 0; i < regionWidth; i++)+ columnOf[i] = Math.Clamp(HideTool.CellOf(left + i, cell) - firstColumn, 0, columns - 1);+ var rowOf = new int[regionHeight];+ for (var j = 0; j < regionHeight; j++)+ rowOf[j] = Math.Clamp(HideTool.CellOf(top + j, cell) - firstRow, 0, rows - 1);++ var sums = new long[columns * rows * channels];+ var counts = new int[columns * rows];+ for (var j = 0; j < regionHeight; j++)+ {+ var rowBase = rowOf[j] * columns;+ var offset = j * regionWidth * channels;+ for (var i = 0; i < regionWidth; i++, offset += channels)+ {+ var square = rowBase + columnOf[i];+ counts[square]++;+ var sum = square * channels;+ for (var c = 0; c < channels; c++)+ sums[sum + c] += data[offset + c];+ }+ }+ var averages = new byte[sums.Length];+ for (var square = 0; square < counts.Length; square++)+ {+ var count = counts[square];+ if (count == 0)+ continue;+ for (var c = 0; c < channels; c++)+ averages[square * channels + c] = (byte)((sums[square * channels + c] + count / 2) / count);+ }++ // Only the part takes the squares' colours.+ for (var j = y - top; j < y - top + h; j++)+ {+ var rowBase = rowOf[j] * columns;+ for (var i = x - left; i < x - left + w; i++)+ {+ var square = (rowBase + columnOf[i]) * channels;+ Array.Copy(averages, square, data, (j * regionWidth + i) * channels, channels);+ }+ }+ // Copied over the picture as a picture of their own: writing the area into the pixels of a picture as the image+ // engine reads it left the rest of that picture black.+ using var squares = new MagickImage();+ squares.ReadPixels(data, new PixelReadSettings((uint)regionWidth, (uint)regionHeight, StorageType.Char, mapping));+ image.Composite(squares, left, top, 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.+ /// </summary>+ /// <remarks>+ /// A light blur can be undone: it is a known convolution, and deconvolving it (sharpening with the inverse) brings+ /// back text whose strokes it only smeared. Here the part is first scaled down by averaging, which throws pixels+ /// away for good, and then blurred so widely (a sigma about a line of text, see <see cref="HideTool.EffectSize"/>)+ /// that the detail of a letter is far below what an 8-bit pixel can hold. Pixels beside the part are blurred with+ /// it, so its edge doesn't show a seam, but only the part is written back.+ /// </remarks>+ public static void Blur(IMagickImage<byte> image, (int X, int Y, int Width, int Height) bounds, double sigma)+ {+ sigma = Math.Max(1, sigma);+ int width = (int)image.Width, height = (int)image.Height;+ var (x, y, w, h) = bounds;+ if (w <= 0 || h <= 0)+ return;+ var margin = (int)Math.Ceiling(2 * sigma);+ var left = Math.Max(0, x - margin);+ var top = Math.Max(0, y - margin);+ var right = Math.Min(width, x + w + margin);+ var bottom = Math.Min(height, y + h + margin);+ int regionWidth = right - left, regionHeight = bottom - top;++ using var part = image.CloneArea(new MagickGeometry(left, top, (uint)regionWidth, (uint)regionHeight));+ part.ResetPage();+ var step = Math.Max(1, (int)Math.Floor(sigma / 3));+ if (step > 1)+ {+ part.Scale(new MagickGeometry((uint)Math.Max(1, (regionWidth + step - 1) / step), (uint)Math.Max(1, (regionHeight + step - 1) / step))+ {+ IgnoreAspectRatio = true,+ });+ }+ part.GaussianBlur(0, sigma / step);+ if (step > 1)+ {+ part.FilterType = FilterType.Triangle;+ part.Resize(new MagickGeometry((uint)regionWidth, (uint)regionHeight) { IgnoreAspectRatio = true });+ }+ part.Crop(new MagickGeometry(x - left, y - top, (uint)w, (uint)h));+ part.ResetPage();+ image.Composite(part, x, y, CompositeOperator.Copy);+ }++ /// <summary>+ /// Drops the small previews a file may carry of the picture as it was: EXIF's thumbnail, Photoshop's (in its 8BIM+ /// resources) and XMP's. Viewers that show them would show the hidden parts.+ /// </summary>+ internal static void DropPreviews(IMagickImage<byte> image)+ {+ if (image.GetExifProfile() is { } exif && exif.ThumbnailLength > 0)+ {+ exif.RemoveThumbnail();+ image.SetProfile(exif);+ }+ if (image.HasProfile("8bim"))+ image.RemoveProfile("8bim");+ if (image.GetXmpProfile() is { } xmp+ && System.Text.Encoding.UTF8.GetString(xmp.ToByteArray()).Contains("Thumbnails", StringComparison.Ordinal))+ image.RemoveProfile("xmp");+ }+}diff --git a/src/Filee.Engines/Magick/ImageEncoder.cs b/src/Filee.Engines/Magick/ImageEncoder.csindex 1296655a..ee34b200 100644--- a/src/Filee.Engines/Magick/ImageEncoder.cs+++ b/src/Filee.Engines/Magick/ImageEncoder.cs@@ -268,6 +268,10 @@ internal static class ImageEncodervar turned = options.TurnsOrMirrors || image.Orientation is not (OrientationType.TopLeft or OrientationType.Undefined);image.AutoOrient();+ // "Pixelate / blur": the parts were drawn on the picture as it is seen, before it is turned or resized. It also+ // drops the small previews of the uncovered picture a file can carry.+ AreaHider.Apply(image, options);+// After AutoOrient, so a phone photo turns the way it looks, not the way its pixels are stored.Turn(image, options);// The small preview kept in the EXIF data still shows the picture as it was: Explorer and photo apps thatdiff --git a/tests/Filee.App.Tests/HideWindowTests.cs b/tests/Filee.App.Tests/HideWindowTests.csnew file mode 100644index 00000000..f251e5f3--- /dev/null+++ b/tests/Filee.App.Tests/HideWindowTests.cs@@ -0,0 +1,464 @@+// The "Pixelate / blur" window: the empty picture's hint, frames showing the picture already pixelated or blurred, the+// strip of several files and the end summary (screenshots in light, dark, Material You and a theme.json, short, long+// and right-to-left languages), drawing and dragging frames with the mouse, its keys, the conversion it starts and the+// choice it remembers.++using System.IO;+using Avalonia;+using Avalonia.Controls;+using Avalonia.Headless;+using Avalonia.Headless.XUnit;+using Avalonia.Input;+using Avalonia.Threading;+using Avalonia.VisualTree;+using Filee.App.Controls;+using Filee.App.Services;+using Filee.App.ViewModels;+using Filee.App.Views;+using Filee.Core.Localization;+using Filee.Core.Presets;+using Filee.Core.Settings;+using ImageMagick;+using ImageMagick.Drawing;+using static Filee.App.Tests.RenderTests;++namespace Filee.App.Tests;++public class HideWindowTests+{+ public static TheoryData<string, string> Looks => new()+ {+ { "en", "light" }, { "en", "dark" }, { "ko", "light" }, { "ko", "dark" }, { "de", "light" }, { "de", "dark" },+ { "ar", "light" }, { "ar", "dark" }, { "ru", "light" }, { "hi", "light" }, { "ne", "dark" }, { "ja", "light" },+ { "en", "material" }, { "en", "custom" },+ };++ /// <summary>The frames of the screenshots: a name, a phone number, a face.</summary>+ private static readonly Rect[] Frames = [new(0.062, 0.148, 0.16, 0.07), new(0.07, 0.62, 0.38, 0.08), new(0.63, 0.19, 0.24, 0.39)];++ [AvaloniaTheory]+ [MemberData(nameof(Looks))]+ public void A_picture_shows_the_hint_then_its_frames_pixelated_or_blurred(string language, string look)+ {+ WithWindow(language, look, ["chat.png"], (window, vm, suffix, _) =>+ {+ Assert.False(vm.HasMultipleFiles);+ Assert.Equal(AppHost.Get<ILocalizer>()["hide.save"], vm.SaveText);+ Assert.True(vm.ShowEmptyHint);+ Assert.False(vm.CanSave);+ Assert.False(vm.SaveCommand.CanExecute(null));+ Settle(window);+ Save(window, $"hide-empty-{suffix}.png");++ vm.Strength = 5;+ vm.SetStyle(HideStyle.Pixelate);+ foreach (var frame in Frames)+ vm.Areas.Add(frame);+ vm.Areas.Select(1);+ WaitForCover(vm);+ Settle(window);+ Assert.False(vm.ShowEmptyHint);+ Assert.True(vm.CanSave);+ Save(window, $"hide-pixelate-{suffix}.png");++ vm.SetStyle(HideStyle.Blur);+ vm.Strength = 7;+ vm.Areas.Select(2);+ WaitForCover(vm);+ Settle(window);+ Save(window, $"hide-blur-{suffix}.png");+ });+ }++ [AvaloniaTheory]+ [InlineData("en", "light")]+ [InlineData("en", "dark")]+ [InlineData("de", "light")]+ [InlineData("ar", "dark")]+ [InlineData("ko", "light")]+ [InlineData("ru", "dark")]+ public void Several_files_show_a_strip_and_the_frames_carry_on_to_the_next(string language, string look)+ {+ WithWindow(language, look, ["one.png", "two.png", "spinner.gif", "four.png"], (window, vm, suffix, exported) =>+ {+ Assert.True(vm.HasMultipleFiles);+ Assert.Equal(AppHost.Get<ILocalizer>()["hide.save_next"], vm.SaveText);++ vm.Areas.Add(Frames[0]);+ vm.Areas.Add(Frames[2]);+ _ = vm.SaveAsync();+ WaitFor(() => vm.CurrentIndex == 1 && !vm.IsBusy && vm.CoverImage is not null);++ // The second picture starts with the first one's frames, none selected.+ Assert.Equal(2, vm.Areas.Count);+ AssertClose(Frames[0], vm.Areas.Areas[0]);+ AssertClose(Frames[2], vm.Areas.Areas[1]);+ Assert.Equal(-1, vm.Areas.Selected);+ Assert.False(vm.CanUndo);+ vm.Areas.Select(0);+ WaitForCover(vm);+ Settle(window);+ Save(window, $"hide-multi-{suffix}.png");++ // Skipped; the animated GIF can't be opened and fails on its own; the last one is saved.+ _ = vm.SkipAsync();+ WaitFor(() => vm.CurrentIndex == 3 && !vm.IsBusy && vm.PreviewImage is not null);+ Assert.Equal(+ [CropItemState.Done, CropItemState.Skipped, CropItemState.Failed, CropItemState.Current],+ vm.Queue.Select(q => q.State));+ _ = vm.SaveAsync();+ WaitFor(() => vm.IsFinished);+ Assert.Equal((2, 1, 1), (vm.DoneCount, vm.SkippedCount, vm.FailedCount));+ Assert.Equal(2, exported.Count);+ Settle(window);+ Save(window, $"hide-summary-{suffix}.png");+ });+ }++ [AvaloniaFact]+ public void Dragging_on_the_picture_draws_a_frame_that_moves_sizes_and_shows_the_cover_at_once()+ {+ WithWindow("en", "light", ["chat.png"], (window, vm, _, _) =>+ {+ var canvas = window.HideCanvas;+ var picture = canvas.CalculateImageBounds();+ var origin = (Vector)canvas.TranslatePoint(default, window)!.Value;+ Point At(double x, double y) => new Point(picture.X + picture.Width * x, picture.Y + picture.Height * y) + origin;++ // A click beside every frame draws nothing.+ window.MouseDown(At(0.5, 0.5), MouseButton.Left);+ window.MouseUp(At(0.5, 0.5), MouseButton.Left);+ Assert.Equal(0, vm.Areas.Count);++ // A drag draws one, selected, already covered while the button is still down.+ window.MouseDown(At(0.1, 0.1), MouseButton.Left);+ window.MouseMove(At(0.2, 0.15));+ window.MouseMove(At(0.4, 0.3));+ Pump();+ Assert.Equal(1, vm.Areas.Count);+ Assert.Equal(0, vm.Areas.Selected);+ WaitForCover(vm);+ Settle(window);+ Save(window, "hide-drag-en.png");+ window.MouseUp(At(0.4, 0.3), MouseButton.Left);+ AssertClose(new Rect(0.1, 0.1, 0.3, 0.2), vm.Areas.Areas[0]);++ // Moved by its middle, sized by its corner; each drag is one undo step.+ window.MouseDown(At(0.25, 0.2), MouseButton.Left);+ window.MouseMove(At(0.3, 0.25));+ window.MouseMove(At(0.35, 0.3));+ window.MouseUp(At(0.35, 0.3), MouseButton.Left);+ AssertClose(new Rect(0.2, 0.2, 0.3, 0.2), vm.Areas.Areas[0]);+ var corner = At(0.5, 0.4);+ window.MouseDown(corner, MouseButton.Left);+ window.MouseMove(corner + new Vector(10, 10));+ window.MouseMove(At(0.6, 0.5));+ window.MouseUp(At(0.6, 0.5), MouseButton.Left);+ AssertClose(new Rect(0.2, 0.2, 0.4, 0.3), vm.Areas.Areas[0]);+ vm.Undo();+ AssertClose(new Rect(0.2, 0.2, 0.3, 0.2), vm.Areas.Areas[0]);+ vm.Undo();+ AssertClose(new Rect(0.1, 0.1, 0.3, 0.2), vm.Areas.Areas[0]);+ vm.Redo();+ AssertClose(new Rect(0.2, 0.2, 0.3, 0.2), vm.Areas.Areas[0]);++ // A second frame; a click on the first selects it again, a click beside both selects none.+ window.MouseDown(At(0.7, 0.7), MouseButton.Left);+ window.MouseMove(At(0.8, 0.8));+ window.MouseMove(At(0.9, 0.9));+ window.MouseUp(At(0.9, 0.9), MouseButton.Left);+ Assert.Equal((2, 1), (vm.Areas.Count, vm.Areas.Selected));+ window.MouseDown(At(0.3, 0.3), MouseButton.Left);+ window.MouseUp(At(0.3, 0.3), MouseButton.Left);+ Assert.Equal(0, vm.Areas.Selected);+ window.MouseDown(At(0.05, 0.9), MouseButton.Left);+ window.MouseUp(At(0.05, 0.9), MouseButton.Left);+ Assert.Equal(-1, vm.Areas.Selected);+ Assert.False(vm.HasSelection);++ // Under the pointer a frame that isn't selected shows its full outline.+ vm.Areas.Select(1);+ window.MouseMove(At(0.3, 0.3));+ Settle(window);+ Save(window, "hide-hover-en.png");+ });+ }++ [AvaloniaFact]+ public void Keys_pick_move_remove_and_undo_frames_change_the_cover_save_and_close()+ {+ WithWindow("en", "light", ["chat.png"], (window, vm, _, exported) =>+ {+ // Without frames Enter saves nothing, and Tab leaves the frames alone.+ Press(window, Key.Enter);+ Assert.Empty(exported);++ vm.Areas.Add(new Rect(0.25, 0.25, 0.5, 0.5)); // 400, 250, 800 × 500 of 1600 × 1000+ vm.Areas.Add(new Rect(0.1, 0.1, 0.1, 0.1));+ vm.Areas.Select(-1);++ // Tab goes from frame to frame, Shift+Tab back.+ Press(window, Key.Tab);+ Assert.Equal(0, vm.Areas.Selected);+ Press(window, Key.Tab);+ Assert.Equal(1, vm.Areas.Selected);+ Press(window, Key.Tab);+ Assert.Equal(0, vm.Areas.Selected);+ Press(window, Key.Tab, RawInputModifiers.Shift);+ Assert.Equal(1, vm.Areas.Selected);+ Press(window, Key.Tab, RawInputModifiers.Shift);+ Assert.Equal(0, vm.Areas.Selected);++ // Arrows move it by pixels of the picture, Shift by ten.+ Press(window, Key.Right);+ Press(window, Key.Right);+ Press(window, Key.Down, RawInputModifiers.Shift);+ Assert.Equal(new Rect(402 / 1600.0, 260 / 1000.0, 0.5, 0.5), vm.Areas.Areas[0]);++ // Delete removes it, Ctrl+Z brings it back, Ctrl+Y removes it again.+ Press(window, Key.Delete);+ Assert.Equal(1, vm.Areas.Count);+ Press(window, Key.Z, RawInputModifiers.Control);+ Assert.Equal(2, vm.Areas.Count);+ Press(window, Key.Y, RawInputModifiers.Control);+ Assert.Equal(1, vm.Areas.Count);+ Press(window, Key.Z, RawInputModifiers.Control);++ // R clears every frame, undoably.+ Press(window, Key.R);+ Assert.Equal(0, vm.Areas.Count);+ Press(window, Key.Z, RawInputModifiers.Control);+ Assert.Equal(2, vm.Areas.Count);++ // P, B and + / − choose the cover.+ Press(window, Key.B);+ Assert.Equal(HideStyle.Blur, vm.Style);+ Press(window, Key.P);+ Assert.Equal(HideStyle.Pixelate, vm.Style);+ var strength = vm.Strength;+ Press(window, Key.OemPlus);+ Assert.Equal(strength + 1, vm.Strength);+ Press(window, Key.OemMinus);+ Press(window, Key.OemMinus);+ Assert.Equal(strength - 1, vm.Strength);+ for (var i = 0; i < 20; i++)+ Press(window, Key.OemMinus);+ Assert.Equal(HideTool.MinStrength, vm.Strength);++ // Enter saves: one conversion of the picture with both frames, as chosen, and the window closes.+ vm.SetStyle(HideStyle.Blur);+ vm.Strength = 8;+ var closed = false;+ window.Closed += (_, _) => closed = true;+ Press(window, Key.Enter);+ WaitFor(() => closed);+ var (path, conversion) = Assert.Single(exported);+ Assert.EndsWith("chat.png", path);+ Assert.Equal(PresetKind.Convert, conversion.Kind);+ Assert.Equal(BuiltInData.SameAsSource, conversion.TargetFormat);+ Assert.Equal(HideStyle.Blur, conversion.Image.HideStyle);+ Assert.Equal(8, conversion.Image.HideStrength);+ Assert.Equal(2, conversion.Image.HiddenAreas!.Count);+ Assert.Equal(402 / 1600.0, conversion.Image.HiddenAreas[0].X, 6);+ });+ }++ [AvaloniaFact]+ public void Escape_closes_without_saving_and_the_choice_is_remembered_in_the_tool()+ {+ WithWindow("en", "light", ["chat.png"], (window, vm, _, exported) =>+ {+ vm.Areas.Add(Frames[0]);+ vm.SetStyle(HideStyle.Blur);+ vm.Strength = 9;+ var closed = false;+ window.Closed += (_, _) => closed = true;+ Press(window, Key.Escape);+ Assert.True(closed);+ Assert.Empty(exported);+ var saved = AppHost.Get<UserDataStore>().FindPreset("tool-hide")!;+ Assert.Equal((HideStyle.Blur, 9), (saved.Image.HideStyle, saved.Image.HideStrength));+ Assert.Null(saved.Image.HiddenAreas);+ });++ // The next window opens with it.+ WithWindow("en", "light", ["chat.png"], (_, vm, _, _) => Assert.Equal((HideStyle.Blur, 9), (vm.Style, vm.Strength)),+ resetTool: false);+ var store = AppHost.Get<UserDataStore>();+ HideTool.Remember(store.FindPreset("tool-hide")!, HideStyle.Pixelate, HideTool.DefaultStrength);+ store.SaveLibrary();+ }++ [AvaloniaTheory]+ [InlineData("de", "light")]+ [InlineData("ru", "dark")]+ [InlineData("ne", "light")]+ [InlineData("ar", "light")]+ [InlineData("en", "light")]+ public void At_its_smallest_the_toolbar_still_fits_the_window(string language, string look)+ {+ WithWindow(language, look, ["one.png", "two.png"], (window, vm, suffix, _) =>+ {+ window.Width = window.MinWidth;+ window.Height = window.MinHeight;+ vm.Areas.Add(Frames[0]);+ WaitForCover(vm);+ Settle(window);+ // Every button of the toolbar is whole inside the window (also in a right-to-left one), Hide & Next too.+ var buttons = window.GetVisualDescendants().OfType<Border>().Single(b => b.Name == "Toolbar")+ .GetVisualDescendants().OfType<Button>().Where(b => b.IsEffectivelyVisible).ToList();+ Assert.Contains(buttons, b => b.Name == "PrimaryButton");+ foreach (var button in buttons)+ {+ var a = button.TranslatePoint(default, window)!.Value;+ var b = button.TranslatePoint(new Point(button.Bounds.Width, button.Bounds.Height), window)!.Value;+ var bounds = new Rect(a, b).Normalize();+ Assert.True(bounds.Left >= 12 && bounds.Right <= window.Bounds.Width - 12, $"{button.Name}: {bounds} outside {window.Bounds}");+ }+ Assert.Contains("compact", window.Classes); // the names don't fit next to each other here+ Save(window, $"hide-narrow-{suffix}.png");++ // Wide again: the names come back.+ window.Width = 1040;+ Settle(window);+ Assert.DoesNotContain("compact", window.Classes);+ });+ }++ // ───────────────────────── Helpers ─────────────────────────++ private static void AssertClose(Rect expected, Rect actual)+ {+ Assert.Equal(expected.X, actual.X, 2);+ Assert.Equal(expected.Y, actual.Y, 2);+ Assert.Equal(expected.Width, actual.Width, 2);+ Assert.Equal(expected.Height, actual.Height, 2);+ }++ private static void WithWindow(string language, string look, string[] names,+ Action<HideWindow, HideWindowViewModel, string, List<(string Path, Preset Conversion)>> act, bool resetTool = true)+ {+ TestServices.EnsureInitialized(language);+ var theme = AppHost.Get<ThemeService>();+ switch (look)+ {+ case "dark":+ theme.Apply(new ThemeSettings { Mode = ThemeMode.Dark }, language);+ break;+ case "material":+ theme.Apply(new ThemeSettings { Style = ThemeStyle.MaterialYou, Accent = "#2E7D5B" }, language);+ break;+ case "custom":+ theme.Apply(new ThemeSettings { Mode = ThemeMode.Dark }, language, new CustomTheme+ {+ Dark = { ["page"] = "#101820", ["surface"] = "#18222C", ["surfaceAlt"] = "#22303C", ["text"] = "#E8E4D8" },+ });+ break;+ }+ var store = AppHost.Get<UserDataStore>();+ var tool = store.FindPreset("tool-hide");+ if (tool is null)+ {+ tool = BuiltInData.HidePresets().Single();+ store.Presets.Add(tool);+ }+ // Each test starts from the built-in choice, unless it looks at what the last one kept.+ if (resetTool)+ HideTool.Remember(tool, HideStyle.Pixelate, HideTool.DefaultStrength);+ var folder = Directory.CreateTempSubdirectory("filee-hide-").FullName;+ HideWindow? window = null;+ var exported = new List<(string, Preset)>();+ try+ {+ var files = names.Select(name => Picture(folder, name)).ToList();+ var vm = new HideWindowViewModel(files, tool, AppHost.Get<ILocalizer>(), store,+ _ => BuiltInData.SameAsSource, (path, conversion) => exported.Add((path, conversion)));+ window = new HideWindow { DataContext = vm, Width = 1040, Height = 720 };+ theme.ApplyWindowClass(window);+ window.Show();+ WaitFor(() => vm.PreviewImage is not null && !vm.IsBusy);+ WaitForCover(vm);+ Pump();+ window.HideCanvas.FinishAnimations();+ act(window, vm, $"{language}-{look}", exported);+ }+ finally+ {+ if (window?.IsVisible == true)+ window.Close();+ if (look != "light")+ theme.Apply(new ThemeSettings(), language);+ try { Directory.Delete(folder, true); } catch (IOException) { }+ }+ }++ /// <summary>+ /// A 1600 × 1000 chat screenshot: a name, a message, a phone number and a face-like circle; or a two-frame GIF+ /// ("…gif").+ /// </summary>+ internal static string Picture(string folder, string name)+ {+ var path = Path.Combine(folder, name);+ if (name.EndsWith(".gif", StringComparison.Ordinal))+ {+ using var frames = new MagickImageCollection();+ frames.Add(new MagickImage(MagickColors.Coral, 40, 40));+ frames.Add(new MagickImage(MagickColors.Teal, 40, 40));+ frames.Write(path, MagickFormat.Gif);+ return path;+ }+ var hue = name.Sum(c => c) % 3;+ string[] skies = ["#F4F1FB-#E3ECFA", "#FDF4EC-#F6E7F1", "#EEF7F1-#E2EEF8"];+ using var image = new MagickImage($"gradient:{skies[hue]}", 1600, 1000);+ var draw = new Drawables()+ .FillColor(new MagickColor("#FFFFFF")).RoundRectangle(80, 110, 760, 260, 28, 28)+ .FillColor(new MagickColor("#7F77DD")).RoundRectangle(80, 560, 860, 740, 28, 28)+ .FillColor(new MagickColor("#F2C9A0")).Circle(1200, 380, 1200, 560)+ .FillColor(new MagickColor("#3A3530")).Circle(1135, 350, 1135, 372).Circle(1265, 350, 1265, 372)+ .StrokeColor(new MagickColor("#3A3530")).StrokeWidth(10).FillColor(MagickColors.Transparent)+ .Arc(1120, 380, 1280, 480, 20, 160)+ .StrokeWidth(0);+ draw.Draw(image);+ try+ {+ new Drawables().FontPointSize(54).FillColor(new MagickColor("#2B2930"))+ .Text(110, 205, "Alex Kim")+ .FontPointSize(40).FillColor(new MagickColor("#4A4650")).Text(110, 250, "See you at 7, near the station")+ .FontPointSize(58).FillColor(new MagickColor("#FFFFFF")).Text(120, 680, "+82 10-1234-5678")+ .Draw(image);+ }+ catch (MagickException)+ {+ // No font here: bars in place of the text are enough to see the frames.+ new Drawables().FillColor(new MagickColor("#2B2930")).Rectangle(110, 160, 400, 210)+ .FillColor(new MagickColor("#FFFFFF")).Rectangle(120, 630, 700, 690).Draw(image);+ }+ image.Write(path, MagickFormat.Png);+ return path;+ }++ private static void WaitForCover(HideWindowViewModel vm) => WaitFor(() => vm.IsCoverCurrent);++ private static void Settle(HideWindow window)+ {+ Pump();+ window.SettleForCapture();+ Pump();+ }++ private static void Press(HideWindow window, Key key, RawInputModifiers modifiers = RawInputModifiers.None)+ {+ window.KeyPress(key, modifiers, PhysicalKey.None, null);+ Dispatcher.UIThread.RunJobs();+ }++ private static void WaitFor(Func<bool> condition)+ {+ for (var i = 0; i < 500 && !condition(); i++)+ {+ Dispatcher.UIThread.RunJobs();+ Thread.Sleep(10);+ }+ Assert.True(condition());+ }+}diff --git a/tests/Filee.App.Tests/RenderTests.cs b/tests/Filee.App.Tests/RenderTests.csindex bbe3de5b..4411c3bf 100644--- a/tests/Filee.App.Tests/RenderTests.cs+++ b/tests/Filee.App.Tests/RenderTests.cs@@ -918,7 +918,7 @@ public class RenderTestswindow.DonutControl.SetExternalHighlight(1);Pump();- Assert.Equal(10, vm.Items.Count); // with "Trace to SVG" and "Line art to SVG"+ Assert.Equal(11, vm.Items.Count); // with "Trace to SVG", "Line art to SVG" and "Pixelate / blur"Assert.Equal(title, vm.CenterTitle);Save(window, $"donut-images-{language}.png");window.Close();diff --git a/tests/Filee.App.Tests/ToolbarPaletteViewTests.cs b/tests/Filee.App.Tests/ToolbarPaletteViewTests.csindex 2066268e..997af4b6 100644--- a/tests/Filee.App.Tests/ToolbarPaletteViewTests.cs+++ b/tests/Filee.App.Tests/ToolbarPaletteViewTests.cs@@ -486,15 +486,18 @@ public class ToolbarPaletteViewTestsAssert.Equal(PaletteTab.All, view.Selected);Assert.Contains("test-jpg", view.Chips);- // Back on JPG: All again. Its only edit preset goes on the donut, the Edit tab empties and All takes over.+ // Back on JPG: All again. Its only edit presets go on the donut, the Edit tab empties and All takes over.profiles.SelectedItem = vm.Profiles.Single(p => p.Profile == jpg);RenderTests.Pump();Assert.Equal(PaletteTab.All, view.Selected);view.ClickTab(PaletteTab.Edit);- Assert.Equal(["pdf-edit", "rotate", "flip", "test-group", "tool-crop"], view.Chips);+ Assert.Equal(["pdf-edit", "rotate", "flip", "test-group", "tool-crop", "tool-hide"], view.Chips);DoubleTap(view.Chip("tool-crop"));RenderTests.Pump();Assert.Equal(["tool-crop"], jpg.PresetIds);+ DoubleTap(view.Chip("tool-hide"));+ RenderTests.Pump();+ Assert.Equal(["tool-crop", "tool-hide"], jpg.PresetIds);Assert.DoesNotContain(PaletteTab.Edit, view.TabIds);Assert.Equal(PaletteTab.All, view.Selected);Assert.Equal(["pdf-edit", "rotate", "flip", "test-group", "extract-motion", "test-motion"], view.Chips);diff --git a/tests/Filee.Core.Tests/BackFaceTests.cs b/tests/Filee.Core.Tests/BackFaceTests.csindex 1f15ee4f..d27e522d 100644--- a/tests/Filee.Core.Tests/BackFaceTests.cs+++ b/tests/Filee.Core.Tests/BackFaceTests.cs@@ -94,8 +94,8 @@ public class BackFaceTests[Fact]public void The_fronts_stay_as_they_were_before_back_faces(){- Assert.Equal(["to-png", "to-jpg", "to-webp", "to-pdf", "trace-svg", "trace-line-art", "to-tiff", "to-bmp", "to-ico", "half-size"],- BuiltIn("images").PresetIds);+ Assert.Equal(["to-png", "to-jpg", "to-webp", "to-pdf", "trace-svg", "trace-line-art", "to-tiff", "to-bmp", "to-ico", "half-size",+ "tool-hide"], BuiltIn("images").PresetIds);Assert.Equal(BuiltInData.PdfDonut, BuiltIn("pdf").PresetIds);Assert.Equal(["to-pdf", "to-hwpx", "to-hwp", "to-docx", "to-odt", "to-txt", "to-html", "to-epub", "to-png", "merge-pdf"],BuiltIn("office").PresetIds);diff --git a/tests/Filee.Core.Tests/HideToolTests.cs b/tests/Filee.Core.Tests/HideToolTests.csnew file mode 100644index 00000000..d07f9451--- /dev/null+++ b/tests/Filee.Core.Tests/HideToolTests.cs@@ -0,0 +1,404 @@+// "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_crop_and_on_the_images_donut_after_half_size()+ {+ var presets = BuiltInData.CreatePresets();+ Assert.Equal("tool-crop", presets[presets.FindIndex(p => p.Id == "tool-hide") - 1].Id);+ var images = BuiltInData.CreateProfiles().Single(p => p.Id == "images");+ Assert.Equal("tool-hide", images.PresetIds[images.PresetIds.IndexOf("half-size") + 1]);+ Assert.DoesNotContain("tool-hide", images.BackPresetIds!);+ Assert.InRange(images.PresetIds.Count, 1, ToolbarProfile.MaxSlices);+ }++ private static (List<Preset> Presets, List<ToolbarProfile> Profiles, ToolbarProfile Images) Version50()+ {+ 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_50_libraries_get_the_tool_after_half_size_once()+ {+ var (presets, profiles, images) = Version50();++ Assert.True(SettingsMigrations.ApplyToLibrary(50, 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()+ {+ var (presets, profiles, images) = Version50();+ images.PresetIds.Insert(images.PresetIds.IndexOf("half-size") + 1, "tool-image-edit");++ SettingsMigrations.ApplyToLibrary(51, presets, profiles);++ Assert.Equal(["half-size", "tool-image-edit", "tool-hide"], images.PresetIds.Skip(images.PresetIds.IndexOf("half-size")).Take(3));+ }++ [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) = Version50();+ while (images.PresetIds.Count < ToolbarProfile.MaxSlices)+ images.PresetIds.Add("to-gif");+ images.BackPresetIds!.Remove("grayscale");+ SettingsMigrations.ApplyToLibrary(50, 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) = Version50();+ 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(50, 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) = Version50();+ images.BackPresetIds!.Remove("grayscale");+ images.BackPresetIds.Insert(0, "tool-hide");+ presets.Insert(0, Tool());+ SettingsMigrations.ApplyToLibrary(50, 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);+ }+ }+}diff --git a/tests/Filee.Engines.Tests/HideAreasTests.cs b/tests/Filee.Engines.Tests/HideAreasTests.csnew file mode 100644index 00000000..c2f1f265--- /dev/null+++ b/tests/Filee.Engines.Tests/HideAreasTests.cs@@ -0,0 +1,237 @@+// "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+// (EXIF orientation), the format stays, and the previews a file carries of the uncovered picture go.++using Filee.Core.Conversion;+using Filee.Core.Presets;+using Filee.Engines.Magick;+using ImageMagick;++namespace Filee.Engines.Tests;++public class HideAreasTests(EngineFixture fx) : IClassFixture<EngineFixture>+{+ private static Preset Hide(HideStyle style, int strength, params HiddenArea[] areas)+ {+ var tool = BuiltInData.CreatePresets().Single(p => p.Id == "tool-hide");+ HideTool.Remember(tool, style, strength);+ return HideTool.ConversionOf(tool, BuiltInData.SameAsSource, areas);+ }++ private static HiddenArea Area(double x, double y, double w, double h) => new() { X = x, Y = y, Width = w, Height = h };++ /// <summary>A picture of random grey noise: every pixel differs from its neighbours, the hardest thing to cover.</summary>+ private static MagickImage Noise(uint width, uint height, int seed = 7)+ {+ var random = new Random(seed);+ var pixels = new byte[width * height * 3];+ random.NextBytes(pixels);+ var image = new MagickImage(MagickColors.Black, width, height);+ image.ImportPixels(pixels, new PixelImportSettings(width, height, StorageType.Char, PixelMapping.RGB));+ return image;+ }++ private async Task<string> RunAsync(string input, Preset preset)+ {+ var job = await fx.ConvertAsync([input], preset);+ Assert.True(job.State == JobState.Completed, string.Join("; ", job.Files.Select(f => $"{f.ErrorKey} {f.ErrorDetail}")));+ return Assert.Single(job.Outputs);+ }++ private static byte[] Rgb(IMagickImage<byte> image) => image.GetPixels().ToByteArray(PixelMapping.RGB)!;++ [Fact]+ public async Task Pixelate_turns_the_part_into_squares_of_its_average_and_keeps_everything_else()+ {+ var folder = fx.NewFolder();+ var path = Path.Combine(folder, "noise.png");+ using (var source = Noise(500, 400))+ source.Write(path, MagickFormat.Png);+ // Strength 5 on a 400 px tall picture: squares of 16 px (4 %), laid from the top-left corner of the picture.+ var cell = (int)Math.Round(HideTool.EffectSize(5, 500, 400));+ Assert.Equal(16, cell);++ var output = await RunAsync(path, Hide(HideStyle.Pixelate, 5, Area(0.1, 0.1, 0.4, 0.5))); // 50, 40, 200 × 200++ Assert.Equal(Path.Combine(folder, "noise_hidden.png"), output);+ using var before = new MagickImage(path);+ using var after = new MagickImage(output);+ var (a, b) = (Rgb(before), Rgb(after));+ int Index(int x, int y) => (y * 500 + x) * 3;+ for (var y = 0; y < 400; y++)+ {+ for (var x = 0; x < 500; x++)+ {+ var inside = x is >= 50 and < 250 && y is >= 40 and < 240;+ if (!inside)+ {+ Assert.True(a[Index(x, y)] == b[Index(x, y)] && a[Index(x, y) + 2] == b[Index(x, y) + 2], $"({x}, {y}) changed");+ continue;+ }+ // Inside: the colour of its square's first pixel inside the part, and of no single source pixel nearby.+ var (sx, sy) = (Math.Max(50, x / cell * cell), Math.Max(40, y / cell * cell));+ Assert.Equal(b[Index(sx, sy)], b[Index(x, y)]);+ }+ }+ // A square wholly inside the part (64…80 × 48…64) is its exact average.+ for (var c = 0; c < 3; c++)+ {+ long sum = 0;+ for (var y = 48; y < 64; y++)+ for (var x = 64; x < 80; x++)+ sum += a[Index(x, y) + c];+ Assert.Equal((byte)((sum + 128) / 256), b[Index(70, 50) + c]);+ }+ }++ [Fact]+ public async Task Blur_leaves_none_of_the_parts_detail_and_keeps_everything_else()+ {+ var folder = fx.NewFolder();+ var path = Path.Combine(folder, "noise.png");+ using (var source = Noise(600, 400))+ source.Write(path, MagickFormat.Png);++ var output = await RunAsync(path, Hide(HideStyle.Blur, HideTool.MinStrength, Area(0.25, 0.25, 0.5, 0.5))); // 150, 100, 300 × 200++ using var before = new MagickImage(path);+ using var after = new MagickImage(output);+ var (a, b) = (Rgb(before), Rgb(after));+ int Index(int x, int y) => (y * 600 + x) * 3;+ // Noise has a spread of about 74 levels; even the weakest blur leaves next to none inside the part (away from its+ // edges, where the noise around it still counts).+ var inside = new List<double>();+ for (var y = 130; y < 270; y++)+ for (var x = 180; x < 420; x++)+ inside.Add(b[Index(x, y)]);+ var mean = inside.Average();+ var spread = Math.Sqrt(inside.Average(v => (v - mean) * (v - mean)));+ Assert.True(spread < 3, $"spread {spread:0.00}");+ Assert.InRange(mean, 110, 145);+ // Outside, every pixel as it was.+ for (var y = 0; y < 400; y += 3)+ {+ for (var x = 0; x < 600; x += 3)+ {+ if (x is >= 150 and < 450 && y is >= 100 and < 300)+ continue;+ Assert.True(a[Index(x, y)] == b[Index(x, y)], $"({x}, {y}) changed");+ }+ }+ }++ [Fact]+ public void A_light_blur_would_keep_the_detail_this_one_takes()+ {+ // The reason for the size: a blur of a pixel and a half leaves strokes of a desktop screenshot's text (4 px apart)+ // easy to tell, and sharpening would bring them back; the weakest blur on that screenshot (1920 × 1080) leaves+ // no more than the rounding of a level of 255 of them.+ var data = new byte[400 * 200 * 3];+ for (var y = 0; y < 200; y++)+ for (var x = 0; x < 400; x++)+ data[(y * 400 + x) * 3] = data[(y * 400 + x) * 3 + 1] = data[(y * 400 + x) * 3 + 2] = (byte)(x / 4 % 2 == 0 ? 0 : 255);+ using var stripes = new MagickImage(MagickColors.White, 400, 200);+ stripes.ImportPixels(data, new PixelImportSettings(400, 200, StorageType.Char, PixelMapping.RGB));++ double Contrast(double sigma)+ {+ using var copy = stripes.Clone();+ AreaHider.Blur(copy, (0, 0, 400, 200), sigma);+ var row = copy.GetPixels().ToByteArray(0, 100, 400, 1, PixelMapping.RGB)!;+ var values = Enumerable.Range(100, 200).Select(x => (double)row[x * 3]).ToList();+ return values.Max() - values.Min();+ }++ var light = Contrast(1.5);+ var weakest = Contrast(HideTool.EffectSize(HideTool.MinStrength, 1920, 1080));+ Assert.True(light > 100, $"{light}");+ Assert.True(weakest <= 1, $"{weakest}");+ }++ [Fact]+ public async Task Two_parts_that_meet_share_one_grid_and_a_jpeg_stays_a_jpeg()+ {+ var folder = fx.NewFolder();+ var path = Path.Combine(folder, "shot.jpg");+ using (var source = Noise(800, 500))+ {+ source.Quality = 95;+ source.Write(path, MagickFormat.Jpeg);+ }++ var output = await RunAsync(path, Hide(HideStyle.Pixelate, 1, Area(0.1, 0.2, 0.2, 0.3), Area(0.3, 0.2, 0.2, 0.3)));++ Assert.Equal(Path.Combine(folder, "shot_hidden.jpg"), output);+ using var after = new MagickImage(output);+ Assert.Equal(MagickFormat.Jpeg, after.Format);+ Assert.Equal((800u, 500u), (after.Width, after.Height));+ }++ [Fact]+ public async Task The_parts_land_where_they_were_drawn_on_a_photo_turned_by_its_EXIF_orientation()+ {+ // Stored 300 × 200, shown upright as 200 × 300 (turned 90° clockwise): the part is on the upright picture's top+ // left quarter.+ var folder = fx.NewFolder();+ var path = Path.Combine(folder, "phone.png");+ using (var stored = Noise(300, 200))+ {+ stored.Orientation = OrientationType.RightTop;+ stored.Write(path, MagickFormat.Png);+ }+ using var upright = new MagickImage(path);+ upright.AutoOrient();+ Assert.Equal((200u, 300u), (upright.Width, upright.Height));++ var output = await RunAsync(path, Hide(HideStyle.Pixelate, 5, Area(0, 0, 0.5, 0.5)));++ using var after = new MagickImage(output);+ after.AutoOrient();+ Assert.Equal((200u, 300u), (after.Width, after.Height));+ var (a, b) = (Rgb(upright), Rgb(after));+ int Index(int x, int y) => (y * 200 + x) * 3;+ Assert.NotEqual(a[Index(10, 10)..(Index(10, 10) + 30)], b[Index(10, 10)..(Index(10, 10) + 30)]); // covered+ Assert.Equal(a[Index(150, 200)..(Index(150, 200) + 30)], b[Index(150, 200)..(Index(150, 200) + 30)]); // as it was+ }++ [Fact]+ public void The_window_shows_what_the_file_gets()+ {+ // The preview covers the whole picture with the same squares the conversion lays on a part.+ using var picture = Noise(320, 240);+ using var preview = picture.Clone();+ var cell = Math.Round(HideTool.EffectSize(5, 320, 240));+ Assert.Equal(10, cell);+ AreaHider.Cover(preview, HideStyle.Pixelate, cell);+ using var converted = picture.Clone();+ AreaHider.Apply(converted, new ImageOptions { HideStrength = 5, HiddenAreas = [Area(0.25, 0.25, 0.5, 0.5)] });+ Assert.Equal(preview.GetPixels().ToByteArray(80, 60, 160, 120, PixelMapping.RGB),+ converted.GetPixels().ToByteArray(80, 60, 160, 120, PixelMapping.RGB));+ }++ [Fact]+ public void Previews_of_the_uncovered_picture_go_and_other_metadata_stays()+ {+ using var image = Noise(64, 64);+ image.SetProfile(new ImageProfile("8bim", [0x38, 0x42, 0x49, 0x4D, 0x04, 0x0C, 0, 0, 0, 0, 0, 0]));+ image.SetProfile(new XmpProfile(System.Text.Encoding.UTF8.GetBytes(+ "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\"><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">" ++ "<rdf:Description xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\"><xmp:Thumbnails>thumb</xmp:Thumbnails></rdf:Description>" ++ "</rdf:RDF></x:xmpmeta>")));+ var exif = new ExifProfile();+ exif.SetValue(ExifTag.Make, "Phone");+ image.SetProfile(exif);++ AreaHider.Apply(image, new ImageOptions { HiddenAreas = [Area(0.1, 0.1, 0.5, 0.5)] });++ Assert.False(image.HasProfile("8bim"));+ Assert.Null(image.GetXmpProfile());+ Assert.Equal("Phone", image.GetExifProfile()?.GetValue(ExifTag.Make)?.Value);++ // Without parts nothing is touched.+ using var untouched = Noise(64, 64);+ untouched.SetProfile(new ImageProfile("8bim", [0x38, 0x42, 0x49, 0x4D, 0x04, 0x0C, 0, 0, 0, 0, 0, 0]));+ AreaHider.Apply(untouched, new ImageOptions());+ Assert.True(untouched.HasProfile("8bim"));+ }+}