YUV420sp To JPEG

 create Eudora

void YUV420ToJPEG_CPU(const U8* yuv_420, U8* jpeg_output, int imageWidth, int imageHeight, int quality, EN_HOLLYLAND_PIXEL_FORMAT type){
	HYY_LOGD("YUV420ToJPEG");
	struct jpeg_compress_struct cinfo;
    struct jpeg_error_mgr jerr;
	U8* outbuffer;
	outbuffer = NULL;
    JSAMPROW row_pointer[1];
	cinfo.err = jpeg_std_error(&jerr);
    jpeg_create_compress(&cinfo);
    cinfo.image_width = imageWidth;
    cinfo.image_height = imageHeight;
    cinfo.input_components = 3;
    cinfo.in_color_space = JCS_YCbCr;
    jpeg_set_defaults(&cinfo);
	jpeg_set_quality(&cinfo, quality, TRUE);

	unsigned long jpegsize = 0;
    jpeg_mem_dest(&cinfo, &outbuffer, &jpegsize);
	jpeg_start_compress(&cinfo, TRUE);

	int y_size = imageWidth * imageHeight;
    const unsigned char* y_ptr = yuv_420;
	const unsigned char* uv_ptr = yuv_420 + y_size;

    JSAMPLE* row = (JSAMPLE*)malloc(imageWidth * 3);
    while (cinfo.next_scanline < cinfo.image_height) 
		{
			int row_index = cinfo.next_scanline;
			for (int i = 0; i < imageWidth; i++) 
				{
					int y = y_ptr[row_index * imageWidth + i];
					int u = uv_ptr[(row_index / 2) * imageWidth + (i / 2) * 2];
					int v = uv_ptr[(row_index / 2) * imageWidth + (i / 2) * 2 + 1];
					row[i * 3] = y;
					row[i * 3 + 1] = u;
					row[i * 3 + 2] = v;	
				}
			row_pointer[0] = row;
			jpeg_write_scanlines(&cinfo, row_pointer, 1);
		}
    jpeg_finish_compress(&cinfo);
	for(int i = 0; i < (int)jpegsize; i++)
		{
			jpeg_output[i] = outbuffer[i];
		}
    jpeg_destroy_compress(&cinfo);

	if(NULL != outbuffer)
		{
			free(outbuffer);
			outbuffer = NULL;
		}
	free(row);
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值