예제 #1
0
        public static FinderPattern findFinderPattern(bool[][] image)
        {
            Line[]  lineCross = FinderPattern.findLineCross(FinderPattern.findLineAcross(image));
            Point[] center;
            try
            {
                center = FinderPattern.getCenter(lineCross);
            }
            catch (FinderPatternNotFoundException ex)
            {
                throw ex;
            }
            int[]   angle      = FinderPattern.getAngle(center);
            Point[] pointArray = FinderPattern.sort(center, angle);
            int[]   width      = FinderPattern.getWidth(image, pointArray, angle);
            int[]   moduleSize = new int[3]
            {
                (width[0] << QRCodeImageReader.DECIMAL_POINT) / 7,
                (width[1] << QRCodeImageReader.DECIMAL_POINT) / 7,
                (width[2] << QRCodeImageReader.DECIMAL_POINT) / 7
            };
            int version = FinderPattern.calcRoughVersion(pointArray, width);

            if (version > 6)
            {
                try
                {
                    version = FinderPattern.calcExactVersion(pointArray, angle, moduleSize, image);
                }
                catch (VersionInformationException ex)
                {
                }
            }
            return(new FinderPattern(pointArray, version, angle, width, moduleSize));
        }
예제 #2
0
        public static FinderPattern findFinderPattern(bool[][] image)
        {
            Line[]  lineAcross = FinderPattern.findLineAcross(image);
            Line[]  lineCross  = FinderPattern.findLineCross(lineAcross);
            Point[] center     = null;
            try
            {
                center = FinderPattern.getCenter(lineCross);
            }
            catch (FinderPatternNotFoundException e)
            {
                throw e;
            }
            int[] sincos = FinderPattern.getAngle(center);
            center = FinderPattern.sort(center, sincos);
            int[] width      = FinderPattern.getWidth(image, center, sincos);
            int[] moduleSize = new int[]
            {
                (width[0] << QRCodeImageReader.DECIMAL_POINT) / 7,
                (width[1] << QRCodeImageReader.DECIMAL_POINT) / 7,
                (width[2] << QRCodeImageReader.DECIMAL_POINT) / 7
            };
            int version = FinderPattern.calcRoughVersion(center, width);

            if (version > 6)
            {
                try
                {
                    version = FinderPattern.calcExactVersion(center, sincos, moduleSize, image);
                }
                catch (VersionInformationException e_AC)
                {
                }
            }
            return(new FinderPattern(center, version, sincos, width, moduleSize));
        }
        internal static Point[][] getCenter(bool[][] image, FinderPattern finderPattern, Point[][] logicalCenters)
        {
            int  modulePitch = finderPattern.getModuleSize();
            Axis axis        = new Axis(finderPattern.getAngle(), modulePitch);
            int  length      = logicalCenters.Length;

            Point[][] pointArray = new Point[length][];
            for (int i = 0; i < length; i++)
            {
                pointArray[i] = new Point[length];
            }
            axis.Origin      = finderPattern.getCenter(0);
            pointArray[0][0] = axis.translate(3, 3);
            canvas.drawCross(pointArray[0][0], Color_Fields.BLUE);
            axis.Origin = finderPattern.getCenter(1);
            pointArray[length - 1][0] = axis.translate(-3, 3);
            canvas.drawCross(pointArray[length - 1][0], Color_Fields.BLUE);
            axis.Origin = finderPattern.getCenter(2);
            pointArray[0][length - 1] = axis.translate(3, -3);
            canvas.drawCross(pointArray[0][length - 1], Color_Fields.BLUE);
            Point point = pointArray[0][0];

            for (int j = 0; j < length; j++)
            {
                for (int k = 0; k < length; k++)
                {
                    if ((((k != 0) || (j != 0)) && ((k != 0) || (j != (length - 1)))) && ((k != (length - 1)) || (j != 0)))
                    {
                        Point point2 = null;
                        if (j == 0)
                        {
                            if ((k > 0) && (k < (length - 1)))
                            {
                                point2 = axis.translate(pointArray[k - 1][j], logicalCenters[k][j].X - logicalCenters[k - 1][j].X, 0);
                            }
                            pointArray[k][j] = new Point(point2.X, point2.Y);
                            canvas.drawCross(pointArray[k][j], Color_Fields.RED);
                        }
                        else if (k == 0)
                        {
                            if ((j > 0) && (j < (length - 1)))
                            {
                                point2 = axis.translate(pointArray[k][j - 1], 0, logicalCenters[k][j].Y - logicalCenters[k][j - 1].Y);
                            }
                            pointArray[k][j] = new Point(point2.X, point2.Y);
                            canvas.drawCross(pointArray[k][j], Color_Fields.RED);
                        }
                        else
                        {
                            Point point3 = axis.translate(pointArray[k - 1][j], logicalCenters[k][j].X - logicalCenters[k - 1][j].X, 0);
                            Point point4 = axis.translate(pointArray[k][j - 1], 0, logicalCenters[k][j].Y - logicalCenters[k][j - 1].Y);
                            pointArray[k][j] = new Point((point3.X + point4.X) / 2, ((point3.Y + point4.Y) / 2) + 1);
                        }
                        if (finderPattern.Version > 1)
                        {
                            Point other = getPrecisionCenter(image, pointArray[k][j]);
                            if (pointArray[k][j].distanceOf(other) < 6)
                            {
                                canvas.drawCross(pointArray[k][j], Color_Fields.RED);
                                int num6 = other.X - pointArray[k][j].X;
                                int num7 = other.Y - pointArray[k][j].Y;
                                canvas.println(string.Concat(new object[] { "Adjust AP(", k, ",", j, ") to d(", num6, ",", num7, ")" }));
                                pointArray[k][j] = other;
                            }
                        }
                        canvas.drawCross(pointArray[k][j], Color_Fields.BLUE);
                        canvas.drawLine(new Line(point, pointArray[k][j]), Color_Fields.LIGHTBLUE);
                        point = pointArray[k][j];
                    }
                }
            }
            return(pointArray);
        }
		// For only version 1 which has no Alignement Patterns
		/*	SamplingGrid getSamplingGrid1(FinderPattern finderPattern) {
		int sqrtNumArea = 1;
		int sqrtNumModules = finderPattern.getSqrtNumModules(); //get nummber of modules at side
		int sqrtNumAreaModules = sqrtNumModules / sqrtNumArea;
		Point[] centers = finderPattern.getCenter();
		int logicalDistance = 14;
		SamplingGrid samplingGrid = new SamplingGrid(sqrtNumArea);
		Line baseLineX, baseLineY, gridLineX, gridLineY;
		
		
		ModulePitch modulePitch = new ModulePitch(); //store (up,left) order
		modulePitch.top = getAreaModulePitch(centers[0], centers[1], logicalDistance);
		modulePitch.left = getAreaModulePitch(centers[0], centers[2], logicalDistance);
		
		//X軸に垂直の基線(一般に縦)
		baseLineX = new Line(
		finderPattern.getCenter(FinderPattern.UL), 
		finderPattern.getCenter(FinderPattern.DL));
		
		Axis axis = new Axis(finderPattern.getAngle(), modulePitch.top);
		axis.setOrigin(baseLineX.getP1());
		baseLineX.setP1(axis.translate(-3, -3));
		
		axis.setModulePitch(modulePitch.left);
		axis.setOrigin(baseLineX.getP2());
		baseLineX.setP2(axis.translate(-3, 3));
		
		//Y軸に垂直の基線(一般に横)
		baseLineY =
		new Line(finderPattern.getCenter(FinderPattern.UL),
		finderPattern.getCenter(FinderPattern.UR));
		
		axis.setModulePitch(modulePitch.left);
		axis.setOrigin(baseLineY.getP1());
		baseLineY.setP1(axis.translate(-3, -3));
		
		
		axis.setModulePitch(modulePitch.left);
		axis.setOrigin(baseLineY.getP2());
		baseLineY.setP2(axis.translate(3, -3));
		
		//baseLineX.translate(1,1);
		//baseLineY.translate(1,1);
		
		samplingGrid.initGrid(0, 0, sqrtNumAreaModules, sqrtNumAreaModules);
		
		for (int i = 0; i < sqrtNumAreaModules; i++) {
		
		gridLineX = new Line(baseLineX.getP1(), baseLineX.getP2());
		
		axis.setOrigin(gridLineX.getP1());
		axis.setModulePitch(modulePitch.top);
		gridLineX.setP1(axis.translate(i,0));
		
		axis.setOrigin(gridLineX.getP2());
		axis.setModulePitch(modulePitch.top);
		gridLineX.setP2(axis.translate(i,0));
		
		
		gridLineY = new Line(baseLineY.getP1(), baseLineY.getP2());
		axis.setOrigin(gridLineY.getP1());
		axis.setModulePitch(modulePitch.left);
		gridLineY.setP1(axis.translate(0,i));
		
		axis.setOrigin(gridLineY.getP2());
		axis.setModulePitch(modulePitch.left);
		gridLineY.setP2(axis.translate(0,i));
		
		
		samplingGrid.setXLine(0,0,i,gridLineX);
		samplingGrid.setYLine(0,0,i,gridLineY);
		}
		for (int ay = 0; ay < samplingGrid.getHeight(); ay++) {
		for (int ax = 0; ax < samplingGrid.getWidth();ax++) {
		canvas.drawLines(samplingGrid.getXLines(ax,ay), Color.BLUE);
		canvas.drawLines(samplingGrid.getYLines(ax,ay), Color.BLUE);
		}
		}
		return samplingGrid;
		}*/
		
		//sampllingGrid[areaX][areaY][direction(x=0,y=1)][EachLines]	
		/*	SamplingGrid getSamplingGrid2_6(FinderPattern finderPattern, AlignmentPattern alignmentPattern) {
		
		Point centers[][] = alignmentPattern.getCenter();
		centers[0][0] = finderPattern.getCenter(FinderPattern.UL);
		centers[1][0] = finderPattern.getCenter(FinderPattern.UR);
		centers[0][1] = finderPattern.getCenter(FinderPattern.DL);
		int sqrtNumModules = finderPattern.getSqrtNumModules(); //一辺当たりのモジュール数を得る
		
		SamplingGrid samplingGrid = new SamplingGrid(1);
		Line baseLineX, baseLineY, gridLineX, gridLineY;
		
		int logicalDistance = alignmentPattern.getLogicalDistance();
		Axis axis = new Axis(finderPattern.getAngle(), finderPattern.getModuleSize());
		
		ModulePitch modulePitch = new ModulePitch(); //top left bottom rightの順に格納
		
		modulePitch.top = getAreaModulePitch(centers[0][0], centers[1][0], logicalDistance + 6);
		modulePitch.left = getAreaModulePitch(centers[0][0], centers[0][1], logicalDistance + 6);
		axis.setModulePitch(modulePitch.top);
		axis.setOrigin(centers[0][1]);
		modulePitch.bottom = getAreaModulePitch(axis.translate(0, -3), centers[1][1], logicalDistance + 3);
		axis.setModulePitch(modulePitch.left);
		axis.setOrigin(centers[1][0]);
		modulePitch.right = getAreaModulePitch(axis.translate(-3, 0), centers[1][1], logicalDistance + 3);
		
		//X軸に垂直の基線(一般に縦)
		baseLineX = new Line();
		baseLineY = new Line();
		
		axis.setOrigin(centers[0][0]);
		modulePitch.top = getAreaModulePitch(centers[0][0], centers[1][0], logicalDistance + 6);
		modulePitch.left = getAreaModulePitch(centers[0][0], centers[0][1], logicalDistance + 6);
		axis.setModulePitch(modulePitch.top);
		axis.setOrigin(centers[0][1]);
		modulePitch.bottom = getAreaModulePitch(axis.translate(0,-3), centers[1][1], logicalDistance + 3);
		axis.setModulePitch(modulePitch.left);
		axis.setOrigin(centers[1][0]);
		modulePitch.right = getAreaModulePitch(axis.translate(-3,0), centers[1][1], logicalDistance + 3);
		
		
		axis.setOrigin(centers[0][0]);
		axis.setModulePitch(modulePitch.top);
		baseLineX.setP1(axis.translate(-3,-3));
		
		axis.setModulePitch(modulePitch.left);
		baseLineY.setP1(axis.translate(-3,-3));
		
		axis.setOrigin(centers[0][1]);
		axis.setModulePitch(modulePitch.bottom);
		baseLineX.setP2(axis.translate(-3,3));
		
		axis.setOrigin(centers[1][0]);
		axis.setModulePitch(modulePitch.right);
		baseLineY.setP2(axis.translate(3,-3));
		
		
		baseLineX.translate(1,1);
		baseLineY.translate(1,1);
		
		samplingGrid.initGrid(0, 0, sqrtNumModules, sqrtNumModules);
		
		for (int i = 0; i < sqrtNumModules; i++) {
		gridLineX = new Line(baseLineX.getP1(), baseLineX.getP2());
		
		axis.setOrigin(gridLineX.getP1());
		axis.setModulePitch(modulePitch.top);
		gridLineX.setP1(axis.translate(i,0));
		
		axis.setOrigin(gridLineX.getP2());
		axis.setModulePitch(modulePitch.bottom);
		gridLineX.setP2(axis.translate(i,0));
		
		
		gridLineY = new Line(baseLineY.getP1(), baseLineY.getP2());
		
		axis.setOrigin(gridLineY.getP1());
		axis.setModulePitch(modulePitch.left);
		gridLineY.setP1(axis.translate(0,i));
		
		axis.setOrigin(gridLineY.getP2());
		axis.setModulePitch(modulePitch.right);
		gridLineY.setP2(axis.translate(0,i));
		
		
		samplingGrid.setXLine(0,0,i,gridLineX);
		samplingGrid.setYLine(0,0,i,gridLineY);
		
		}
		
		for (int ay = 0; ay < samplingGrid.getHeight(); ay++) {
		for (int ax = 0; ax < samplingGrid.getWidth();ax++) {
		canvas.drawLines(samplingGrid.getXLines(ax,ay), java.awt.Color.BLUE);
		canvas.drawLines(samplingGrid.getYLines(ax,ay), java.awt.Color.BLUE);
		}
		}
		return samplingGrid;
		}
		
		
		
		//for version 7-13
		SamplingGrid getSamplingGrid7_13(FinderPattern finderPattern, AlignmentPattern alignmentPattern) {
		
		Point centers[][] = alignmentPattern.getCenter();
		centers[0][0] = finderPattern.getCenter(FinderPattern.UL);
		centers[2][0] = finderPattern.getCenter(FinderPattern.UR);
		centers[0][2] = finderPattern.getCenter(FinderPattern.DL);
		int sqrtNumModules = finderPattern.getSqrtNumModules(); //一辺当たりのモジュール数を得る
		int sqrtNumArea = 2;
		int sqrtNumAreaModules = sqrtNumModules / sqrtNumArea;
		sqrtNumAreaModules++;
		SamplingGrid samplingGrid = new SamplingGrid(sqrtNumArea);
		Line baseLineX, baseLineY, gridLineX, gridLineY;
		
		int logicalDistance = alignmentPattern.getLogicalDistance();
		Axis axis = new Axis(finderPattern.getAngle(), finderPattern.getModuleSize());
		ModulePitch modulePitch;
		for (int ay = 0; ay < sqrtNumArea; ay++) {
		for (int ax = 0; ax < sqrtNumArea; ax++) {
		modulePitch = new ModulePitch(); //top left bottom rightの順に格納
		baseLineX = new Line();
		baseLineY = new Line();
		axis.setModulePitch(finderPattern.getModuleSize());
		if (ax == 0 && ay == 0) {
		axis.setOrigin(centers[0][0]);
		modulePitch.top = getAreaModulePitch(axis.translate(0,3), centers[1][0], logicalDistance + 3);
		modulePitch.left = getAreaModulePitch(axis.translate(3,0), centers[0][1], logicalDistance + 3);
		axis.setModulePitch(modulePitch.top);
		modulePitch.bottom = getAreaModulePitch(centers[0][1], centers[1][1], logicalDistance);
		axis.setModulePitch(modulePitch.left);
		modulePitch.right = getAreaModulePitch(centers[1][0], centers[1][1], logicalDistance);
		
		axis.setModulePitch(modulePitch.top);
		baseLineX.setP1(axis.translate(-3,-3));
		
		axis.setModulePitch(modulePitch.left);
		baseLineY.setP1(axis.translate(-3,-3));
		
		axis.setOrigin(centers[0][1]);
		axis.setModulePitch(modulePitch.bottom);
		baseLineX.setP2(axis.translate(-6,0));
		
		axis.setOrigin(centers[1][0]);
		axis.setModulePitch(modulePitch.right);
		baseLineY.setP2(axis.translate(0,-6));
		}
		else if (ax == 1 && ay == 0) {
		axis.setOrigin(centers[1][0]);
		modulePitch.top = getAreaModulePitch(axis.translate(0,-3), centers[2][0], logicalDistance + 3);
		modulePitch.left = getAreaModulePitch(centers[1][0], centers[1][1], logicalDistance);
		axis.setModulePitch(modulePitch.top);
		modulePitch.bottom = getAreaModulePitch(centers[1][1], centers[2][1], logicalDistance);
		axis.setModulePitch(modulePitch.left);
		axis.setOrigin(centers[2][0]);
		modulePitch.right = getAreaModulePitch(axis.translate(-3,0), centers[2][1], logicalDistance + 3);
		
		axis.setOrigin(centers[1][0]);
		axis.setModulePitch(modulePitch.left);
		baseLineX.setP1(axis.translate(0,-6));
		
		baseLineY.setP1(axis.translate(0,-6));
		
		baseLineX.setP2(centers[1][1]);
		
		axis.setOrigin(centers[2][0]);
		axis.setModulePitch(modulePitch.right);
		baseLineY.setP2(axis.translate(3,-3));
		}
		else if (ax == 0 && ay == 1) {
		modulePitch.top = getAreaModulePitch(centers[0][1], centers[1][1], logicalDistance);
		axis.setOrigin(centers[0][2]);
		modulePitch.left = getAreaModulePitch(centers[0][1], axis.translate(3,0), logicalDistance + 3);
		axis.setModulePitch(modulePitch.top);
		modulePitch.bottom = getAreaModulePitch(axis.translate(0,-3), centers[1][2], logicalDistance + 3);
		axis.setModulePitch(modulePitch.bottom);
		modulePitch.right = getAreaModulePitch(centers[1][1], centers[1][2], logicalDistance);
		
		axis.setOrigin(centers[0][1]);
		axis.setModulePitch(modulePitch.top);
		baseLineX.setP1(axis.translate(-6,0));
		
		baseLineY.setP1(axis.translate(-6,0));
		
		axis.setOrigin(centers[0][2]);
		axis.setModulePitch(modulePitch.bottom);
		baseLineX.setP2(axis.translate(-3, 3));
		
		baseLineY.setP2(centers[1][1]);					
		}
		else if (ax == 1 && ay == 1) {
		modulePitch.top = getAreaModulePitch(centers[1][1], centers[2][1], logicalDistance);
		modulePitch.left = getAreaModulePitch(centers[1][1], centers[1][2], logicalDistance);
		modulePitch.bottom = getAreaModulePitch(centers[1][2], centers[2][2], logicalDistance);
		modulePitch.right = getAreaModulePitch(centers[2][1], centers[2][2], logicalDistance);
		
		baseLineX.setP1(centers[1][1]);
		baseLineY.setP1(centers[1][1]);
		
		axis.setOrigin(centers[1][2]);
		axis.setModulePitch(modulePitch.left);
		baseLineX.setP2(axis.translate(0,6));
		
		axis.setOrigin(centers[2][1]);
		axis.setModulePitch(modulePitch.top);
		baseLineY.setP2(axis.translate(6,0));
		}
		
		samplingGrid.initGrid(ax,ay, sqrtNumAreaModules, sqrtNumAreaModules);
		
		for (int i = 0; i < sqrtNumAreaModules; i++) {
		gridLineX = new Line(baseLineX.getP1(), baseLineX.getP2());
		
		axis.setOrigin(gridLineX.getP1());
		axis.setModulePitch(modulePitch.top);
		gridLineX.setP1(axis.translate(i,0));
		
		axis.setOrigin(gridLineX.getP2());
		axis.setModulePitch(modulePitch.bottom);
		gridLineX.setP2(axis.translate(i,0));
		
		
		gridLineY = new Line(baseLineY.getP1(), baseLineY.getP2());
		
		axis.setOrigin(gridLineY.getP1());
		axis.setModulePitch(modulePitch.left);
		gridLineY.setP1(axis.translate(0,i));
		
		axis.setOrigin(gridLineY.getP2());
		axis.setModulePitch(modulePitch.right);
		gridLineY.setP2(axis.translate(0,i));
		
		samplingGrid.setXLine(ax,ay,i,gridLineX);
		samplingGrid.setYLine(ax,ay,i,gridLineY);
		
		}
		}
		}
		
		for (int ay = 0; ay < samplingGrid.getHeight(); ay++) {
		for (int ax = 0; ax < samplingGrid.getWidth();ax++) {
		canvas.drawLines(samplingGrid.getXLines(ax,ay), java.awt.Color.BLUE);
		canvas.drawLines(samplingGrid.getYLines(ax,ay), java.awt.Color.BLUE);
		}
		}
		
		return samplingGrid;
		}*/
		/// <summary> Generic Sampling grid method</summary>
		internal virtual SamplingGrid getSamplingGrid(FinderPattern finderPattern, AlignmentPattern alignmentPattern)
		{
			
			Point[][] centers = alignmentPattern.getCenter();
			
			int version = finderPattern.Version;
			int sqrtCenters = (version / 7) + 2;
			
			centers[0][0] = finderPattern.getCenter(FinderPattern.UL);
			centers[sqrtCenters - 1][0] = finderPattern.getCenter(FinderPattern.UR);
			centers[0][sqrtCenters - 1] = finderPattern.getCenter(FinderPattern.DL);
			//int sqrtNumModules = finderPattern.getSqrtNumModules(); /// The number of modules per one side is obtained
			int sqrtNumArea = sqrtCenters - 1;
			
			//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//
			SamplingGrid samplingGrid = new SamplingGrid(sqrtNumArea);
			
			Line baseLineX, baseLineY, gridLineX, gridLineY;
			
			///???
			//Point[] targetCenters;
			
			//int logicalDistance = alignmentPattern.getLogicalDistance();
			Axis axis = new Axis(finderPattern.getAngle(), finderPattern.getModuleSize());
			ModulePitch modulePitch;
			
			// for each area :
			for (int ay = 0; ay < sqrtNumArea; ay++)
			{
				for (int ax = 0; ax < sqrtNumArea; ax++)
				{
					modulePitch = new ModulePitch(this); /// Housing to order
					baseLineX = new Line();
					baseLineY = new Line();
					axis.ModulePitch = finderPattern.getModuleSize();
					
					Point[][] logicalCenters = AlignmentPattern.getLogicalCenter(finderPattern);
					
					Point upperLeftPoint = centers[ax][ay];
					Point upperRightPoint = centers[ax + 1][ay];
					Point lowerLeftPoint = centers[ax][ay + 1];
					Point lowerRightPoint = centers[ax + 1][ay + 1];
					
					Point logicalUpperLeftPoint = logicalCenters[ax][ay];
					Point logicalUpperRightPoint = logicalCenters[ax + 1][ay];
					Point logicalLowerLeftPoint = logicalCenters[ax][ay + 1];
					Point logicalLowerRightPoint = logicalCenters[ax + 1][ay + 1];
					
					if (ax == 0 && ay == 0)
					// left upper corner
					{
						if (sqrtNumArea == 1)
						{
							upperLeftPoint = axis.translate(upperLeftPoint, - 3, - 3);
							upperRightPoint = axis.translate(upperRightPoint, 3, - 3);
							lowerLeftPoint = axis.translate(lowerLeftPoint, - 3, 3);
							lowerRightPoint = axis.translate(lowerRightPoint, 6, 6);
							
							logicalUpperLeftPoint.translate(- 6, - 6);
							logicalUpperRightPoint.translate(3, - 3);
							logicalLowerLeftPoint.translate(- 3, 3);
							logicalLowerRightPoint.translate(6, 6);
						}
						else
						{
							upperLeftPoint = axis.translate(upperLeftPoint, - 3, - 3);
							upperRightPoint = axis.translate(upperRightPoint, 0, - 6);
							lowerLeftPoint = axis.translate(lowerLeftPoint, - 6, 0);
							
							logicalUpperLeftPoint.translate(- 6, - 6);
							logicalUpperRightPoint.translate(0, - 6);
							logicalLowerLeftPoint.translate(- 6, 0);
						}
					}
					else if (ax == 0 && ay == sqrtNumArea - 1)
					// left bottom corner
					{
						upperLeftPoint = axis.translate(upperLeftPoint, - 6, 0);
						lowerLeftPoint = axis.translate(lowerLeftPoint, - 3, 3);
						lowerRightPoint = axis.translate(lowerRightPoint, 0, 6);
						
						
						logicalUpperLeftPoint.translate(- 6, 0);
						logicalLowerLeftPoint.translate(- 6, 6);
						logicalLowerRightPoint.translate(0, 6);
					}
					else if (ax == sqrtNumArea - 1 && ay == 0)
					// right upper corner
					{
						upperLeftPoint = axis.translate(upperLeftPoint, 0, - 6);
						upperRightPoint = axis.translate(upperRightPoint, 3, - 3);
						lowerRightPoint = axis.translate(lowerRightPoint, 6, 0);
						
						logicalUpperLeftPoint.translate(0, - 6);
						logicalUpperRightPoint.translate(6, - 6);
						logicalLowerRightPoint.translate(6, 0);
					}
					else if (ax == sqrtNumArea - 1 && ay == sqrtNumArea - 1)
					// right bottom corner
					{
						lowerLeftPoint = axis.translate(lowerLeftPoint, 0, 6);
						upperRightPoint = axis.translate(upperRightPoint, 6, 0);
						lowerRightPoint = axis.translate(lowerRightPoint, 6, 6);
						
						logicalLowerLeftPoint.translate(0, 6);
						logicalUpperRightPoint.translate(6, 0);
						logicalLowerRightPoint.translate(6, 6);
					}
					else if (ax == 0)
					// left side
					{
						upperLeftPoint = axis.translate(upperLeftPoint, - 6, 0);
						lowerLeftPoint = axis.translate(lowerLeftPoint, - 6, 0);
						
						logicalUpperLeftPoint.translate(- 6, 0);
						logicalLowerLeftPoint.translate(- 6, 0);
					}
					else if (ax == sqrtNumArea - 1)
					// right
					{
						upperRightPoint = axis.translate(upperRightPoint, 6, 0);
						lowerRightPoint = axis.translate(lowerRightPoint, 6, 0);
						
						logicalUpperRightPoint.translate(6, 0);
						logicalLowerRightPoint.translate(6, 0);
					}
					else if (ay == 0)
					// top
					{
						upperLeftPoint = axis.translate(upperLeftPoint, 0, - 6);
						upperRightPoint = axis.translate(upperRightPoint, 0, - 6);
						
						logicalUpperLeftPoint.translate(0, - 6);
						logicalUpperRightPoint.translate(0, - 6);
					}
					else if (ay == sqrtNumArea - 1)
					// bottom
					{
						lowerLeftPoint = axis.translate(lowerLeftPoint, 0, 6);
						lowerRightPoint = axis.translate(lowerRightPoint, 0, 6);
						
						logicalLowerLeftPoint.translate(0, 6);
						logicalLowerRightPoint.translate(0, 6);
					}
					
					if (ax == 0)
					{
						logicalUpperRightPoint.translate(1, 0);
						logicalLowerRightPoint.translate(1, 0);
					}
					else
					{
						logicalUpperLeftPoint.translate(- 1, 0);
						logicalLowerLeftPoint.translate(- 1, 0);
					}
					
					if (ay == 0)
					{
						logicalLowerLeftPoint.translate(0, 1);
						logicalLowerRightPoint.translate(0, 1);
					}
					else
					{
						logicalUpperLeftPoint.translate(0, - 1);
						logicalUpperRightPoint.translate(0, - 1);
					}
					
					int logicalWidth = logicalUpperRightPoint.X - logicalUpperLeftPoint.X;
					int logicalHeight = logicalLowerLeftPoint.Y - logicalUpperLeftPoint.Y;
					
					if (version < 7)
					{
						logicalWidth += 3;
						logicalHeight += 3;
					}
					modulePitch.top = getAreaModulePitch(upperLeftPoint, upperRightPoint, logicalWidth - 1);
					modulePitch.left = getAreaModulePitch(upperLeftPoint, lowerLeftPoint, logicalHeight - 1);
					modulePitch.bottom = getAreaModulePitch(lowerLeftPoint, lowerRightPoint, logicalWidth - 1);
					modulePitch.right = getAreaModulePitch(upperRightPoint, lowerRightPoint, logicalHeight - 1);
					
					baseLineX.setP1(upperLeftPoint);
					baseLineY.setP1(upperLeftPoint);
					baseLineX.setP2(lowerLeftPoint);
					baseLineY.setP2(upperRightPoint);
					
					samplingGrid.initGrid(ax, ay, logicalWidth, logicalHeight);
					
					for (int i = 0; i < logicalWidth; i++)
					{
						gridLineX = new Line(baseLineX.getP1(), baseLineX.getP2());
						
						axis.Origin = gridLineX.getP1();
						axis.ModulePitch = modulePitch.top;
						gridLineX.setP1(axis.translate(i, 0));
						
						axis.Origin = gridLineX.getP2();
						axis.ModulePitch = modulePitch.bottom;
						gridLineX.setP2(axis.translate(i, 0));
						
						samplingGrid.setXLine(ax, ay, i, gridLineX);
					}
					
					for (int i = 0; i < logicalHeight; i++)
					{
						
						gridLineY = new Line(baseLineY.getP1(), baseLineY.getP2());
						
						axis.Origin = gridLineY.getP1();
						axis.ModulePitch = modulePitch.left;
						gridLineY.setP1(axis.translate(0, i));
						
						axis.Origin = gridLineY.getP2();
						axis.ModulePitch = modulePitch.right;
						gridLineY.setP2(axis.translate(0, i));
						
						samplingGrid.setYLine(ax, ay, i, gridLineY);
					}
				}
			}
			
			return samplingGrid;
		}
        internal static Point[][] getCenter(bool[][] image, FinderPattern finderPattern, Point[][] logicalCenters)
        {
            int moduleSize = finderPattern.getModuleSize();

            Axis axis        = new Axis(finderPattern.getAngle(), moduleSize);
            int  sqrtCenters = logicalCenters.Length;

            Point[][] centers = new Point[sqrtCenters][];
            for (int i = 0; i < sqrtCenters; i++)
            {
                centers[i] = new Point[sqrtCenters];
            }

            axis.Origin   = finderPattern.getCenter(FinderPattern.UL);
            centers[0][0] = axis.translate(3, 3);
            canvas.drawCross(centers[0][0], ThoughtWorks.QRCode.Codec.Util.Color_Fields.BLUE);

            axis.Origin = finderPattern.getCenter(FinderPattern.UR);
            centers[sqrtCenters - 1][0] = axis.translate(-3, 3);
            canvas.drawCross(centers[sqrtCenters - 1][0], ThoughtWorks.QRCode.Codec.Util.Color_Fields.BLUE);

            axis.Origin = finderPattern.getCenter(FinderPattern.DL);
            centers[0][sqrtCenters - 1] = axis.translate(3, -3);
            canvas.drawCross(centers[0][sqrtCenters - 1], ThoughtWorks.QRCode.Codec.Util.Color_Fields.BLUE);

            Point tmpPoint = centers[0][0];

            for (int y = 0; y < sqrtCenters; y++)
            {
                for (int x = 0; x < sqrtCenters; x++)
                {
                    if ((x == 0 && y == 0) || (x == 0 && y == sqrtCenters - 1) || (x == sqrtCenters - 1 && y == 0))
                    {
                        //					canvas.drawCross(centers[x][y], java.awt.Color.MAGENTA);
                        continue;
                    }
                    Point target = null;
                    if (y == 0)
                    {
                        if (x > 0 && x < sqrtCenters - 1)
                        {
                            target = axis.translate(centers[x - 1][y], logicalCenters[x][y].X - logicalCenters[x - 1][y].X, 0);
                        }
                        centers[x][y] = new Point(target.X, target.Y);
                        canvas.drawCross(centers[x][y], ThoughtWorks.QRCode.Codec.Util.Color_Fields.RED);
                    }
                    else if (x == 0)
                    {
                        if (y > 0 && y < sqrtCenters - 1)
                        {
                            target = axis.translate(centers[x][y - 1], 0, logicalCenters[x][y].Y - logicalCenters[x][y - 1].Y);
                        }
                        centers[x][y] = new Point(target.X, target.Y);
                        canvas.drawCross(centers[x][y], ThoughtWorks.QRCode.Codec.Util.Color_Fields.RED);
                    }
                    else
                    {
                        Point t1 = axis.translate(centers[x - 1][y], logicalCenters[x][y].X - logicalCenters[x - 1][y].X, 0);
                        Point t2 = axis.translate(centers[x][y - 1], 0, logicalCenters[x][y].Y - logicalCenters[x][y - 1].Y);
                        centers[x][y] = new Point((t1.X + t2.X) / 2, (t1.Y + t2.Y) / 2 + 1);
                    }
                    if (finderPattern.Version > 1)
                    {
                        Point precisionCenter = getPrecisionCenter(image, centers[x][y]);

                        if (centers[x][y].distanceOf(precisionCenter) < 6)
                        {
                            canvas.drawCross(centers[x][y], ThoughtWorks.QRCode.Codec.Util.Color_Fields.RED);
                            int dx = precisionCenter.X - centers[x][y].X;
                            int dy = precisionCenter.Y - centers[x][y].Y;
                            canvas.println("Adjust AP(" + x + "," + y + ") to d(" + dx + "," + dy + ")");

                            centers[x][y] = precisionCenter;
                        }
                    }
                    canvas.drawCross(centers[x][y], ThoughtWorks.QRCode.Codec.Util.Color_Fields.BLUE);
                    canvas.drawLine(new Line(tmpPoint, centers[x][y]), ThoughtWorks.QRCode.Codec.Util.Color_Fields.LIGHTBLUE);
                    tmpPoint = centers[x][y];
                }
            }
            return(centers);
        }
