+ FastLZ: FastLZ压缩解压类

This commit is contained in:
Sunny 2022-03-31 22:08:21 +08:00
parent aa409b0d7b
commit 8f34889655
6 changed files with 56 additions and 18 deletions

Binary file not shown.

View File

@ -1,4 +1,33 @@
using System;
/******************************************************************************
* SunnyUI
* CopyRight (C) 2012-2022 ShenYongHua().
* QQ群56829229 QQ17612584 EMailSunnyUI@QQ.Com
*
* Blog: https://www.cnblogs.com/yhuse
* Gitee: https://gitee.com/yhuse/SunnyUI
* GitHub: https://github.com/yhuse/SunnyUI
*
* SunnyUI.dll can be used for free under the GPL-3.0 license.
* If you use this code, please keep this note.
* 使
******************************************************************************
* : FastLZ.cs
* : FastLZ压缩解压类
* : V3.1
* : 2022-03-31
* : https://ariya.github.io/FastLZ/
*
* FastLZ (MIT license) is an ANSI C/C90 implementation of Lempel-Ziv 77
* algorithm (LZ77) of lossless data compression. It is suitable to compress
* series of text/paragraphs, sequences of raw pixel data, or any other blocks
* of data with lots of repetition. It is not intended to be used on images,
* videos, and other formats of data typically already in an optimal
* compressed form.
*
* 2022-03-31: V3.1.2
******************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
@ -37,7 +66,7 @@ namespace Sunny.UI
/// 是否64位
/// </summary>
/// <returns></returns>
public static bool IsSys64bit()
public static bool Is64bitApp()
{
return IntPtr.Size == 8;
}
@ -48,7 +77,7 @@ namespace Sunny.UI
fixed (void* pSrc1 = &input[begin])
fixed (void* pSrc2 = output)
{
int outlen = IsSys64bit() ? FastLZx64.FastLZ_Compress(pSrc1, len, pSrc2) : FastLZx86.FastLZ_Compress(pSrc1, len, pSrc2);
int outlen = Is64bitApp() ? FastLZx64.FastLZ_Compress(pSrc1, len, pSrc2) : FastLZx86.FastLZ_Compress(pSrc1, len, pSrc2);
byte[] result = new byte[outlen];
Array.Copy(output, 0, result, 0, outlen);
return result;
@ -61,7 +90,7 @@ namespace Sunny.UI
fixed (void* pSrc1 = &input[begin])
fixed (void* pSrc2 = output)
{
int outlen = IsSys64bit() ? FastLZx64.FastLZ_Compress_level(level, pSrc1, len, pSrc2) : FastLZx86.FastLZ_Compress_level(level, pSrc1, len, pSrc2);
int outlen = Is64bitApp() ? FastLZx64.FastLZ_Compress_level(level, pSrc1, len, pSrc2) : FastLZx86.FastLZ_Compress_level(level, pSrc1, len, pSrc2);
byte[] result = new byte[outlen];
Array.Copy(output, 0, result, 0, outlen);
return result;
@ -74,7 +103,7 @@ namespace Sunny.UI
fixed (byte* pSrc1 = &input[begin])
fixed (byte* pSrc2 = output)
{
int outlen = IsSys64bit() ? FastLZx64.FastLZ_Decompress(pSrc1, length, pSrc2, maxout) : FastLZx86.FastLZ_Decompress(pSrc1, length, pSrc2, maxout);
int outlen = Is64bitApp() ? FastLZx64.FastLZ_Decompress(pSrc1, length, pSrc2, maxout) : FastLZx86.FastLZ_Decompress(pSrc1, length, pSrc2, maxout);
byte[] result = new byte[outlen];
Array.Copy(output, 0, result, 0, outlen);
return result;

View File

@ -209,7 +209,7 @@ namespace Sunny.UI
/// </summary>
/// <param name="filename">文件名</param>
/// <returns>结果</returns>
public static FileInfo FileInfo(this string filename)
public static FileInfo FileInfo(string filename)
{
return File.Exists(filename) ? new FileInfo(filename) : null;
}
@ -254,7 +254,8 @@ namespace Sunny.UI
/// <returns>是否运行</returns>
public static bool IsRun(string filename)
{
return filename.FileInfo().IsRun();
FileInfo info = FileInfo(filename);
return info == null ? false : info.IsRun();
}
/// <summary>
@ -492,7 +493,8 @@ namespace Sunny.UI
/// <returns>结果</returns>
public static bool TryDelete(string file)
{
return file.FileInfo().TryDelete();
FileInfo info = FileInfo(file);
return info == null ? false : info.TryDelete();
}
/// <summary>

View File

@ -210,7 +210,7 @@ namespace Sunny.UI
return colors;
}
public static void Smooth(this Graphics g, bool smooth = true)
public static Graphics Smooth(this Graphics g, bool smooth = true)
{
if (smooth)
{
@ -220,6 +220,8 @@ namespace Sunny.UI
{
g.SetDefaultQuality();
}
return g;
}
@ -336,22 +338,24 @@ namespace Sunny.UI
/// 设置GDI高质量模式抗锯齿
/// </summary>
/// <param name="g"></param>
public static void SetHighQuality(this Graphics g)
public static Graphics SetHighQuality(this Graphics g)
{
g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.CompositingQuality = CompositingQuality.HighQuality;
return g;
}
/// <summary>
/// 设置GDI默认值
/// </summary>
/// <param name="g"></param>
public static void SetDefaultQuality(this Graphics g)
public static Graphics SetDefaultQuality(this Graphics g)
{
g.SmoothingMode = SmoothingMode.Default;
g.InterpolationMode = InterpolationMode.Default;
g.CompositingQuality = CompositingQuality.Default;
return g;
}
public static string ToHTML(this Color color)

View File

@ -133,12 +133,16 @@ namespace Sunny.UI
/// <param name="ms">The ms.</param>
public static void Delay(int ms)
{
int start = Environment.TickCount;
while (Environment.TickCount - start < ms)
{
System.Threading.Thread.Sleep(1);
Application.DoEvents();
System.Threading.Thread.Sleep(Math.Max(0, ms));
}
/// <summary>
/// 是否64位
/// </summary>
/// <returns></returns>
public static bool Is64bitApp()
{
return IntPtr.Size == 8;
}
/// <summary>

View File

@ -665,7 +665,6 @@ namespace Sunny.UI
{
topmost = baseForm.TopMost;
baseForm.TopMost = true;
Application.DoEvents();
}
Form mask = new Form();