Skip to content

Commit

Permalink
Updates to image effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2776 committed Jan 10, 2025
1 parent efebb32 commit f1e8245
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 38 deletions.
7 changes: 7 additions & 0 deletions src/PicView.Avalonia/ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,17 @@ public void UpdateLanguage()
DirectionalBlur = TranslationHelper.Translation.DirectionalBlur;
PencilSketch = TranslationHelper.Translation.PencilSketch;
OldMovie = TranslationHelper.Translation.OldMovie;
Posterize = TranslationHelper.Translation.Posterize;
}

#region Strings

public string? Posterize
{
get;
set => this.RaiseAndSetIfChanged(ref field, value);
}

public string? OldMovie
{
get;
Expand Down
112 changes: 75 additions & 37 deletions src/PicView.Avalonia/Views/EffectsView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
xmlns:customControls="clr-namespace:PicView.Avalonia.CustomControls"
xmlns:viewModels="clr-namespace:PicView.Avalonia.ViewModels"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Styles>
<Styles>
<Style Selector="NumericUpDown">
<Setter Property="Width" Value="56" />
<Setter Property="FormatString" Value="N0" />
<Setter Property="Background" Value="{DynamicResource MainBackgroundColor}" />
<Setter Property="BorderBrush" Value="{DynamicResource MainBorderColor}" />
<Setter Property="Foreground" Value="{DynamicResource MainTextColor}" />
</Style>
</Styles>
</UserControl.Styles>

<StackPanel Width="500">
<Expander IsExpanded="True" Margin="0,15,0,10">
Expand Down Expand Up @@ -61,13 +72,9 @@
</customControls:CustomSlider.Background>
</customControls:CustomSlider>
<NumericUpDown
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
Foreground="{DynamicResource MainTextColor}"
Maximum="{Binding Path=Maximum, ElementName=BrightnessSlider}"
Minimum="{Binding Path=Minimum, ElementName=BrightnessSlider}"
Value="{Binding Path=Value, ElementName=BrightnessSlider}"
Width="56" />
Value="{Binding Path=Value, ElementName=BrightnessSlider}" />
<customControls:IconButton
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
Expand Down Expand Up @@ -130,13 +137,9 @@
</customControls:CustomSlider.Background>
</customControls:CustomSlider>
<NumericUpDown
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
Foreground="{DynamicResource MainTextColor}"
Maximum="{Binding Path=Maximum, ElementName=ContrastSlider}"
Minimum="{Binding Path=Minimum, ElementName=ContrastSlider}"
Value="{Binding Path=Value, ElementName=ContrastSlider}"
Width="56" />
Value="{Binding Path=Value, ElementName=ContrastSlider}" />
<customControls:IconButton
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
Expand Down Expand Up @@ -204,13 +207,9 @@
Width="376"
x:Name="BlurSlider" />
<NumericUpDown
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
Foreground="{DynamicResource MainTextColor}"
Maximum="{Binding Path=Maximum, ElementName=BlurSlider}"
Minimum="{Binding Path=Minimum, ElementName=BlurSlider}"
Value="{Binding Path=Value, ElementName=BlurSlider}"
Width="56" />
Value="{Binding Path=Value, ElementName=BlurSlider}" />
<customControls:IconButton
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
Expand Down Expand Up @@ -262,13 +261,9 @@
Width="376"
x:Name="MotionBlurSlider" />
<NumericUpDown
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
Foreground="{DynamicResource MainTextColor}"
Maximum="{Binding Path=Maximum, ElementName=MotionBlurSlider}"
Minimum="{Binding Path=Minimum, ElementName=MotionBlurSlider}"
Value="{Binding Path=Value, ElementName=MotionBlurSlider}"
Width="56" />
Value="{Binding Path=Value, ElementName=MotionBlurSlider}" />
<customControls:IconButton
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
Expand All @@ -283,6 +278,23 @@
x:Name="ResetMotionBlurBtn" />
</StackPanel>



</StackPanel>

</Expander>

<Expander IsExpanded="True" Margin="0,0,0,10">
<Expander.Header>
<TextBlock
Classes="txt"
FontFamily="/Assets/Fonts/Roboto-Bold.ttf#Roboto"
FontSize="14"
Padding="10,5"
Text="{CompiledBinding Effects}" />
</Expander.Header>
<StackPanel Margin="15,0">

<!-- Pencil Sketch -->
<Panel Margin="0,10,0,5">
<TextBlock
Expand Down Expand Up @@ -311,13 +323,9 @@
Width="376"
x:Name="PencilSketchSlider" />
<NumericUpDown
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
Foreground="{DynamicResource MainTextColor}"
Maximum="{Binding Path=Maximum, ElementName=PencilSketchSlider}"
Minimum="{Binding Path=Minimum, ElementName=PencilSketchSlider}"
Value="{Binding Path=Value, ElementName=PencilSketchSlider}"
Width="56" />
Value="{Binding Path=Value, ElementName=PencilSketchSlider}" />
<customControls:IconButton
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
Expand All @@ -332,20 +340,50 @@
x:Name="ResetPencilSketchBtn" />
</StackPanel>

</StackPanel>
<!-- Posterize -->
<Panel Margin="0,10,0,5">
<TextBlock
Classes="txt"
HorizontalAlignment="Left"
Text="{CompiledBinding Posterize}"
VerticalAlignment="Center" />
</Panel>

</Expander>
<StackPanel Orientation="Horizontal">

<Expander IsExpanded="True" Margin="0,0,0,10">
<Expander.Header>
<TextBlock
Classes="txt"
FontFamily="/Assets/Fonts/Roboto-Bold.ttf#Roboto"
FontSize="14"
Padding="10,5"
Text="{CompiledBinding Effects}" />
</Expander.Header>
<StackPanel Margin="15,0">
<customControls:CustomSlider
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
BorderThickness="1"
Height="30"
IsSnapToTickEnabled="True"
LargeChange="1"
Margin="0,1,10,1"
Maximum="8"
Minimum="0"
SmallChange="1"
Theme="{StaticResource SetBg}"
TickFrequency="1"
Value="0"
Width="376"
x:Name="PosterizeSlider" />
<NumericUpDown
Maximum="{Binding Path=Maximum, ElementName=PosterizeSlider}"
Minimum="{Binding Path=Minimum, ElementName=PosterizeSlider}"
Value="{Binding Path=Value, ElementName=PosterizeSlider}" />
<customControls:IconButton
Background="{DynamicResource MainButtonBackgroundColor}"
BorderBrush="{DynamicResource MainBorderColor}"
BorderThickness="1"
Classes="hover"
Foreground="{DynamicResource MainTextColor}"
Icon="{StaticResource UndoImage}"
IconHeight="12"
IconWidth="12"
Margin="5,0,0,0"
Width="30"
x:Name="ResetPosterizeSketchBtn" />
</StackPanel>


<!-- Black/White -->
Expand Down
19 changes: 19 additions & 0 deletions src/PicView.Avalonia/Views/EffectsView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class EffectsView : UserControl
private Percentage _contrast = new(0);

private double _sketchStrokeWidth;
private int _posterizeLevel;

private Timer? _debounceTimer;

Expand Down Expand Up @@ -53,6 +54,10 @@ public EffectsView()
{
PencilSketchSlider.Value = 0;
};
ResetPosterizeSketchBtn.Click += delegate
{
PosterizeSlider.Value = 0;
};


if (DataContext is not MainViewModel vm)
Expand Down Expand Up @@ -81,6 +86,13 @@ public EffectsView()
DebounceSliderChange();
};

