Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit 5767262

Browse files
committed
GUI Image To Image process added
1 parent 6b3235b commit 5767262

File tree

10 files changed

+649
-12
lines changed

10 files changed

+649
-12
lines changed

OnnxStack.UI/MainWindow.xaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@
3636
<views:TextToImageView />
3737
</TabItem>
3838

39+
<!--Image To Image-->
40+
<TabItem>
41+
<TabItem.Header>
42+
<StackPanel Orientation="Horizontal" Margin="5">
43+
<StackPanel Orientation="Horizontal">
44+
<userControls:FontAwesome Icon="&#xf1c5;" IconStyle="Light"/>
45+
<userControls:FontAwesome Icon="&#xf054;" IconStyle="Regular" Size="8" Margin="3"/>
46+
<userControls:FontAwesome Icon="&#xf1c5;" IconStyle="Light"/>
47+
</StackPanel>
48+
<TextBlock Text="Image To Image" Margin="5,0,0,0"/>
49+
</StackPanel>
50+
</TabItem.Header>
51+
<views:ImageToImage />
52+
</TabItem>
53+
3954
</TabControl>
4055
</Grid>
4156
</Window>

OnnxStack.UI/Models/ImageInput.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Text.Json.Serialization;
2+
using System.Windows.Media.Imaging;
3+
4+
namespace OnnxStack.UI.Models
5+
{
6+
public class ImageInput
7+
{
8+
[JsonIgnore]
9+
public BitmapSource Image { get; init; }
10+
public string FileName { get; set; }
11+
public string FileSize { get; set; }
12+
}
13+
}

