public void Execute(byte[] bytes, int width, int height) { BitmapWrapper bmpWrapper = new BitmapWrapper(bytes, height, width); Color[,] tmpBuffer = new Color[height, width]; for (int j = 1; j < height - 1; j++) { for (int i = 1; i < width - 1; i++) { int r = 0; int g = 0; int b = 0; for (int k = 0; k < 9; k++) { var col = bmpWrapper.GetPixel(j + cordinatesY[k], i + cordinatesX[k]); r += col.R * mask[k]; g += col.G * mask[k]; b += col.B * mask[k]; } int maskSum = mask.Sum(); tmpBuffer[j, i] = Color.FromArgb(255, r / maskSum, g / maskSum, b / maskSum); } } for (int j = 1; j < height - 1; j++) { for (int i = 1; i < width - 1; i++) { bmpWrapper.SetPixel(j, i, tmpBuffer[j, i]); } } }
public void Execute(byte[] bytes, int width, int height) { double contrastLevel = Math.Pow((100.0 + threshold) / 100.0, 2); BitmapWrapper bmpWrapper = new BitmapWrapper(bytes, height, width); for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { Color col = bmpWrapper.GetPixel(j, i); int r = (int)(((((col.R / 255.0) - 0.5) * contrastLevel) + 0.5) * 255.0); int g = (int)(((((col.G / 255.0) - 0.5) * contrastLevel) + 0.5) * 255.0); int b = (int)(((((col.B / 255.0) - 0.5) * contrastLevel) + 0.5) * 255.0); r = Math.Max(0, Math.Min(255, r)); g = Math.Max(0, Math.Min(255, g)); b = Math.Max(0, Math.Min(255, b)); bmpWrapper.SetPixel(j, i, Color.FromArgb(col.A, r, g, b)); } } }
private void DrawPixel(int markerX, int markerY, Color color) { for (int x = 0; x < _horizontalScale; x++) { for (int y = 0; y < VERTICAL_SCALE; y++) { _bitmapWrapper.SetPixel(markerX + x, markerY + y, color); } } }
public void Execute(byte[] bytes, int width, int height) { BitmapWrapper bmpWrapper = new BitmapWrapper(bytes, height, width); for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { Color col = bmpWrapper.GetPixel(j, i); bmpWrapper.SetPixel(j, i, Color.FromArgb(col.A, 255 - col.R, 255 - col.G, 255 - col.B)); } } }
public void Execute(byte[] bytes, int width, int height) { BitmapWrapper bmpWrapper = new BitmapWrapper(bytes, height, width); for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { Color col = bmpWrapper.GetPixel(j, i); int grayScale = (int)((col.R * 0.3) + (col.G * 0.59) + (col.B * 0.11)); bmpWrapper.SetPixel(j, i, Color.FromArgb(col.A, grayScale, grayScale, grayScale)); } } }
public void Execute(byte[] bytes, int width, int height) { BitmapWrapper bmpWrapper = new BitmapWrapper(bytes, height, width); Color[,] tmpBuffer = new Color[height, width]; for (int j = 1; j < height - 1; j++) { for (int i = 1; i < width - 1; i++) { int rx = 0; int gx = 0; int bx = 0; int ry = 0; int gy = 0; int by = 0; for (int k = 0; k < 9; k++) { var col = bmpWrapper.GetPixel(j + cordinatesY[k], i + cordinatesX[k]); rx += col.R * maskX[k]; gx += col.G * maskX[k]; bx += col.B * maskX[k]; ry += col.R * maskY[k]; gy += col.G * maskY[k]; by += col.B * maskY[k]; } int r = Math.Abs(rx + ry); int g = Math.Abs(gx + gy); int b = Math.Abs(bx + by); r = Math.Max(0, Math.Min(255, r)); g = Math.Max(0, Math.Min(255, g)); b = Math.Max(0, Math.Min(255, b)); tmpBuffer[j, i] = Color.FromArgb(255, r, g, b); } } for (int j = 1; j < height - 1; j++) { for (int i = 1; i < width - 1; i++) { bmpWrapper.SetPixel(j, i, tmpBuffer[j, i]); } } }
public void Execute(byte[] bytes, int width, int height) { BitmapWrapper bmpWrapper = new BitmapWrapper(bytes, height, width); Color[,] tmpBuffer = new Color[height, width]; for (int j = 1; j < height - 1; j++) { for (int i = 1; i < width - 1; i++) { int fr = 0; int fg = 0; int fb = 0; int sr = 0; int sg = 0; int sb = 0; for (int k = 0; k < 4; k++) { var col = bmpWrapper.GetPixel(j + cordinatesY[k], i + cordinatesX[k]); fr += col.R * firstMask[k]; fg += col.G * firstMask[k]; fb += col.B * firstMask[k]; sr += col.R * secondMask[k]; sg += col.G * secondMask[k]; sb += col.B * secondMask[k]; } fr = Math.Abs(fr); fg = Math.Abs(fg); fb = Math.Abs(fb); sr = Math.Abs(sr); sg = Math.Abs(sg); sb = Math.Abs(sb); tmpBuffer[j, i] = Color.FromArgb(255, TruncateColor(fr + sr), TruncateColor(fg + sg), TruncateColor(fb + sb)); } } for (int j = 1; j < height - 1; j++) { for (int i = 1; i < width - 1; i++) { bmpWrapper.SetPixel(j, i, tmpBuffer[j, i]); } } }
public void Fill(Bitmap bitmap) { BitmapData sourceData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); byte[] pixelBuffer = new byte[sourceData.Stride * sourceData.Height]; Marshal.Copy(sourceData.Scan0, pixelBuffer, 0, pixelBuffer.Length); bitmap.UnlockBits(sourceData); BitmapWrapper bmpWrapper = new BitmapWrapper(pixelBuffer, bitmap.Height, bitmap.Width); List <EdgeSummary> ActiveEdges = new List <EdgeSummary>(); int y = 0; for (y = 0; y < edgesBucket.Length; y++) { if (edgesBucket[y] != null && edgesBucket[y].Any()) { break; } } for (; y < edgesBucket.Length; y++) { if (edgesBucket[y] != null) { foreach (var edgeSummary in edgesBucket[y]) { ActiveEdges.Add(new EdgeSummary(edgeSummary)); } } ActiveEdges = ActiveEdges.OrderBy(x => x.X).ToList(); ActiveEdges.RemoveAll(x => x.YMax <= y); for (int i = 1; i < ActiveEdges.Count; i++) { if (i % 2 == 0) { continue; } for (int x = (int)ActiveEdges[i - 1].X; x <= ActiveEdges[i].X; x++) { bmpWrapper.SetPixel(y, x, GetColor(x, y)); } } foreach (var edgeSummary in ActiveEdges) { edgeSummary.X += edgeSummary.Factor; } if (!ActiveEdges.Any()) { break; } } BitmapData resultData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); Marshal.Copy(pixelBuffer, 0, resultData.Scan0, pixelBuffer.Length); bitmap.UnlockBits(resultData); }