Chinaunix首页 | 论坛 | 博客
  • 博客访问: 154938
  • 博文数量: 24
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 225
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-09 13:04
个人简介

人若是没有理想,那跟咸鱼有什么区别!

文章分类

全部博文(24)

文章存档

2018年(1)

2017年(2)

2016年(8)

2015年(11)

2014年(2)

我的朋友

分类: LINUX

2015-03-12 18:21:25

使用jpeg版本:jpegsrc.v9a.tar.gz

configure参数:./configure --prefix=/usr/local/jpeglib_arm/ --host=arm-none-linux-gnueabi

之后make; make install


调用jpeg接口

  1. /*
  2.     将bgr数据转换为jpg图像存储
  3.     filename: 生成的jpg文件名
  4.     width height:    传入bmp file 的宽和高
  5.     pBGRBuffer:    传入bgr数据
  6. */
  7. int convert_to_jpg(char *filename, int width, int height, unsigned char *pBGRBuffer)
  8. {
  9.     FILE *fJpg;
  10.     struct jpeg_compress_struct cinfo;
  11.     struct jpeg_error_mgr jerr;
  12.     JSAMPROW row_pointer[1];
  13.     int row_stride;

  14.     cinfo.err = jpeg_std_error(&jerr);
  15.     jpeg_create_compress(&cinfo);
  16.     fJpg = fopen(filename, "wb");
  17.     if(fJpg == NULL){
  18.         debugE("Cannot open file %s\n", filename);
  19.         return -1;
  20.     }
  21.     jpeg_stdio_dest(&cinfo, fJpg);
  22.     cinfo.image_width = width;
  23.     cinfo.image_height = height;
  24.     cinfo.input_components = 3;
  25.     cinfo.in_color_space = JCS_RGB;
  26.     jpeg_set_defaults(&cinfo);
  27.     jpeg_set_quality(&cinfo, 30, TRUE);
  28.     jpeg_start_compress(&cinfo, TRUE);
  29.     row_stride = cinfo.image_width * 3;    /* JSAMPLEs per row in image_buffer */
  30.     while (cinfo.next_scanline < cinfo.image_height) {
  31.         /* jpeg_write_scanlines expects an array of pointers to scanlines.
  32.          * Here the array is only one element long, but you could pass
  33.          * more than one scanline at a time if that's more convenient.
  34.          */
  35.         //row_pointer[0] = & pBMPBuffer[cinfo.next_scanline * row_stride];
  36.         row_pointer[0] = &pBGRBuffer[row_stride*(cinfo.image_height - cinfo.next_scanline - 1)];
  37.         (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
  38.     }

  39.     jpeg_finish_compress(&cinfo);
  40.     jpeg_destroy_compress(&cinfo);
  41.     fclose(fJpg);

  42.     return 0;
  43. }


阅读(1708) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~