public virtual sbyte[] decodeBytes(QRCodeImage qrCodeImage) { Point[] adjusts = this.AdjustPoints; ArrayList results = ArrayList.Synchronized(new ArrayList(10)); sbyte[] decodedBytes; while (this.numTryDecode < adjusts.Length) { try { QRCodeDecoder.DecodeResult result = this.decode(qrCodeImage, adjusts[this.numTryDecode]); if (result.CorrectionSucceeded) { decodedBytes = result.DecodedBytes; return(decodedBytes); } results.Add(result); QRCodeDecoder.canvas.println("Decoding succeeded but could not correct"); QRCodeDecoder.canvas.println("all errors. Retrying.."); } catch (DecodingFailedException dfe) { if (dfe.Message.IndexOf("Finder Pattern") >= 0) { throw dfe; } } finally { this.numTryDecode++; } } if (results.Count == 0) { throw new DecodingFailedException("Give up decoding"); } int lowestErrorIndex = -1; int lowestError = 2147483647; for (int i = 0; i < results.Count; i++) { QRCodeDecoder.DecodeResult result = (QRCodeDecoder.DecodeResult)results[i]; if (result.NumErrors < lowestError) { lowestError = result.NumErrors; lowestErrorIndex = i; } } QRCodeDecoder.canvas.println("All trials need for correct error"); QRCodeDecoder.canvas.println("Reporting #" + lowestErrorIndex + " that,"); QRCodeDecoder.canvas.println("corrected minimum errors (" + lowestError + ")"); QRCodeDecoder.canvas.println("Decoding finished."); decodedBytes = ((QRCodeDecoder.DecodeResult)results[lowestErrorIndex]).DecodedBytes; return(decodedBytes); }
public virtual sbyte[] decodeBytes(QRCodeImage qrCodeImage) { Point[] adjustPoints = this.AdjustPoints; ArrayList arrayList = ArrayList.Synchronized(new ArrayList(10)); while (this.numTryDecode < adjustPoints.Length) { try { QRCodeDecoder.DecodeResult decodeResult = this.decode(qrCodeImage, adjustPoints[this.numTryDecode]); if (decodeResult.CorrectionSucceeded) { return(decodeResult.DecodedBytes); } arrayList.Add((object)decodeResult); QRCodeDecoder.canvas.println("Decoding succeeded but could not correct"); QRCodeDecoder.canvas.println("all errors. Retrying.."); } catch (DecodingFailedException ex) { if (ex.Message.IndexOf("Finder Pattern") >= 0) { throw ex; } } finally { ++this.numTryDecode; } } if (arrayList.Count == 0) { throw new DecodingFailedException("Give up decoding"); } int index1 = -1; int num = int.MaxValue; for (int index2 = 0; index2 < arrayList.Count; ++index2) { QRCodeDecoder.DecodeResult decodeResult = (QRCodeDecoder.DecodeResult)arrayList[index2]; if (decodeResult.NumErrors < num) { num = decodeResult.NumErrors; index1 = index2; } } QRCodeDecoder.canvas.println("All trials need for correct error"); QRCodeDecoder.canvas.println("Reporting #" + (object)index1 + " that,"); QRCodeDecoder.canvas.println("corrected minimum errors (" + (object)num + ")"); QRCodeDecoder.canvas.println("Decoding finished."); return(((QRCodeDecoder.DecodeResult)arrayList[index1]).DecodedBytes); }
internal virtual QRCodeDecoder.DecodeResult decode(QRCodeImage qrCodeImage, Point adjust) { try { if (this.numTryDecode == 0) { QRCodeDecoder.canvas.println("Decoding started"); int[][] intImage = this.imageToIntArray(qrCodeImage); this.imageReader = new QRCodeImageReader(); this.qrCodeSymbol = this.imageReader.getQRCodeSymbol(intImage); } else { QRCodeDecoder.canvas.println("--"); QRCodeDecoder.canvas.println("Decoding restarted #" + this.numTryDecode); this.qrCodeSymbol = this.imageReader.getQRCodeSymbolWithAdjustedGrid(adjust); } } catch (SymbolNotFoundException e) { throw new DecodingFailedException(e.Message); } QRCodeDecoder.canvas.println("Created QRCode symbol."); QRCodeDecoder.canvas.println("Reading symbol."); QRCodeDecoder.canvas.println("Version: " + this.qrCodeSymbol.VersionReference); QRCodeDecoder.canvas.println("Mask pattern: " + this.qrCodeSymbol.MaskPatternRefererAsString); int[] blocks = this.qrCodeSymbol.Blocks; QRCodeDecoder.canvas.println("Correcting data errors."); blocks = this.correctDataBlocks(blocks); QRCodeDecoder.DecodeResult result; try { sbyte[] decodedByteArray = this.getDecodedByteArray(blocks, this.qrCodeSymbol.Version, this.qrCodeSymbol.NumErrorCollectionCode); result = new QRCodeDecoder.DecodeResult(this, decodedByteArray, this.numLastCorrections, this.correctionSucceeded); } catch (InvalidDataBlockException e2) { QRCodeDecoder.canvas.println(e2.Message); throw new DecodingFailedException(e2.Message); } return(result); }