OnnxStack.UI/Models/ImageResult.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ public class ImageResult
1919
public SchedulerOptions SchedulerOptions { get; init; }
2020
public double Elapsed { get; init; }
2121
}
22-
2322
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<UserControl x:Class="OnnxStack.UI.UserControls.ImageInputControl"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:OnnxStack.UI.UserControls"
7+
xmlns:userControls="clr-namespace:OnnxStack.UI.UserControls"
8+
xmlns:behaviors="clr-namespace:OnnxStack.UI.Behaviors"
9+
xmlns:models="clr-namespace:OnnxStack.UI.Models"
10+
mc:Ignorable="d"
11+
d:DesignWidth="500" Name="UI">
12+
<UserControl.Resources>
13+
<Style TargetType="{x:Type Label}">
14+
<Setter Property="Margin" Value="-4,0,0,-4"/>
15+
</Style>
16+
</UserControl.Resources>
17+
18+
<Border DataContext="{Binding ElementName=UI}" BorderBrush="LightGray" BorderThickness="2" >
19+
<StackPanel Margin="2" >
20+
<Image Source="{Binding Result.Image, FallbackValue={StaticResource PlaceholderImage}, TargetNullValue={StaticResource PlaceholderImage}}" Width="{Binding SchedulerOptions.Width}" Height="{Binding SchedulerOptions.Height}" MinHeight="512" MinWidth="512"/>
21+
<UniformGrid Columns="1" Height="30" Visibility="{Binding HasResult, Converter={StaticResource BooleanToHiddenConverter}}">
22+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,3">
23+
<TextBlock Text="Image File:" Margin="5,0,0,0" FontSize="10" Opacity=".6" VerticalAlignment="Center" FontStyle="Italic"/>
24+
<TextBlock Text="{Binding Result.FileName}" Margin="5,0,0,0" VerticalAlignment="Center"/>
25+
</StackPanel>
26+
<!--<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,3">
27+
<TextBlock Text="Size:" Margin="5,0,0,0" FontSize="10" Opacity=".6" VerticalAlignment="Center" FontStyle="Italic"/>
28+
<TextBlock Text="{Binding Result.FileSize}" Margin="5,0,0,0"/>
29+
</StackPanel>-->
30+
</UniformGrid>
31+
<DockPanel Height="30">
32+
<Button DockPanel.Dock="Right" Command="{Binding ClearImageCommand}" BorderThickness="0,1,1,1" Width="50">
33+
<userControls:FontAwesome Icon="&#xf2ed;" IconStyle="Light" />
34+
</Button>
35+
<Button Command="{Binding LoadImageCommand}" ToolTip="Load Image File" >
36+
<StackPanel Orientation="Horizontal">
37+
<userControls:FontAwesome Icon="&#xf1c5;" IconStyle="Light" Size="13" />
38+
<TextBlock Text="Load Image" Margin="5,0,0,0"/>
39+
</StackPanel>
40+
</Button>
41+
</DockPanel>
42+
</StackPanel>
43+
</Border>
44+
</UserControl>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using OnnxStack.UI.Commands;
2+
using OnnxStack.UI.Dialogs;
3+
using OnnxStack.UI.Models;
4+
using OnnxStack.UI.Services;
5+
using System.ComponentModel;
6+
using System.Runtime.CompilerServices;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
11+
namespace OnnxStack.UI.UserControls
12+
{
13+
public partial class ImageInputControl : UserControl, INotifyPropertyChanged
14+
{
15+
private readonly IDialogService _dialogService;
16+
17+
/// <summary>Initializes a new instance of the <see cref="ImageInputControl" /> class.</summary>
18+
public ImageInputControl()
19+
{
20+
if (!DesignerProperties.GetIsInDesignMode(this))
21+
_dialogService = App.GetService<IDialogService>();
22+
23+
LoadImageCommand = new AsyncRelayCommand(LoadImage);
24+
ClearImageCommand = new AsyncRelayCommand(ClearImage);
25+
InitializeComponent();
26+
}
27+
28+
public AsyncRelayCommand LoadImageCommand { get; }
29+
public AsyncRelayCommand ClearImageCommand { get; }
30+
31+
public ImageInput Result
32+
{
33+
get { return (ImageInput)GetValue(ResultProperty); }
34+
set { SetValue(ResultProperty, value); }
35+
}
36+
37+
public static readonly DependencyProperty ResultProperty =
38+
DependencyProperty.Register("Result", typeof(ImageInput), typeof(ImageInputControl));
39+
40+
41+
public SchedulerOptionsModel SchedulerOptions
42+
{
43+
get { return (SchedulerOptionsModel)GetValue(SchedulerOptionsProperty); }
44+
set { SetValue(SchedulerOptionsProperty, value); }
45+
}
46+
47+
public static readonly DependencyProperty SchedulerOptionsProperty =
48+
DependencyProperty.Register("SchedulerOptions", typeof(SchedulerOptionsModel), typeof(ImageInputControl));
49+
50+
51+
public bool HasResult
52+
{
53+
get { return (bool)GetValue(HasResultProperty); }
54+
set { SetValue(HasResultProperty, value); }
55+
}
56+
57+
public static readonly DependencyProperty HasResultProperty =
58+
DependencyProperty.Register("HasResult", typeof(bool), typeof(ImageInputControl));
59+
60+
61+
private Task LoadImage()
62+
{
63+
var loadImageDialog = _dialogService.GetDialog<CropImageDialog>();
64+
loadImageDialog.Initialize(SchedulerOptions.Width, SchedulerOptions.Height);
65+
if (loadImageDialog.ShowDialog() == true)
66+
{
67+
Result = new ImageInput
68+
{
69+
Image = loadImageDialog.GetImageResult(),
70+
FileName = loadImageDialog.ImageFile,
71+
};
72+
HasResult = true;
73+
}
74+
return Task.CompletedTask;
75+
}
76+
77+
78+
private Task ClearImage()
79+
{
80+
Result = null;
81+
HasResult = false;
82+
return Task.CompletedTask;
83+
}
84+
85+
#region INotifyPropertyChanged
86+
public event PropertyChangedEventHandler PropertyChanged;
87+
public void NotifyPropertyChanged([CallerMemberName] string property = "")
88+
{
89+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
90+
}
91+
#endregion
92+
}
93+
}