PosterizeSlider.ValueChanged += (_, e) =>
{
var newValue = (int)e.NewValue;
_posterizeLevel = newValue is 1 ? 2 : newValue;
DebounceSliderChange();
};

BlackAndWhiteToggleButton.Click += async (_, _) =>
{
if (!BlackAndWhiteToggleButton.IsChecked.HasValue)
Expand Down Expand Up @@ -205,6 +217,13 @@ await Dispatcher.UIThread.InvokeAsync(() =>
magick.Charcoal(_sketchStrokeWidth, 0);
}

if (_posterizeLevel is not 0)
{
magick.Posterize(_posterizeLevel);
}



var bitmap = magick.ToWriteableBitmap();
vm.ImageSource = bitmap;
}
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"Pixelate": "Pixeler",
"Pixels": "pixels",
"Portrait": "Portræt",
"Posterize": "Posterize",
"PressKey": "Tryk på tasten...",
"PrevFolder": "Gå til forrige mappe",
"PrevImage": "Forrige billede",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"Pixelate": "Verpixeln",
"Pixels": "Pixel",
"Portrait": "Porträt",
"Posterize": "Posterisieren",
"PressKey": "Taste drücken...",
"PrevFolder": "Zum vorherigen Ordner wechseln",
"PrevImage": "Vorheriges Bild",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"Pixelate": "Pixelate",
"Pixels": "pixels",
"Portrait": "Portrait",
"Posterize": "Posterize",
"PressKey": "Press key...",
"PrevFolder": "Navigate to previous folder",
"PrevImage": "Previous image",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
"Pixelate": "Pixelado",
"Pixels": "pixeles",
"Portrait": "Vertical",
"Posterize": "Posterizar",
"PressKey": "Presiona tecla...",
"PrevFolder": "Navegar a la carpeta anterior",
"PrevImage": "Imagen anterior",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"Pixelate": "Pixéliser",
"Pixels": "pixels",
"Portrait": "Portrait",
"Posterize": "Postériser",
"PressKey": "Appuyez sur la touche...",
"PrevFolder": "Accéder au dossier précédent",
"PrevImage": "Image précédente",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"Pixelate": "Pixelare",
"Pixels": "Pixel",
"Portrait": "Ritratto",
"Posterize": "Posterizzare",
"PressKey": "Premi il tasto...",
"PrevFolder": "Torna alla cartella precedente",
"PrevImage": "Immagine precedente",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"Pixelate": "픽셀 레이트",
"Pixels": "픽셀",
"Portrait": "세로",
"Posterize": "포스터라이즈",
"PressKey": "키를 누르세요...",
"PrevFolder": "이전 폴더로 이동",
"PrevImage": "이전 이미지",
Expand Down
3 changes: 2 additions & 1 deletion src/PicView.Core/Config/Languages/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"ExposureBias": "Kompensacja ekspozycji",
"ExposureProgram": "Program ekspozycji",
"ExposureTime": "Czas ekspozycji",
"FNumber": "Liczba F",
"File": "plik",
"FileCopy": "Dodano plik do schowka",
"FileCopyPath": "Kopiuj ścieżkę do pliku",
Expand Down Expand Up @@ -139,7 +140,6 @@
"Flip": "Przeróć poziomo",
"Flipped": "Przerócone",
"Fluorescent": "Świetlówka",
"FNumber": "Liczba F",
"FocalLength": "Długość ogniskowej",
"FocalLength35mm": "Długość ogniskowej (35mm)",
"Folder": "Folder",
Expand Down Expand Up @@ -251,6 +251,7 @@
"Pixelate": "Pikselizacja",
"Pixels": "pikseli",
"Portrait": "Portretowy",
"Posterize": "Posteryzacja",
"PressKey": "Naciśnij klawisz...",
"PrevFolder": "Przejdź do poprzedniego folderu",
"PrevImage": "Poprzedni obraz",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
"Pixelate": "Pixelada",
"Pixels": "pixels",
"Portrait": "Retrato",
"Posterize": "Posterizar",
"PressKey": "Aperta uma tecla...",
"PrevFolder": "Navegar para a pasta anterior",
"PrevImage": "Imagem anterior",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/ro.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"Pixelate": "Pixelare",
"Pixels": "pixeli",
"Portrait": "Portret",
"Posterize": "Posterize",
"PressKey": "Apasă tasta...",
"PrevFolder": "Navighează la folderul anterior",
"PrevImage": "Imaginea anterioară",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"Pixelate": "Пикселизация",
"Pixels": "пиксели",
"Portrait": "Портрет",
"Posterize": "Постеризация",
"PressKey": "Нажмите клавишу...",
"PrevFolder": "Перейти к предыдущей папке",
"PrevImage": "Предыдущее изображение",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
"Pixelate": "Pixla",
"Pixels": "pixlar",
"Portrait": "Stående",
"Posterize": "Posterize",
"PressKey": "Tryck en tangent...",
"PrevFolder": "Föregående mapp",
"PrevImage": "Föregående bild",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"Pixelate": "Pikselleştir",
"Pixels": "pikseller",
"Portrait": "Portre",
"Posterize": "Posteri",
"PressKey": "Tuşa basın...",
"PrevFolder": "Önceki klasöre git",
"PrevImage": "Önceki resim",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"Pixelate": "像素化",
"Pixels": "px",
"Portrait": "纵向",
"Posterize": "色调分离",
"PressKey": "按键...",
"PrevFolder": "导航到上一个文件夹",
"PrevImage": "上一张图片",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Config/Languages/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
"Pixelate": "像素化",
"Pixels": "像素",
"Portrait": "縱向",
"Posterize": "色調分離",
"PressKey": "按鍵...",
"PrevFolder": "導覽至上一個資料夾",
"PrevImage": "上一張圖片",
Expand Down
1 change: 1 addition & 0 deletions src/PicView.Core/Localization/LanguageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public record LanguageModel
public string? BlackAndWhite { get; set; }
public string? ColorTone { get; set; }
public string? OldMovie { get; set; }
public string? Posterize { get; set; }
public string? Bloom { get; set; }
public string? Gloom { get; set; }
public string? Monochrome { get; set; }
Expand Down

0 comments on commit f1e8245

Please sign in to comment.