/// <summary> /// Careful use (only 4 of 40 version enabled) /// </summary> /// <param name="str">string to encode</param> /// <param name="errorCorrection">0 - 7%;1 - 15%; 2 - 25%; 3 - 30%</param> /// <param name="mode">0- numeric; 1- alphanumeric;2- Byte; 3- Kanji;</param> /// <param name="version">varsion of </param> /// <param name="maxCapacity">max capasity for input string</param> public static void GetMaxCapacityAndVersion(string str, ErrorCorrectionLvl errorCorrection, EncodeMode mode, out int version, out int maxCapacity) { maxCapacity = 0; version = 0; while (str.Length > maxCapacity) { maxCapacity = DataMaxCapacityAndVersion[version * 4 + (int)errorCorrection, 2 + (int)mode]; version++; } }
private void buttonGenerate_Click(object sender, EventArgs e) { ErrorCorrectionLvl errorCorrectionLvl = ErrorCorrectionLvl.Lvl7; //by default #region determine err correction lvl switch (this.comboBoxErrorCorrection.Text) { case "L(7%)": errorCorrectionLvl = ErrorCorrectionLvl.Lvl7; break; case "M(15%)": errorCorrectionLvl = ErrorCorrectionLvl.Lvl15; break; case "Q(25%)": errorCorrectionLvl = ErrorCorrectionLvl.Lvl25; break; case "H(30%)": errorCorrectionLvl = ErrorCorrectionLvl.Lvl30; break; default: break; } #endregion if ((EncodeMode)this.comboBoxMode.SelectedItem == EncodeMode.Alphanumeric) { this.textBoxInput.Text = this.textBoxInput.Text.ToUpper(); } int Qrversion; try { this.pictureBoxQRCode.Image = Encode.GetImage( new EncodeProperties { Mode = (EncodeMode)this.comboBoxMode.SelectedItem, ErrorCorrectionLvl = errorCorrectionLvl, Text = this.textBoxInput.Text, Size = (int)this.numericUpDownBitmapSize.Value }, out Qrversion, (MaskPatterns)this.comboBoxMaskPattern.SelectedItem ); this.Text = "version of Qr code: " + Qrversion.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static bool[] GetInfoString(int version, ErrorCorrectionLvl errorCorrectionLvl, MaskPatterns maskPattern) { if (version < 7) { try { return(Dict[errorCorrectionLvl][maskPattern]); } catch (Exception) { throw new NotImplementedException("format not implemented"); } } else { throw new NotImplementedException(); } }
public static int GetNumOfCodeWordsInBlocksInGroup2(ErrorCorrectionLvl errorCorrectionLvl, int version) { version--; return(table[version * 4 + (int)errorCorrectionLvl, 7]); }
public static int GetNumOfBlocksInGroup1(ErrorCorrectionLvl errorCorrectionLvl, int version) { version--; return(table[version * 4 + (int)errorCorrectionLvl, 4]); }
public static int GetErrorCorrectionCodewordsPerBlock(ErrorCorrectionLvl errorCorrectionLvl, int version) { version--; return(table[version * 4 + (int)errorCorrectionLvl, 3]); }
/// <summary> /// Careful use (only 4 of 40 version enabled) /// </summary> /// <param name="str">string to encode</param> /// <param name="errorCorrection">0 - 7%;1 - 15%; 2 - 25%; 3 - 30%</param> /// <param name="mode">0- numeric; 1- alphanumeric;2- Byte; 3- Kanji;</param> /// <param name="version">varsion of </param> /// <param name="maxCapacity">max capasity for input string</param> public static void GetMaxCapacityAndVersion( string str , ErrorCorrectionLvl errorCorrection , EncodeMode mode , out int version, out int maxCapacity ) { maxCapacity = 0; version = 0; while ( str.Length > maxCapacity ) { maxCapacity = DataMaxCapacityAndVersion[version * 4 + (int) errorCorrection , 2 + (int) mode]; version++; } }
public static Bitmap Generate(int version, bool[] characterCountIndicator, bool[] messageData, bool[] terminator, bool[] datatype, bool[] errCorrKeyWords, int thickness, ErrorCorrectionLvl errorCorrectionLvl, MaskPatterns maskPattern = MaskPatterns.Pattern0) { Bitmap ans = new Bitmap((21 + version * 4) * thickness + thickness * 10, (21 + version * 4) * thickness + thickness * 10); Graphics g = Graphics.FromImage(ans); int pixel = 0; bool[] fullData = new bool[0]; var formatInfoData = FormatInfoStringsList.GetInfoString(version, errorCorrectionLvl, maskPattern); return(DrawBitmap(version, errCorrKeyWords, formatInfoData, 1000, maskPattern)); }
private static int[] PolynomialDevision(ErrorCorrectionLvl ErrCorr, int version, int[] FullDataInts) { int ErrCorrectionCodewordsCount; int[] MessagePolynomial; AlphaPow[] GeneratorPolinomial; int DevisionSteps; int[] GeneratorPolinomialInt; int[] XORresult; ErrCorrectionCodewordsCount = ErrorCorrectionTable.GetErrorCorrectionCodewordsPerBlock(ErrCorr, version); MessagePolynomial = FullDataInts; GeneratorPolinomial = Helper.generatePolinomial(ErrCorrectionCodewordsCount); Array.Reverse(GeneratorPolinomial); DevisionSteps = MessagePolynomial.Length; // int[] mult = new int[ErrCorrectionCodewordsCount]; //DevisionSteps->ErrCorrectionCodewordsCount MessagePolynomial = Helper.joinArrs <int> (MessagePolynomial, mult); AlphaPow[] mult1 = new AlphaPow[MessagePolynomial.Length - GeneratorPolinomial.Length]; for (int i = 0; i < mult1.Length; i++) { mult1[i] = new AlphaPow(-1, false); } GeneratorPolinomial = Helper.joinArrs <AlphaPow> (GeneratorPolinomial, mult1); GeneratorPolinomialInt = new int[GeneratorPolinomial.Length]; bool[][] Codewords = new bool[DevisionSteps][]; //first step AlphaPow[] GenPolRes = new AlphaPow[GeneratorPolinomial.Length]; Array.Copy(GeneratorPolinomial, GenPolRes, GeneratorPolinomial.Length); for (int j = 0; j < GeneratorPolinomial.Length; j++) { if (GenPolRes[j].pow == -1) { GeneratorPolinomialInt[j] = 0; } else { AlphaPow a = new AlphaPow(AlphaPow.getPow(MessagePolynomial[0]), false); GenPolRes[j] *= a; GeneratorPolinomialInt[j] = GenPolRes[j].getInt(); //GeneratorPolinomial[j] = new AlphaPow( AlphaPow.getPow( GeneratorPolinomialInt[j] ^ MessagePolynomial[j]),false); } } XORresult = new int[GeneratorPolinomial.Length]; for (int j = 0; j < GeneratorPolinomial.Length; j++) { XORresult[j] = GeneratorPolinomialInt[j] ^ MessagePolynomial[j]; } if (XORresult[0] == 0) { int[] tempIntArr = new int[XORresult.Length - 1]; Array.Copy(XORresult, 1, tempIntArr, 0, tempIntArr.Length); XORresult = new int[tempIntArr.Length]; Array.Copy(tempIntArr, XORresult, tempIntArr.Length); } AlphaPow[] tempArr = new AlphaPow[GeneratorPolinomial.Length - 1]; Array.Copy(GeneratorPolinomial, 0, tempArr, 0, GeneratorPolinomial.Length - 1); GeneratorPolinomial = new AlphaPow[tempArr.Length]; Array.Copy(tempArr, GeneratorPolinomial, tempArr.Length); ////////////////// bool[][] DataCodewords = new bool[DevisionSteps][]; DataCodewords[0] = new bool[8]; bool[] tempT = Encode.Binary( XORresult[0]); for (int up = 0; up < 8; up++) { DataCodewords[0][up] = tempT[up]; } Array.Copy(tempT, DataCodewords[0], 8); for (int i = 1; i < DevisionSteps; i++) { DataCodewords[i] = new bool[8]; //Array.Copy(Encoder.Binary(XORresult[0]), DataCodewords[i], 8); for (int up = 0; up < 8; up++) { DataCodewords[0][up] = Encode.Binary(XORresult[0])[up]; } Array.Copy(GeneratorPolinomial, GenPolRes, GeneratorPolinomial.Length); for (int j = 0; j < GeneratorPolinomial.Length; j++) { if (GenPolRes[j].pow == -1) { GeneratorPolinomialInt[j] = 0; } else { AlphaPow a = new AlphaPow(AlphaPow.getPow(XORresult[0]), false); GenPolRes[j] *= a; GeneratorPolinomialInt[j] = GenPolRes[j].getInt(); //GeneratorPolinomial[j] = new AlphaPow( AlphaPow.getPow( GeneratorPolinomialInt[j] ^ MessagePolynomial[j]),false); } } int[] XORtemp = new int[XORresult.Length]; Array.Copy(XORresult, XORtemp, XORresult.Length); XORresult = new int[GeneratorPolinomial.Length]; for (int j = 0; j < GeneratorPolinomial.Length; j++) { XORresult[j] = GeneratorPolinomialInt[j] ^ XORtemp[j]; } if (XORresult[0] == 0) { int[] tempIntArr = new int[XORresult.Length - 1]; Array.Copy(XORresult, 1, tempIntArr, 0, tempIntArr.Length); XORresult = new int[tempIntArr.Length]; Array.Copy(tempIntArr, XORresult, tempIntArr.Length); } tempArr = new AlphaPow[GeneratorPolinomial.Length - 1]; Array.Copy(GeneratorPolinomial, 0, tempArr, 0, GeneratorPolinomial.Length - 1); GeneratorPolinomial = new AlphaPow[tempArr.Length]; Array.Copy(tempArr, GeneratorPolinomial, tempArr.Length); } int size = XORresult.Length; //for ( int i = 0 ; i < size ; i++ ) { // if ( XORresult[i] == 0 ) { // int[] Xtemp = new int[i]; // Array.Copy ( XORresult , 0 , Xtemp , 0 , i ); // XORresult = new int[Xtemp.Length]; // Array.Copy ( Xtemp , XORresult , Xtemp.Length ); // break; // } //} ////////////////// for (int i = size - 1; i >= 0; i--) { if (XORresult[i] == 0) { int[] Xtemp = new int[i]; Array.Copy(XORresult, 0, Xtemp, 0, i); XORresult = new int[Xtemp.Length]; Array.Copy(Xtemp, XORresult, Xtemp.Length); } else { break; } } return(XORresult); }
public static bool[] GetInfoString(int version,ErrorCorrectionLvl errorCorrectionLvl,MaskPatterns maskPattern) { if (version<7) { try { return Dict[errorCorrectionLvl][maskPattern]; } catch ( Exception ) { throw new NotImplementedException("format not implemented"); } } else { throw new NotImplementedException(); } }
private static int[] PolynomialDevision( ErrorCorrectionLvl ErrCorr , int version , int[] FullDataInts ) { int ErrCorrectionCodewordsCount; int[] MessagePolynomial; AlphaPow[] GeneratorPolinomial; int DevisionSteps; int[] GeneratorPolinomialInt; int[] XORresult; ErrCorrectionCodewordsCount = ErrorCorrectionTable.GetErrorCorrectionCodewordsPerBlock ( ErrCorr , version ); MessagePolynomial = FullDataInts; GeneratorPolinomial = Helper.generatePolinomial ( ErrCorrectionCodewordsCount ); Array.Reverse ( GeneratorPolinomial ); DevisionSteps = MessagePolynomial.Length;// int[] mult = new int[ErrCorrectionCodewordsCount];//DevisionSteps->ErrCorrectionCodewordsCount MessagePolynomial = Helper.joinArrs<int> ( MessagePolynomial , mult ); AlphaPow[] mult1 = new AlphaPow[MessagePolynomial.Length - GeneratorPolinomial.Length]; for ( int i = 0 ; i < mult1.Length ; i++ ) mult1[i] = new AlphaPow ( -1 , false ); GeneratorPolinomial = Helper.joinArrs<AlphaPow> ( GeneratorPolinomial , mult1 ); GeneratorPolinomialInt = new int[GeneratorPolinomial.Length]; bool[][] Codewords = new bool[DevisionSteps][]; //first step AlphaPow[] GenPolRes = new AlphaPow[GeneratorPolinomial.Length]; Array.Copy ( GeneratorPolinomial , GenPolRes , GeneratorPolinomial.Length ); for ( int j = 0 ; j < GeneratorPolinomial.Length ; j++ ) { if ( GenPolRes[j].pow == -1 ) { GeneratorPolinomialInt[j] = 0; } else { AlphaPow a = new AlphaPow ( AlphaPow.getPow ( MessagePolynomial[0] ) , false ); GenPolRes[j] *= a; GeneratorPolinomialInt[j] = GenPolRes[j].getInt (); //GeneratorPolinomial[j] = new AlphaPow( AlphaPow.getPow( GeneratorPolinomialInt[j] ^ MessagePolynomial[j]),false); } } XORresult = new int[GeneratorPolinomial.Length]; for ( int j = 0 ; j < GeneratorPolinomial.Length ; j++ ) { XORresult[j] = GeneratorPolinomialInt[j] ^ MessagePolynomial[j]; } if ( XORresult[0] == 0 ) { int[] tempIntArr = new int[XORresult.Length - 1]; Array.Copy ( XORresult , 1 , tempIntArr , 0 , tempIntArr.Length ); XORresult = new int[tempIntArr.Length]; Array.Copy ( tempIntArr , XORresult , tempIntArr.Length ); } AlphaPow[] tempArr = new AlphaPow[GeneratorPolinomial.Length - 1]; Array.Copy ( GeneratorPolinomial , 0 , tempArr , 0 , GeneratorPolinomial.Length - 1 ); GeneratorPolinomial = new AlphaPow[tempArr.Length]; Array.Copy ( tempArr , GeneratorPolinomial , tempArr.Length ); ////////////////// bool[][] DataCodewords = new bool[DevisionSteps][]; DataCodewords[0] = new bool[8]; bool[] tempT = Encode.Binary ( XORresult[0] ); for ( int up = 0 ; up < 8 ; up++ ) DataCodewords[0][up] = tempT[up]; Array.Copy ( tempT , DataCodewords[0] , 8 ); for ( int i = 1 ; i < DevisionSteps ; i++ ) { DataCodewords[i] = new bool[8]; //Array.Copy(Encoder.Binary(XORresult[0]), DataCodewords[i], 8); for ( int up = 0 ; up < 8 ; up++ ) DataCodewords[0][up] = Encode.Binary ( XORresult[0] )[up]; Array.Copy ( GeneratorPolinomial , GenPolRes , GeneratorPolinomial.Length ); for ( int j = 0 ; j < GeneratorPolinomial.Length ; j++ ) { if ( GenPolRes[j].pow == -1 ) { GeneratorPolinomialInt[j] = 0; } else { AlphaPow a = new AlphaPow ( AlphaPow.getPow ( XORresult[0] ) , false ); GenPolRes[j] *= a; GeneratorPolinomialInt[j] = GenPolRes[j].getInt (); //GeneratorPolinomial[j] = new AlphaPow( AlphaPow.getPow( GeneratorPolinomialInt[j] ^ MessagePolynomial[j]),false); } } int[] XORtemp = new int[XORresult.Length]; Array.Copy ( XORresult , XORtemp , XORresult.Length ); XORresult = new int[GeneratorPolinomial.Length]; for ( int j = 0 ; j < GeneratorPolinomial.Length ; j++ ) { XORresult[j] = GeneratorPolinomialInt[j] ^ XORtemp[j]; } if ( XORresult[0] == 0 ) { int[] tempIntArr = new int[XORresult.Length - 1]; Array.Copy ( XORresult , 1 , tempIntArr , 0 , tempIntArr.Length ); XORresult = new int[tempIntArr.Length]; Array.Copy ( tempIntArr , XORresult , tempIntArr.Length ); } tempArr = new AlphaPow[GeneratorPolinomial.Length - 1]; Array.Copy ( GeneratorPolinomial , 0 , tempArr , 0 , GeneratorPolinomial.Length - 1 ); GeneratorPolinomial = new AlphaPow[tempArr.Length]; Array.Copy ( tempArr , GeneratorPolinomial , tempArr.Length ); } int size = XORresult.Length; //for ( int i = 0 ; i < size ; i++ ) { // if ( XORresult[i] == 0 ) { // int[] Xtemp = new int[i]; // Array.Copy ( XORresult , 0 , Xtemp , 0 , i ); // XORresult = new int[Xtemp.Length]; // Array.Copy ( Xtemp , XORresult , Xtemp.Length ); // break; // } //} ////////////////// for ( int i = size - 1 ; i >= 0 ; i-- ) { if ( XORresult[i] == 0 ) { int[] Xtemp = new int[i]; Array.Copy ( XORresult , 0 , Xtemp , 0 , i ); XORresult = new int[Xtemp.Length]; Array.Copy ( Xtemp , XORresult , Xtemp.Length ); } else { break; } } return XORresult; }
public static Bitmap Generate( int version , bool[] characterCountIndicator , bool[] messageData , bool[] terminator , bool[] datatype , bool[] errCorrKeyWords , int thickness,ErrorCorrectionLvl errorCorrectionLvl,MaskPatterns maskPattern = MaskPatterns.Pattern0 ) { Bitmap ans = new Bitmap ( ( 21 + version * 4 ) * thickness + thickness * 10 , ( 21 + version * 4 ) * thickness + thickness * 10 ); Graphics g = Graphics.FromImage ( ans ); int pixel = 0; bool[] fullData = new bool[0]; var formatInfoData = FormatInfoStringsList.GetInfoString(version, errorCorrectionLvl, maskPattern); return DrawBitmap ( version , errCorrKeyWords , formatInfoData ,1000,maskPattern); }
public static int GetNumOfCodeWordsInBlocksInGroup2( ErrorCorrectionLvl errorCorrectionLvl , int version ) { version--; return table[version * 4 + (int) errorCorrectionLvl , 7]; }
public static int GetNumOfBlocksInGroup1(ErrorCorrectionLvl errorCorrectionLvl, int version) { version--; return table[version * 4 + (int)errorCorrectionLvl , 4]; }
public static int GetErrorCorrectionCodewordsPerBlock( ErrorCorrectionLvl errorCorrectionLvl , int version ) { version--; return table[version * 4 + (int)errorCorrectionLvl , 3]; }