jpeg 交叉编译以及接口的使用

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

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

之后make; make install


调用jpeg接口

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

	cinfo.err = jpeg_std_error(&jerr);
	jpeg_create_compress(&cinfo);
	fJpg = fopen(filename, "wb");
	if(fJpg == NULL){
		debugE("Cannot open file %s\n", filename);
		return -1;
	}
	jpeg_stdio_dest(&cinfo, fJpg);
	cinfo.image_width = width;
	cinfo.image_height = height;
	cinfo.input_components = 3;
	cinfo.in_color_space = JCS_RGB;
	jpeg_set_defaults(&cinfo);
	jpeg_set_quality(&cinfo, 30, TRUE);
	jpeg_start_compress(&cinfo, TRUE);
	row_stride = cinfo.image_width * 3;	/* JSAMPLEs per row in image_buffer */
	while (cinfo.next_scanline < cinfo.image_height) {
		/* jpeg_write_scanlines expects an array of pointers to scanlines.
		 * Here the array is only one element long, but you could pass
		 * more than one scanline at a time if that's more convenient.
		 */
		//row_pointer[0] = & pBMPBuffer[cinfo.next_scanline * row_stride];
		row_pointer[0] = &pBGRBuffer[row_stride*(cinfo.image_height - cinfo.next_scanline - 1)];
		(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
	}

	jpeg_finish_compress(&cinfo);
	jpeg_destroy_compress(&cinfo);
	fclose(fJpg);

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值