-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathPhoto.h
216 lines (180 loc) · 6.32 KB
/
Photo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// ---------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
// ---------------------------------------------------------------------------------
#pragma once
#include "Photo.g.h"
namespace winrt::PhotoEditor::implementation
{
struct Photo : PhotoT<Photo>
{
Photo() = default;
Photo(Windows::Storage::FileProperties::ImageProperties const& props,
Windows::Storage::StorageFile const& imageFile,
hstring const& name,
hstring const& type) :
m_imageProperties(props),
m_imageName(name),
m_imageFileType(type),
m_imageFile(imageFile)
{
}
// Gets the thumbnail of current image file (m_imageFile).
Windows::Foundation::IAsyncOperation<Windows::UI::Xaml::Media::Imaging::BitmapImage> GetImageThumbnailAsync() const;
// Gets the full image of the current image file (m_imageFile).
Windows::Foundation::IAsyncOperation<Windows::UI::Xaml::Media::Imaging::BitmapImage> GetImageSourceAsync() const;
// File and information properties.
Windows::Storage::StorageFile ImageFile() const
{
return m_imageFile;
}
Windows::Storage::FileProperties::ImageProperties ImageProperties() const
{
return m_imageProperties;
}
hstring ImageName() const
{
return m_imageName;
}
hstring ImageFileType() const
{
return m_imageFileType;
}
// Gets or sets the image title.
hstring ImageTitle() const
{
return m_imageProperties.Title() == L"" ? m_imageName : m_imageProperties.Title();
}
void ImageTitle(hstring const& value);
hstring ImageDimensions() const;
// Exposure property for light effect.
float Exposure() const
{
return m_exposure;
}
void Exposure(float value)
{
UpdateValue(L"Exposure", m_exposure, value);
}
// Temperature property for color effect.
float Temperature() const
{
return m_temperature;
}
void Temperature(float value)
{
UpdateValue(L"Temperature", m_temperature, value);
}
// Tint property for tint and contrast effect.
float Tint() const
{
return m_tint;
}
void Tint(float value)
{
UpdateValue(L"Tint", m_tint, value);
}
// Contrast property for tin and contrast effect.
float Contrast() const
{
return m_contrast;
}
void Contrast(float value)
{
UpdateValue(L"Contrast", m_contrast, value);
}
// Satruration property for saturation effect.
float Saturation() const
{
return m_saturation;
}
void Saturation(float value)
{
UpdateValue(L"Saturation", m_saturation, value);
}
// Blur amount for Gaussian blur effect.
float BlurAmount() const
{
return m_blur;
}
void BlurAmount(float value)
{
UpdateValue<float>(L"BlurAmount", m_blur, value);
}
// Intensity for sepia effect.
float Intensity() const
{
return m_sepiaIntensity;
}
void Intensity(float value)
{
UpdateValue<float>(L"Intensity", m_sepiaIntensity, value);
}
// Property changed notifications.
event_token PropertyChanged(Windows::UI::Xaml::Data::PropertyChangedEventHandler const& value)
{
return m_propertyChanged.add(value);
}
void PropertyChanged(event_token const& token)
{
m_propertyChanged.remove(token);
}
private:
// File and information fields.
Windows::Storage::FileProperties::ImageProperties m_imageProperties{ nullptr };
Windows::Storage::StorageFile m_imageFile{ nullptr };
hstring m_imageName;
hstring m_imageFileType;
hstring m_imageTitle;
// Fields for image effects.
float m_exposure{ 0 };
float m_temperature{ 0 };
float m_tint{ 0 };
float m_contrast{ 0 };
float m_saturation{ 1 };
float m_blur{ 0 };
float m_sepiaIntensity{ .5f };
// Size field for image tile size on MainPage.
double m_size{ 250 };
// Property changed notification.
event<Windows::UI::Xaml::Data::PropertyChangedEventHandler> m_propertyChanged;
template <class T>
void UpdateValue(hstring const& propertyName, T & var, T value)
{
if (var != value)
{
var = value;
RaisePropertyChanged(propertyName);
}
}
void RaisePropertyChanged(hstring const& propertyName)
{
m_propertyChanged(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs(propertyName));
}
};
}
namespace winrt::PhotoEditor::factory_implementation
{
struct Photo : PhotoT<Photo, implementation::Photo>
{
};
}