예제 #6
0
 internal virtual SamplingGrid getSamplingGrid(FinderPattern finderPattern, AlignmentPattern alignmentPattern)
 {
     Point[][] pointArray = alignmentPattern.getCenter();
     int version = finderPattern.Version;
     int num2 = (version / 7) + 2;
     pointArray[0][0] = finderPattern.getCenter(0);
     pointArray[num2 - 1][0] = finderPattern.getCenter(1);
     pointArray[0][num2 - 1] = finderPattern.getCenter(2);
     int sqrtNumArea = num2 - 1;
     SamplingGrid grid = new SamplingGrid(sqrtNumArea);
     Axis axis = new Axis(finderPattern.getAngle(), finderPattern.getModuleSize());
     for (int i = 0; i < sqrtNumArea; i++)
     {
         for (int j = 0; j < sqrtNumArea; j++)
         {
             ModulePitch pitch = new ModulePitch(this);
             Line line = new Line();
             Line line2 = new Line();
             axis.ModulePitch = finderPattern.getModuleSize();
             Point[][] pointArray2 = AlignmentPattern.getLogicalCenter(finderPattern);
             Point origin = pointArray[j][i];
             Point point2 = pointArray[j + 1][i];
             Point point3 = pointArray[j][i + 1];
             Point point4 = pointArray[j + 1][i + 1];
             Point point5 = pointArray2[j][i];
             Point point6 = pointArray2[j + 1][i];
             Point point7 = pointArray2[j][i + 1];
             Point point8 = pointArray2[j + 1][i + 1];
             if ((j == 0) && (i == 0))
             {
                 if (sqrtNumArea == 1)
                 {
                     origin = axis.translate(origin, -3, -3);
                     point2 = axis.translate(point2, 3, -3);
                     point3 = axis.translate(point3, -3, 3);
                     point4 = axis.translate(point4, 6, 6);
                     point5.translate(-6, -6);
                     point6.translate(3, -3);
                     point7.translate(-3, 3);
                     point8.translate(6, 6);
                 }
                 else
                 {
                     origin = axis.translate(origin, -3, -3);
                     point2 = axis.translate(point2, 0, -6);
                     point3 = axis.translate(point3, -6, 0);
                     point5.translate(-6, -6);
                     point6.translate(0, -6);
                     point7.translate(-6, 0);
                 }
             }
             else if ((j == 0) && (i == (sqrtNumArea - 1)))
             {
                 origin = axis.translate(origin, -6, 0);
                 point3 = axis.translate(point3, -3, 3);
                 point4 = axis.translate(point4, 0, 6);
                 point5.translate(-6, 0);
                 point7.translate(-6, 6);
                 point8.translate(0, 6);
             }
             else if ((j == (sqrtNumArea - 1)) && (i == 0))
             {
                 origin = axis.translate(origin, 0, -6);
                 point2 = axis.translate(point2, 3, -3);
                 point4 = axis.translate(point4, 6, 0);
                 point5.translate(0, -6);
                 point6.translate(6, -6);
                 point8.translate(6, 0);
             }
             else if ((j == (sqrtNumArea - 1)) && (i == (sqrtNumArea - 1)))
             {
                 point3 = axis.translate(point3, 0, 6);
                 point2 = axis.translate(point2, 6, 0);
                 point4 = axis.translate(point4, 6, 6);
                 point7.translate(0, 6);
                 point6.translate(6, 0);
                 point8.translate(6, 6);
             }
             else if (j == 0)
             {
                 origin = axis.translate(origin, -6, 0);
                 point3 = axis.translate(point3, -6, 0);
                 point5.translate(-6, 0);
                 point7.translate(-6, 0);
             }
             else if (j == (sqrtNumArea - 1))
             {
                 point2 = axis.translate(point2, 6, 0);
                 point4 = axis.translate(point4, 6, 0);
                 point6.translate(6, 0);
                 point8.translate(6, 0);
             }
             else if (i == 0)
             {
                 origin = axis.translate(origin, 0, -6);
                 point2 = axis.translate(point2, 0, -6);
                 point5.translate(0, -6);
                 point6.translate(0, -6);
             }
             else if (i == (sqrtNumArea - 1))
             {
                 point3 = axis.translate(point3, 0, 6);
                 point4 = axis.translate(point4, 0, 6);
                 point7.translate(0, 6);
                 point8.translate(0, 6);
             }
             if (j == 0)
             {
                 point6.translate(1, 0);
                 point8.translate(1, 0);
             }
             else
             {
                 point5.translate(-1, 0);
                 point7.translate(-1, 0);
             }
             if (i == 0)
             {
                 point7.translate(0, 1);
                 point8.translate(0, 1);
             }
             else
             {
                 point5.translate(0, -1);
                 point6.translate(0, -1);
             }
             int width = point6.X - point5.X;
             int height = point7.Y - point5.Y;
             if (version < 7)
             {
                 width += 3;
                 height += 3;
             }
             pitch.top = this.getAreaModulePitch(origin, point2, width - 1);
             pitch.left = this.getAreaModulePitch(origin, point3, height - 1);
             pitch.bottom = this.getAreaModulePitch(point3, point4, width - 1);
             pitch.right = this.getAreaModulePitch(point2, point4, height - 1);
             line.setP1(origin);
             line2.setP1(origin);
             line.setP2(point3);
             line2.setP2(point2);
             grid.initGrid(j, i, width, height);
             int moveX = 0;
             while (moveX < width)
             {
                 Line line3 = new Line(line.getP1(), line.getP2());
                 axis.Origin = line3.getP1();
                 axis.ModulePitch = pitch.top;
                 line3.setP1(axis.translate(moveX, 0));
                 axis.Origin = line3.getP2();
                 axis.ModulePitch = pitch.bottom;
                 line3.setP2(axis.translate(moveX, 0));
                 grid.setXLine(j, i, moveX, line3);
                 moveX++;
             }
             for (moveX = 0; moveX < height; moveX++)
             {
                 Line line4 = new Line(line2.getP1(), line2.getP2());
                 axis.Origin = line4.getP1();
                 axis.ModulePitch = pitch.left;
                 line4.setP1(axis.translate(0, moveX));
                 axis.Origin = line4.getP2();
                 axis.ModulePitch = pitch.right;
                 line4.setP2(axis.translate(0, moveX));
                 grid.setYLine(j, i, moveX, line4);
             }
         }
     }
     return grid;
 }
