internal static Line[] findLineAcross(bool[][] image) { int READ_HORIZONTAL = 0; int READ_VERTICAL = 1; int imageWidth = image.Length; int imageHeight = image[0].Length; Point current = new Point(); ArrayList lineAcross = ArrayList.Synchronized(new ArrayList(10)); int[] lengthBuffer = new int[5]; int bufferPointer = 0; int direction = READ_HORIZONTAL; bool lastElement = false; while (true) { bool currentElement = image[current.X][current.Y]; if (currentElement == lastElement) { lengthBuffer[bufferPointer]++; } else { if (!currentElement) { if (FinderPattern.checkPattern(lengthBuffer, bufferPointer)) { int x; int x2; int y3; int y2; if (direction == READ_HORIZONTAL) { x = current.X; for (int i = 0; i < 5; i++) { x -= lengthBuffer[i]; } x2 = current.X - 1; y2 = (y3 = current.Y); } else { x2 = (x = current.X); y3 = current.Y; for (int i = 0; i < 5; i++) { y3 -= lengthBuffer[i]; } y2 = current.Y - 1; } lineAcross.Add(new Line(x, y3, x2, y2)); } } bufferPointer = (bufferPointer + 1) % 5; lengthBuffer[bufferPointer] = 1; lastElement = !lastElement; } if (direction == READ_HORIZONTAL) { if (current.X < imageWidth - 1) { current.translate(1, 0); } else { if (current.Y < imageHeight - 1) { current.set_Renamed(0, current.Y + 1); lengthBuffer = new int[5]; } else { current.set_Renamed(0, 0); lengthBuffer = new int[5]; direction = READ_VERTICAL; } } } else { if (current.Y < imageHeight - 1) { current.translate(0, 1); } else { if (current.X >= imageWidth - 1) { break; } current.set_Renamed(current.X + 1, 0); lengthBuffer = new int[5]; } } } Line[] foundLines = new Line[lineAcross.Count]; for (int j = 0; j < foundLines.Length; j++) { foundLines[j] = (Line)lineAcross[j]; } FinderPattern.canvas.drawLines(foundLines, Color_Fields.LIGHTGREEN); return(foundLines); }
internal static Line[] findLineAcross(bool[][] image) { int num1 = 0; int num2 = 1; int length1 = image.Length; int length2 = image[0].Length; Point point = new Point(); ArrayList arrayList = ArrayList.Synchronized(new ArrayList(10)); int[] buffer = new int[5]; int pointer = 0; int num3 = num1; bool flag1 = false; while (true) { bool flag2 = image[point.X][point.Y]; if (flag2 == flag1) { ++buffer[pointer]; } else { if (!flag2 && FinderPattern.checkPattern(buffer, pointer)) { int x1; int x2; int y2; int y1; if (num3 == num1) { x1 = point.X; for (int index = 0; index < 5; ++index) { x1 -= buffer[index]; } x2 = point.X - 1; y1 = y2 = point.Y; } else { x1 = x2 = point.X; y1 = point.Y; for (int index = 0; index < 5; ++index) { y1 -= buffer[index]; } y2 = point.Y - 1; } arrayList.Add((object)new Line(x1, y1, x2, y2)); } pointer = (pointer + 1) % 5; buffer[pointer] = 1; flag1 = !flag1; } if (num3 == num1) { if (point.X < length1 - 1) { point.translate(1, 0); } else if (point.Y < length2 - 1) { point.set_Renamed(0, point.Y + 1); buffer = new int[5]; } else { point.set_Renamed(0, 0); buffer = new int[5]; num3 = num2; } } else if (point.Y < length2 - 1) { point.translate(0, 1); } else if (point.X < length1 - 1) { point.set_Renamed(point.X + 1, 0); buffer = new int[5]; } else { break; } } Line[] lines = new Line[arrayList.Count]; for (int index = 0; index < lines.Length; ++index) { lines[index] = (Line)arrayList[index]; } FinderPattern.canvas.drawLines(lines, Color_Fields.LIGHTGREEN); return(lines); }