
[历史归档]本文原发布于 cstriker1407.info 个人博客内容为历史存档仅供参考。发布时间2017-11-12 标题交叉编译libzbar和libjpeg的简单笔记分类编程 / C C 标签CC·zbar·libjpeg交叉编译libzbar和libjpeg的简单笔记zbar正常编译交叉编译libjpeg正常编译交叉编译DEMO最近项目上需要使用二维码识别网上简单的搜索了下相关知识这里简单的笔记下流水账。zbar首先下载zbar源码官方网址解压后发现是configure这种方式编译的。正常编译cstriker1407:/zbar/zbar-0.10$ ./configure--helpconfigure configures zbar0.10to adapt to many kinds of systems. 。。。。。。 。。。。。。 Report bugs tospadixusers.sourceforge.net.由于项目只用于识别二维码因此简单起见去掉所有的编译可选项。cstriker1407:/zbar/zbar-0.10$ ./configure --disable-video --without-imagemagick --without-xv --without-xshm --without-gtk --without-python -without-qt --disable-assert 。。。。。。。。 。。。。。。。。 cstriker1407:/zbar/zbar-0.10$make。。。。。。。。 。。。。。。。。编译完成后的库就在 zbar/.libs/ 中。交叉编译cstriker1407:/zbar/zbar-0.10$CCXXXXXXXX/bin/arm-unknown-linux-uclibcgnueabi-gcc ./configure --disable-video --without-imagemagick --without-xv --without-xshm --without-gtk --without-python -without-qt --disable-assert--buildx86_64-hostarm-unknown-linux-uclibcgnueabi --disable-shared cstriker1407:/zbar/zbar-0.10$makelibjpeglibjpeg的下载地址【 https://sourceforge.net/projects/libjpeg/ 】正常编译cstriker1407:/libjpeg/jpeg-9b$ ./configure cstriker1407:/libjpeg/jpeg-9b$make交叉编译cstriker1407:/libjpeg/jpeg-9b$CCusr/bin/arm-unknown-linux-uclibcgnueabi-gcc ./configure--buildx86_64-hostarm-unknown-linux-uclibcgnueabi cstriker1407:/libjpeg/jpeg-9b$makeDEMO#includestdio.h#includestdlib.h#includestdio.h#includestring.h#includeunistd.h#includezbar.h#includejpeglib.h#includejerror.hstaticvoid_convert_data(constunsignedchar*p_jpg_buffer,unsignedintjpg_size,int*width,int*height,void**raw){structjpeg_decompress_structcinfo;structjpeg_error_mgrerr;cinfo.errjpeg_std_error(err);jpeg_create_decompress(cinfo);jpeg_mem_src(cinfo,(unsignedchar*)p_jpg_buffer,jpg_size);(void)jpeg_read_header(cinfo,TRUE);cinfo.out_color_spaceJCS_GRAYSCALE;// cinfo.two_pass_quantize TRUE;(void)jpeg_start_decompress(cinfo);*widthcinfo.image_width;*heightcinfo.image_height;*raw(void*)malloc(cinfo.output_width*cinfo.output_height*3);unsignedbplcinfo.output_width*cinfo.output_components;JSAMPROW buf(void*)*raw;JSAMPARRAY linebuf;for(;cinfo.output_scanlinecinfo.output_height;bufbpl){jpeg_read_scanlines(cinfo,line,1);}(void)jpeg_finish_decompress(cinfo);jpeg_destroy_decompress(cinfo);}intmain(intargc,char**argv){if(argc2)return(1);FILE*pFilefopen(argv[1],rb);unsignedchar*p_ReadBuffermalloc(81920);memset(p_ReadBuffer,0,81920);intfreadResultfread(p_ReadBuffer,1,81920,pFile);printf(read%d ,freadResult);zbar_image_scanner_t*scannerNULL;scannerzbar_image_scanner_create();zbar_image_scanner_set_config(scanner,ZBAR_QRCODE,ZBAR_CFG_ENABLE,1);/* obtain image data */intwidth0,height0;void*rawNULL;_convert_data(p_ReadBuffer,freadResult,width,height,raw);free(p_ReadBuffer);printf(width:%d height:%d ,width,height);/* wrap image data */zbar_image_t*imagezbar_image_create();zbar_image_set_format(image,*(int*)Y800);zbar_image_set_size(image,width,height);zbar_image_set_data(image,raw,width*height,zbar_image_free_data);/* scan the image for barcodes */intnzbar_scan_image(scanner,image);/* extract results */constzbar_symbol_t*symbolzbar_image_first_symbol(image);for(;symbol;symbolzbar_symbol_next(symbol)){/* do something useful with results */zbar_symbol_type_ttypzbar_symbol_get_type(symbol);constchar*datazbar_symbol_get_data(symbol);printf(decoded%s symbol \%s\ ,zbar_get_symbol_name(typ),data);}/* clean up */zbar_image_destroy(image);zbar_image_scanner_destroy(scanner);return0;}