예제 #7
0
        internal static Point[][] getCenter(bool[][] image, FinderPattern finderPattern, Point[][] logicalCenters)
        {
            int  moduleSize = finderPattern.getModuleSize();
            Axis axis       = new Axis(finderPattern.getAngle(), moduleSize);
            int  num        = logicalCenters.Length;

            Point[][] array = new Point[num][];
            for (int i = 0; i < num; i++)
            {
                array[i] = new Point[num];
            }
            axis.Origin = finderPattern.getCenter(0);
            array[0][0] = axis.translate(3, 3);
            canvas.drawCross(array[0][0], Color_Fields.BLUE);
            axis.Origin       = finderPattern.getCenter(1);
            array[num - 1][0] = axis.translate(-3, 3);
            canvas.drawCross(array[num - 1][0], Color_Fields.BLUE);
            axis.Origin       = finderPattern.getCenter(2);
            array[0][num - 1] = axis.translate(3, -3);
            canvas.drawCross(array[0][num - 1], Color_Fields.BLUE);
            Point p = array[0][0];

            for (int j = 0; j < num; j++)
            {
                for (int k = 0; k < num; k++)
                {
                    if ((k == 0 && j == 0) || (k == 0 && j == num - 1) || (k == num - 1 && j == 0))
                    {
                        continue;
                    }
                    Point point = null;
                    if (j == 0)
                    {
                        if (k > 0 && k < num - 1)
                        {
                            point = axis.translate(array[k - 1][j], logicalCenters[k][j].X - logicalCenters[k - 1][j].X, 0);
                        }
                        array[k][j] = new Point(point.X, point.Y);
                        canvas.drawCross(array[k][j], Color_Fields.RED);
                    }
                    else if (k == 0)
                    {
                        if (j > 0 && j < num - 1)
                        {
                            point = axis.translate(array[k][j - 1], 0, logicalCenters[k][j].Y - logicalCenters[k][j - 1].Y);
                        }
                        array[k][j] = new Point(point.X, point.Y);
                        canvas.drawCross(array[k][j], Color_Fields.RED);
                    }
                    else
                    {
                        Point point2 = axis.translate(array[k - 1][j], logicalCenters[k][j].X - logicalCenters[k - 1][j].X, 0);
                        Point point3 = axis.translate(array[k][j - 1], 0, logicalCenters[k][j].Y - logicalCenters[k][j - 1].Y);
                        array[k][j] = new Point((point2.X + point3.X) / 2, (point2.Y + point3.Y) / 2 + 1);
                    }
                    if (finderPattern.Version > 1)
                    {
                        Point precisionCenter = getPrecisionCenter(image, array[k][j]);
                        if (array[k][j].distanceOf(precisionCenter) < 6)
                        {
                            canvas.drawCross(array[k][j], Color_Fields.RED);
                            int num2 = precisionCenter.X - array[k][j].X;
                            int num3 = precisionCenter.Y - array[k][j].Y;
                            canvas.println("Adjust AP(" + k + "," + j + ") to d(" + num2 + "," + num3 + ")");
                            array[k][j] = precisionCenter;
                        }
                    }
                    canvas.drawCross(array[k][j], Color_Fields.BLUE);
                    canvas.drawLine(new Line(p, array[k][j]), Color_Fields.LIGHTBLUE);
                    p = array[k][j];
                }
            }
            return(array);
        }
