public static BitmapHolder ToRounded(BitmapHolder source, int rad, double cropWidthRatio, double cropHeightRatio, double borderSize, string borderHexColor) { double num = source.Width; double num2 = source.Height; double num3 = num; double num4 = num2; double num5 = cropWidthRatio / cropHeightRatio; double num6 = num / num2; if (num6 > num5) { num3 = cropWidthRatio * num2 / cropHeightRatio; } else if (num6 < num5) { num4 = cropHeightRatio * num / cropWidthRatio; } double num7 = (num - num3) / 2.0; double num8 = (num2 - num4) / 2.0; BitmapHolder bitmapHolder = null; bitmapHolder = ((num7 == 0.0 && num8 == 0.0) ? new BitmapHolder(source.PixelData, source.Width, source.Height) : CropTransformation.ToCropped(source, (int)num7, (int)num8, (int)num3, (int)num4)); rad = ((rad != 0) ? ((int)((double)rad * (num3 + num4) / 2.0 / 500.0)) : ((int)(Math.Min(num3, num4) / 2.0))); int num9 = (int)num3; int num10 = (int)num4; ColorHolder transparent = ColorHolder.Transparent; for (int i = 0; i < num10; i++) { for (int j = 0; j < num9; j++) { if (j <= rad && i <= rad) { if (!CheckRoundedCorner(rad, rad, rad, Corner.TopLeftCorner, j, i)) { bitmapHolder.SetPixel(i * num9 + j, transparent); } } else if (j >= num9 - rad && i <= rad) { if (!CheckRoundedCorner(num9 - rad, rad, rad, Corner.TopRightCorner, j, i)) { bitmapHolder.SetPixel(i * num9 + j, transparent); } } else if (j >= num9 - rad && i >= num10 - rad) { if (!CheckRoundedCorner(num9 - rad, num10 - rad, rad, Corner.BottomRightCorner, j, i)) { bitmapHolder.SetPixel(i * num9 + j, transparent); } } else if (j <= rad && i >= num10 - rad && !CheckRoundedCorner(rad, num10 - rad, rad, Corner.BottomLeftCorner, j, i)) { bitmapHolder.SetPixel(i * num9 + j, transparent); } } } return(bitmapHolder); }
public static void ToReplacedColor(BitmapHolder bmp, int r, int g, int b, int a) { int width = bmp.Width; int height = bmp.Height; int pixelCount = bmp.PixelCount; float num = (float)a / 255f; float num2 = 1f - num; int val = (int)((float)r - (float)r * num2); int val2 = (int)((float)g - (float)g * num2); int val3 = (int)((float)b - (float)b * num2); int val4 = (int)((float)r + (float)r * num2); int val5 = (int)((float)g + (float)g * num2); int val6 = (int)((float)b + (float)b * num2); for (int i = 0; i < pixelCount; i++) { ColorHolder pixel = bmp.GetPixel(i); int a2 = pixel.A; byte r2 = pixel.R; byte g2 = pixel.G; byte b2 = pixel.B; int val7 = (int)((float)(int)r2 + (float)(255 - r2) * (num * (float)r / 255f)); int val8 = (int)((float)(int)g2 + (float)(255 - g2) * (num * (float)g / 255f)); int val9 = (int)((float)(int)b2 + (float)(255 - b2) * (num * (float)b / 255f)); val7 = Math.Min(Math.Max(val, val7), val4); val8 = Math.Min(Math.Max(val2, val8), val5); val9 = Math.Min(Math.Max(val3, val9), val6); bmp.SetPixel(i, new ColorHolder(pixel.A, val7, val8, val9)); } }
public static void ToSepia(BitmapHolder bmp) { int width = bmp.Width; int height = bmp.Height; int pixelCount = bmp.PixelCount; for (int i = 0; i < pixelCount; i++) { ColorHolder pixel = bmp.GetPixel(i); int a = pixel.A; int r = pixel.R; int g = pixel.G; int b = pixel.B; int num = (int)Math.Min(0.393 * (double)r + 0.769 * (double)g + 0.189 * (double)b, 255.0); int num2 = (int)Math.Min(0.349 * (double)r + 0.686 * (double)g + 0.168 * (double)b, 255.0); int num3 = (int)Math.Min(0.272 * (double)r + 0.534 * (double)g + 0.131 * (double)b, 255.0); if (num > 255) { num = 255; } if (num2 > 255) { num2 = 255; } if (num3 > 255) { num3 = 255; } bmp.SetPixel(i, new ColorHolder(a, num, num2, num3)); } }
private static void CircleAA(BitmapHolder bitmap, int size, ColorHolder color) { int centerX = bitmap.Width / 2; double num = (bitmap.Width - size) / 2; int centerY = bitmap.Height / 2; double num2 = (bitmap.Height - size) / 2; double num3 = num * num; double num4 = num2 * num2; int num5 = (int)Math.Round(num3 / Math.Sqrt(num3 + num4)); for (int i = 0; i <= num5; i++) { double num6 = Math.Floor(num2 * Math.Sqrt(1.0 - (double)(i * i) / num3)); double num7 = num6 - Math.Floor(num6); int num8 = (int)Math.Round(num7 * 255.0); SetPixel4(bitmap, centerX, centerY, i, (int)Math.Floor(num6), new ColorHolder(num8, color.R, color.G, color.B)); SetPixel4(bitmap, centerX, centerY, i, (int)Math.Floor(num6) + 1, new ColorHolder(255 - num8, color.R, color.G, color.B)); } num5 = (int)Math.Round(num4 / Math.Sqrt(num3 + num4)); for (int j = 0; j <= num5; j++) { double num9 = Math.Floor(num * Math.Sqrt(1.0 - (double)(j * j) / num4)); double num10 = num9 - Math.Floor(num9); int num11 = (int)Math.Round(num10 * 255.0); SetPixel4(bitmap, centerX, centerY, (int)Math.Floor(num9), j, new ColorHolder(num11, color.R, color.G, color.B)); SetPixel4(bitmap, centerX, centerY, (int)Math.Floor(num9) + 1, j, new ColorHolder(255 - num11, color.R, color.G, color.B)); } }
private SolidBrush GetBrush(ColorHolder colorHolder) { var color = GetColor(colorHolder); var brush = new SolidBrush(color); return(brush); }
public static ColorHolder BlendColor(ColorHolder color, ColorHolder backColor) { float num = (float)(int)color.A / 255f; byte r = (byte)((float)(int)color.R * num + (float)(int)backColor.R * (1f - num)); byte g = (byte)((float)(int)color.G * num + (float)(int)backColor.G * (1f - num)); byte b = (byte)((float)(int)color.B * num + (float)(int)backColor.B * (1f - num)); return(new ColorHolder(r, g, b)); }
public void SetPixel(int pos, ColorHolder color) { int bytePos = pos * 4; PixelData[bytePos] = color.B; PixelData[bytePos + 1] = color.G; PixelData[bytePos + 2] = color.R; PixelData[bytePos + 3] = color.A; }
public void SetPixel(int pos, ColorHolder color) { int num = pos * 4; PixelData[num] = color.B; PixelData[num + 1] = color.G; PixelData[num + 2] = color.R; PixelData[num + 3] = color.A; }
public static ColorHolder BlendColor(ColorHolder color, ColorHolder backColor) { float amount = (float)color.A / 255; byte r = (byte)((color.R * amount) + backColor.R * (1 - amount)); byte g = (byte)((color.G * amount) + backColor.G * (1 - amount)); byte b = (byte)((color.B * amount) + backColor.B * (1 - amount)); return(new ColorHolder(r, g, b)); }
protected override BitmapHolder Transform(BitmapHolder bitmapSource, string path, ImageSource source, bool isPlaceholder, string key) { int pixelCount = bitmapSource.PixelCount; ColorHolder backColor = HexColor.ToColorFromHex(); for (int i = 0; i < pixelCount; i++) { ColorHolder pixel = bitmapSource.GetPixel(i); bitmapSource.SetPixel(i, BlendColor(pixel, backColor)); } return(bitmapSource); }
public static void ToGrayscale(BitmapHolder bmp) { int width = bmp.Width; int height = bmp.Height; int pixelCount = bmp.PixelCount; for (int i = 0; i < pixelCount; i++) { ColorHolder pixel = bmp.GetPixel(i); int a = pixel.A; int r = pixel.R; int g = pixel.G; int b = pixel.B; int num = r * 6966 + g * 23436 + b * 2366 >> 15; r = (g = (b = num)); bmp.SetPixel(i, new ColorHolder(a, r, g, b)); } }
private static async Task MsgRec(SocketMessage arg) { if (arg.Channel.GetType() == typeof(SocketDMChannel) && Associations.ContainsValue(arg.Author.Id) && !arg.Author.IsBot) { var Emb = new EmbedBuilder() { Author = new EmbedAuthorBuilder() { Name = $"{arg.Author.Username}#{arg.Author.Discriminator}", IconUrl = arg.Author.GetAvatarUrl(), }, Color = ColorHolder.Parse(arg.Content), Description = arg.Content, Timestamp = arg.Timestamp }; foreach (var Key in Associations.Keys) { var Val = Associations[Key]; if (Val == arg.Author.Id) { await((SocketTextChannel)Program.Client.GetChannel(Key)).SendMessageAsync("", false, Emb.Build()); break; } } } else if (Associations.ContainsKey(arg.Channel.Id) && !arg.Author.IsBot && RankingManager.BotOwners.ContainsKey(arg.Author.Id) && RankingManager.BotOwners[arg.Author.Id] >= 20 && !arg.Content.Contains($"{Program.Prefix}dm0")) { try { var UserToDm = Program.Client.GetUser(Associations[arg.Channel.Id]); await UserToDm.SendMessageAsync(arg.Content); //await arg.AddReactionAsync(Emote.Parse("<:PleadingCold:752119782660374576>")); var Ems = ((SocketTextChannel)arg.Channel).Guild.Emotes; await arg.AddReactionAsync(Ems.ElementAt(new Random().Next(0, Ems.Count - 1))); } catch (Exception e) { await arg.Channel.SendMessageAsync(e.Message); } } }
public static void ToColorSpace(BitmapHolder bmp, float[][] rgbawMatrix) { float num = rgbawMatrix[0][0]; float num2 = rgbawMatrix[0][1]; float num3 = rgbawMatrix[0][2]; float num4 = rgbawMatrix[0][3]; float num5 = rgbawMatrix[1][0]; float num6 = rgbawMatrix[1][1]; float num7 = rgbawMatrix[1][2]; float num8 = rgbawMatrix[1][3]; float num9 = rgbawMatrix[2][0]; float num10 = rgbawMatrix[2][1]; float num11 = rgbawMatrix[2][2]; float num12 = rgbawMatrix[2][3]; float num13 = rgbawMatrix[3][0]; float num14 = rgbawMatrix[3][1]; float num15 = rgbawMatrix[3][2]; float num16 = rgbawMatrix[3][3]; float num17 = rgbawMatrix[4][0]; float num18 = rgbawMatrix[4][1]; float num19 = rgbawMatrix[4][2]; float num20 = rgbawMatrix[4][3]; int width = bmp.Width; int height = bmp.Height; int pixelCount = bmp.PixelCount; for (int i = 0; i < pixelCount; i++) { ColorHolder pixel = bmp.GetPixel(i); byte a = pixel.A; byte r = pixel.R; byte g = pixel.G; byte b = pixel.B; int r2 = (int)((float)(int)r * num + (float)(int)g * num5 + (float)(int)b * num9 + (float)(int)a * num13 + num17); int g2 = (int)((float)(int)r * num2 + (float)(int)g * num6 + (float)(int)b * num10 + (float)(int)a * num14 + num18); int b2 = (int)((float)(int)r * num3 + (float)(int)g * num7 + (float)(int)b * num11 + (float)(int)a * num15 + num19); int a2 = (int)((float)(int)r * num4 + (float)(int)g * num8 + (float)(int)b * num12 + (float)(int)a * num16 + num20); bmp.SetPixel(i, new ColorHolder(a2, r2, g2, b2)); } }
static void CircleAA(BitmapHolder bitmap, int size, ColorHolder color) { if (size % 2 != 0) { size++; } int centerX = bitmap.Width / 2; double radiusX = (bitmap.Width - size) / 2; int centerY = bitmap.Height / 2; double radiusY = (bitmap.Height - size) / 2; const int maxTransparency = 127; // default: 127 double radiusX2 = radiusX * radiusX; double radiusY2 = radiusY * radiusY; // upper and lower halves int quarter = (int)Math.Round(radiusX2 / Math.Sqrt(radiusX2 + radiusY2)); for (int x = 0; x <= quarter; x++) { double y = Math.Floor(radiusY * Math.Sqrt(1 - x * x / radiusX2)); double error = y - Math.Floor(y); int transparency = (int)Math.Round(error * maxTransparency); SetPixel4(bitmap, centerX, centerY, x, (int)Math.Floor(y), new ColorHolder(transparency, color.R, color.G, color.B)); SetPixel4(bitmap, centerX, centerY, x, (int)Math.Floor(y) + 1, new ColorHolder(maxTransparency - transparency, color.R, color.G, color.B)); } // right and left halves quarter = (int)Math.Round(radiusY2 / Math.Sqrt(radiusX2 + radiusY2)); for (int y = 0; y <= quarter; y++) { double x = Math.Floor(radiusX * Math.Sqrt(1 - y * y / radiusY2)); double error = x - Math.Floor(x); int transparency = (int)Math.Round(error * maxTransparency); SetPixel4(bitmap, centerX, centerY, (int)Math.Floor(x), y, new ColorHolder(transparency, color.R, color.G, color.B)); SetPixel4(bitmap, centerX, centerY, (int)Math.Floor(x) + 1, y, new ColorHolder(maxTransparency - transparency, color.R, color.G, color.B)); } }
static void Main(string[] args) { Dictionary <string, object> dict = new Dictionary <string, object>(); dict["Rainbow"] = new ColorHolder { Value = Color.FromArgb(10, 20, 30, 40) }; JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto, Formatting = Formatting.Indented }; string json = JsonConvert.SerializeObject(dict, settings); Console.WriteLine(json); Console.WriteLine(); var d = JsonConvert.DeserializeObject <Dictionary <string, object> >(json, settings); ColorHolder holder = (ColorHolder)d["Rainbow"]; Console.WriteLine("A=" + holder.Value.A); Console.WriteLine("R=" + holder.Value.R); Console.WriteLine("G=" + holder.Value.G); Console.WriteLine("B=" + holder.Value.B); }
public static void ToLegacyBlurred(BitmapHolder source, int radius) { int width = source.Width; int height = source.Height; int num = width - 1; int val = height - 1; int num2 = width * height; int num3 = radius + radius + 1; int[] array = new int[num2]; int[] array2 = new int[num2]; int[] array3 = new int[num2]; int[] array4 = new int[Math.Max(width, height)]; int[] array5 = new int[Math.Max(width, height)]; int[] array6 = new int[256 * num3]; for (int i = 0; i < 256 * num3; i++) { array6[i] = i / num3; } int num4; int num5 = (num4 = 0); for (int j = 0; j < height; j++) { int num7; int num6; int num8 = (num7 = (num6 = 0)); for (int i = -radius; i <= radius; i++) { ColorHolder pixel = source.GetPixel(num4 + Math.Min(num, Math.Max(i, 0))); num8 += pixel.R; num7 += pixel.G; num6 += pixel.B; } for (int k = 0; k < width; k++) { array[num4] = array6[num8]; array2[num4] = array6[num7]; array3[num4] = array6[num6]; if (j == 0) { array4[k] = Math.Min(k + radius + 1, num); array5[k] = Math.Max(k - radius, 0); } ColorHolder pixel2 = source.GetPixel(num5 + array4[k]); ColorHolder pixel3 = source.GetPixel(num5 + array5[k]); num8 += pixel2.R - pixel3.R; num7 += pixel2.G - pixel3.G; num6 += pixel2.B - pixel3.B; num4++; } num5 += width; } for (int k = 0; k < width; k++) { int num7; int num6; int num8 = (num7 = (num6 = 0)); int num9 = -radius * width; for (int i = -radius; i <= radius; i++) { num4 = Math.Max(0, num9) + k; num8 += array[num4]; num7 += array2[num4]; num6 += array3[num4]; num9 += width; } num4 = k; for (int j = 0; j < height; j++) { ColorHolder color = new ColorHolder(source.GetPixel(num4).A, array6[num8], array6[num7], array6[num6]); source.SetPixel(num4, color); if (k == 0) { array4[j] = Math.Min(j + radius + 1, val) * width; array5[j] = Math.Max(j - radius, 0) * width; } int num10 = k + array4[j]; int num11 = k + array5[j]; num8 += array[num10] - array[num11]; num7 += array2[num10] - array2[num11]; num6 += array3[num10] - array3[num11]; num4 += width; } } }
private Color GetColor(ColorHolder colorHolder) { Color color = Color.FromArgb(255, colorHolder.R, colorHolder.G, colorHolder.B); return(color); }
public void SetPixel(int x, int y, ColorHolder color) { int pixelPos = (y * Width + x); SetPixel(pixelPos, color); }
// helper function, draws pixel and mirrors it static void SetPixel4(BitmapHolder bitmap, int centerX, int centerY, int deltaX, int deltaY, ColorHolder color) { bitmap.SetPixel(centerX + deltaX, centerY + deltaY, color); bitmap.SetPixel(centerX - deltaX, centerY + deltaY, color); bitmap.SetPixel(centerX + deltaX, centerY - deltaY, color); bitmap.SetPixel(centerX - deltaX, centerY - deltaY, color); }
public static BitmapHolder ToRotated(BitmapHolder source, double degrees, bool ccw, bool resize) { if (degrees == 0.0 || degrees % 360.0 == 0.0) { return(source); } if (ccw) { degrees = 360.0 - degrees; } double num = -Math.PI / 180.0 * degrees; int width = source.Width; int height = source.Height; int num2; int num3; if (!resize || degrees % 180.0 == 0.0) { num2 = width; num3 = height; } else { double num4 = degrees / (180.0 / Math.PI); num2 = (int)Math.Ceiling(Math.Abs(Math.Sin(num4) * (double)height) + Math.Abs(Math.Cos(num4) * (double)width)); num3 = (int)Math.Ceiling(Math.Abs(Math.Sin(num4) * (double)width) + Math.Abs(Math.Cos(num4) * (double)height)); } int num5 = width / 2; int num6 = height / 2; int num7 = num2 / 2; int num8 = num3 / 2; BitmapHolder bitmapHolder = new BitmapHolder(new byte[num2 * num3 * 4], num2, num3); int width2 = source.Width; for (int i = 0; i < num3; i++) { for (int j = 0; j < num2; j++) { int num9 = j - num7; int num10 = num8 - i; double num11 = Math.Sqrt(num9 * num9 + num10 * num10); double num12; if (num9 == 0) { if (num10 == 0) { bitmapHolder.SetPixel(i * num2 + j, source.GetPixel(num6 * width2 + num5)); continue; } num12 = ((num10 >= 0) ? (Math.PI / 2.0) : 4.71238898038469); } else { num12 = Math.Atan2(num10, num9); } num12 -= num; double num13 = num11 * Math.Cos(num12); double num14 = num11 * Math.Sin(num12); num13 += (double)num5; num14 = (double)num6 - num14; int num15 = (int)Math.Floor(num13); int num16 = (int)Math.Floor(num14); int num17 = (int)Math.Ceiling(num13); int num18 = (int)Math.Ceiling(num14); if (num15 >= 0 && num17 >= 0 && num15 < width && num17 < width && num16 >= 0 && num18 >= 0 && num16 < height && num18 < height) { double num19 = num13 - (double)num15; double num20 = num14 - (double)num16; ColorHolder pixel = source.GetPixel(num16 * width2 + num15); ColorHolder pixel2 = source.GetPixel(num16 * width2 + num17); ColorHolder pixel3 = source.GetPixel(num18 * width2 + num15); ColorHolder pixel4 = source.GetPixel(num18 * width2 + num17); double num21 = (1.0 - num19) * (double)(int)pixel.A + num19 * (double)(int)pixel2.A; double num22 = (1.0 - num19) * (double)(int)pixel.R + num19 * (double)(int)pixel2.R; double num23 = (1.0 - num19) * (double)(int)pixel.G + num19 * (double)(int)pixel2.G; double num24 = (1.0 - num19) * (double)(int)pixel.B + num19 * (double)(int)pixel2.B; double num25 = (1.0 - num19) * (double)(int)pixel3.A + num19 * (double)(int)pixel4.A; double num26 = (1.0 - num19) * (double)(int)pixel3.R + num19 * (double)(int)pixel4.R; double num27 = (1.0 - num19) * (double)(int)pixel3.G + num19 * (double)(int)pixel4.G; double num28 = (1.0 - num19) * (double)(int)pixel3.B + num19 * (double)(int)pixel4.B; int r = (int)Math.Round((1.0 - num20) * num22 + num20 * num26); int g = (int)Math.Round((1.0 - num20) * num23 + num20 * num27); int b = (int)Math.Round((1.0 - num20) * num24 + num20 * num28); int num29 = (int)Math.Round((1.0 - num20) * num21 + num20 * num25); int num30 = num29 + 1; bitmapHolder.SetPixel(i * num2 + j, new ColorHolder(num29, r, g, b)); } } } return(bitmapHolder); }
public static BitmapHolder ToTransformedCorners(BitmapHolder source, double topLeftCornerSize, double topRightCornerSize, double bottomLeftCornerSize, double bottomRightCornerSize, CornerTransformType cornersTransformType, double cropWidthRatio, double cropHeightRatio) { double num = source.Width; double num2 = source.Height; double num3 = num; double num4 = num2; double num5 = cropWidthRatio / cropHeightRatio; double num6 = num / num2; if (num6 > num5) { num3 = cropWidthRatio * num2 / cropHeightRatio; } else if (num6 < num5) { num4 = cropHeightRatio * num / cropWidthRatio; } double num7 = (num - num3) / 2.0; double num8 = (num2 - num4) / 2.0; BitmapHolder bitmapHolder = null; bitmapHolder = ((num7 == 0.0 && num8 == 0.0) ? new BitmapHolder(source.PixelData, source.Width, source.Height) : CropTransformation.ToCropped(source, (int)num7, (int)num8, (int)num3, (int)num4)); topLeftCornerSize = topLeftCornerSize * (num3 + num4) / 2.0 / 100.0; topRightCornerSize = topRightCornerSize * (num3 + num4) / 2.0 / 100.0; bottomLeftCornerSize = bottomLeftCornerSize * (num3 + num4) / 2.0 / 100.0; bottomRightCornerSize = bottomRightCornerSize * (num3 + num4) / 2.0 / 100.0; int num9 = (int)topLeftCornerSize; int num10 = (int)topRightCornerSize; int num11 = (int)bottomLeftCornerSize; int num12 = (int)bottomRightCornerSize; int width = bitmapHolder.Width; int height = bitmapHolder.Height; ColorHolder transparent = ColorHolder.Transparent; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (j <= num9 && i <= num9) { if (!CheckCorner(num9, num9, num9, cornersTransformType, Corner.TopLeftCorner, j, i)) { bitmapHolder.SetPixel(i * width + j, transparent); } } else if (j >= width - num10 && i <= num10 && num10 > 0) { if (!CheckCorner(width - num10, num10, num10, cornersTransformType, Corner.TopRightCorner, j, i)) { bitmapHolder.SetPixel(i * width + j, transparent); } } else if (j >= width - num12 && i >= height - num12 && num12 > 0) { if (!CheckCorner(width - num12, height - num12, num12, cornersTransformType, Corner.BottomRightCorner, j, i)) { bitmapHolder.SetPixel(i * width + j, transparent); } } else if (j <= num11 && i >= height - num11 && num11 > 0 && !CheckCorner(num11, height - num11, num11, cornersTransformType, Corner.BottomLeftCorner, j, i)) { bitmapHolder.SetPixel(i * width + j, transparent); } } } return(bitmapHolder); }
public void SetPixel(int x, int y, ColorHolder color) { int pos = y * Width + x; SetPixel(pos, color); }
// Source: http://incubator.quasimondo.com/processing/superfast_blur.php public static void ToLegacyBlurred(BitmapHolder source, int radius) { int w = source.Width; int h = source.Height; int wm = w - 1; int hm = h - 1; int wh = w * h; int div = radius + radius + 1; int[] r = new int[wh]; int[] g = new int[wh]; int[] b = new int[wh]; int rsum, gsum, bsum, x, y, i, yp, yi, yw; int[] vmin = new int[Math.Max(w, h)]; int[] vmax = new int[Math.Max(w, h)]; int[] dv = new int[256 * div]; for (i = 0; i < 256 * div; i++) { dv[i] = (i / div); } yw = yi = 0; for (y = 0; y < h; y++) { rsum = gsum = bsum = 0; for (i = -radius; i <= radius; i++) { var p = source.GetPixel(yi + Math.Min(wm, Math.Max(i, 0))); rsum += p.R; gsum += p.G; bsum += p.B; } for (x = 0; x < w; x++) { r[yi] = dv[rsum]; g[yi] = dv[gsum]; b[yi] = dv[bsum]; if (y == 0) { vmin[x] = Math.Min(x + radius + 1, wm); vmax[x] = Math.Max(x - radius, 0); } var p1 = source.GetPixel(yw + vmin[x]); var p2 = source.GetPixel(yw + vmax[x]); rsum += p1.R - p2.R; gsum += p1.G - p2.G; bsum += p1.B - p2.B; yi++; } yw += w; } for (x = 0; x < w; x++) { rsum = gsum = bsum = 0; yp = -radius * w; for (i = -radius; i <= radius; i++) { yi = Math.Max(0, yp) + x; rsum += r[yi]; gsum += g[yi]; bsum += b[yi]; yp += w; } yi = x; for (y = 0; y < h; y++) { // Preserve alpha channel: ( 0xff000000 & pix[yi] ) var oldColor = source.GetPixel(yi); var newColor = new ColorHolder(oldColor.A, dv[rsum], dv[gsum], dv[bsum]); source.SetPixel(yi, newColor); if (x == 0) { vmin[y] = Math.Min(y + radius + 1, hm) * w; vmax[y] = Math.Max(y - radius, 0) * w; } var p1 = x + vmin[y]; var p2 = x + vmax[y]; rsum += r[p1] - r[p2]; gsum += g[p1] - g[p2]; bsum += b[p1] - b[p2]; yi += w; } } }
private static void SetPixel4(BitmapHolder bitmap, int centerX, int centerY, int deltaX, int deltaY, ColorHolder color) { if (centerX + deltaX < bitmap.Width && centerY + deltaY < bitmap.Height) { bitmap.SetPixel(centerX + deltaX, centerY + deltaY, color); } if (centerX - deltaX >= 0 && centerY + deltaY < bitmap.Height) { bitmap.SetPixel(centerX - deltaX, centerY + deltaY, color); } if (centerX + deltaX < bitmap.Width && centerY - deltaY >= 0) { bitmap.SetPixel(centerX + deltaX, centerY - deltaY, color); } if (centerX - deltaX >= 0 && centerY - deltaY >= 0) { bitmap.SetPixel(centerX - deltaX, centerY - deltaY, color); } }