diff --git a/.editorconfig b/.editorconfig
index afdb1f3..9965a8a 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -2,3 +2,122 @@
# CA1416: 验证平台兼容性
dotnet_diagnostic.CA1416.severity = none
+
+[*.cs]
+#### 命名样式 ####
+
+# 命名规则
+
+dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
+dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
+dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
+
+dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.types_should_be_pascal_case.symbols = types
+dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
+
+dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
+dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
+
+# 符号规范
+
+dotnet_naming_symbols.interface.applicable_kinds = interface
+dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.interface.required_modifiers =
+
+dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
+dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.types.required_modifiers =
+
+dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
+dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.non_field_members.required_modifiers =
+
+# 命名样式
+
+dotnet_naming_style.begins_with_i.required_prefix = I
+dotnet_naming_style.begins_with_i.required_suffix =
+dotnet_naming_style.begins_with_i.word_separator =
+dotnet_naming_style.begins_with_i.capitalization = pascal_case
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+csharp_using_directive_placement = outside_namespace:silent
+csharp_style_expression_bodied_methods = false:silent
+csharp_style_expression_bodied_constructors = false:silent
+csharp_style_expression_bodied_operators = false:silent
+csharp_style_expression_bodied_properties = true:silent
+csharp_style_expression_bodied_indexers = true:silent
+csharp_style_expression_bodied_accessors = true:silent
+csharp_style_expression_bodied_lambdas = true:silent
+csharp_style_expression_bodied_local_functions = false:silent
+csharp_style_conditional_delegate_call = true:suggestion
+csharp_style_var_for_built_in_types = false:silent
+csharp_space_around_binary_operators = before_and_after
+csharp_indent_labels = one_less_than_current
+
+[*.vb]
+#### 命名样式 ####
+
+# 命名规则
+
+dotnet_naming_rule.interface_should_be_以_i_开始.severity = suggestion
+dotnet_naming_rule.interface_should_be_以_i_开始.symbols = interface
+dotnet_naming_rule.interface_should_be_以_i_开始.style = 以_i_开始
+
+dotnet_naming_rule.类型_should_be_帕斯卡拼写法.severity = suggestion
+dotnet_naming_rule.类型_should_be_帕斯卡拼写法.symbols = 类型
+dotnet_naming_rule.类型_should_be_帕斯卡拼写法.style = 帕斯卡拼写法
+
+dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.severity = suggestion
+dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.symbols = 非字段成员
+dotnet_naming_rule.非字段成员_should_be_帕斯卡拼写法.style = 帕斯卡拼写法
+
+# 符号规范
+
+dotnet_naming_symbols.interface.applicable_kinds = interface
+dotnet_naming_symbols.interface.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
+dotnet_naming_symbols.interface.required_modifiers =
+
+dotnet_naming_symbols.类型.applicable_kinds = class, struct, interface, enum
+dotnet_naming_symbols.类型.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
+dotnet_naming_symbols.类型.required_modifiers =
+
+dotnet_naming_symbols.非字段成员.applicable_kinds = property, event, method
+dotnet_naming_symbols.非字段成员.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
+dotnet_naming_symbols.非字段成员.required_modifiers =
+
+# 命名样式
+
+dotnet_naming_style.以_i_开始.required_prefix = I
+dotnet_naming_style.以_i_开始.required_suffix =
+dotnet_naming_style.以_i_开始.word_separator =
+dotnet_naming_style.以_i_开始.capitalization = pascal_case
+
+dotnet_naming_style.帕斯卡拼写法.required_prefix =
+dotnet_naming_style.帕斯卡拼写法.required_suffix =
+dotnet_naming_style.帕斯卡拼写法.word_separator =
+dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case
+
+dotnet_naming_style.帕斯卡拼写法.required_prefix =
+dotnet_naming_style.帕斯卡拼写法.required_suffix =
+dotnet_naming_style.帕斯卡拼写法.word_separator =
+dotnet_naming_style.帕斯卡拼写法.capitalization = pascal_case
+
+[*.{cs,vb}]
+end_of_line = crlf
+dotnet_style_qualification_for_field = false:silent
+dotnet_style_qualification_for_property = false:silent
+dotnet_style_qualification_for_method = false:silent
+dotnet_style_qualification_for_event = false:silent
+tab_width = 4
+indent_size = 4
+dotnet_style_operator_placement_when_wrapping = beginning_of_line
\ No newline at end of file
diff --git a/Electrical Weathering.sln b/Electrical Weathering.sln
index 9611e95..6f3b005 100644
--- a/Electrical Weathering.sln
+++ b/Electrical Weathering.sln
@@ -5,11 +5,6 @@ VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Electrical Weathering", "Electrical Weathering\Electrical Weathering.csproj", "{8A23BF79-FD70-4942-85F3-61839911616F}"
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{78D47EC2-309B-45A8-A103-7E7EAABAA745}"
- ProjectSection(SolutionItems) = preProject
- .editorconfig = .editorconfig
- EndProjectSection
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
diff --git a/Electrical Weathering/App.config b/Electrical Weathering/App.config
index bcb2ae2..aa7ac40 100644
--- a/Electrical Weathering/App.config
+++ b/Electrical Weathering/App.config
@@ -1,6 +1,6 @@
-
+
@@ -11,4 +11,4 @@
-
+
\ No newline at end of file
diff --git a/Electrical Weathering/App.xaml b/Electrical Weathering/App.xaml
index 18fd9c7..15ac3dc 100644
--- a/Electrical Weathering/App.xaml
+++ b/Electrical Weathering/App.xaml
@@ -3,6 +3,5 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
-
-
+
\ No newline at end of file
diff --git a/Electrical Weathering/App.xaml.cs b/Electrical Weathering/App.xaml.cs
index 1d9a7a0..3a7b710 100644
--- a/Electrical Weathering/App.xaml.cs
+++ b/Electrical Weathering/App.xaml.cs
@@ -8,4 +8,4 @@ namespace Electrical_Weathering
public partial class App : Application
{
}
-}
+}
\ No newline at end of file
diff --git a/Electrical Weathering/Electrical Weathering.csproj b/Electrical Weathering/Electrical Weathering.csproj
index 414be34..dcb59e4 100644
--- a/Electrical Weathering/Electrical Weathering.csproj
+++ b/Electrical Weathering/Electrical Weathering.csproj
@@ -1,6 +1,6 @@
- net6.0-windows7.0
+ net6.0-windows10.0.19041.0
WinExe
false
publish\
@@ -13,9 +13,9 @@
false
false
true
- 4.0.0.0
+ 4.1.0.0
0
- 4.0.0.%2a
+ 4.1.0.%2a
false
true
false
@@ -24,111 +24,57 @@
x64
zh-Hans
AnyCPU
+ app.manifest
+ 10.0.19041.0
+ full
+
+
+ zh-CN
+ true
+
AppIcon.ico
+
bin\x64\Debug\
true
+
bin\x64\Release\
true
-
- app.manifest
- 7.0
- full
-
-
- zh-CN
- true
-
-
- True
- 4096
-
-
- True
- 4096
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- False
- Microsoft .NET Framework 4.8 %28x86 和 x64%29
- true
-
-
- False
- .NET Framework 3.5 SP1
- false
-
-
+
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
- True
- True
- Settings.settings
-
-
-
-
- SettingsSingleFileGenerator
- Settings.Designer.cs
-
+
\ No newline at end of file
diff --git a/Electrical Weathering/MainWindow.xaml b/Electrical Weathering/MainWindow.xaml
index 060a707..542b921 100644
--- a/Electrical Weathering/MainWindow.xaml
+++ b/Electrical Weathering/MainWindow.xaml
@@ -3,29 +3,27 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:Electrical_Weathering"
+ xmlns:local="clr-namespace:Electrical_Weathering"
mc:Ignorable="d"
- Title="Electrical Weathering"
- Height="720" Width="1280"
- WindowStyle="ThreeDBorderWindow"
- Icon="Weathering.bmp"
-
- DataContext="{Binding RelativeSource={RelativeSource Self}}" MinWidth="1280" MinHeight="720" FontSize="18"
- >
+ Title="Electrical Weathering"
+ Height="720" Width="1280"
+ WindowStyle="ThreeDBorderWindow"
+ Icon="Weathering.bmp"
-
+ DataContext="{Binding RelativeSource={RelativeSource Self}}" MinWidth="1280" MinHeight="720" FontSize="18">
+
+
-
-
+
+
-
-
+
+
-
@@ -35,53 +33,51 @@
-
-
-
-
-
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+
@@ -89,43 +85,37 @@
-
-
-
-
+
+
+
+
-
-
+
-
-
+
-
-
+
-
-
+
-
-
- Copyright © 2021
-
+ ZNHIndustry™
+
KingsZNHONE@Bilibili
-
-
+
-
+
\ No newline at end of file
diff --git a/Electrical Weathering/MainWindow.xaml.cs b/Electrical Weathering/MainWindow.xaml.cs
index 388ed15..9e2fb4a 100644
--- a/Electrical Weathering/MainWindow.xaml.cs
+++ b/Electrical Weathering/MainWindow.xaml.cs
@@ -1,4 +1,6 @@
using Microsoft.Win32;
+using OpenCvSharp;
+using OpenCvSharp.WpfExtensions;
using System;
using System.Diagnostics;
using System.IO;
@@ -18,18 +20,20 @@ public enum WeatheringMode
///
/// MainWindow.xaml 的交互逻辑
///
- public partial class MainWindow : Window
+ public partial class MainWindow : System.Windows.Window
{
- BitmapSource SelectedBitmap;
- Stopwatch stopwatch = new();
- WeatheringMode Mode;
- WeatheringMachine WM = new();
- Random rand = new Random();
+ private BitmapSource SelectedBitmap;
+ private Stopwatch stopwatch = new();
+ private WeatheringMode Mode;
+ private WeatheringMachine WM = new();
+ private Random rand = new Random();
+
public MainWindow()
{
InitializeComponent();
string path = $"Resources/Demo{rand.Next(1, 9)}.jpg";
+
PreviewImage.Source = new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute));
SelectedBitmap = (BitmapSource)PreviewImage.Source;
@@ -37,12 +41,10 @@ public MainWindow()
Mode = WeatheringMode.Classic;
ModeClassic.IsChecked = true;
- Btn_Revert.IsEnabled = false;
+ Btn_Revert.IsEnabled = true;
CenterWindowOnScreen();
}
-
-
private void CenterWindowOnScreen()
{
double screenWidth = SystemParameters.PrimaryScreenWidth;
@@ -53,7 +55,7 @@ private void CenterWindowOnScreen()
this.Top = (screenHeight / 2) - (windowHeight / 2);
}
- private void Generate()
+ private async void Generate()
{
BitmapSource Result;
stopwatch.Restart();
@@ -65,15 +67,15 @@ private void Generate()
AspectRatio = Slider_Scaling.Value,
};
+ Func ConvertToMatFunc = (source) => source.ToMat();
+
if (Mode == WeatheringMode.Classic)
{
-
- Result = WM.WeatheringClassic((BitmapImage)SelectedBitmap, param,Check_Watermark.IsChecked.Value);
-
+ Result = WM.WeatheringSkia((BitmapImage)SelectedBitmap, param, Check_Watermark.IsChecked.Value);
}
else
{
- Result = WM.WeatheringNG((BitmapImage)SelectedBitmap, param, Check_Watermark.IsChecked.Value);
+ Result = WM.WeatheringCV((BitmapImage)SelectedBitmap, param, Check_Watermark.IsChecked.Value);
}
stopwatch.Stop();
PreviewImage.Source = Result;
@@ -91,7 +93,6 @@ private void FileSelectBtn_Click(object sender, RoutedEventArgs e)
FilePathTextBox.Text = openFileDialog.FileName;
LoadImageFromPath(FilePathTextBox.Text);
Btn_Revert.IsEnabled = true;
-
}
}
catch
@@ -117,7 +118,7 @@ private void LoadImageFromPath(string path)
PreviewImage.Source = SelectedBitmap;
ImageSizeText.Text = $"{SelectedBitmap.PixelWidth} x {SelectedBitmap.PixelHeight}";
- Check_Watermark.IsEnabled = SelectedBitmap.PixelWidth>=240&&SelectedBitmap.PixelHeight>= 120;
+ Check_Watermark.IsEnabled = SelectedBitmap.PixelWidth >= 240 && SelectedBitmap.PixelHeight >= 120;
ControlReset();
}
@@ -147,13 +148,12 @@ private void Slider_Greening_ValueChanged(object sender, RoutedPropertyChangedEv
{
if (Mode == WeatheringMode.Classic)
{
- TextGreeningValue.Text = $"{(int)(Slider_Greening.Value*100)} 迭代";
+ TextGreeningValue.Text = $"{(int)(Slider_Greening.Value * 100)} 迭代";
}
else
{
TextGreeningValue.Text = $"{Slider_Greening.Value:P0}";
}
-
}
private void Slider_Compressing_ValueChanged(object sender, RoutedPropertyChangedEventArgs e)
@@ -168,7 +168,6 @@ private void Slider_Scaling_ValueChanged(object sender, RoutedPropertyChangedEve
TextScalingValue.Text = $"{Slider_Scaling.Value:P0}";
}
catch (NullReferenceException) { }
-
}
private void RB_Low_Click(object sender, RoutedEventArgs e)
@@ -257,11 +256,19 @@ private void Btn_Save_Click(object sender, RoutedEventArgs e)
private void Btn_Revert_Click(object sender, RoutedEventArgs e)
{
- LoadImageFromPath(FilePathTextBox.Text);
+ try
+ {
+ LoadImageFromPath(FilePathTextBox.Text);
+ }
+ catch
+ {
+ }
Slider_Noise.Value = 0.0;
Slider_Greening.Value = 0.0;
Slider_Compressing.Value = 0.0;
Slider_Scaling.Value = 1.0;
+
+ Generate();
}
private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
@@ -279,7 +286,7 @@ private void ModeClassic_Checked(object sender, RoutedEventArgs e)
{
Generate();
}
- catch { }
+ catch { }
}
private void ModeNG_Checked(object sender, RoutedEventArgs e)
@@ -289,7 +296,7 @@ private void ModeNG_Checked(object sender, RoutedEventArgs e)
{
Generate();
}
- catch { }
+ catch { }
}
private void Slider_KeyUp(object sender, KeyEventArgs e)
@@ -302,4 +309,4 @@ private void Check_Watermark_Click(object sender, RoutedEventArgs e)
Generate();
}
}
-}
+}
\ No newline at end of file
diff --git a/Electrical Weathering/Properties/AssemblyInfo.cs b/Electrical Weathering/Properties/AssemblyInfo.cs
index 3cae5a2..b42aa8f 100644
--- a/Electrical Weathering/Properties/AssemblyInfo.cs
+++ b/Electrical Weathering/Properties/AssemblyInfo.cs
@@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ZNH™ Industry")]
[assembly: AssemblyProduct("Electrical Weathering")]
-[assembly: AssemblyCopyright("Copyright © 2017 - 2022 KingsZNHONE")]
+[assembly: AssemblyCopyright("Copyright © 2017 - 2023 KingsZNHONE")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -28,7 +28,6 @@
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
-
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //主题特定资源词典所处位置
//(未在页面中找到资源时使用,
@@ -38,8 +37,7 @@
//、应用程序或任何主题专用资源字典中找到时使用)
)]
-
-// 程序集的版本信息由下列四个值组成:
+// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
@@ -49,5 +47,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("4.0.0.0")]
-[assembly: AssemblyFileVersion("4.0.0.0")]
+[assembly: AssemblyVersion("4.1.0.0")]
+[assembly: AssemblyFileVersion("4.1.0.0")]
\ No newline at end of file
diff --git a/Electrical Weathering/Properties/Settings.Designer.cs b/Electrical Weathering/Properties/Settings.Designer.cs
deleted file mode 100644
index 28ca248..0000000
--- a/Electrical Weathering/Properties/Settings.Designer.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-//------------------------------------------------------------------------------
-//
-// 此代码由工具生成。
-// 运行时版本:4.0.30319.42000
-//
-// 对此文件的更改可能会导致不正确的行为,并且如果
-// 重新生成代码,这些更改将会丢失。
-//
-//------------------------------------------------------------------------------
-
-namespace Electrical_Weathering.Properties {
-
-
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")]
- internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
-
- private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
-
- public static Settings Default {
- get {
- return defaultInstance;
- }
- }
- }
-}
diff --git a/Electrical Weathering/Properties/Settings.settings b/Electrical Weathering/Properties/Settings.settings
deleted file mode 100644
index 033d7a5..0000000
--- a/Electrical Weathering/Properties/Settings.settings
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/Electrical Weathering/Resources/Test.bmp b/Electrical Weathering/Resources/Test.bmp
new file mode 100644
index 0000000..b6133bb
Binary files /dev/null and b/Electrical Weathering/Resources/Test.bmp differ
diff --git a/Electrical Weathering/WeatheringMachine.cs b/Electrical Weathering/WeatheringMachine.cs
index baf51cb..b5e4639 100644
--- a/Electrical Weathering/WeatheringMachine.cs
+++ b/Electrical Weathering/WeatheringMachine.cs
@@ -1,15 +1,27 @@
using OpenCvSharp;
using OpenCvSharp.WpfExtensions;
using System;
-using System.Drawing;
-using System.Drawing.Imaging;
-using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
-using System.Windows;
using System.Windows.Media.Imaging;
+
namespace Electrical_Weathering
{
+ [StructLayout(LayoutKind.Explicit)]
+ public struct TempBGRA
+ {
+ [FieldOffset(0)]
+ public byte B;
+
+ [FieldOffset(1)]
+ public byte G;
+
+ [FieldOffset(2)]
+ public byte R;
+
+ [FieldOffset(3)]
+ public byte A;
+ }
public struct WeatheringParam
{
@@ -21,10 +33,10 @@ public struct WeatheringParam
public class WeatheringMachine
{
- Mat Watermark_Zhihu;
- Mat Watermark_Sina;
- Mat Watermark_Tieba;
- Mat Watermark_Toutiao;
+ private Mat Watermark_Zhihu;
+ private Mat Watermark_Sina;
+ private Mat Watermark_Tieba;
+ private Mat Watermark_Toutiao;
public WeatheringMachine()
{
@@ -42,10 +54,11 @@ public WeatheringMachine()
private Func ClampUV = (int x) => x < -128 ? -128 : x <= 127 ? x : 127;
- public BitmapSource WeatheringClassic(BitmapImage input, WeatheringParam param,bool Watermark)
+ public unsafe BitmapSource WeatheringSkia(BitmapImage input, WeatheringParam param, bool Watermark)
{
Mat SourceMat = input.ToMat();
+ //Some Meme only have one color channel.
if (SourceMat.Type() == MatType.CV_8UC1)
{
SourceMat = SourceMat.CvtColor(ColorConversionCodes.GRAY2BGRA);
@@ -64,14 +77,15 @@ public BitmapSource WeatheringClassic(BitmapImage input, WeatheringParam param,b
Noising(ref SourceMat, param.Noise);
}
- for (int iter = 0; iter < param.Green*100; iter++)
- {
+ //Greening
+ for (int iter = 0; iter < param.Green * 100; iter++)
+ {
Parallel.For(0, SourceMat.Height, (y, state) =>
{
- Parallel.For(0, SourceMat.Width, (x, state) =>
+ for (int x = 0; x < SourceMat.Width; x++)
{
SourceMat.Set(y, x, SkiaYUV(SourceMat.Get(y, x)));
- });
+ }
});
}
@@ -85,12 +99,11 @@ public BitmapSource WeatheringClassic(BitmapImage input, WeatheringParam param,b
OpenCvSharp.Size size = new OpenCvSharp.Size(0, 0);
SourceMat = SourceMat.Resize(size, param.AspectRatio, param.AspectRatio, InterpolationFlags.Area);
}
-
- return SourceMat.ToBitmapSource();
+ return SourceMat.ToBitmapSource();
}
- public BitmapSource WeatheringNG(BitmapSource SourceImage, WeatheringParam param, bool Watermark)
+ public BitmapSource WeatheringCV(BitmapSource SourceImage, WeatheringParam param, bool Watermark)
{
Mat SourceMat = SourceImage.ToMat();
if (SourceMat.Type() == MatType.CV_8UC1)
@@ -100,7 +113,7 @@ public BitmapSource WeatheringNG(BitmapSource SourceImage, WeatheringParam param
if (Watermark)
{
AddWatermark(ref SourceMat, Watermark_Zhihu);
- AddWatermark(ref SourceMat, Watermark_Sina);
+ AddWatermark(ref SourceMat, Watermark_Sina);
AddWatermark(ref SourceMat, Watermark_Toutiao);
AddWatermark(ref SourceMat, Watermark_Tieba);
}
@@ -127,7 +140,7 @@ public BitmapSource WeatheringNG(BitmapSource SourceImage, WeatheringParam param
public void AddWatermark(ref Mat SourceMat, Mat Watermark)
{
- Mat ROI = SourceMat.SubMat(new OpenCvSharp.Rect(SourceMat.Width-Watermark.Width, SourceMat.Height- Watermark.Height, Watermark.Width, Watermark.Height));
+ Mat ROI = SourceMat.SubMat(new OpenCvSharp.Rect(SourceMat.Width - Watermark.Width, SourceMat.Height - Watermark.Height, Watermark.Width, Watermark.Height));
Vec4b vf;
Vec3b vb;
double alpha = 1;
@@ -153,18 +166,17 @@ private Vec3b SkiaYUV(Vec3b p)
{
int Y = ClampRGB(((77 * p.Item2 + 150 * p.Item1 + 29 * p.Item0) >> 8) - 1);
int U = ClampUV(((-43 * p.Item2 + -85 * p.Item1 + 128 * p.Item0) >> 8) - 1);
- int V = ClampUV(((128 * p.Item2 + -107 * p.Item1 + -21 *p.Item0)>> 8) - 1);
+ int V = ClampUV(((128 * p.Item2 + -107 * p.Item1 + -21 * p.Item0) >> 8) - 1);
- int YY1 = Y<<16;
+ int YY1 = Y << 16;
- var newPixel =new Vec3b
+ var newPixel = new Vec3b
{
Item0 = Convert.ToByte(ClampRGB((YY1 + 116130 * U) >> 16)), // B
Item1 = Convert.ToByte(ClampRGB((YY1 - 22553 * U - 46802 * V) >> 16)), // G
Item2 = Convert.ToByte(ClampRGB((YY1 + 91881 * V) >> 16)) // R
};
return newPixel;
-
}
private void Noising(ref Mat SourceMat, double intensity)
@@ -180,12 +192,22 @@ private void Greening(ref Mat SourceMat, double intensity)
{
using (Mat GreenMat = new Mat(SourceMat.Height, SourceMat.Width, MatType.CV_8UC4, new Scalar(0, 255, 0, 255)))
{
- Cv2.AddWeighted(SourceMat, 1 - intensity, GreenMat, intensity, 0, SourceMat);
- SourceMat.ConvertTo(SourceMat, SourceMat.Type(), 1, -intensity * 128);
+ double DesiredAlpha = 1 - 0.5 * intensity; //[0.5,1]
+ double DesiredBeta = 0.5 * Math.Sqrt(intensity); //[0,0.5]
+ double DesiredGamma = -3 * intensity * 100;
+ DesiredGamma = DesiredGamma >= -45 ? DesiredGamma : -45;// [-45,0]
+
+ //Mix with 2 mat
+ Cv2.AddWeighted(SourceMat, DesiredAlpha, GreenMat, DesiredBeta, DesiredGamma, SourceMat);
+
+ //
+ SourceMat.ConvertTo(SourceMat, SourceMat.Type(), 1 + 0.25 * intensity, -intensity * 128);
+
+ //Lift G channel brightness
Mat[] bgra;
Cv2.Split(SourceMat, out bgra);
- Cv2.Rectangle(bgra[3], new OpenCvSharp.Rect(0, 0, bgra[3].Width, bgra[3].Height), new Scalar(255), -1);
- bgra[1].ConvertTo(bgra[1], bgra[1].Type(),1, 32 * intensity);
+ //Cv2.Rectangle(bgra[3], new OpenCvSharp.Rect(0, 0, bgra[3].Width, bgra[3].Height), new Scalar(255), -1);
+ bgra[1].ConvertTo(bgra[1], bgra[1].Type(), 1, 32 * intensity);
Cv2.Merge(bgra, SourceMat);
}
}
@@ -196,6 +218,5 @@ private Mat Compressing(Mat SourceMat, double intensity)
byte[] buffer = SourceMat.ImEncode(".jpg", param);
return Mat.ImDecode(buffer);
}
-
}
-}
+}
\ No newline at end of file
diff --git a/README.md b/README.md
index 578aece..4e437b1 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,23 @@ A weared Emojpg like a medal. An internet veteran medal.
## 更新日志 Change Log
+### 2023.03.24 v4.1
+
+优化Skia算法的多线程加速,速度提高3倍
+
+Optimize Skia Method. 3x Faster.
+
+调整CV算法的参数,更贴近Skia算法的生成效果
+
+Change args of CV Method. Make result more like Skia Method.
+
+#### Skia Method
+
+
+#### CV Method
+
+
+
### 2022.04.11 v4.0
增加绿图罪魁祸首的原版Skia算法,性能比较差
@@ -82,7 +99,7 @@ Initial Publish
## 最低要求 Minimal Requirement
-Windows 10 2004 (20H1) with .NET 6 runtime
+Windows 10 19041 (20H1) with .NET 6 runtime
## Stargazers over time
diff --git a/WeatheringCV.png b/WeatheringCV.png
new file mode 100644
index 0000000..a23c12d
Binary files /dev/null and b/WeatheringCV.png differ
diff --git a/WeatheringSkia.png b/WeatheringSkia.png
new file mode 100644
index 0000000..414932d
Binary files /dev/null and b/WeatheringSkia.png differ