예제 #8
0
        internal static Point[][] getCenter(bool[][] image, FinderPattern finderPattern, Point[][] logicalCenters)
        {
            int  moduleSize  = finderPattern.getModuleSize();
            Axis axis        = new Axis(finderPattern.getAngle(), moduleSize);
            int  sqrtCenters = logicalCenters.Length;

            Point[][] centers = new Point[sqrtCenters][];
            for (int i = 0; i < sqrtCenters; i++)
            {
                centers[i] = new Point[sqrtCenters];
            }
            axis.Origin   = finderPattern.getCenter(0);
            centers[0][0] = axis.translate(3, 3);
            AlignmentPattern.canvas.drawCross(centers[0][0], Color_Fields.BLUE);
            axis.Origin = finderPattern.getCenter(1);
            centers[sqrtCenters - 1][0] = axis.translate(-3, 3);
            AlignmentPattern.canvas.drawCross(centers[sqrtCenters - 1][0], Color_Fields.BLUE);
            axis.Origin = finderPattern.getCenter(2);
            centers[0][sqrtCenters - 1] = axis.translate(3, -3);
            AlignmentPattern.canvas.drawCross(centers[0][sqrtCenters - 1], Color_Fields.BLUE);
            Point tmpPoint = centers[0][0];

            for (int y = 0; y < sqrtCenters; y++)
            {
                for (int x = 0; x < sqrtCenters; x++)
                {
                    if ((x != 0 || y != 0) && (x != 0 || y != sqrtCenters - 1) && (x != sqrtCenters - 1 || y != 0))
                    {
                        Point target = null;
                        if (y == 0)
                        {
                            if (x > 0 && x < sqrtCenters - 1)
                            {
                                target = axis.translate(centers[x - 1][y], logicalCenters[x][y].X - logicalCenters[x - 1][y].X, 0);
                            }
                            centers[x][y] = new Point(target.X, target.Y);
                            AlignmentPattern.canvas.drawCross(centers[x][y], Color_Fields.RED);
                        }
                        else
                        {
                            if (x == 0)
                            {
                                if (y > 0 && y < sqrtCenters - 1)
                                {
                                    target = axis.translate(centers[x][y - 1], 0, logicalCenters[x][y].Y - logicalCenters[x][y - 1].Y);
                                }
                                centers[x][y] = new Point(target.X, target.Y);
                                AlignmentPattern.canvas.drawCross(centers[x][y], Color_Fields.RED);
                            }
                            else
                            {
                                Point t  = axis.translate(centers[x - 1][y], logicalCenters[x][y].X - logicalCenters[x - 1][y].X, 0);
                                Point t2 = axis.translate(centers[x][y - 1], 0, logicalCenters[x][y].Y - logicalCenters[x][y - 1].Y);
                                centers[x][y] = new Point((t.X + t2.X) / 2, (t.Y + t2.Y) / 2 + 1);
                            }
                        }
                        if (finderPattern.Version > 1)
                        {
                            Point precisionCenter = AlignmentPattern.getPrecisionCenter(image, centers[x][y]);
                            if (centers[x][y].distanceOf(precisionCenter) < 6)
                            {
                                AlignmentPattern.canvas.drawCross(centers[x][y], Color_Fields.RED);
                                int dx = precisionCenter.X - centers[x][y].X;
                                int dy = precisionCenter.Y - centers[x][y].Y;
                                AlignmentPattern.canvas.println(string.Concat(new object[]
                                {
                                    "Adjust AP(",
                                    x,
                                    ",",
                                    y,
                                    ") to d(",
                                    dx,
                                    ",",
                                    dy,
                                    ")"
                                }));
                                centers[x][y] = precisionCenter;
                            }
                        }
                        AlignmentPattern.canvas.drawCross(centers[x][y], Color_Fields.BLUE);
                        AlignmentPattern.canvas.drawLine(new Line(tmpPoint, centers[x][y]), Color_Fields.LIGHTBLUE);
                        tmpPoint = centers[x][y];
                    }
                }
            }
            return(centers);
        }
		internal static Point[][] getCenter(bool[][] image, FinderPattern finderPattern, Point[][] logicalCenters)
		{
			int moduleSize = finderPattern.getModuleSize();
			
			Axis axis = new Axis(finderPattern.getAngle(), moduleSize);
			int sqrtCenters = logicalCenters.Length;
			Point[][] centers = new Point[sqrtCenters][];
			for (int i = 0; i < sqrtCenters; i++)
			{
				centers[i] = new Point[sqrtCenters];
			}
			
			axis.Origin = finderPattern.getCenter(FinderPattern.UL);
			centers[0][0] = axis.translate(3, 3);
			canvas.drawCross(centers[0][0], ThoughtWorks.QRCode.Codec.Util.Color_Fields.BLUE);
			
			axis.Origin = finderPattern.getCenter(FinderPattern.UR);
			centers[sqrtCenters - 1][0] = axis.translate(- 3, 3);
			canvas.drawCross(centers[sqrtCenters - 1][0], ThoughtWorks.QRCode.Codec.Util.Color_Fields.BLUE);
			
			axis.Origin = finderPattern.getCenter(FinderPattern.DL);
			centers[0][sqrtCenters - 1] = axis.translate(3, - 3);
			canvas.drawCross(centers[0][sqrtCenters - 1], ThoughtWorks.QRCode.Codec.Util.Color_Fields.BLUE);
			
			Point tmpPoint = centers[0][0];
			
			for (int y = 0; y < sqrtCenters; y++)
			{
				for (int x = 0; x < sqrtCenters; x++)
				{
					if ((x == 0 && y == 0) || (x == 0 && y == sqrtCenters - 1) || (x == sqrtCenters - 1 && y == 0))
					{
						//					canvas.drawCross(centers[x][y], java.awt.Color.MAGENTA);
						continue;
					}
					Point target = null;
					if (y == 0)
					{
						if (x > 0 && x < sqrtCenters - 1)
						{
							target = axis.translate(centers[x - 1][y], logicalCenters[x][y].X - logicalCenters[x - 1][y].X, 0);
						}
						centers[x][y] = new Point(target.X, target.Y);
						canvas.drawCross(centers[x][y], ThoughtWorks.QRCode.Codec.Util.Color_Fields.RED);
					}
					else if (x == 0)
					{
						if (y > 0 && y < sqrtCenters - 1)
						{
							target = axis.translate(centers[x][y - 1], 0, logicalCenters[x][y].Y - logicalCenters[x][y - 1].Y);
						}
						centers[x][y] = new Point(target.X, target.Y);
						canvas.drawCross(centers[x][y], ThoughtWorks.QRCode.Codec.Util.Color_Fields.RED);
					}
					else
					{
						Point t1 = axis.translate(centers[x - 1][y], logicalCenters[x][y].X - logicalCenters[x - 1][y].X, 0);
						Point t2 = axis.translate(centers[x][y - 1], 0, logicalCenters[x][y].Y - logicalCenters[x][y - 1].Y);
						centers[x][y] = new Point((t1.X + t2.X) / 2, (t1.Y + t2.Y) / 2 + 1);
					}
					if (finderPattern.Version > 1)
					{
						Point precisionCenter = getPrecisionCenter(image, centers[x][y]);
						
						if (centers[x][y].distanceOf(precisionCenter) < 6)
						{
							canvas.drawCross(centers[x][y], ThoughtWorks.QRCode.Codec.Util.Color_Fields.RED);
							int dx = precisionCenter.X - centers[x][y].X;
							int dy = precisionCenter.Y - centers[x][y].Y;
							canvas.println("Adjust AP(" + x + "," + y + ") to d(" + dx + "," + dy + ")");
							
							centers[x][y] = precisionCenter;
						}
					}
					canvas.drawCross(centers[x][y], ThoughtWorks.QRCode.Codec.Util.Color_Fields.BLUE);
					canvas.drawLine(new Line(tmpPoint, centers[x][y]), ThoughtWorks.QRCode.Codec.Util.Color_Fields.LIGHTBLUE);
					tmpPoint = centers[x][y];					
				}
			}
			return centers;
		}
