{ "name": "GuassianLockUpdate", "language": 0, "code": "using System;\r\nusing System.Collections.Generic;\r\nusing System.Diagnostics;\r\nusing System.Drawing;\r\nusing System.Drawing.Imaging;\r\nusing System.IO;\r\nusing System.Threading.Tasks;\r\nusing System.Windows.Forms;\r\nusing System.Runtime.InteropServices;\r\n\r\n// requires the following registry key setting:\r\n//[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PersonalizationCSP]\r\n//\"LockScreenImagePath\"=\"C:\\\\Temp\\\\BlurredLockScreen.jpg\"\r\npublic static class DisplayFusionFunction\r\n{\r\n\tpublic static void Run(IntPtr windowHandle) {\r\n if (!BFS.General.IsDesktopLocked()) {\r\n using (Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)) {\r\n using (Graphics g = Graphics.FromImage(bmpScreenCapture)) {\r\n g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y,\r\n 0, 0,\r\n bmpScreenCapture.Size,\r\n CopyPixelOperation.SourceCopy);\r\n }\r\n var blurredbmp = bmpScreenCapture.FastGaussianBlurAsync(5);\r\n blurredbmp.Save(@\"C:\\Temp\\BlurredLockScreen.jpg\", ImageFormat.Jpeg);\r\n }\r\n }\r\n\t}\r\n}\r\n\r\npublic class GaussianBlur {\r\n private readonly int[] _alpha;\r\n private readonly int[] _red;\r\n private readonly int[] _green;\r\n private readonly int[] _blue;\r\n\r\n private readonly int _width;\r\n private readonly int _height;\r\n\r\n private readonly ParallelOptions _pOptions = new ParallelOptions { MaxDegreeOfParallelism = 16 };\r\n\r\n public GaussianBlur(Bitmap image) {\r\n var rct = new Rectangle(0, 0, image.Width, image.Height);\r\n var source = new int[rct.Width * rct.Height];\r\n var bits = image.LockBits(rct, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);\r\n Marshal.Copy(bits.Scan0, source, 0, source.Length);\r\n image.UnlockBits(bits);\r\n\r\n _width = image.Width;\r\n _height = image.Height;\r\n\r\n _alpha = new int[_width * _height];\r\n _red = new int[_width * _height];\r\n _green = new int[_width * _height];\r\n _blue = new int[_width * _height];\r\n\r\n Parallel.For(0, source.Length, _pOptions, i => {\r\n _alpha[i] = (int)((source[i] & 0xff000000) >> 24);\r\n _red[i] = (source[i] & 0xff0000) >> 16;\r\n _green[i] = (source[i] & 0x00ff00) >> 8;\r\n _blue[i] = (source[i] & 0x0000ff);\r\n });\r\n }\r\n\r\n public Bitmap Process(int radial) {\r\n var newAlpha = new int[_width * _height];\r\n var newRed = new int[_width * _height];\r\n var newGreen = new int[_width * _height];\r\n var newBlue = new int[_width * _height];\r\n var dest = new int[_width * _height];\r\n\r\n Parallel.Invoke(\r\n () => gaussBlur_4(_alpha, newAlpha, radial),\r\n () => gaussBlur_4(_red, newRed, radial),\r\n () => gaussBlur_4(_green, newGreen, radial),\r\n () => gaussBlur_4(_blue, newBlue, radial));\r\n\r\n Parallel.For(0, dest.Length, _pOptions, i => {\r\n if (newAlpha[i] > 255) newAlpha[i] = 255;\r\n if (newRed[i] > 255) newRed[i] = 255;\r\n if (newGreen[i] > 255) newGreen[i] = 255;\r\n if (newBlue[i] > 255) newBlue[i] = 255;\r\n\r\n if (newAlpha[i] < 0) newAlpha[i] = 0;\r\n if (newRed[i] < 0) newRed[i] = 0;\r\n if (newGreen[i] < 0) newGreen[i] = 0;\r\n if (newBlue[i] < 0) newBlue[i] = 0;\r\n\r\n dest[i] = (int)((uint)(newAlpha[i] << 24) | (uint)(newRed[i] << 16) | (uint)(newGreen[i] << 8) | (uint)newBlue[i]);\r\n });\r\n\r\n var image = new Bitmap(_width, _height);\r\n var rct = new Rectangle(0, 0, image.Width, image.Height);\r\n var bits2 = image.LockBits(rct, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);\r\n Marshal.Copy(dest, 0, bits2.Scan0, dest.Length);\r\n image.UnlockBits(bits2);\r\n return image;\r\n }\r\n\r\n private void gaussBlur_4(int[] source, int[] dest, int r) {\r\n var bxs = boxesForGauss(r, 3);\r\n boxBlur_4(source, dest, _width, _height, (bxs[0] - 1) / 2);\r\n boxBlur_4(dest, source, _width, _height, (bxs[1] - 1) / 2);\r\n boxBlur_4(source, dest, _width, _height, (bxs[2] - 1) / 2);\r\n }\r\n\r\n private int[] boxesForGauss(int sigma, int n) {\r\n var wIdeal = Math.Sqrt((12 * sigma * sigma / n) + 1);\r\n var wl = (int)Math.Floor(wIdeal);\r\n if (wl % 2 == 0) wl--;\r\n var wu = wl + 2;\r\n\r\n var mIdeal = (double)(12 * sigma * sigma - n * wl * wl - 4 * n * wl - 3 * n) / (-4 * wl - 4);\r\n var m = Math.Round(mIdeal);\r\n\r\n var sizes = new List();\r\n for (var i = 0; i < n; i++) sizes.Add(i < m ? wl : wu);\r\n return sizes.ToArray();\r\n }\r\n\r\n private void boxBlur_4(int[] source, int[] dest, int w, int h, int r) {\r\n for (var i = 0; i < source.Length; i++) dest[i] = source[i];\r\n boxBlurH_4(dest, source, w, h, r);\r\n boxBlurT_4(source, dest, w, h, r);\r\n }\r\n\r\n private void boxBlurH_4(int[] source, int[] dest, int w, int h, int r) {\r\n var iar = (double)1 / (r + r + 1);\r\n Parallel.For(0, h, _pOptions, i => {\r\n var ti = i * w;\r\n var li = ti;\r\n var ri = ti + r;\r\n var fv = source[ti];\r\n var lv = source[ti + w - 1];\r\n var val = (r + 1) * fv;\r\n for (var j = 0; j < r; j++) val += source[ti + j];\r\n for (var j = 0; j <= r; j++) {\r\n val += source[ri++] - fv;\r\n dest[ti++] = (int)Math.Round(val * iar);\r\n }\r\n for (var j = r + 1; j < w - r; j++) {\r\n val += source[ri++] - dest[li++];\r\n dest[ti++] = (int)Math.Round(val * iar);\r\n }\r\n for (var j = w - r; j < w; j++) {\r\n val += lv - source[li++];\r\n dest[ti++] = (int)Math.Round(val * iar);\r\n }\r\n });\r\n }\r\n\r\n private void boxBlurT_4(int[] source, int[] dest, int w, int h, int r) {\r\n var iar = (double)1 / (r + r + 1);\r\n Parallel.For(0, w, _pOptions, i => {\r\n var ti = i;\r\n var li = ti;\r\n var ri = ti + r * w;\r\n var fv = source[ti];\r\n var lv = source[ti + w * (h - 1)];\r\n var val = (r + 1) * fv;\r\n for (var j = 0; j < r; j++) val += source[ti + j * w];\r\n for (var j = 0; j <= r; j++) {\r\n val += source[ri] - fv;\r\n dest[ti] = (int)Math.Round(val * iar);\r\n ri += w;\r\n ti += w;\r\n }\r\n for (var j = r + 1; j < h - r; j++) {\r\n val += source[ri] - source[li];\r\n dest[ti] = (int)Math.Round(val * iar);\r\n li += w;\r\n ri += w;\r\n ti += w;\r\n }\r\n for (var j = h - r; j < h; j++) {\r\n val += lv - source[li];\r\n dest[ti] = (int)Math.Round(val * iar);\r\n li += w;\r\n ti += w;\r\n }\r\n });\r\n }\r\n}\r\n\r\npublic static class BitmapExt {\r\n public static Bitmap FastGaussianBlurAsync(this Bitmap bmp, int radius) {\r\n var gb = new GaussianBlur(bmp);\r\n return gb.Process(radius);\r\n }\r\n}", "description": "Update Lock Screen background with gaussian blur of main screen", "references": "System.Core.dll|System.Data.dll|System.dll|System.Drawing.dll|System.Management.dll|System.Web.dll|System.Windows.Forms.dll|System.Xml.dll" }