libjpeg编译windows

第一步 
下载libjpeg 下载地址:http://www.ijg.org/  
下载jpegsr9a.zip这个文件。解压这个压缩包到一个纯英文目录下。 我的位置是E:\C_example\jpeg-9a 第二步 

打开cmd命令行窗口,将目录切换到你刚才解压的那个目录下面

d:\temp\jpeg-9a>

然后输入下面命令

nmake /fmakefile.vc set-vc6      //生成vc6工程

nmake /fmakefile.vc set-v10 //生成vs2010工程


生成工程文件编译后,产出静态库;使用时除了需要lib文件,还需要jconfig.h、jmorecfg.h、jpeglib.h头文件;


================================================================================

以下为yuv420 转jpg代码,转自http://blog.csdn.net/liujb861213/article/details/9162839,验证通过

================================================================================

  1. #include <Windows.h>  
  2. #include <stdio.h>  
  3.   
  4. extern  "C" {  
  5. #include <jpeglib.h>   
  6. }  
  7.   
  8. #define WIDTH 352  
  9. #define HEIGHT 288  
  10. #define QUALITY 80  
  11. #define BUFFER_SZIE (WIDTH*HEIGHT*2)  
  12.   
  13. /* The following declarations and 5 functions are jpeg related  
  14.  * functions used by put_jpeg_grey_memory and put_jpeg_yuv420p_memory 
  15.  */  
  16. typedef struct {  
  17.     struct jpeg_destination_mgr pub;  
  18.     JOCTET *buf;  
  19.     size_t bufsize;  
  20.     size_t jpegsize;  
  21. } mem_destination_mgr;  
  22.   
  23. typedef mem_destination_mgr *mem_dest_ptr;  
  24.   
  25.   
  26. METHODDEF(void) init_destination(j_compress_ptr cinfo)  
  27. {  
  28.     mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest;  
  29.     dest->pub.next_output_byte = dest->buf;  
  30.     dest->pub.free_in_buffer = dest->bufsize;  
  31.     dest->jpegsize = 0;  
  32. }  
  33.   
  34. METHODDEF(boolean) empty_output_buffer(j_compress_ptr cinfo)  
  35. {  
  36.     mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest;  
  37.     dest->pub.next_output_byte = dest->buf;  
  38.     dest->pub.free_in_buffer = dest->bufsize;  
  39.   
  40.     return FALSE;  
  41. }  
  42.   
  43. METHODDEF(void) term_destination(j_compress_ptr cinfo)  
  44. {  
  45.     mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest;  
  46.     dest->jpegsize = dest->bufsize - dest->pub.free_in_buffer;  
  47. }  
  48.   
  49. static GLOBAL(void) jpeg_mem_dest(j_compress_ptr cinfo, JOCTET* buf, size_t bufsize)  
  50. {  
  51.     mem_dest_ptr dest;  
  52.   
  53.     if (cinfo->dest == NULL) {  
  54.         cinfo->dest = (struct jpeg_destination_mgr *)  
  55.             (*cinfo->mem->alloc_small)((j_common_ptr)cinfo, JPOOL_PERMANENT,  
  56.             sizeof(mem_destination_mgr));  
  57.     }  
  58.   
  59.     dest = (mem_dest_ptr) cinfo->dest;  
  60.   
  61.     dest->pub.init_destination    = init_destination;  
  62.     dest->pub.empty_output_buffer = empty_output_buffer;  
  63.     dest->pub.term_destination    = term_destination;  
  64.   
  65.     dest->buf      = buf;  
  66.     dest->bufsize  = bufsize;  
  67.     dest->jpegsize = 0;  
  68. }  
  69.   
  70. static GLOBAL(int) jpeg_mem_size(j_compress_ptr cinfo)  
  71. {  
  72.     mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest;  
  73.     return dest->jpegsize;  
  74. }  
  75.   
  76.   
  77.   
  78. /* put_jpeg_yuv420p_memory converts an input image in the YUV420P format into a jpeg image and puts 
  79.  * it in a memory buffer. 
  80.  * Inputs: 
  81.  * - input_image is the image in YUV420P format. 
  82.  * - width and height are the dimensions of the image 
  83.  * Output: 
  84.  * - dest_image is a pointer to the jpeg image buffer 
  85.  * Returns buffer size of jpeg image      
  86.  */  
  87. static int put_jpeg_yuv420p_memory(unsigned char *dest_image,  
  88.                                    unsigned char *input_image, int width, int height)  
  89. {  
  90.     int i, j, jpeg_image_size;  
  91.   
  92.     JSAMPROW y[16],cb[16],cr[16]; // y[2][5] = color sample of row 2 and pixel column 5; (one plane)  
  93.     JSAMPARRAY data[3]; // t[0][2][5] = color sample 0 of row 2 and column 5  
  94.   
  95.     struct jpeg_compress_struct cinfo;  
  96.     struct jpeg_error_mgr jerr;  
  97.   
  98.     data[0] = y;  
  99.     data[1] = cb;  
  100.     data[2] = cr;  
  101.   
  102.     cinfo.err = jpeg_std_error(&jerr);  // errors get written to stderr   
  103.       
  104.     jpeg_create_compress(&cinfo);  
  105.     cinfo.image_width = width;  
  106.     cinfo.image_height = height;  
  107.     cinfo.input_components = 3;  
  108.     jpeg_set_defaults (&cinfo);  
  109.   
  110.     jpeg_set_colorspace(&cinfo, JCS_YCbCr);  
  111.   
  112.     cinfo.raw_data_in = TRUE;                  // supply downsampled data  
  113.     cinfo.do_fancy_downsampling = FALSE;       // fix segfaulst with v7  
  114.     cinfo.comp_info[0].h_samp_factor = 2;  
  115.     cinfo.comp_info[0].v_samp_factor = 2;  
  116.     cinfo.comp_info[1].h_samp_factor = 1;  
  117.     cinfo.comp_info[1].v_samp_factor = 1;  
  118.     cinfo.comp_info[2].h_samp_factor = 1;  
  119.     cinfo.comp_info[2].v_samp_factor = 1;  
  120.   
  121.     jpeg_set_quality(&cinfo, QUALITY, TRUE);  
  122.     cinfo.dct_method = JDCT_FASTEST;  
  123.   
  124.     jpeg_mem_dest(&cinfo, dest_image, BUFFER_SZIE);    // data written to mem  
  125.       
  126.     jpeg_start_compress (&cinfo, TRUE);  
  127.   
  128.     for (j = 0; j < height; j += 16) {  
  129.         for (i = 0; i < 16; i++) {  
  130.             y[i] = input_image + width * (i + j);  
  131.             if (i%2 == 0) {  
  132.                 cb[i/2] = input_image + width * height + width / 2 * ((i + j) / 2);  
  133.                 cr[i/2] = input_image + width * height + width * height / 4 + width / 2 * ((i + j) / 2);  
  134.             }  
  135.         }  
  136.         jpeg_write_raw_data(&cinfo, data, 16);  
  137.     }  
  138.   
  139.     jpeg_finish_compress(&cinfo);  
  140.     jpeg_image_size = jpeg_mem_size(&cinfo);  
  141.     jpeg_destroy_compress(&cinfo);  
  142.       
  143.     return jpeg_image_size;  
  144. }  
  145.   
  146.   
  147. int main( int argc, TCHAR * argv[], TCHAR * envp[] )  
  148. {  
  149.     HANDLE fyuv,fyuvjpg;  
  150.     BYTE *pSrc ,*pDst;  
  151.     LONG  lSize = 0;  
  152.     DWORD  readsize;  
  153.     DWORD  writesize;  
  154.   
  155.     pSrc = new BYTE[BUFFER_SZIE];  
  156.     fyuv = CreateFile(L"cif.yuv", GENERIC_ALL, 0, NULL, OPEN_EXISTING, 0, NULL);  
  157.     ReadFile(fyuv , pSrc ,BUFFER_SZIE ,&readsize,NULL);  
  158.   
  159.     pDst = new BYTE[BUFFER_SZIE];  
  160.     lSize = put_jpeg_yuv420p_memory(pDst,pSrc , WIDTH ,HEIGHT);  
  161.     fyuvjpg = CreateFile(L"cif_yuv.jpg", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);  
  162.     WriteFile(fyuvjpg, pDst, lSize, &writesize, NULL);  
  163.   
  164.     CloseHandle(fyuv);  
  165.     CloseHandle(fyuvjpg);  
  166.     return 0;  
  167. }  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值