internal static int[] getAngle(Point[] centers) { Line[] array = new Line[3]; for (int i = 0; i < array.Length; i++) { array[i] = new Line(centers[i], centers[(i + 1) % array.Length]); } Line longest = Line.getLongest(array); Point point = new Point(); for (int i = 0; i < centers.Length; i++) { if (!longest.getP1().equals(centers[i]) && !longest.getP2().equals(centers[i])) { point = centers[i]; break; } } canvas.println("originPoint is: " + point); Point point2 = new Point(); point2 = (((point.Y <= longest.getP1().Y) & (point.Y <= longest.getP2().Y)) ? ((longest.getP1().X >= longest.getP2().X) ? longest.getP1() : longest.getP2()) : (((point.X >= longest.getP1().X) & (point.X >= longest.getP2().X)) ? ((longest.getP1().Y >= longest.getP2().Y) ? longest.getP1() : longest.getP2()) : (((point.Y >= longest.getP1().Y) & (point.Y >= longest.getP2().Y)) ? ((longest.getP1().X >= longest.getP2().X) ? longest.getP2() : longest.getP1()) : ((longest.getP1().Y >= longest.getP2().Y) ? longest.getP2() : longest.getP1())))); int length = new Line(point, point2).Length; return(new int[2] { (point2.Y - point.Y << QRCodeImageReader.DECIMAL_POINT) / length, (point2.X - point.X << QRCodeImageReader.DECIMAL_POINT) / length }); }
internal static int calcExactVersion(Point[] centers, int[] angle, int[] moduleSize, bool[][] image) { Point point; int num2; bool[] target = new bool[0x12]; Point[] points = new Point[0x12]; Axis axis = new Axis(angle, moduleSize[1]) { Origin = centers[1] }; int num = 0; while (num < 6) { for (num2 = 0; num2 < 3; num2++) { point = axis.translate((int)(num2 - 7), (int)(num - 3)); target[num2 + (num * 3)] = image[point.X][point.Y]; points[num2 + (num * 3)] = point; } num++; } canvas.drawPoints(points, Color_Fields.RED); int num3 = 0; try { num3 = checkVersionInfo(target); } catch (InvalidVersionInfoException) { canvas.println("Version info error. now retry with other place one."); axis.Origin = centers[2]; axis.ModulePitch = moduleSize[2]; for (num2 = 0; num2 < 6; num2++) { for (num = 0; num < 3; num++) { point = axis.translate((int)(num2 - 3), (int)(num - 7)); target[num + (num2 * 3)] = image[point.X][point.Y]; points[num2 + (num * 3)] = point; } } canvas.drawPoints(points, Color_Fields.RED); try { num3 = checkVersionInfo(target); } catch (VersionInformationException exception2) { throw exception2; } } return(num3); }
public virtual sbyte[] get8bitByteArray(int dataLength) { int num = dataLength; int num2 = 0; MemoryStream memoryStream = new MemoryStream(); do { canvas.println("Length: " + num); num2 = getNextBits(8); memoryStream.WriteByte((byte)num2); num--; } while (num > 0); return SystemUtils.ToSByteArray(memoryStream.ToArray()); }
public virtual sbyte[] get8bitByteArray(int dataLength) { int length = dataLength; int intData = 0; MemoryStream output = new MemoryStream(); do { canvas.println("Length: " + length); intData = getNextBits(8); output.WriteByte((byte)intData); length--; }while (length > 0); return(SystemUtils.ToSByteArray(output.ToArray())); }
public virtual sbyte[] decodeBytes(QRCodeImage qrCodeImage) { Point[] adjusts = AdjustPoints; System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); while (numTryDecode < adjusts.Length) { try { DecodeResult result = decode(qrCodeImage, adjusts[numTryDecode]); if (result.CorrectionSucceeded) { return(result.DecodedBytes); } else { results.Add(result); canvas.println("Decoding succeeded but could not correct"); canvas.println("all errors. Retrying.."); } } catch (DecodingFailedException dfe) { if (dfe.Message.IndexOf("Finder Pattern") >= 0) { throw dfe; } } finally { numTryDecode += 1; } } if (results.Count == 0) { throw new DecodingFailedException("Give up decoding"); } int lowestErrorIndex = -1; int lowestError = System.Int32.MaxValue; for (int i = 0; i < results.Count; i++) { DecodeResult result = (DecodeResult)results[i]; if (result.NumErrors < lowestError) { lowestError = result.NumErrors; lowestErrorIndex = i; } } canvas.println("All trials need for correct error"); canvas.println("Reporting #" + (lowestErrorIndex) + " that,"); canvas.println("corrected minimum errors (" + lowestError + ")"); canvas.println("Decoding finished."); return(((DecodeResult)results[lowestErrorIndex]).DecodedBytes); }
public virtual QRCodeSymbol getQRCodeSymbol(int[][] image) { int longSide = (image.Length < image[0].Length)?image[0].Length:image.Length; QRCodeImageReader.DECIMAL_POINT = 23 - QRCodeUtility.sqrt(longSide / 256); bitmap = filterImage(image); canvas.println("Drawing matrix."); canvas.drawMatrix(bitmap); canvas.println("Scanning Finder Pattern."); FinderPattern finderPattern = null; try { finderPattern = FinderPattern.findFinderPattern(bitmap); } catch (FinderPatternNotFoundException) { canvas.println("Not found, now retrying..."); bitmap = applyCrossMaskingMedianFilter(bitmap, 5); canvas.drawMatrix(bitmap); for (int i = 0; i < 1000000000; i++) { ; } try { finderPattern = FinderPattern.findFinderPattern(bitmap); } catch (FinderPatternNotFoundException e2) { throw new SymbolNotFoundException(e2.Message); } catch (VersionInformationException e2) { throw new SymbolNotFoundException(e2.Message); } } catch (VersionInformationException e) { throw new SymbolNotFoundException(e.Message); } canvas.println("FinderPattern at"); String finderPatternCoordinates = finderPattern.getCenter(FinderPattern.UL).ToString() + finderPattern.getCenter(FinderPattern.UR).ToString() + finderPattern.getCenter(FinderPattern.DL).ToString(); canvas.println(finderPatternCoordinates); int[] sincos = finderPattern.getAngle(); canvas.println("Angle*4098: Sin " + System.Convert.ToString(sincos[0]) + " " + "Cos " + System.Convert.ToString(sincos[1])); int version = finderPattern.Version; canvas.println("Version: " + System.Convert.ToString(version)); if (version < 1 || version > 40) { throw new InvalidVersionException("Invalid version: " + version); } AlignmentPattern alignmentPattern = null; try { alignmentPattern = AlignmentPattern.findAlignmentPattern(bitmap, finderPattern); } catch (AlignmentPatternNotFoundException e) { throw new SymbolNotFoundException(e.Message); } int matrixLength = alignmentPattern.getCenter().Length; canvas.println("AlignmentPatterns at"); for (int y = 0; y < matrixLength; y++) { String alignmentPatternCoordinates = ""; for (int x = 0; x < matrixLength; x++) { alignmentPatternCoordinates += alignmentPattern.getCenter()[x][y].ToString(); } canvas.println(alignmentPatternCoordinates); } //for(int i = 0; i < 500000; i++) Console.out.println(""); canvas.println("Creating sampling grid."); //[TODO] need all-purpose method //samplingGrid = getSamplingGrid2_6(finderPattern, alignmentPattern); samplingGrid = getSamplingGrid(finderPattern, alignmentPattern); canvas.println("Reading grid."); bool[][] qRCodeMatrix = null; try { qRCodeMatrix = getQRCodeMatrix(bitmap, samplingGrid); } catch (System.IndexOutOfRangeException) { throw new SymbolNotFoundException("Sampling grid exceeded image boundary"); } //canvas.drawMatrix(qRCodeMatrix); return(new QRCodeSymbol(qRCodeMatrix)); }
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); }
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], QRStudio.Engine.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], QRStudio.Engine.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], QRStudio.Engine.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)) { 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], QRStudio.Engine.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], QRStudio.Engine.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], QRStudio.Engine.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], QRStudio.Engine.Codec.Util.Color_Fields.BLUE); canvas.drawLine(new Line(tmpPoint, centers[x][y]), QRStudio.Engine.Codec.Util.Color_Fields.LIGHTBLUE); tmpPoint = centers[x][y]; } } return(centers); }
internal static int[] getAngle(Point[] centers) { Line[] additionalLine = new Line[3]; for (int i = 0; i < additionalLine.Length; i++) { additionalLine[i] = new Line(centers[i], centers[(i + 1) % additionalLine.Length]); } Line remoteLine = Line.getLongest(additionalLine); Point originPoint = new Point(); for (int i = 0; i < centers.Length; i++) { if (!remoteLine.getP1().equals(centers[i]) && !remoteLine.getP2().equals(centers[i])) { originPoint = centers[i]; break; } } canvas.println("originPoint is: " + originPoint); Point remotePoint = new Point(); if (originPoint.Y <= remoteLine.getP1().Y & originPoint.Y <= remoteLine.getP2().Y) { if (remoteLine.getP1().X < remoteLine.getP2().X) { remotePoint = remoteLine.getP2(); } else { remotePoint = remoteLine.getP1(); } } else if (originPoint.X >= remoteLine.getP1().X & originPoint.X >= remoteLine.getP2().X) { if (remoteLine.getP1().Y < remoteLine.getP2().Y) { remotePoint = remoteLine.getP2(); } else { remotePoint = remoteLine.getP1(); } } else if (originPoint.Y >= remoteLine.getP1().Y & originPoint.Y >= remoteLine.getP2().Y) { if (remoteLine.getP1().X < remoteLine.getP2().X) { remotePoint = remoteLine.getP1(); } else { remotePoint = remoteLine.getP2(); } } else if (remoteLine.getP1().Y < remoteLine.getP2().Y) { remotePoint = remoteLine.getP1(); } else { remotePoint = remoteLine.getP2(); } int r = new Line(originPoint, remotePoint).Length; int[] angle = new int[2]; angle[0] = ((remotePoint.Y - originPoint.Y) << QRCodeImageReader.DECIMAL_POINT) / r; angle[1] = ((remotePoint.X - originPoint.X) << (QRCodeImageReader.DECIMAL_POINT)) / r; return(angle); }
public virtual sbyte[] decodeBytes(QRCodeImage qrCodeImage) { Point[] adjustPoints = AdjustPoints; ArrayList arrayList = ArrayList.Synchronized(new ArrayList(10)); while (numTryDecode < adjustPoints.Length) { try { DecodeResult decodeResult = decode(qrCodeImage, adjustPoints[numTryDecode]); if (decodeResult.CorrectionSucceeded) { return(decodeResult.DecodedBytes); } arrayList.Add(decodeResult); canvas.println("Decoding succeeded but could not correct"); canvas.println("all errors. Retrying.."); } catch (DecodingFailedException ex) { if (ex.Message.IndexOf("Finder Pattern") >= 0) { throw ex; } } finally { numTryDecode++; } } if (arrayList.Count == 0) { throw new DecodingFailedException("Give up decoding"); } int num = -1; int num2 = int.MaxValue; for (int i = 0; i < arrayList.Count; i++) { DecodeResult decodeResult = (DecodeResult)arrayList[i]; if (decodeResult.NumErrors < num2) { num2 = decodeResult.NumErrors; num = i; } } canvas.println("All trials need for correct error"); canvas.println("Reporting #" + num + " that,"); canvas.println("corrected minimum errors (" + num2 + ")"); canvas.println("Decoding finished."); return(((DecodeResult)arrayList[num]).DecodedBytes); }
internal virtual int[] correctDataBlocks(int[] blocks) { ReedSolomon solomon; int num8; int num9; int num10; int num = 0; int dataCapacity = this.qrCodeSymbol.DataCapacity; int[] numArray = new int[dataCapacity]; int numErrorCollectionCode = this.qrCodeSymbol.NumErrorCollectionCode; int numRSBlocks = this.qrCodeSymbol.NumRSBlocks; int nPAR = numErrorCollectionCode / numRSBlocks; if (numRSBlocks == 1) { solomon = new ReedSolomon(blocks, nPAR); solomon.correct(); num += solomon.NumCorrectedErrors; if (num > 0) { canvas.println(Convert.ToString(num) + " data errors corrected."); } else { canvas.println("No errors found."); } this.numLastCorrections = num; this.correctionSucceeded = solomon.CorrectionSucceeded; return(blocks); } int num6 = dataCapacity % numRSBlocks; if (num6 == 0) { int num7 = dataCapacity / numRSBlocks; int[][] numArray2 = new int[numRSBlocks][]; for (num8 = 0; num8 < numRSBlocks; num8++) { numArray2[num8] = new int[num7]; } int[][] numArray3 = numArray2; for (num8 = 0; num8 < numRSBlocks; num8++) { num9 = 0; while (num9 < num7) { numArray3[num8][num9] = blocks[(num9 * numRSBlocks) + num8]; num9++; } solomon = new ReedSolomon(numArray3[num8], nPAR); solomon.correct(); num += solomon.NumCorrectedErrors; this.correctionSucceeded = solomon.CorrectionSucceeded; } num10 = 0; for (num8 = 0; num8 < numRSBlocks; num8++) { num9 = 0; while (num9 < (num7 - nPAR)) { numArray[num10++] = numArray3[num8][num9]; num9++; } } } else { int num11 = dataCapacity / numRSBlocks; int num12 = (dataCapacity / numRSBlocks) + 1; int num13 = numRSBlocks - num6; int[][] numArray4 = new int[num13][]; for (int i = 0; i < num13; i++) { numArray4[i] = new int[num11]; } int[][] numArray5 = numArray4; int[][] numArray6 = new int[num6][]; for (int j = 0; j < num6; j++) { numArray6[j] = new int[num12]; } int[][] numArray7 = numArray6; for (num8 = 0; num8 < numRSBlocks; num8++) { int num16; if (num8 < num13) { num16 = 0; num9 = 0; while (num9 < num11) { if (num9 == (num11 - nPAR)) { num16 = num6; } numArray5[num8][num9] = blocks[((num9 * numRSBlocks) + num8) + num16]; num9++; } solomon = new ReedSolomon(numArray5[num8], nPAR); solomon.correct(); num += solomon.NumCorrectedErrors; this.correctionSucceeded = solomon.CorrectionSucceeded; } else { num16 = 0; num9 = 0; while (num9 < num12) { if (num9 == (num11 - nPAR)) { num16 = num13; } numArray7[num8 - num13][num9] = blocks[((num9 * numRSBlocks) + num8) - num16]; num9++; } solomon = new ReedSolomon(numArray7[num8 - num13], nPAR); solomon.correct(); num += solomon.NumCorrectedErrors; this.correctionSucceeded = solomon.CorrectionSucceeded; } } num10 = 0; for (num8 = 0; num8 < numRSBlocks; num8++) { if (num8 < num13) { num9 = 0; while (num9 < (num11 - nPAR)) { numArray[num10++] = numArray5[num8][num9]; num9++; } } else { for (num9 = 0; num9 < (num12 - nPAR); num9++) { numArray[num10++] = numArray7[num8 - num13][num9]; } } } } if (num > 0) { canvas.println(Convert.ToString(num) + " data errors corrected."); } else { canvas.println("No errors found."); } this.numLastCorrections = num; return(numArray); }
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); }
//obtain slope of symbol internal static int[] getAngle(Point[] centers) { Line[] additionalLine = new Line[3]; for (int i = 0; i < additionalLine.Length; i++) { additionalLine[i] = new Line(centers[i], centers[(i + 1) % additionalLine.Length]); } // remoteLine - does not contain UL center Line remoteLine = Line.getLongest(additionalLine); Point originPoint = new Point(); for (int i = 0; i < centers.Length; i++) { if (!remoteLine.getP1().equals(centers[i]) && !remoteLine.getP2().equals(centers[i])) { originPoint = centers[i]; break; } } canvas.println("originPoint is: " + originPoint); Point remotePoint = new Point(); //with origin that the center of Left-Up Finder Pattern, determine other two patterns center. //then calculate symbols angle if (originPoint.Y <= remoteLine.getP1().Y & originPoint.Y <= remoteLine.getP2().Y) { if (remoteLine.getP1().X < remoteLine.getP2().X) { remotePoint = remoteLine.getP2(); } else { remotePoint = remoteLine.getP1(); } } else if (originPoint.X >= remoteLine.getP1().X & originPoint.X >= remoteLine.getP2().X) { if (remoteLine.getP1().Y < remoteLine.getP2().Y) { remotePoint = remoteLine.getP2(); } else { remotePoint = remoteLine.getP1(); } } else if (originPoint.Y >= remoteLine.getP1().Y & originPoint.Y >= remoteLine.getP2().Y) { if (remoteLine.getP1().X < remoteLine.getP2().X) { remotePoint = remoteLine.getP1(); } else { remotePoint = remoteLine.getP2(); } } //1st or 4th quadrant else if (remoteLine.getP1().Y < remoteLine.getP2().Y) { remotePoint = remoteLine.getP1(); } else { remotePoint = remoteLine.getP2(); } int r = new Line(originPoint, remotePoint).Length; //canvas.println(Integer.toString(((remotePoint.getX() - originPoint.getX()) << QRCodeImageReader.DECIMAL_POINT))); int[] angle = new int[2]; angle[0] = ((remotePoint.Y - originPoint.Y) << QRCodeImageReader.DECIMAL_POINT) / r; //Sin angle[1] = ((remotePoint.X - originPoint.X) << (QRCodeImageReader.DECIMAL_POINT)) / r; //Cos return(angle); }
public virtual QRCodeSymbol getQRCodeSymbol(int[][] image) { int num = ((image.Length < image[0].Length) ? image[0].Length : image.Length); DECIMAL_POINT = 23 - QRCodeUtility.sqrt(num / 256); bitmap = filterImage(image); canvas.println("Drawing matrix."); canvas.drawMatrix(bitmap); canvas.println("Scanning Finder Pattern."); FinderPattern finderPattern = null; try { finderPattern = FinderPattern.findFinderPattern(bitmap); } catch (FinderPatternNotFoundException) { canvas.println("Not found, now retrying..."); bitmap = applyCrossMaskingMedianFilter(bitmap, 5); canvas.drawMatrix(bitmap); for (int i = 0; i < 1000000000; i++) { } try { finderPattern = FinderPattern.findFinderPattern(bitmap); } catch (FinderPatternNotFoundException ex) { throw new SymbolNotFoundException(ex.Message); } catch (VersionInformationException ex2) { throw new SymbolNotFoundException(ex2.Message); } } catch (VersionInformationException ex4) { throw new SymbolNotFoundException(ex4.Message); } canvas.println("FinderPattern at"); string str = finderPattern.getCenter(0).ToString() + finderPattern.getCenter(1).ToString() + finderPattern.getCenter(2).ToString(); canvas.println(str); int[] angle = finderPattern.getAngle(); canvas.println("Angle*4098: Sin " + Convert.ToString(angle[0]) + " Cos " + Convert.ToString(angle[1])); int version = finderPattern.Version; canvas.println("Version: " + Convert.ToString(version)); if (version < 1 || version > 40) { throw new InvalidVersionException("Invalid version: " + version); } AlignmentPattern alignmentPattern = null; try { alignmentPattern = AlignmentPattern.findAlignmentPattern(bitmap, finderPattern); } catch (AlignmentPatternNotFoundException ex5) { throw new SymbolNotFoundException(ex5.Message); } int num2 = alignmentPattern.getCenter().Length; canvas.println("AlignmentPatterns at"); for (int j = 0; j < num2; j++) { string text = ""; for (int k = 0; k < num2; k++) { text += alignmentPattern.getCenter()[k][j].ToString(); } canvas.println(text); } canvas.println("Creating sampling grid."); samplingGrid = getSamplingGrid(finderPattern, alignmentPattern); canvas.println("Reading grid."); bool[][] array = null; try { array = getQRCodeMatrix(bitmap, samplingGrid); } catch (IndexOutOfRangeException) { throw new SymbolNotFoundException("Sampling grid exceeded image boundary"); } return(new QRCodeSymbol(array)); }