Skip to content

Commit 753847c

Browse files
Merge branch 'user/t-limay/StyleTransfer-Controls' into user/t-limay/StyleTransfer
2 parents 8e14cc7 + fbc8810 commit 753847c

File tree

66 files changed

+1077
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1077
-0
lines changed

Samples/StyleTransfer/App.xaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Application
2+
x:Class="StyleTransfer.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:StyleTransfer">
6+
7+
<Application.Resources>
8+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
9+
</Application.Resources>
10+
11+
</Application>

Samples/StyleTransfer/App.xaml.cs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using Windows.ApplicationModel;
7+
using Windows.ApplicationModel.Activation;
8+
using Windows.Foundation;
9+
using Windows.Foundation.Collections;
10+
using Windows.UI.Xaml;
11+
using Windows.UI.Xaml.Controls;
12+
using Windows.UI.Xaml.Controls.Primitives;
13+
using Windows.UI.Xaml.Data;
14+
using Windows.UI.Xaml.Input;
15+
using Windows.UI.Xaml.Media;
16+
using Windows.UI.Xaml.Navigation;
17+
18+
namespace StyleTransfer
19+
{
20+
/// <summary>
21+
/// Provides application-specific behavior to supplement the default Application class.
22+
/// </summary>
23+
sealed partial class App : Application
24+
{
25+
/// <summary>
26+
/// Initializes the singleton application object. This is the first line of authored code
27+
/// executed, and as such is the logical equivalent of main() or WinMain().
28+
/// </summary>
29+
public App()
30+
{
31+
this.InitializeComponent();
32+
this.Suspending += OnSuspending;
33+
}
34+
35+
/// <summary>
36+
/// Invoked when the application is launched normally by the end user. Other entry points
37+
/// will be used such as when the application is launched to open a specific file.
38+
/// </summary>
39+
/// <param name="e">Details about the launch request and process.</param>
40+
protected override void OnLaunched(LaunchActivatedEventArgs e)
41+
{
42+
Frame rootFrame = Window.Current.Content as Frame;
43+
44+
// Do not repeat app initialization when the Window already has content,
45+
// just ensure that the window is active
46+
if (rootFrame == null)
47+
{
48+
// Create a Frame to act as the navigation context and navigate to the first page
49+
rootFrame = new Frame();
50+
51+
rootFrame.NavigationFailed += OnNavigationFailed;
52+
53+
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
54+
{
55+
//TODO: Load state from previously suspended application
56+
}
57+
58+
// Place the frame in the current Window
59+
Window.Current.Content = rootFrame;
60+
}
61+
62+
if (e.PrelaunchActivated == false)
63+
{
64+
if (rootFrame.Content == null)
65+
{
66+
// When the navigation stack isn't restored navigate to the first page,
67+
// configuring the new page by passing required information as a navigation
68+
// parameter
69+
rootFrame.Navigate(typeof(MainPage), e.Arguments);
70+
}
71+
// Ensure the current window is active
72+
Window.Current.Activate();
73+
}
74+
}
75+
76+
/// <summary>
77+
/// Invoked when Navigation to a certain page fails
78+
/// </summary>
79+
/// <param name="sender">The Frame which failed navigation</param>
80+
/// <param name="e">Details about the navigation failure</param>
81+
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
82+
{
83+
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
84+
}
85+
86+
/// <summary>
87+
/// Invoked when application execution is being suspended. Application state is saved
88+
/// without knowing whether the application will be terminated or resumed with the contents
89+
/// of memory still intact.
90+
/// </summary>
91+
/// <param name="sender">The source of the suspend request.</param>
92+
/// <param name="e">Details about the suspend request.</param>
93+
private void OnSuspending(object sender, SuspendingEventArgs e)
94+
{
95+
var deferral = e.SuspendingOperation.GetDeferral();
96+
//TODO: Save application state and stop any background activity
97+
deferral.Complete();
98+
}
99+
}
100+
}

Samples/StyleTransfer/AppModel.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Diagnostics;
5+
using System.Linq;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices.WindowsRuntime;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using Windows.Media;
11+
using Windows.Media.Core;
12+
13+
namespace StyleTransfer
14+
{
15+
class AppModel : INotifyPropertyChanged
16+
{
17+
public AppModel()
18+
{
19+
this._useGPU = true;
20+
}
21+
22+
private string _modelSource;
23+
public string ModelSource
24+
{
25+
get { return _modelSource; }
26+
set
27+
{
28+
_modelSource = value;
29+
OnPropertyChanged();
30+
}
31+
}
32+
33+
private string _inputMediaSource;
34+
public string InputMediaSource
35+
{
36+
get { return _inputMediaSource; }
37+
set
38+
{
39+
_inputMediaSource = value;
40+
OnPropertyChanged();
41+
}
42+
}
43+
44+
private bool _useGPU;
45+
public bool UseGPU
46+
{
47+
get { return _useGPU; }
48+
set
49+
{
50+
_useGPU = value;
51+
OnPropertyChanged();
52+
}
53+
}
54+
55+
// In AppModel or in AppViewModel?
56+
private VideoFrame _outputFrame;
57+
public VideoFrame OutputFrame
58+
{
59+
get { return _outputFrame; }
60+
set
61+
{
62+
_outputFrame = value;
63+
OnPropertyChanged();
64+
}
65+
}
66+
67+
public event PropertyChangedEventHandler PropertyChanged;
68+
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
69+
{
70+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
71+
}
72+
}
73+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows.Input;
8+
using Windows.Media.Core;
9+
using GalaSoft.MvvmLight.Command;
10+
11+
namespace StyleTransfer
12+
{
13+
class AppViewModel : INotifyPropertyChanged
14+
{
15+
public AppViewModel()
16+
{
17+
_appModel = new AppModel();
18+
// TODO: Add a param to check if have an image to save.
19+
SaveCommand = new RelayCommand(this.SaveOutput);
20+
MediaSourceCommand = new RelayCommand<string>(SetMediaSource);
21+
}
22+
23+
private AppModel _appModel;
24+
public AppModel CurrentApp
25+
{
26+
get { return _appModel; }
27+
}
28+
29+
private ICommand _saveCommand;
30+
public ICommand SaveCommand
31+
{
32+
get { return _saveCommand; }
33+
set
34+
{
35+
_saveCommand = value;
36+
}
37+
}
38+
39+
public ICommand MediaSourceCommand { get; set; }
40+
41+
public event PropertyChangedEventHandler PropertyChanged;
42+
43+
public void SaveOutput()
44+
{
45+
// TODO: Take from UIButtonSaveImage_Click
46+
return;
47+
}
48+
public void SetMediaSource(object obj)
49+
{
50+
// TODO: Convert to a better value for the appModel object here.
51+
_appModel.InputMediaSource = obj.ToString();
52+
53+
// If video source, whole different code flow
54+
55+
// If camera/image upload, gather input image then put to eval/render
56+
// If source == upload --> HelperMethods::LoadVideoFrameFromFilePickedAsync
57+
return;
58+
}
59+
}
60+
}
277 KB
19.8 KB
29.2 KB
39.1 KB
61.9 KB
173 KB

0 commit comments

Comments
 (0)