找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 8934|回复: 11
打印 上一主题 下一主题
收起左侧

QrcodeVC二维码生成VC源代码

  [复制链接]
跳转到指定楼层
楼主
QrcodeVC二维码生成VC源代码.rar (1014.98 KB, 下载次数: 79)

部分程序预览:
  1. // Qrcode.cpp: implementation of the Qrcode class.
  2. //
  3. //////////////////////////////////////////////////////////////////////

  4. #include "stdafx.h"
  5. #include "QrcodeApp.h"
  6. #include "Qrcode.h"
  7. #include <math.h>

  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. #define QRCODE_DATA_PATH  "qrcode_data"
  14. //////////////////////////////////////////////////////////////////////
  15. // Construction/Destruction
  16. //////////////////////////////////////////////////////////////////////

  17. Qrcode::Qrcode()
  18. {       
  19.         qrcodeErrorCorrect = 'M';
  20.         qrcodeEncodeMode = 'B';
  21.         qrcodeVersion = 0;
  22.         qrcodeStructureappendN = 0;
  23.         qrcodeStructureappendM = 0;
  24.         qrcodeStructureappendParity = 0;
  25.         qrcodeStructureappendOriginaldata = "";       
  26. }

  27. Qrcode::~Qrcode()
  28. {
  29.        
  30. }

  31. void Qrcode::setQrcodeErrorCorrect(char c)
  32. {
  33.         qrcodeErrorCorrect = c;
  34. }

  35. char Qrcode::getQrcodeErrorCorrect()
  36. {
  37.         return qrcodeErrorCorrect;
  38. }

  39. int Qrcode::getQrcodeVersion()
  40. {
  41.         return qrcodeVersion;
  42. }

  43. void Qrcode::setQrcodeVersion(int i)
  44. {
  45.         if(i >= 0 && i <= 40)
  46.                 qrcodeVersion = i;
  47. }

  48. void Qrcode::setQrcodeEncodeMode(char c)
  49. {
  50.         qrcodeEncodeMode = c;
  51. }

  52. char Qrcode::getQrcodeEncodeMode()
  53. {
  54.         return qrcodeEncodeMode;
  55. }

  56. void Qrcode::setStructureappend(int i, int j, int k)
  57. {
  58.         if(j > 1 && j <= 16 && i > 0 && i <= 16 && k >= 0 && k <= 255)
  59.         {
  60.                 qrcodeStructureappendM = i;
  61.                 qrcodeStructureappendN = j;
  62.                 qrcodeStructureappendParity = k;
  63.         }
  64. }

  65. //int Qrcode::calStructureappendParity(char abyte0[],int i)
  66. int Qrcode::calStructureappendParity(char* abyte0,int i)
  67. {
  68.         int j = 0;
  69.         int k = 0;
  70.         //int i = abyte0.length;
  71.         if(i > 1)
  72.         {
  73.                 k = 0;
  74.                 for(; j < i; j++)
  75.                         k ^= abyte0[j] & 255;
  76.                
  77.         } else
  78.         {
  79.                 k = -1;
  80.         }
  81.         return k;
  82. }

  83. //bool** Qrcode::calQrcode(char abyte0[],int iLen0,int& iLenRet)
  84. bool** Qrcode::calQrcode(char* abyte0,int iLen0,int& iLenRet)
  85. {
  86.         int j = 0;
  87.         int n1;
  88.         int i = iLen0;
  89.         //int ai[] = new int[i + 32];
  90.         int* ai = new int[i + 32];
  91.         //char abyte1[] = new char[i + 32];
  92.         char* abyte1 = new char[i + 32];
  93.         memset(abyte1,0,i+32);
  94.         if(i <= 0)
  95.         {               
  96.                 bool** aflag=new bool*[1];
  97.                 aflag[0]=new bool[1];
  98.                 aflag[0][0]=false;
  99.                 iLenRet=1;
  100.                 return aflag;
  101.         }
  102.         if(qrcodeStructureappendN > 1)
  103.         {
  104.                 ai[0] = 3;
  105.                 abyte1[0] = 4;
  106.                 ai[1] = qrcodeStructureappendM - 1;
  107.                 abyte1[1] = 4;
  108.                 ai[2] = qrcodeStructureappendN - 1;
  109.                 abyte1[2] = 4;
  110.                 ai[3] = qrcodeStructureappendParity;
  111.                 abyte1[3] = 8;
  112.                 j = 4;
  113.         }
  114.         abyte1[j] = 4;
  115.         //int* ai1=new int[41];
  116.         int ai1[41];
  117.         int k;
  118.         switch(qrcodeEncodeMode)
  119.         {
  120.         case 65: // 'A'
  121.                          /*ai1 = (new int[] {
  122.                          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123.                          2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  124.                          2, 2, 2, 2, 2, 2, 2, 4, 4, 4,
  125.                          4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  126.                          4
  127.         });*/
  128.                 {
  129.                         for(int ii=0;ii<41;ii++)
  130.                         {
  131.                                 if(ii<=9)ai1[ii]=0;
  132.                                 else if(ii<=26)ai1[ii]=2;
  133.                                 else ai1[ii]=4;
  134.                         }
  135.                        
  136.                         ai[j] = 2;
  137.                         j++;
  138.                         ai[j] = i;
  139.                         abyte1[j] = 9;
  140.                         k = j;
  141.                         j++;
  142.                         for(int l = 0; l < i; l++)
  143.                         {
  144.                                 char c = (char)abyte0[l];
  145.                                 char byte0 = 0;
  146.                                 if(c >= '0' && c < ':')
  147.                                         byte0 = (char)(c - 48);
  148.                                 else
  149.                                         if(c >= 'A' && c < '[')
  150.                                         {
  151.                                                 byte0 = (char)(c - 55);
  152.                                         } else
  153.                                         {
  154.                                                 if(c == ' ')
  155.                                                         byte0 = 36;
  156.                                                 if(c == '

  157. )
  158.                                                         byte0 = 37;
  159.                                                 if(c == '%')
  160.                                                         byte0 = 38;
  161.                                                 if(c == '*')
  162.                                                         byte0 = 39;
  163.                                                 if(c == '+')
  164.                                                         byte0 = 40;
  165.                                                 if(c == '-')
  166.                                                         byte0 = 41;
  167.                                                 if(c == '.')
  168.                                                         byte0 = 42;
  169.                                                 if(c == '/')
  170.                                                         byte0 = 43;
  171.                                                 if(c == ':')
  172.                                                         byte0 = 44;
  173.                                         }
  174.                                         if(l % 2 == 0)
  175.                                         {
  176.                                                 ai[j] = byte0;
  177.                                                 abyte1[j] = 6;
  178.                                         } else
  179.                                         {
  180.                                                 ai[j] = ai[j] * 45 + byte0;
  181.                                                 abyte1[j] = 11;
  182.                                                 if(l < i - 1)
  183.                                                         j++;
  184.                                         }
  185.                         }                       
  186.                         j++;                       
  187.                 }               
  188.                 break;               
  189.         case 78: // 'N'
  190.                          /*ai1 = (new int[] {
  191.                          0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  192.                          2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  193.                          2, 2, 2, 2, 2, 2, 2, 4, 4, 4,
  194.                          4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  195.                          4
  196.         });*/
  197.                 {
  198.                         for(int ii=0;ii<41;ii++)
  199.                         {
  200.                                 if(ii<=9)ai1[ii]=0;
  201.                                 else if(ii<=26)ai1[ii]=2;
  202.                                 else ai1[ii]=4;
  203.                         }
  204.                         ai[j] = 1;
  205.                         j++;
  206.                         ai[j] = i;
  207.                         abyte1[j] = 10;
  208.                         k = j;
  209.                         j++;
  210.                         for(int i1 = 0; i1 < i; i1++)
  211.                                 if(i1 % 3 == 0)
  212.                                 {
  213.                                         ai[j] = abyte0[i1] - 48;
  214.                                         abyte1[j] = 4;
  215.                                 } else
  216.                                 {
  217.                                         ai[j] = ai[j] * 10 + (abyte0[i1] - 48);
  218.                                         if(i1 % 3 == 1)
  219.                                         {
  220.                                                 abyte1[j] = 7;
  221.                                         } else
  222.                                         {
  223.                                                 abyte1[j] = 10;
  224.                                                 if(i1 < i - 1)
  225.                                                         j++;
  226.                                         }
  227.                                 }
  228.                                
  229.                                 j++;
  230.                                
  231.                 }               
  232.                 break;                       
  233.         default:
  234.         /*ai1 = (new int[] {
  235.                                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  236.                 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  237.                 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  238.                 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  239.                 8
  240.                 });*/               
  241.                 for(int ii=0;ii<41;ii++)
  242.                 {
  243.                         if(ii<=9)ai1[ii]=0;                       
  244.                         else ai1[ii]=8;
  245.                 }
  246.                 ai[j] = 4;
  247.                 j++;
  248.                 ai[j] = i;
  249.                 abyte1[j] = 8;
  250.                 k = j;
  251.                 j++;
  252.                 for(int j1 = 0; j1 < i; j1++)
  253.                 {
  254.                         ai[j1 + j] = abyte0[j1] & 255;
  255.                         abyte1[j1 + j] = 8;
  256.                 }
  257.                
  258.                 j += i;
  259.                 break;
  260.         }
  261.         int k1 = 0;
  262.         for(int l1 = 0; l1 < j; l1++)
  263.             k1 += abyte1[l1];
  264.                
  265.         char byte1;
  266.         switch(qrcodeErrorCorrect)
  267.         {
  268.         case 76: // 'L'
  269.             byte1 = 1;
  270.             break;
  271.                        
  272.         case 81: // 'Q'
  273.             byte1 = 3;
  274.             break;
  275.                        
  276.         case 72: // 'H'
  277.             byte1 = 2;
  278.             break;
  279.                        
  280.         default:
  281.             byte1 = 0;
  282.             break;
  283.         }

  284.         //int ai2[4][41] = {
  285.                 int ai2[4][41] = {
  286.             {
  287.                                         0, 128, 224, 352, 512, 688, 864, 992, 1232, 1456,
  288.                                         1728, 2032, 2320, 2672, 2920, 3320, 3624, 4056, 4504, 5016,
  289.                                         5352, 5712, 6256, 6880, 7312, 8000, 8496, 9024, 9544, 10136,
  290.                                         10984, 11640, 12328, 13048, 13800, 14496, 15312, 15936, 16816, 17728,
  291.                                         18672
  292.             },
  293.                         {
  294.                                         0, 152, 272, 440, 640, 864, 1088, 1248, 1552, 1856,
  295.                                         2192, 2592, 2960, 3424, 3688, 4184, 4712, 5176, 5768, 6360,
  296.                                         6888, 7456, 8048, 8752, 9392, 10208, 10960, 11744, 12248, 13048,
  297.                                         13880, 14744, 15640, 16568, 17528, 18448, 19472, 20528, 21616, 22496,
  298.                                         23648
  299.                                 },
  300.                                 {
  301.                                                 0, 72, 128, 208, 288, 368, 480, 528, 688, 800,
  302.                                                         976, 1120, 1264, 1440, 1576, 1784, 2024, 2264, 2504, 2728,
  303.                                                         3080, 3248, 3536, 3712, 4112, 4304, 4768, 5024, 5288, 5608,
  304.                                                         5960, 6344, 6760, 7208, 7688, 7888, 8432, 8768, 9136, 9776,
  305.                                                         10208
  306.                                         },
  307.                                         {
  308.                                                         0, 104, 176, 272, 384, 496, 608, 704, 880, 1056,
  309.                                                                 1232, 1440, 1648, 1952, 2088, 2360, 2600, 2936, 3176, 3560,
  310.                                                                 3880, 4096, 4544, 4912, 5312, 5744, 6032, 6464, 6968, 7288,
  311.                                                                 7880, 8264, 8920, 9368, 9848, 10288, 10832, 11408, 12016, 12656,
  312.                                                                 13328
  313.                                                 }
  314.         };
  315.         int i2 = 0;
  316.         if(qrcodeVersion == 0)
  317.         {
  318.             qrcodeVersion = 1;
  319.             for(int j2 = 1; j2 <= 40; j2++)
  320.             {
  321.                 if(ai2[byte1][j2] >= k1 + ai1[qrcodeVersion])
  322.                 {
  323.                     i2 = ai2[byte1][j2];
  324.                     break;
  325.                 }
  326.                 qrcodeVersion++;
  327.             }
  328.                        
  329.         } else
  330.         {
  331.             i2 = ai2[byte1][qrcodeVersion];
  332.         }
  333.         k1 += ai1[qrcodeVersion];
  334.         abyte1[k] += ai1[qrcodeVersion];
  335.         int ai3[] = {
  336.             0, 26, 44, 70, 100, 134, 172, 196, 242, 292,
  337.                                 346, 404, 466, 532, 581, 655, 733, 815, 901, 991,
  338.                                 1085, 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051,
  339.                                 2185, 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532,
  340.                                 3706
  341.         };
  342.         int k2 = ai3[qrcodeVersion];
  343.         int l2 = 17 + (qrcodeVersion << 2);
  344.         int ai4[] = {
  345.             0, 0, 7, 7, 7, 7, 7, 0, 0, 0,
  346.                                 0, 0, 0, 0, 3, 3, 3, 3, 3, 3,
  347.                                 3, 4, 4, 4, 4, 4, 4, 4, 3, 3,
  348.                                 3, 3, 3, 3, 3, 0, 0, 0, 0, 0,
  349.                                 0
  350.         };
  351.         int i3 = ai4[qrcodeVersion] + (k2 << 3);
  352.         char* abyte2 = new char[i3];
  353.         char* abyte3 = new char[i3];
  354.         char* abyte4 = new char[i3];               
  355.                 char abyte5[15];
  356.                 char abyte6[15];
  357.                 char abyte7[1];
  358.                 char abyte8[128];
  359.                
  360.                 memset(abyte2,0,i3);
  361.                 memset(abyte3,0,i3);
  362.                 memset(abyte4,0,i3);
  363.                 memset(abyte5,0,15);
  364.                 memset(abyte6,0,15);
  365.                 memset(abyte7,0,1);
  366.                 memset(abyte8,0,128);
  367.                
  368.         try
  369.         {
  370.             //CString s = "qrcode_data/qrv" + Integer.toString(qrcodeVersion) + "_" + Integer.toString(byte1) + ".dat";
  371.                         CString s;
  372.                         s.Format("qrcode_data/qrv%d_%d.dat",qrcodeVersion,byte1);                       
  373.                        
  374.                         //CFile f(s, CFile::modeCreate | CFile::modeWrite );       
  375.                         CFile f(s, CFile::modeRead);
  376.                         try
  377.                         {                               
  378.                                 f.Read(abyte2, i3);
  379.                                 f.Read(abyte3, i3);
  380.                                 f.Read(abyte4, i3);
  381.                                 f.Read(abyte5, 15);
  382.                                 f.Read(abyte6, 15);
  383.                                 f.Read(abyte7, 1);
  384.                                 f.Read(abyte8, 128);
  385.                                 f.Close();
  386.                        
  387.                         }
  388.                         catch(...)
  389.                         {                       
  390.                                 f.Close();
  391.                         }
  392.                        
  393.                         //写临时文件
  394.             /*InputStream inputstream = (com.swetake.util.Qrcode.class).getResourceAsStream(s);
  395.             BufferedInputStream bufferedinputstream = new BufferedInputStream(inputstream);
  396.             bufferedinputstream.read(abyte2);
  397.             bufferedinputstream.read(abyte3);
  398.             bufferedinputstream.read(abyte4);
  399.             bufferedinputstream.read(abyte5);
  400.             bufferedinputstream.read(abyte6);
  401.             bufferedinputstream.read(abyte7);
  402.             bufferedinputstream.read(abyte8);
  403.             bufferedinputstream.close();
  404.             inputstream.close();*/
  405.         }
  406.         catch(CException exception)
  407.         {
  408.                         //AfxMessageBox(exception.)
  409.             //exception.printStackTrace();
  410.         }
  411.         int j3 = 1;
  412.         for(char byte2 = 1; byte2 < 128; byte2++)
  413.         {
  414.             if(abyte8[byte2] != 0)
  415.                 continue;
  416.             j3 = byte2;
  417.             break;
  418.         }
  419.                
  420.         char* abyte9 = new char[j3+1];
  421.                 memset(abyte9,0,j3);
  422.                 memcpy(abyte9,abyte8,j3);
  423.                 abyte9[j3]=0;
  424.         //System.arraycopy(abyte8, 0, abyte9, 0, j3);
  425.         char abyte10[15] = {
  426.                         0, 1, 2, 3, 4, 5, 7, 8, 8, 8,
  427.                                 8, 8, 8, 8, 8
  428.         };
  429.         char abyte11[15] = {
  430.                         8, 8, 8, 8, 8, 8, 8, 8, 7, 5,
  431.                                 4, 3, 2, 1, 0
  432.         };
  433.         int k3 = i2 >> 3;
  434.         int l3 = 4 * qrcodeVersion + 17;
  435.         int i4 = l3 * l3;
  436.         char* abyte12 = new char[i4 + l3];
  437.                 memset(abyte12,0,i4 + l3);
  438.         try
  439.         {
  440.             //CString s1 = "qrcode_data/qrvfr" + Integer.toString(qrcodeVersion) + ".dat";
  441.                         CString s1;
  442.                         s1.Format("qrcode_data/qrvfr%d.dat",qrcodeVersion);
  443.                         //CFile f1(s1, CFile::modeCreate | CFile::modeWrite );       
  444.                         CFile f1(s1, CFile::modeRead);
  445.                         try
  446.                         {                               
  447.                                 f1.Read(abyte12, i4 + l3);
  448.                                 f1.Close();
  449.                         }
  450.                         catch(...)
  451.                         {                       
  452.                                 f1.Close();
  453.                         }         
  454.         }
  455.         catch(CException exception1)
  456.         {
  457.                         // exception1.printStackTrace();
  458.         }
  459.         if(k1 <= i2 - 4)
  460.         {
  461.             ai[j] = 0;
  462.             abyte1[j] = 4;
  463.         } else
  464.                         if(k1 < i2)
  465.                         {
  466.                                 ai[j] = 0;
  467.                                 abyte1[j] = (char)(i2 - k1);
  468.                         } else
  469.                                 if(k1 > i2)
  470.                                         TRACE("overflow");
  471.                                 //AfxMessageBox()
  472.                                 //        System.out.println("overflow");
  473.                 int iLret1=0;
  474.           char* abyte13 = divideDataBy8Bits(ai, abyte1, k3,i + 32,iLret1);
  475.                

  476.                 char* abyte14 = calculateRSECC(abyte13, abyte7[0], abyte9, k3, k2,iLret1,j3);               
  477.        
  478.                 char** abyte15=new char*[l3];
  479.                 for( n1 = 0; n1 <l3; n1++)
  480.                 {
  481.                         //abyte15[n1] = new char[l3];
  482.                         abyte15[n1] = new char[l3];               
  483.                 }
  484.                
  485.                 for(int j4 = 0; j4 < l3; j4++)
  486.                 {
  487.                         for(int k4 = 0; k4 < l3; k4++)
  488.                                 abyte15[k4][j4] = 0;                       
  489.                 }               

  490.                 for(int l4 = 0; l4 < k2; l4++)
  491.                 {
  492.                         char byte3 = abyte14[l4];
  493.                         for(int j5 = 7; j5 >= 0; j5--)
  494.                         {
  495.                                 int l5 = l4 * 8 + j5;
  496.                                 //if((abyte2[l5]==0)&&(abyte3[l5]==34)) AfxMessageBox("1");
  497.                                 abyte15[abyte2[l5] & 255][abyte3[l5] & 255] = (char)(255 * (byte3 & 1) ^ abyte4[l5]);
  498.                                 //byte3 = (char)((byte3 & 255) >>> 1);
  499.                                 byte3 = (char)((byte3 & 255) >> 1);
  500.                                 //byte3 = (char)((unsigned char)((byte3 & 255) >> 1));
  501.                         }                                       
  502.                 }

  503.                
  504.        
  505.                 /*for( j4 = 0; j4 < l3; j4++)
  506.                 {
  507.                         TestMsg(abyte15[j4],l3);                       
  508.                 }*/
  509.                
  510.                 for(int i5 = ai4[qrcodeVersion]; i5 > 0; i5--)
  511.                 {
  512.                         int k5 = (i5 + k2 * 8) - 1;
  513.                         abyte15[abyte2[k5] & 255][abyte3[k5] & 255] = (char)(255 ^ abyte4[k5]);
  514.                 }
  515.                
  516.        
  517.                 char byte4 = selectMask((char**)abyte15, ai4[qrcodeVersion] + k2 * 8,l3);
  518.                 char byte5 = (char)(1 << byte4);
  519.                 char byte6 = (char)(byte1 << 3 | byte4);
  520.                 CString as[32] = {
  521.                         "101010000010010", "101000100100101", "101111001111100", "101101101001011", "100010111111001", "100000011001110", "100111110010111", "100101010100000", "111011111000100", "111001011110011",
  522.                                 "111110110101010", "111100010011101", "110011000101111", "110001100011000", "110110001000001", "110100101110110", "001011010001001", "001001110111110", "001110011100111", "001100111010000",
  523.                                 "000011101100010", "000001001010101", "000110100001100", "000100000111011", "011010101011111", "011000001101000", "011111100110001", "011101000000110", "010010010110100", "010000110000011",
  524.                                 "010111011011010", "010101111101101"
  525.                 };
  526.                 for(int i6 = 0; i6 < 15; i6++)
  527.                 {                       
  528.                         char byte7=as[byte6][i6]-48;                       
  529.                         abyte15[abyte10[i6] & 255][abyte11[i6] & 255] = (char)(byte7 * 255);
  530.                         abyte15[abyte5[i6] & 255][abyte6[i6] & 255] = (char)(byte7 * 255);                       
  531.                 }

  532.                 //boolean [][]aflag1 = new boolean[l3][l3];
  533.                 bool** aflag1 = new bool*[l3];        //\\\\\\\\\\\                       
  534.                 for( n1 = 0; n1 <l3; n1++)
  535.                 {
  536.                         aflag1[n1] = new bool[l3];
  537.                 }
  538.                 int j6 = 0;
  539.                 for(int k6 = 0; k6 < l3; k6++)
  540.                 {
  541.                         for(int l6 = 0; l6 < l3; l6++)
  542.                         {
  543.                                 if((abyte15[l6][k6] & byte5) != 0 || abyte12[j6] == 49)
  544.                                         aflag1[l6][k6] = true;
  545.                                 else
  546.                                         aflag1[l6][k6] = false;
  547.                                 j6++;
  548.                         }
  549.                        
  550.                         j6++;
  551.                 }
  552.                 //delete[] aflag1;
  553.                 iLenRet=l3;
  554.                 /************************************************************************/
  555.                 /*                                删除new 变量                                                                                         */
  556.                 /************************************************************************/
  557.                 delete []ai;
  558.                 delete []abyte1;
  559.                 delete []abyte2;
  560.                 delete []abyte3;
  561.                 delete []abyte4;
  562.                 delete []abyte9;
  563.                 delete []abyte12;
  564.                 delete []abyte13;
  565.                 delete []abyte14;                               
  566.                
  567.                 for( n1 = 0; n1 <l3; n1++)
  568.                 {
  569.                         delete []abyte15[n1];
  570.                 }
  571.                 delete[] abyte15;
  572.                 return aflag1;
  573. }
  574.        
  575.         //char* Qrcode::divideDataBy8Bits(int ai[], char abyte0[],
  576. char* Qrcode::divideDataBy8Bits(int* ai, char* abyte0,
  577.                 int i,int iLen,int& iLRet)//int i,int j)               
  578.     {
  579.         //int iLen = abyte0.length; iLenAi=ai..length
  580.                 int j=iLen;
  581.         int l = 0;
  582.         int i1 = 8;
  583.         int j1 = 0;
  584.         //if(j == ai.length);
  585.         for(int i2 = 0; i2 < j; i2++)
  586.             j1 += abyte0[i2];
  587.                
  588.         int k = (j1 - 1) / 8 + 1;
  589.         char* abyte1 = new char[i];
  590.                 memset(abyte1,0,i);
  591.         for(int j2 = 0; j2 < k; j2++)
  592.             abyte1[j2] = 0;
  593.                
  594.         for(int k2 = 0; k2 < j; k2++)
  595.         {
  596.             int k1 = ai[k2];
  597.             int l1 = abyte0[k2];
  598.             bool flag = true;
  599.             if(l1 == 0)
  600.                 break;
  601.             while(flag)
  602.                 if(i1 > l1)
  603.                 {
  604.                     abyte1[l] = (char)(abyte1[l] << l1 | k1);
  605.                     i1 -= l1;
  606.                     flag = false;
  607.                 } else
  608.                 {
  609.                     l1 -= i1;
  610.                     abyte1[l] = (char)(abyte1[l] << i1 | k1 >> l1);
  611.                     if(l1 == 0)
  612.                     {
  613.                         flag = false;
  614.                     } else
  615.                     {
  616.                         k1 &= (1 << l1) - 1;
  617.                         flag = true;
  618.                     }
  619.                     l++;
  620.                     i1 = 8;
  621.                 }
  622.         }
  623.                
  624.         if(i1 != 8)
  625.             abyte1[l] = (char)(abyte1[l] << i1);
  626.         else
  627.             l--;
  628.         if(l < i - 1)
  629.         {
  630.             for(bool flag1 = true; l < i - 1; flag1 = !flag1)
  631.             {
  632.                 l++;
  633.                 if(flag1)
  634.                     abyte1[l] = -20;
  635.                 else
  636.                     abyte1[l] = 17;
  637.             }
  638.                        
  639.         }
  640.                 iLRet=i;
  641.         return abyte1;
  642.     }
  643.        
  644.     //private
  645.         //char* Qrcode::calculateRSECC(char abyte0[], char byte0, char abyte1[], int i, int j,
  646. char* Qrcode::calculateRSECC(char* abyte0, char byte0, char* abyte1, int i, int j,
  647.                 int iLen0,int iLen1)
  648.     {

  649.         //iLen1 abyte1.length  ; iLen0 abyte0.length
  650.         char** abyte2 = new char*[256];
  651.                 //char abyte2[][] = new char[256][byte0];
  652.                 int n1;
  653.                 for(n1=0;n1<256;n1++){
  654.                         abyte2[n1]=new char[byte0];
  655.                         memset(abyte2[n1],0,byte0);
  656.                 }
  657.        
  658.         try
  659.         {            
  660.                         CString s;
  661.                         s.Format("qrcode_data/rsc%d.dat" ,byte0);                                               
  662.                         CFile f1(s, CFile::modeRead);
  663.                         try
  664.                         {                       
  665.                                 //for(int i2 = 0; i2 < 256; i2++)   bufferedinputstream.read(abyte2[i2]);
  666.                                 for(int i2 = 0; i2 < 256; i2++)               
  667.                                 f1.Read(abyte2[i2], byte0);
  668.                                 f1.Close();
  669.                         }
  670.                         catch(...)
  671.                         {                       
  672.                                 f1.Close();
  673.                         }
  674.         }
  675.         catch(CException exception)
  676.         {
  677.             //exception.printStackTrace();
  678.         }
  679.         bool flag = false;
  680.         int i1 = 0;
  681.         int k1 = 0;      
  682.                
  683.                 char** abyte3 = new char*[iLen1];
  684.         char* abyte4 = new char[j];
  685.                 memset(abyte4,0,j);               
  686.                 memcpy(abyte4, abyte0, iLen0);
  687.       
  688.                 int ab3Length=0;
  689.                 for(int k = 0; k < iLen1; k++){
  690.                         ab3Length= (abyte1[k] & 255) - byte0;
  691.             abyte3[k] = new char[(abyte1[k] & 255) - byte0];
  692.                         memset(abyte3[k],0,(abyte1[k] & 255) - byte0);
  693.                 }

  694.        for(int l = 0; l < i; l++)
  695.         {
  696.          abyte3[k1][i1] = abyte0[l];
  697.                  if(++i1 >= (abyte1[k1] & 255) - byte0)
  698.             {
  699.                 i1 = 0;
  700.                 k1++;
  701.             }
  702.         }
  703.          /* for(int kkk=0;kkk<ab3Length;kkk++)
  704.           {
  705.         FILE *fp=NULL;
  706.         fp=fopen("C:\\test.txt","at+");       
  707.         fprintf(fp,"%d:  %d\r\n",kkk,abyte3[3][kkk]);
  708.         fclose(fp);
  709.           }*/

  710.                
  711.         //for(int l1 = 0; l1 < abyte1.length; l1++)
  712.                 for(int l1 = 0; l1 < iLen1; l1++)
  713.         {
  714.             //char abyte5[] = (char[])abyte3[l1].clone();                       
  715.                         int iLen5=(abyte1[l1] & 255) - byte0;
  716.                         char* abyte5=new char[iLen5];
  717.                         memset(abyte5,0,iLen5);
  718.                         for (n1=0;n1<iLen5;n1++)
  719.                         {
  720.                                 abyte5[n1]=abyte3[l1][n1];
  721.                         }
  722.                         //char* abyte5 = abyte3[l1];
  723.                        
  724.             int j2 = abyte1[l1] & 255;
  725.             int k2 = j2 - byte0;
  726.             for(int j1 = k2; j1 > 0; j1--)
  727.             {
  728.                 char byte1 = abyte5[0];
  729.                 if(byte1 != 0)
  730.                 {
  731.                     //char abyte6[] = new char[abyte5.length - 1];
  732.                                         char* abyte6 = new char[iLen5];
  733.                                         memcpy(abyte6,abyte5+1,iLen5-1);
  734.                                         abyte6[iLen5-1]=0;
  735.                     //System.arraycopy(abyte5, 1, abyte6, 0, iLen5 - 1);
  736.                     //char abyte9[] = abyte2[byte1 & 255];
  737.                                         char* abyte9 = abyte2[byte1 & 255];
  738.                                         int iLret1;
  739.                     abyte5 = calculateByteArrayBits(abyte6, abyte9, "xor",iLen5-1,byte0,iLret1);
  740.                                         //abyte5[iLen5-1]=0;                                       
  741.                                         delete [] abyte6;
  742.                 } else                               
  743.                                         if(byte0 < iLen5)
  744.                                         {
  745.                                                 //char abyte7[] = new char[abyte5.length - 1];
  746.                                                 char* abyte7 = new char[iLen5 - 1];
  747.                                                 memcpy(abyte7,abyte5+1,iLen5-1);
  748.                                                 for(n1=0;n1<iLen5-1;n1++)
  749.                                                         abyte5[n1]=abyte7[n1];
  750.                                                 //abyte5 = abyte7;
  751.                                                 delete []abyte7;
  752.                                         } else
  753.                                         {                                               
  754.                                                 //char abyte8[] = new char[byte0];
  755.                                                 char* abyte8 = new char[byte0];
  756.                                                 memcpy(abyte8,abyte5+1,iLen5-1);                                               
  757.                                         //        abyte8[byte0 - 1] = 0;       
  758.                                                 for(n1=0;n1<byte0;n1++)
  759.                                                         abyte5[n1]=abyte8[n1];
  760.                                                 //abyte5 = abyte8;
  761.                                                 delete []abyte8;
  762.                                         }

  763.             }
  764.                         memcpy(abyte4+iLen0+l1*byte0,abyte5,byte0);       
  765.                         delete []abyte5;
  766.         }
  767.        
  768.                 for(n1=0;n1<256;n1++){                       
  769.                         delete []abyte2[n1];
  770.                 }
  771.                 delete []abyte2;
  772.                

  773.                 for(n1=0;n1<iLen1;n1++){                       
  774.                         delete []abyte3[n1];
  775.                 }
  776.                 delete []abyte3;

  777.         return abyte4;
  778.     }
  779.        
  780.     //private
  781. char* Qrcode::calculateByteArrayBits(char* abyte0, char* abyte1, CString s,
  782.                 int iLen0,int iLen1,int& iLRet)
  783.     {
  784.                 char* abyte3;//
  785.                 char* abyte4;       
  786.                 int i,j,n1;
  787.                 if(iLen0 > iLen1)
  788.         {            
  789.                         i=iLen0;                       
  790.                         j=iLen1;                       
  791.                         abyte3=new char[i+1];
  792.                         abyte4=new char[j+1];                       
  793.                         memset(abyte3,0,i+1);
  794.                         for (n1=0;n1<i;n1++){
  795.                                 abyte3[n1]=abyte0[n1];                       
  796.                         }
  797.                         memset(abyte4,0,j+1);
  798.                         for (n1=0;n1<j;n1++)
  799.                         {
  800.                                 abyte4[n1]=abyte1[n1];                       
  801.                         }
  802.         } else
  803.         {            
  804.                         i=iLen1;               
  805.                         j=iLen0;       
  806.                         abyte3=new char[i+1];
  807.                         abyte4=new char[j+1];
  808.                         memset(abyte3,0,i+1);
  809.                         for (n1=0;n1<i;n1++)
  810.                         {                               
  811.                                 abyte3[n1]=abyte1[n1];                       
  812.                         }
  813.                         memset(abyte4,0,j+1);
  814.                         for (n1=0;n1<j;n1++)
  815.                         {
  816.                                 abyte4[n1]=abyte0[n1];                       
  817.                         }
  818.         }

  819.                 char* abyte2 = new char[i+1];
  820.                 memset(abyte2,0,i+1);
  821.         for(int k = 0; k < i; k++){
  822.             if(k < j)
  823.             {
  824.                 if(s == "xor")
  825.                     abyte2[k] = (char)(abyte3[k] ^ abyte4[k]);
  826.                 else
  827.                     abyte2[k] = (char)(abyte3[k] | abyte4[k]);
  828.             } else
  829.             {
  830.                 abyte2[k] = abyte3[k];
  831.             }                       
  832.                        
  833.                 }
  834.                 delete []abyte3;
  835.                 delete []abyte4;               
  836.                 return abyte2;
  837.         }
  838.        

  839. void Qrcode::TestMsg(char* myStr,int length)
  840. {
  841. //int kkk = strlen(myStr);
  842. for(int iii=0;iii<length;iii++)
  843. {
  844.         FILE *fp=NULL;
  845.         fp=fopen("C:\\test.txt","at+");       
  846.         fprintf(fp,"%d:  %d\r\n",iii,myStr[iii]);
  847.         fclose(fp);
  848. }
  849. }

  850. char Qrcode::selectMask(char** abyte0, int i,int iLen0)
  851. {
  852.         //iLen0 abyte0.GetLength();
  853.         //int j = abyte0.GetLength();               
  854.         int j = iLen0;
  855.         int ai[] = {
  856.                 0, 0, 0, 0, 0, 0, 0, 0
  857.         };


  858.         int ai1[] = {
  859.                 0, 0, 0, 0, 0, 0, 0, 0
  860.         };
  861.         int ai2[] = {
  862.                 0, 0, 0, 0, 0, 0, 0, 0
  863.         };
  864.         int ai3[] = {
  865.                 0, 0, 0, 0, 0, 0, 0, 0
  866.         };
  867.         int k = 0;
  868.         int l = 0;
  869.         int ai4[] = {
  870.                 0, 0, 0, 0, 0, 0, 0, 0
  871.         };
  872.        
  873.         for(int i1 = 0; i1 < j; i1++)
  874.         {
  875.                 int ai5[] = {
  876.                         0, 0, 0, 0, 0, 0, 0, 0
  877.                 };
  878.                 int ai6[] = {
  879.                         0, 0, 0, 0, 0, 0, 0, 0
  880.                 };
  881.                 bool aflag[] = {
  882.                         false, false, false, false, false, false, false, false
  883.                 };
  884.                 bool aflag1[] = {
  885.                         false, false, false, false, false, false, false, false
  886.                 };
  887.        
  888. for(int l1 = 0; l1 < j; l1++)
  889. {
  890. if(l1 > 0 && i1 > 0)
  891. {
  892.         k = abyte0[l1][i1] & abyte0[l1 - 1][i1] & abyte0[l1][i1 - 1] & abyte0[l1 - 1][i1 - 1] & 255;
  893.         l = abyte0[l1][i1] & 255 | abyte0[l1 - 1][i1] & 255 | abyte0[l1][i1 - 1] & 255 | abyte0[l1 - 1][i1 - 1] & 255;
  894. }
  895.                
  896.       for(int j2 = 0; j2 < 8; j2++)
  897.                         {
  898.                                 // ai5[j2] = (ai5[j2] & 63) << 1 | (abyte0[l1][i1] & 255) >>> j2 & 1;
  899.                                 // ai6[j2] = (ai6[j2] & 63) << 1 | (abyte0[i1][l1] & 255) >>> j2 & 1;//高位自动补零
  900.                                
  901.                                 int n=abyte0[l1][i1] & 255;
  902.                                 int x=j2;                               

  903.                                 ai5[j2] = (ai5[j2] & 63) << 1 |(n>>x)&((int)pow(2,32-x)-1) & 1;
  904.                                 ai6[j2] = (ai6[j2] & 63) << 1 |(n>>x)&((int)pow(2,32-x)-1) & 1;
  905.                                 //ai5[j2] = (ai5[j2] & 63) << 1 |((abyte0[l1][i1] & 255))>> j2 & 1;
  906.                                 //ai6[j2] = (ai6[j2] & 63) << 1 |((abyte0[i1][l1] & 255))>> j2 & 1;
  907.                                 // ai5[j2] = (ai5[j2] & 63) << 1 | (abyte0[l1][i1] & 255) >> j2 & 1;
  908.                                 // ai6[j2] = (ai6[j2] & 63) << 1 | (abyte0[i1][l1] & 255) >> j2 & 1;//高位自动补零
  909.                           
  910.                                
  911.                                 if((abyte0[l1][i1] & 1 << j2) != 0)
  912.                                         ai4[j2]++;
  913.                                 if(ai5[j2] == 93)
  914.                                         ai2[j2] += 40;
  915.                                 if(ai6[j2] == 93)
  916.                                         ai2[j2] += 40;
  917.                                 if(l1 > 0 && i1 > 0)
  918.                                 {
  919.                                         if((k & 1) != 0 || (l & 1) == 0)
  920.                                                 ai1[j2] += 3;
  921.                                         k >>= 1;
  922.                                         l >>= 1;
  923.                                 }
  924.                                 if((ai5[j2] & 31) == 0 || (ai5[j2] & 31) == 31)
  925.                                 {
  926.                                         if(l1 > 3)
  927.                                                 if(aflag[j2])
  928.                                                 {
  929.                                                         ai[j2]++;
  930.                                                 } else
  931.                                                 {
  932.                                                         ai[j2] += 3;
  933.                                                         aflag[j2] = true;
  934.                                                 }
  935.                                 } else
  936.                                 {
  937.                                         aflag[j2] = false;
  938.                                 }
  939.                                 if((ai6[j2] & 31) == 0 || (ai6[j2] & 31) == 31)
  940.                                 {
  941.                                         if(l1 > 3)
  942.                                                 if(aflag1[j2])
  943.                                                 {
  944.                                                         ai[j2]++;
  945.                                                 } else
  946.                                                 {
  947.                                                         ai[j2] += 3;
  948.                                                         aflag1[j2] = true;
  949.                                                 }
  950.                                 } else
  951.                                 {
  952.                                         aflag1[j2] = false;
  953.                                 }
  954.                         }
  955.                        
  956.                 }
  957.                        
  958.         }
  959.        

  960.         int j1 = 0;
  961.         char byte0 = 0;
  962.         int ai7[] = {
  963.                 90, 80, 70, 60, 50, 40, 30, 20, 10, 0,
  964.                         0, 10, 20, 30, 40, 50, 60, 70, 80, 90,
  965.                         90
  966.         };
  967.         for(int k1 = 0; k1 < 8; k1++)
  968.         {
  969.                 ai3[k1] = ai7[(20 * ai4[k1]) / i];
  970.                 int i2 = ai[k1] + ai1[k1] + ai2[k1] + ai3[k1];
  971.                 if(i2 < j1 || k1 == 0)
  972.                 {
  973.                         byte0 = (char)k1;
  974.                         j1 = i2;
  975.                 }
  976.         }
  977.        
  978.         return byte0;
  979. }
