The realization of the C language of the two-dimensional code

Source: Internet
Author: User

QR code in today is quite popular, making two-dimensional code is not difficult, there are many Web sites to make two-dimensional code, input information, immediately converted to two-dimensional code. However, it is not so easy to make a QR code of our own according to the information. The online rough find the next source, almost exclusively is the java/c# version, which for the STM32 chip project does not help much. Finally, I found the Qrencode software package on Linux and ported it over.


First, the primary knowledge of the two-dimensional code

A) Two-dimensional code can store 1850 bytes of information, you can save numbers, letters, men, images

b) QR code three rectangles are used for positioning, the rectangle style can be changed, the whole picture can even be reversed.

c) has redundant information, can choose up to 50% based on fault tolerance rate

D) Because of the redundancy relationship, the middle and lower right corner of the QR code can be placed in the pattern

f) The algorithm of two-dimensional code will produce different patterns according to the difference of fault tolerance rate.


Forage Two-dimensional code: Hello


The two-dimensional code of the joint graph: Hello



It is clear that the algorithm for the two sites is different, but contains the same information. The content can be scanned with any scanning end


Second, the transplant preparation:

A) qrencode-3.4.4.tar.gz as a transplant source Baidu disk: http://pan.baidu.com/s/1ntyvf7r

b) stm32f429i-discovery Exploration Board

c) to transplant the Stemwin routine see the official routine stm32cube_fw_f4_v1.4.0 directory \projects\stm32f429i-discovery\applications\stemwin


Third, the transplant process

A) open the project with Stemwin with IAR. Create a new QRCode Project subdirectory and add all the qrencode.tar.gz. c files that you extracted.




b) Open the project directory in the Windows folder Stm32cube_fw_f4_v1.4.0\projects\stm32f429i-discovery\applications\stemwin\qrcode

Copy all qrencode.tar.gz extracted. c files into the SRC folder

Copy all qrencode.tar.gz extracted. h files into the INC folder

c) Save the compilation first. Reported a lot of errors, it is certain that the source is a Linux LCD library file, the solution is to comment out the error is here.

Add the most important two-dimensional code library call in the main function


QRCode contains the two-dimensional code information that we ultimately need, in fact, is a diagram, with 01 bits of information

Call Fb_qrdisp Display this QR code, here posted fb_qrdisp Source code, commented out is the modified part

<pre name= "code" class= "CPP" >int fb_qrdisp (int ipenx,int ipeny,qrcode*pqrcode) {T_pixeldatasg_toriginpixelda         Tas         T_pixeldatasg_tzoompixeldatas;         Intizoom;                  Inti         G_toriginpixeldatas.iwidth= pqrcode->width;         g_toriginpixeldatas.iheight=pqrcode->width;         G_toriginpixeldatas.ilinebytes=g_toriginpixeldatas.iwidth;    g_toriginpixeldatas.aucpixeldatas= pqrcode->data;/* if (pqrcode->version <= 1) {iZoom= 2;          } else {izoom= 2;         } g_tzoompixeldatas.iwidth = pqrcode->width*izoom;         g_tzoompixeldatas.iheight=pqrcode->width*izoom;         G_tzoompixeldatas.ilinebytes=g_tzoompixeldatas.iwidth;                                                         g_tzoompixeldatas.aucpixeldatas= malloc (g_tzoompixeldatas.iwidth*          G_tzoompixeldatas.iheight); if (g_tzoompixeldatas.aucpixeldatas== NULL) {priNTF ("G_tzoompixeldatas->aucpixeldatasmalloc failed\n");         return-1; } piczoom (&g_toriginpixeldatas,&g_tzoompixeldatas); #if 0 printf ("G_tzoompixeldatas.iwidth=%d,g_tz  Oompixeldatas.iheight=%d\n ", g_tzoompixeldatas.iwidth,g_tzoompixeldatas.iheight); For (i=0;i< (g_tzoompixeldatas.iwidth*g_tzoompixeldatas.iheight); i++) {printf ("0x%x,", G_ Tzoompixeldatas.aucpixeldatas[i]);} printf ("\ n");  #endif */Disp_fixelpic (ipenx,ipeny,&g_tzoompixeldatas); return 0; }


Because the memory is not enough when the stmf429 is running, there is no need to apply the memory to enlarge the data of the two-dimensional code, but the direct stroke. So it's commented out.

e) Immediately following the call to Disp_fixelpic based on the QRCode.

</pre><pre name= "code" class= "CPP" ><pre name= "code" class= "CPP" >void disp_fixelpic (int ipenx,int Ipeny,pt_pixeldatas ptpixeldatas) {    int i=0,j=0;        Gui_setbkcolor (gui_white);        Gui_clear ();            Gui_setpensize (1); for (i=0;i<ptpixeldatas->iheight;i++) {for (j=0;j<ptpixeldatas->iwidth;j++) {if ( PTPIXELDATAS->AUCPIXELDATAS[I*PTPIXELDATAS->IHEIGHT+J]&0X01) {//lcd_pixel_show (J+iPenX, i+iPenY,0x00);                              Gui_setcolor (gui_black);                                 Gui_fillrect (J*8+ipenx, I*8+ipeny,j*8+8+ipenx, I*8+8+ipeny);} else{                              Gui_setcolor (gui_white);  Lcd_pixel_show (J+ipenx, I+ipeny, 0xffffff);                              Gui_drawpoint (J*8+ipenx, i*8+ipeny);                              Gui_fillrect (J*8+ipenx, I*8+ipeny,j*8+8+ipenx, I*8+8+ipeny);}}}

The original LCD stroke function is commented out, but the rectangular fill function provided by Stemwin is used.

f) Compile and run, you can see the LCD shows the QR code. The transplant is complete.

There is a small problem in the porting process, as the brush function of the Stemwin is called, when the Brush gui_setpensize (1), the stroke is a point when the Gui_setpensize (16) is drawn, and the drawing is a large dot, not a square point, It is important to note that you cannot use this brush, but instead use the rectangle fill function gui_fillrect

void disp_fixelpic (int ipenx,intipeny,pt_pixeldatas ptpixeldatas)

{

int i=0,j=0;

Gui_setbkcolor (Gui_white);

Gui_clear ();

Gui_setpensize (1);

for (i=0;i<ptpixeldatas->iheight;i++)

{

for (j=0;j<ptpixeldatas->iwidth;j++)

{

if (PTPIXELDATAS->AUCPIXELDATAS[I*PTPIXELDATAS->IHEIGHT+J]&0X01)

{

Lcd_pixel_show (j+ipenx,i+ipeny,0x00);

Gui_setcolor (Gui_black);

Gui_fillrect (J*8+ipenx, I*8+ipeny,j*8+8+ipenx, I*8+8+ipeny);

}

Else

{

Gui_setcolor (Gui_white);

Lcd_pixel_show (J+ipenx,i+ipeny, 0XFFFFFF);

Gui_drawpoint (J*8+ipenx, I*8+ipeny);

Gui_fillrect (J*8+ipenx, I*8+ipeny,j*8+8+ipenx, I*8+8+ipeny);

}

}

}

}

The realization of the C language of the two-dimensional code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.