Code refactor

This commit is contained in:
Jaex 2020-09-15 03:36:49 +03:00
parent 18ed2567b4
commit ea695ab926
4 changed files with 38 additions and 8 deletions

View file

@ -1390,7 +1390,7 @@ public static void ColorDepth(Bitmap bmp, int bitsPerChannel = 4)
byte Remap(byte color, double interval) byte Remap(byte color, double interval)
{ {
return (byte) Math.Round((Math.Round(color / interval) * interval)); return (byte)Math.Round(Math.Round(color / interval) * interval);
} }
using (UnsafeBitmap unsafeBitmap = new UnsafeBitmap(bmp, true)) using (UnsafeBitmap unsafeBitmap = new UnsafeBitmap(bmp, true))

View file

@ -1,19 +1,50 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2020 ShareX Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using ShareX.HelpersLib;
namespace ShareX.ImageEffectsLib namespace ShareX.ImageEffectsLib
{ {
[Description("Color depth")] [Description("Color depth")]
internal class ColorDepth : ImageEffect internal class ColorDepth : ImageEffect
{ {
private int _bitsPerChannel; private int bitsPerChannel;
[DefaultValue(4)] [DefaultValue(4)]
public int BitsPerChannel public int BitsPerChannel
{ {
get => this._bitsPerChannel; get
set => this._bitsPerChannel = value.Max(1).Min(8); {
return bitsPerChannel;
}
set
{
bitsPerChannel = MathHelpers.Clamp(value, 1, 8);
}
} }
public ColorDepth() public ColorDepth()
@ -23,7 +54,7 @@ public ColorDepth()
public override Bitmap Apply(Bitmap bmp) public override Bitmap Apply(Bitmap bmp)
{ {
ImageHelpers.ColorDepth(bmp, this.BitsPerChannel); ImageHelpers.ColorDepth(bmp, BitsPerChannel);
return bmp; return bmp;
} }
} }

View file

@ -174,7 +174,7 @@ private bool StartEncoding()
private Task<bool> StartEncodingAsync() private Task<bool> StartEncodingAsync()
{ {
return Task.Run(() => StartEncoding()); return Task.Run(StartEncoding);
} }
private void Manager_EncodeProgressChanged(float percentage) private void Manager_EncodeProgressChanged(float percentage)

View file

@ -34,7 +34,6 @@
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<LangVersion>7.3</LangVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>