예제 #10
0
 internal static Point[][] getCenter(bool[][] image, FinderPattern finderPattern, Point[][] logicalCenters)
 {
     int modulePitch = finderPattern.getModuleSize();
     Axis axis = new Axis(finderPattern.getAngle(), modulePitch);
     int length = logicalCenters.Length;
     Point[][] pointArray = new Point[length][];
     for (int i = 0; i < length; i++)
     {
         pointArray[i] = new Point[length];
     }
     axis.Origin = finderPattern.getCenter(0);
     pointArray[0][0] = axis.translate(3, 3);
     canvas.drawCross(pointArray[0][0], Color_Fields.BLUE);
     axis.Origin = finderPattern.getCenter(1);
     pointArray[length - 1][0] = axis.translate(-3, 3);
     canvas.drawCross(pointArray[length - 1][0], Color_Fields.BLUE);
     axis.Origin = finderPattern.getCenter(2);
     pointArray[0][length - 1] = axis.translate(3, -3);
     canvas.drawCross(pointArray[0][length - 1], Color_Fields.BLUE);
     Point point = pointArray[0][0];
     for (int j = 0; j < length; j++)
     {
         for (int k = 0; k < length; k++)
         {
             if ((((k != 0) || (j != 0)) && ((k != 0) || (j != (length - 1)))) && ((k != (length - 1)) || (j != 0)))
             {
                 Point point2 = null;
                 if (j == 0)
                 {
                     if ((k > 0) && (k < (length - 1)))
                     {
                         point2 = axis.translate(pointArray[k - 1][j], logicalCenters[k][j].X - logicalCenters[k - 1][j].X, 0);
                     }
                     pointArray[k][j] = new Point(point2.X, point2.Y);
                     canvas.drawCross(pointArray[k][j], Color_Fields.RED);
                 }
                 else if (k == 0)
                 {
                     if ((j > 0) && (j < (length - 1)))
                     {
                         point2 = axis.translate(pointArray[k][j - 1], 0, logicalCenters[k][j].Y - logicalCenters[k][j - 1].Y);
                     }
                     pointArray[k][j] = new Point(point2.X, point2.Y);
                     canvas.drawCross(pointArray[k][j], Color_Fields.RED);
                 }
                 else
                 {
                     Point point3 = axis.translate(pointArray[k - 1][j], logicalCenters[k][j].X - logicalCenters[k - 1][j].X, 0);
                     Point point4 = axis.translate(pointArray[k][j - 1], 0, logicalCenters[k][j].Y - logicalCenters[k][j - 1].Y);
                     pointArray[k][j] = new Point((point3.X + point4.X) / 2, ((point3.Y + point4.Y) / 2) + 1);
                 }
                 if (finderPattern.Version > 1)
                 {
                     Point other = getPrecisionCenter(image, pointArray[k][j]);
                     if (pointArray[k][j].distanceOf(other) < 6)
                     {
                         canvas.drawCross(pointArray[k][j], Color_Fields.RED);
                         int num6 = other.X - pointArray[k][j].X;
                         int num7 = other.Y - pointArray[k][j].Y;
                         canvas.println(string.Concat(new object[] { "Adjust AP(", k, ",", j, ") to d(", num6, ",", num7, ")" }));
                         pointArray[k][j] = other;
                     }
                 }
                 canvas.drawCross(pointArray[k][j], Color_Fields.BLUE);
                 canvas.drawLine(new Line(point, pointArray[k][j]), Color_Fields.LIGHTBLUE);
                 point = pointArray[k][j];
             }
         }
     }
     return pointArray;
 }
