前的最后一个 我们说,一个直接yuv变成jpg该功能 但是转换不成功 主要功能是yuv420转jpg的 根据研究发现

yuv420的序列是这种

YYYY

YYYY

UVUV

而yuv422的隔行扫描的序列是这种

YU YV YU YV YU YV

所以将函数作例如以下改动

static int put_jpeg_yuv420p_memory(unsigned char *dest_image,
unsigned char *input_image, int width, int height)
{
int i, j, jpeg_image_size; JSAMPROW y[16],cb[16],cr[16]; // y[2][5] = color sample of row 2 and pixel column 5; (one plane)
JSAMPARRAY data[3]; // t[0][2][5] = color sample 0 of row 2 and column 5 struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
char *pbuf = NULL;
int jpglen = 0;
data[0] = y;
data[1] = cb;
data[2] = cr; cinfo.err = jpeg_std_error(&jerr); // errors get written to stderr jpeg_create_compress(&cinfo);
cinfo.image_width = width;
cinfo.image_height = height;
cinfo.input_components = 3;
jpeg_set_defaults (&cinfo); jpeg_set_colorspace(&cinfo, JCS_YCbCr); cinfo.raw_data_in = TRUE; // supply downsampled data
cinfo.do_fancy_downsampling = FALSE; // fix segfaulst with v7
cinfo.comp_info[0].h_samp_factor = 2;
cinfo.comp_info[0].v_samp_factor = 2;
cinfo.comp_info[1].h_samp_factor = 1;
cinfo.comp_info[1].v_samp_factor = 1;
cinfo.comp_info[2].h_samp_factor = 1;
cinfo.comp_info[2].v_samp_factor = 1; jpeg_set_quality(&cinfo, 80, TRUE);
cinfo.dct_method = JDCT_FASTEST; jpeg_mem_dest(&cinfo, &pbuf, &jpglen); // data written to mem jpeg_start_compress (&cinfo, TRUE); for (j = 0; j < height; j += 16) {
for (i = 0; i < 16; i++) {
y[i] = input_image + width * (i + j);
//cb[i/2] = input_image + width * height + width / 2 * ((i + j) / 2);
//cr[i/2] = input_image + width * height + width * height / 4 + width / 2 * ((i + j) / 2);
if (i%2 == 0)
cb[i/2] = input_image + width * ((i + j) / 2);
else
cr[i/2] = input_image + width * ((i + j) / 2);
}
jpeg_write_raw_data(&cinfo, data, 16);
} jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
memcpy(dest_image,pbuf,jpglen);
if(pbuf)
free(pbuf);
return jpglen;
}

就可以将yuv422直接转化成jpg

接口函数改动例如以下

JNIEXPORT jint JNICALL Java_com_hclydao_usbcamera_Fimcgzsd_writefile(JNIEnv * env, jclass obj,jbyteArray yuvdata,jbyteArray filename)//jintArray rgbdata
{
jbyte *ydata = (jbyte*)(*env)->GetByteArrayElements(env, yuvdata, 0);
jbyte *filedir = (jbyte*)(*env)->GetByteArrayElements(env, filename, 0); FILE * outfile;
if ((outfile = fopen(filedir, "wb")) == NULL) {
LOGE("++++++++++++open %s failed\n",filedir);
return -1;
} unsigned char* dst = malloc(mwidth*mheight*3*sizeof(char));
int size = put_jpeg_yuv420p_memory(dst,ydata,mwidth,mheight);
fwrite(dst,size,1,outfile);
if(dst)free(dst);
if(jpgdata)free(jpgdata);
fclose(outfile);
(*env)->ReleaseByteArrayElements(env, yuvdata, ydata, 0);
(*env)->ReleaseByteArrayElements(env, filename, filedir, 0);
}

还是静下心来研究

版权声明:本文博客原创文章。博客,未经同意,不得转载。

最新文章

  1. C++混合编程之idlcpp教程Lua篇(3)
  2. SQL Server 2016里TempDb的提升
  3. Python的更多内容
  4. [译]如何使用 Docker 组件开发 Django 项目?
  5. arm中的ldr指令
  6. MS SQL Server数据库修复/MDF数据文件数据恢复/MDF质疑/mdf无法附加
  7. MySQL连接问题【mysql_connect和mysql_pconnect区别】
  8. 3D位置语音,引领吃鸡游戏体验升级
  9. 为什么对string调用swap会导致迭代器失效
  10. yum安装提示Another app is currently holding the yum lock; waiting for it to exit...
  11. cocos2d JS 错误异常抛出捕获和崩溃拦截
  12. es query_string 和 match 的区别
  13. [VS2013]发布网站时修改配置文件
  14. 微信公众号获取acess_token并存储(php)
  15. Django商城项目笔记No.5用户部分-注册接口-短信验证码
  16. 多态设计 zen of python poem 显式而非隐式 延迟赋值
  17. 大型开放式网络课程MOOC的一点体会
  18. asp.net调用存储过程2
  19. linux基础之Vim
  20. myeclipse 复制项目不包含svn或CVS目录

热门文章

  1. setOnClickListener报空指针异常
  2. SpringMVC开发过程中的中文乱码问题
  3. jfinal框架教程-学习笔记
  4. c++ :: 域操作符
  5. ERWin 7.1 和7.2 的官方FTP下载地址
  6. 第十七篇:实例分析(1)--初探WDDM驱动学习笔记(八)
  7. Mac必备软件推荐
  8. W​i​n​D​B​G​调​试​技​巧
  9. 怎样在Ubuntu上安装最新版本号的Node.js
  10. windows mysql安装、配置