public bool[,] GetPattern(Bitmap shot, HexPatternParameter pparams, int ignore_x, int ignore_y) { BitmapData srcData = shot.LockBits(new Rectangle(0, 0, shot.Width, shot.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); IntPtr Scan0 = srcData.Scan0; int stride = srcData.Stride; int width = shot.Width; int height = shot.Height; bool[,] result = new bool[width, height]; ColorExt.Cache(HexagonCellImage.REAL_COLOR_CELL_ACTIVE); ColorExt.Cache(HexagonCellImage.REAL_COLOR_CELL_HIDDEN); ColorExt.Cache(HexagonCellImage.REAL_COLOR_CELL_INACTIVE); unsafe { byte *p = (byte *)(void *)Scan0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (x > ignore_x && y < ignore_y) { continue; } int idx = (y * stride) + x * 4; result[x, y] = false; if (pparams.UseActiveCellsInBinaryGridRecognition) { var ok = ((pparams.ActiveCellHueThreshold >= 255) || ColorExt.GetHueDistance(p[idx + 2], p[idx + 1], p[idx + 0], HexagonCellImage.REAL_COLOR_CELL_ACTIVE) < pparams.ActiveCellHueThreshold) && ((pparams.ActiveCellSatThreshold >= 255) || ColorExt.GetSaturationDistance(p[idx + 2], p[idx + 1], p[idx + 0], HexagonCellImage.REAL_COLOR_CELL_ACTIVE) < pparams.ActiveCellSatThreshold) && ((pparams.ActiveCellValThreshold >= 255) || ColorExt.GetValueDistance(p[idx + 2], p[idx + 1], p[idx + 0], HexagonCellImage.REAL_COLOR_CELL_ACTIVE) < pparams.ActiveCellValThreshold); if (ok) { result[x, y] = true; continue; } } if (pparams.UseHiddenCellsInBinaryGridRecognition) { var ok = ((pparams.HiddenCellHueThreshold >= 255) || ColorExt.GetHueDistance(p[idx + 2], p[idx + 1], p[idx + 0], HexagonCellImage.REAL_COLOR_CELL_HIDDEN) < pparams.HiddenCellHueThreshold) && ((pparams.HiddenCellSatThreshold >= 255) || ColorExt.GetSaturationDistance(p[idx + 2], p[idx + 1], p[idx + 0], HexagonCellImage.REAL_COLOR_CELL_HIDDEN) < pparams.HiddenCellSatThreshold) && ((pparams.HiddenCellValThreshold >= 255) || ColorExt.GetValueDistance(p[idx + 2], p[idx + 1], p[idx + 0], HexagonCellImage.REAL_COLOR_CELL_HIDDEN) < pparams.HiddenCellValThreshold); if (ok) { result[x, y] = true; continue; } } if (pparams.UseInactiveCellsInBinaryGridRecognition) { var ok = ((pparams.InactiveCellHueThreshold >= 255) || ColorExt.GetHueDistance(p[idx + 2], p[idx + 1], p[idx + 0], HexagonCellImage.REAL_COLOR_CELL_INACTIVE) < pparams.InactiveCellHueThreshold) && ((pparams.InactiveCellSatThreshold >= 255) || ColorExt.GetSaturationDistance(p[idx + 2], p[idx + 1], p[idx + 0], HexagonCellImage.REAL_COLOR_CELL_INACTIVE) < pparams.InactiveCellSatThreshold) && ((pparams.InactiveCellValThreshold >= 255) || ColorExt.GetValueDistance(p[idx + 2], p[idx + 1], p[idx + 0], HexagonCellImage.REAL_COLOR_CELL_INACTIVE) < pparams.InactiveCellValThreshold); if (ok) { result[x, y] = true; continue; } } } } } shot.UnlockBits(srcData); return(result); }