复制代码


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:145151 发表于 2016-10-30 22:49 | 只看该作者
正在学习二维码,正是我需要的
回复

使用道具 举报

板凳
ID:171025 发表于 2017-3-15 19:58 | 只看该作者
VC的二维码真心是少,希望这个对我有参考价值
回复

使用道具 举报

地板
ID:183336 发表于 2017-3-25 16:31 | 只看该作者
最近在处理QR码打印的工作。没有思路了。。。
回复

使用道具 举报

5#
ID:183506 发表于 2017-3-26 13:19 | 只看该作者

 初学者的好资料,51黑有你更精彩
回复

使用道具 举报

6#
ID:227859 发表于 2017-8-16 10:02 | 只看该作者

最近在处理QR码打印的工作。没有思路了。。。
回复

使用道具 举报

7#
ID:227859 发表于 2017-8-16 10:13 | 只看该作者

 初来乍到,看看这个能不能用
回复

使用道具 举报

8#
ID:246457 发表于 2017-11-6 12:39 | 只看该作者
谢谢分享,刚刚开始要做一个二维码的程序
回复

使用道具 举报

9#
ID:88691 发表于 2017-11-19 16:17 | 只看该作者
点击生成是会提示如下错误,暂时尚未找到原因。

回复

使用道具 举报

10#
ID:347834 发表于 2018-6-8 20:24 | 只看该作者
能不能用啊
回复

使用道具 举报

11#
ID:668403 发表于 2019-12-19 15:18 | 只看该作者
正在找这个资料,希望有帮助
回复

使用道具 举报

12#
ID:434018 发表于 2021-11-7 14:48 | 只看该作者
Very Good Thanks!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表