예제 #11
0
        internal static Point[][] getCenter(bool[][] image, FinderPattern finderPattern, Point[][] logicalCenters)
        {
            int  moduleSize = finderPattern.getModuleSize();
            Axis axis       = new Axis(finderPattern.getAngle(), moduleSize);
            int  length     = logicalCenters.Length;

            Point[][] pointArray = new Point[length][];
            for (int index = 0; index < length; ++index)
            {
                pointArray[index] = new Point[length];
            }
            axis.Origin      = finderPattern.getCenter(0);
            pointArray[0][0] = axis.translate(3, 3);
            AlignmentPattern.canvas.drawCross(pointArray[0][0], Color_Fields.BLUE);
            axis.Origin = finderPattern.getCenter(1);
            pointArray[length - 1][0] = axis.translate(-3, 3);
            AlignmentPattern.canvas.drawCross(pointArray[length - 1][0], Color_Fields.BLUE);
            axis.Origin = finderPattern.getCenter(2);
            pointArray[0][length - 1] = axis.translate(3, -3);
            AlignmentPattern.canvas.drawCross(pointArray[0][length - 1], Color_Fields.BLUE);
            Point p1 = pointArray[0][0];

            for (int index1 = 0; index1 < length; ++index1)
            {
                for (int index2 = 0; index2 < length; ++index2)
                {
                    if ((index2 != 0 || index1 != 0) && (index2 != 0 || index1 != length - 1) && (index2 != length - 1 || index1 != 0))
                    {
                        Point point1 = (Point)null;
                        if (index1 == 0)
                        {
                            if (index2 > 0 && index2 < length - 1)
                            {
                                point1 = axis.translate(pointArray[index2 - 1][index1], logicalCenters[index2][index1].X - logicalCenters[index2 - 1][index1].X, 0);
                            }
                            pointArray[index2][index1] = new Point(point1.X, point1.Y);
                            AlignmentPattern.canvas.drawCross(pointArray[index2][index1], Color_Fields.RED);
                        }
                        else if (index2 == 0)
                        {
                            if (index1 > 0 && index1 < length - 1)
                            {
                                point1 = axis.translate(pointArray[index2][index1 - 1], 0, logicalCenters[index2][index1].Y - logicalCenters[index2][index1 - 1].Y);
                            }
                            pointArray[index2][index1] = new Point(point1.X, point1.Y);
                            AlignmentPattern.canvas.drawCross(pointArray[index2][index1], Color_Fields.RED);
                        }
                        else
                        {
                            Point point2 = axis.translate(pointArray[index2 - 1][index1], logicalCenters[index2][index1].X - logicalCenters[index2 - 1][index1].X, 0);
                            Point point3 = axis.translate(pointArray[index2][index1 - 1], 0, logicalCenters[index2][index1].Y - logicalCenters[index2][index1 - 1].Y);
                            pointArray[index2][index1] = new Point((point2.X + point3.X) / 2, (point2.Y + point3.Y) / 2 + 1);
                        }
                        if (finderPattern.Version > 1)
                        {
                            Point precisionCenter = AlignmentPattern.getPrecisionCenter(image, pointArray[index2][index1]);
                            if (pointArray[index2][index1].distanceOf(precisionCenter) < 6)
                            {
                                AlignmentPattern.canvas.drawCross(pointArray[index2][index1], Color_Fields.RED);
                                int num1 = precisionCenter.X - pointArray[index2][index1].X;
                                int num2 = precisionCenter.Y - pointArray[index2][index1].Y;
                                AlignmentPattern.canvas.println("Adjust AP(" + (object)index2 + "," + (string)(object)index1 + ") to d(" + (string)(object)num1 + "," + (string)(object)num2 + ")");
                                pointArray[index2][index1] = precisionCenter;
                            }
                        }
                        AlignmentPattern.canvas.drawCross(pointArray[index2][index1], Color_Fields.BLUE);
                        AlignmentPattern.canvas.drawLine(new Line(p1, pointArray[index2][index1]), Color_Fields.LIGHTBLUE);
                        p1 = pointArray[index2][index1];
                    }
                }
            }
            return(pointArray);
        }