//gridLines[areaX][areaY][direction(x=0,y=1)][EachLines] internal virtual bool[][] getQRCodeMatrix(bool[][] image, SamplingGrid gridLines) { //int gridSize = gridLines.getWidth() * gridLines.getWidth(0,0); int gridSize = gridLines.TotalWidth; // now this is done within the SamplingGrid class... // if (gridLines.getWidth() >= 2) // gridSize-=1; canvas.println("gridSize=" + gridSize); //canvas.println("gridLines.getWidth() * gridLines.getWidth(0,0) = "+gridLines.getWidth() * gridLines.getWidth(0,0)); Point bottomRightPoint = null; bool[][] sampledMatrix = new bool[gridSize][]; for (int i = 0; i < gridSize; i++) { sampledMatrix[i] = new bool[gridSize]; } for (int ay = 0; ay < gridLines.getHeight(); ay++) { for (int ax = 0; ax < gridLines.getWidth(); ax++) { System.Collections.ArrayList sampledPoints = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); //only for visualiz; for (int y = 0; y < gridLines.getHeight(ax, ay); y++) { for (int x = 0; x < gridLines.getWidth(ax, ay); x++) { int x1 = gridLines.getXLine(ax, ay, x).getP1().X; int y1 = gridLines.getXLine(ax, ay, x).getP1().Y; int x2 = gridLines.getXLine(ax, ay, x).getP2().X; int y2 = gridLines.getXLine(ax, ay, x).getP2().Y; int x3 = gridLines.getYLine(ax, ay, y).getP1().X; int y3 = gridLines.getYLine(ax, ay, y).getP1().Y; int x4 = gridLines.getYLine(ax, ay, y).getP2().X; int y4 = gridLines.getYLine(ax, ay, y).getP2().Y; int e = (y2 - y1) * (x3 - x4) - (y4 - y3) * (x1 - x2); int f = (x1 * y2 - x2 * y1) * (x3 - x4) - (x3 * y4 - x4 * y3) * (x1 - x2); int g = (x3 * y4 - x4 * y3) * (y2 - y1) - (x1 * y2 - x2 * y1) * (y4 - y3); sampledMatrix[gridLines.getX(ax, x)][gridLines.getY(ay, y)] = image[f / e][g / e]; if ((ay == gridLines.getHeight() - 1 && ax == gridLines.getWidth() - 1) && y == gridLines.getHeight(ax, ay) - 1 && x == gridLines.getWidth(ax, ay) - 1) { bottomRightPoint = new Point(f / e, g / e); } //calling canvas.drawPoint in loop can be very slow. // use canvas.drawPoints if you need //canvas.drawPoint(new Point(f / e,g / e), Color.RED); } } } } if (bottomRightPoint.X > image.Length - 1 || bottomRightPoint.Y > image[0].Length - 1) { throw new System.IndexOutOfRangeException("Sampling grid pointed out of image"); } canvas.drawPoint(bottomRightPoint, ThoughtWorks.QRCode.Codec.Util.Color_Fields.BLUE); return(sampledMatrix); }
internal virtual bool[][] getQRCodeMatrix(bool[][] image, SamplingGrid gridLines) { int gridSize = gridLines.TotalWidth; canvas.println("gridSize=" + gridSize); Point bottomRightPoint = null; bool[][] sampledMatrix = new bool[gridSize][]; for (int i = 0; i < gridSize; i++) { sampledMatrix[i] = new bool[gridSize]; } for (int ay = 0; ay < gridLines.getHeight(); ay++) { for (int ax = 0; ax < gridLines.getWidth(); ax++) { System.Collections.ArrayList sampledPoints = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); for (int y = 0; y < gridLines.getHeight(ax, ay); y++) { for (int x = 0; x < gridLines.getWidth(ax, ay); x++) { int x1 = gridLines.getXLine(ax, ay, x).getP1().X; int y1 = gridLines.getXLine(ax, ay, x).getP1().Y; int x2 = gridLines.getXLine(ax, ay, x).getP2().X; int y2 = gridLines.getXLine(ax, ay, x).getP2().Y; int x3 = gridLines.getYLine(ax, ay, y).getP1().X; int y3 = gridLines.getYLine(ax, ay, y).getP1().Y; int x4 = gridLines.getYLine(ax, ay, y).getP2().X; int y4 = gridLines.getYLine(ax, ay, y).getP2().Y; int e = (y2 - y1) * (x3 - x4) - (y4 - y3) * (x1 - x2); int f = (x1 * y2 - x2 * y1) * (x3 - x4) - (x3 * y4 - x4 * y3) * (x1 - x2); int g = (x3 * y4 - x4 * y3) * (y2 - y1) - (x1 * y2 - x2 * y1) * (y4 - y3); sampledMatrix[gridLines.getX(ax, x)][gridLines.getY(ay, y)] = image[f / e][g / e]; if ((ay == gridLines.getHeight() - 1 && ax == gridLines.getWidth() - 1) && y == gridLines.getHeight(ax, ay) - 1 && x == gridLines.getWidth(ax, ay) - 1) { bottomRightPoint = new Point(f / e, g / e); } } } } } if (bottomRightPoint.X > image.Length - 1 || bottomRightPoint.Y > image[0].Length - 1) { throw new System.IndexOutOfRangeException("Sampling grid pointed out of image"); } canvas.drawPoint(bottomRightPoint, QRStudio.Engine.Codec.Util.Color_Fields.BLUE); return(sampledMatrix); }
internal virtual bool[][] getQRCodeMatrix(bool[][] image, SamplingGrid gridLines) { int totalWidth = gridLines.TotalWidth; canvas.println("gridSize=" + totalWidth); Point point = null; bool[][] array = new bool[totalWidth][]; for (int i = 0; i < totalWidth; i++) { array[i] = new bool[totalWidth]; } for (int j = 0; j < gridLines.getHeight(); j++) { for (int k = 0; k < gridLines.getWidth(); k++) { ArrayList arrayList = ArrayList.Synchronized(new ArrayList(10)); for (int l = 0; l < gridLines.getHeight(k, j); l++) { for (int m = 0; m < gridLines.getWidth(k, j); m++) { int x = gridLines.getXLine(k, j, m).getP1().X; int y = gridLines.getXLine(k, j, m).getP1().Y; int x2 = gridLines.getXLine(k, j, m).getP2().X; int y2 = gridLines.getXLine(k, j, m).getP2().Y; int x3 = gridLines.getYLine(k, j, l).getP1().X; int y3 = gridLines.getYLine(k, j, l).getP1().Y; int x4 = gridLines.getYLine(k, j, l).getP2().X; int y4 = gridLines.getYLine(k, j, l).getP2().Y; int num = (y2 - y) * (x3 - x4) - (y4 - y3) * (x - x2); int num2 = (x * y2 - x2 * y) * (x3 - x4) - (x3 * y4 - x4 * y3) * (x - x2); int num3 = (x3 * y4 - x4 * y3) * (y2 - y) - (x * y2 - x2 * y) * (y4 - y3); array[gridLines.getX(k, m)][gridLines.getY(j, l)] = image[num2 / num][num3 / num]; if (j == gridLines.getHeight() - 1 && k == gridLines.getWidth() - 1 && l == gridLines.getHeight(k, j) - 1 && m == gridLines.getWidth(k, j) - 1) { point = new Point(num2 / num, num3 / num); } } } } } if (point.X > image.Length - 1 || point.Y > image[0].Length - 1) { throw new IndexOutOfRangeException("Sampling grid pointed out of image"); } canvas.drawPoint(point, Color_Fields.BLUE); return(array); }