OnnxStack.UI/UserControls/ImageResultControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<Border DataContext="{Binding ElementName=UI}" BorderBrush="LightGray" BorderThickness="2" >
1919
<StackPanel Margin="2">
20-
<Image Source="{Binding Result.Image, FallbackValue={StaticResource PlaceholderImage}, TargetNullValue={StaticResource PlaceholderImage}}" Width="{Binding SchedulerOptions.Width, FallbackValue=512}" Height="{Binding SchedulerOptions.Height, FallbackValue=512}" MinWidth="512" MinHeight="512"/>
20+
<Image Source="{Binding Result.Image, FallbackValue={StaticResource PlaceholderImage}, TargetNullValue={StaticResource PlaceholderImage}}" Width="{Binding SchedulerOptions.Width, FallbackValue=512}" Height="{Binding SchedulerOptions.Height, FallbackValue=512}" MinHeight="512" MinWidth="512"/>
2121
<StackPanel Visibility="{Binding HasResult, Converter={StaticResource InverseBooleanToVisibilityConverter}}" Margin="0,4">
2222
<ProgressBar Maximum="{Binding ProgressMax}" behaviors:SmoothProgressBarBehavior.SmoothValue="{Binding ProgressValue}" Height="22" />
2323
</StackPanel>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<UserControl x:Class="OnnxStack.UI.Views.ImageToImage"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
7+
xmlns:userControls="clr-namespace:OnnxStack.UI.UserControls"
8+
Name="UI" mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="800" >
9+
<Grid DataContext="{Binding ElementName=UI}" >
10+
<Grid.ColumnDefinitions>
11+
<ColumnDefinition Width="340" />
12+
<ColumnDefinition Width="10" />
13+
<ColumnDefinition Width="*" />
14+
</Grid.ColumnDefinitions>
15+
16+
<!--Control Panel-->
17+
<DockPanel Grid.Column="0" DataContext="{Binding ElementName=UI}" Margin="3">
18+
<UniformGrid DockPanel.Dock="Bottom" Columns="2" Height="30">
19+
<Button Content="Cancel" Command="{Binding CancelCommand}" BorderThickness="1,1,0,1"/>
20+
<Button Content="Generate" Command="{Binding GenerateCommand}" />
21+
</UniformGrid>
22+
<DockPanel>
23+
<StackPanel IsEnabled="{Binding IsGenerating, Converter={StaticResource InverseBoolConverter}}">
24+
<userControls:PromptControl PromptOptions="{Binding PromptOptions}" />
25+
<userControls:SchedulerControl SchedulerOptions="{Binding SchedulerOptions, Mode=TwoWay}" ProcessType="ImageToImage" Margin="0, 10, 0 ,0"/>
26+
</StackPanel>
27+
</DockPanel>
28+
</DockPanel>
29+
30+
<GridSplitter Grid.Column="1" Width="4" HorizontalAlignment="Stretch" />
31+
32+
<!--Content Panel-->
33+
<DockPanel Grid.Column="2" >
34+
35+
<!--Generate Tab-->
36+
<TabControl SelectedIndex="{Binding SelectedTabIndex}">
37+
<TabItem>
38+
<TabItem.Header>
39+
<StackPanel Orientation="Horizontal" Margin="15,5">
40+
<userControls:FontAwesome Icon="&#xf0d0;" IconStyle="Light"/>
41+
<TextBlock Text="Generate" Margin="5,0,0,0"/>
42+
</StackPanel>
43+
</TabItem.Header>
44+
<UniformGrid Columns="2" VerticalAlignment="Center" HorizontalAlignment="Center">
45+
<Viewbox Margin="40,40,20,40" >
46+
<userControls:ImageInputControl
47+
Result="{Binding InputImage, Mode=TwoWay}"
48+
HasResult="{Binding HasInputResult, Mode=TwoWay}"
49+
SchedulerOptions="{Binding SchedulerOptions}" />
50+
</Viewbox>
51+
<Viewbox Margin="20,40,40,40" >
52+
<userControls:ImageResultControl
53+
Result="{Binding ResultImage}"
54+
HasResult="{Binding HasResult}"
55+
ProgressMax="{Binding ProgressMax}"
56+
ProgressValue="{Binding ProgressValue}"
57+
SchedulerOptions="{Binding SchedulerOptions, Mode=TwoWay}" />
58+
</Viewbox>
59+
</UniformGrid>
60+
</TabItem>
61+
62+
<!--History Tab-->
63+
<TabItem>
64+
<TabItem.Header>
65+
<StackPanel Orientation="Horizontal" Margin="15,5">
66+
<userControls:FontAwesome Icon="&#xf03a;" IconStyle="Light"/>
67+
<TextBlock Text="History" Margin="5,0,0,0"/>
68+
</StackPanel>
69+
</TabItem.Header>
70+
<DockPanel>
71+
<DockPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right">
72+
<StackPanel Orientation="Horizontal" Margin="0,4,0,0">
73+
<Button Command="{Binding ClearHistoryCommand}" Padding="10,3" Height="30">
74+
<userControls:FontAwesome Icon="&#xf2ed;" IconStyle="Light"/>
75+
</Button>
76+
</StackPanel>
77+
</DockPanel>
78+
<ListBox ItemsSource="{Binding}" ItemContainerStyle="{StaticResource ImageResultListBoxItem}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
79+
<ListBox.DataContext>
80+
<CollectionViewSource Source="{Binding ImageResults, ElementName=UI}">
81+
<CollectionViewSource.SortDescriptions>
82+
<scm:SortDescription PropertyName="Timestamp" Direction="Descending" />
83+
</CollectionViewSource.SortDescriptions>
84+
</CollectionViewSource>
85+
</ListBox.DataContext>
86+
<ListBox.ItemsPanel>
87+
<ItemsPanelTemplate>
88+
<WrapPanel />
89+
</ItemsPanelTemplate>
90+
</ListBox.ItemsPanel>
91+
</ListBox>
92+
</DockPanel>
93+
</TabItem>
94+
95+
</TabControl>
96+
</DockPanel>
97+
</Grid>
98+
</UserControl>

0 commit comments

Comments
 (0)